Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic Data from bluetooth plotting
    primarykey
    data
    text
    <p>First of all, I am very new to Java programming language, And I tried searching for what I want but nothing was specific. Secondly, I am trying to plot Dynamic data from a bluetooth device,</p> <p>The data can be plotted simply using the <code>Sensorgraph</code> application (open source app), however the plot is not very clear ( I can't zoom in or out, no x or y axis...). Hence, I need another way to try and plot the data to show it in a better way. Here is the <code>SensorGraph</code> code:</p> <pre><code>public class SensorGraph extends Activity { Button Start, Stop, Pause; private static final String TAG = "SensorGraph"; // change this to your Bluetooth device address private static final String DEVICE_ADDRESS = "00:06:66:4B:E2:B7"; //"00:06:66:03:73:7B"; private GraphView mGraph; private TextView mValueTV; private ArduinoReceiver arduinoReceiver = new ArduinoReceiver(); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // get handles to Views defined in our layout file mGraph = (GraphView)findViewById(R.id.graph); mValueTV = (TextView) findViewById(R.id.value); mGraph.setMaxValue(1024); } @Override protected void onStart() { super.onStart(); // in order to receive broadcasted intents we need to register our receiver registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED)); // this is how you tell Amarino to connect to a specific BT device from within your own code Amarino.connect(this, DEVICE_ADDRESS); } @Override protected void onStop() { super.onStop(); // if you connect in onStart() you must not forget to disconnect when your app is closed Amarino.disconnect(this, DEVICE_ADDRESS); // do never forget to unregister a registered receiver unregisterReceiver(arduinoReceiver); } /** * ArduinoReceiver is responsible for catching broadcasted Amarino * events. * * It extracts data from the intent and updates the graph accordingly. */ public class ArduinoReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String data = null; // the device address from which the data was sent, we don't need it here but to demonstrate how you retrieve it final String address = intent.getStringExtra(AmarinoIntent.EXTRA_DEVICE_ADDRESS); // the type of data which is added to the intent final int dataType = intent.getIntExtra(AmarinoIntent.EXTRA_DATA_TYPE, -1); // we only expect String data though, but it is better to check if really string was sent // later Amarino will support differnt data types, so far data comes always as string and // you have to parse the data to the type you have sent from Arduino, like it is shown below if (dataType == AmarinoIntent.STRING_EXTRA){ data = intent.getStringExtra(AmarinoIntent.EXTRA_DATA); if (data != null){ mValueTV.setText(data); try { // since we know that our string value is an int number we can parse it to an integer final int sensorReading = Integer.parseInt(data); mGraph.addDataPoint(sensorReading); } catch (NumberFormatException e) { /* oh data was not an integer */ } } } } } } </code></pre> <p>The graphview code is the following:</p> <pre><code> public class GraphView extends View { private Bitmap mBitmap; private Paint mPaint = new Paint(); private Canvas mCanvas = new Canvas(); private float mSpeed = 1.0f; private float mLastX; private float mScale; private float mLastValue; private float mYOffset; private int mColor; private float mWidth; private float maxValue = 1024f; public GraphView(Context context) { super(context); init(); } public GraphView(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init(){ mColor = Color.argb(192, 64, 128, 64); mPaint.setFlags(Paint.ANTI_ALIAS_FLAG); } public void addDataPoint(float value){ final Paint paint = mPaint; float newX = mLastX + mSpeed; final float v = mYOffset + value * mScale; paint.setColor(mColor); mCanvas.drawLine(mLastX, mLastValue, newX, v, paint); mLastValue = v; mLastX += mSpeed; invalidate(); } public void setMaxValue(int max){ maxValue = max; mScale = - (mYOffset * (1.0f / maxValue)); } public void setSpeed(float speed){ mSpeed = speed; } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565); mCanvas.setBitmap(mBitmap); mCanvas.drawColor(0xFFFFFFFF); mYOffset = h; mScale = - (mYOffset * (1.0f / maxValue)); mWidth = w; mLastX = mWidth; super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { synchronized (this) { if (mBitmap != null) { if (mLastX &gt;= mWidth) { mLastX = 0; final Canvas cavas = mCanvas; cavas.drawColor(0xFFFFFFFF); mPaint.setColor(0xFF777777); cavas.drawLine(0, mYOffset, mWidth, mYOffset, mPaint); } canvas.drawBitmap(mBitmap, 0, 0, null); } } } </code></pre> <p>}</p> <p>The part I need to change is mostly the sensor reading and make it plot on another graph! Thank you so much and I appreciate any help. If you have a question please let me know.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload