Author Topic: Send various values Rfduino for android  (Read 644 times)

Tiago10

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Send various values Rfduino for android
« on: July 01, 2016, 05:59:06 AM »
I want to send three values ​​of acceleration (x, y, z) for an Android application.
Code: [Select]
Code arduino:

 RFduinoBLE.sendFloat (accelerometer.x ());
 RFduinoBLE.sendFloat (accelerometer.y ());
 RFduinoBLE.sendFloat (accelerometer.z ());

Android Code:

 numberdisplay = (. ByteBuffer.wrap (characteristic.getValue ()) order (ByteOrder.LITTLE_ENDIAN) .getFloat ());

                runOnUiThread (new Runnable () {
                    @Override
                    public void run () {
                        int count = 0;
                                if (count == 0)
                                textResponsex.setText (Float.toString (numberdisplay));
                                 else if (count == 1)
                                {
                                textResponsey.setText (Float.toString (numberdisplay));}
                                else if (count == 2)
                                {TextResponsey.setText (Float.toString (numberdisplay));
                        }

                        count ++;

                        }


The problem with this code is only send the last value in this case (accelerometer.z ())

I wanted to send the 3 values.. Can anyone help me? Thank you
« Last Edit: July 01, 2016, 06:00:44 AM by Tiago10 »

tolson

  • Global Moderator
  • *****
  • Posts: 812
  • Karma: +19/-0
    • View Profile
    • Thomas Olson Consulting
Re: Send various values Rfduino for android
« Reply #1 on: July 01, 2016, 07:24:44 AM »
I want to send three values ​​of acceleration (x, y, z) for an Android application.

Code arduino:

Code: [Select]
RFduinoBLE.sendFloat (accelerometer.x ());
 RFduinoBLE.sendFloat (accelerometer.y ());
 RFduinoBLE.sendFloat (accelerometer.z ());

Android Code:

Code: [Select]
numberdisplay = (. ByteBuffer.wrap (characteristic.getValue ()) order (ByteOrder.LITTLE_ENDIAN) .getFloat ());

                runOnUiThread (new Runnable () {
                    @Override
                    public void run () {
                        int count = 0;
                                if (count == 0)
                                textResponsex.setText (Float.toString (numberdisplay));
                                 else if (count == 1)
                                {
                                textResponsey.setText (Float.toString (numberdisplay));}
                                else if (count == 2)
                                {TextResponsey.setText (Float.toString (numberdisplay));
                        }

                        count ++;

                        }


The problem with this code is only send the last value in this case (accelerometer.z ())

I wanted to send the 3 values.. Can anyone help me? Thank you

Hi Tiago10,
Define a structure.

Code: [Select]
struct accel_t
{
  float X;
  float Y;
  float Z;
};

struct accel_t value = {
0.0,
0.0,
0.0
};

Fill the structure.

Code: [Select]
value.X = accelerometer.x();
value.Y = accelerometer.y();
value.Z = accelerometer.z();

Send the structure.

Code: [Select]
RFduinoBLE.send( (char *)&value, sizeof(value) );



Tiago10

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Send various values Rfduino for android
« Reply #2 on: July 04, 2016, 08:16:19 AM »
Hi tolson!

thanks for the answer. Did I could now say how I can read the values of structure in android studio and put in three different textview .. Thanks

 

anything