Мне нужно отобразить сигнал ЭКГ, который поступает через Bluetooth, в режиме реального времени.Но у меня есть код, который находится в виде графика.Но я хотел построить график в mpandroid.Я не знаю, как написать код с вводом данных, чтобы получить значения ЭКГ.Я думаю, что я не могу понять, как получить доступ к данным, полученным через Bluetooth
Это код с графическим представлением:
Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch(msg.what){
case Bluetooth.SUCCESS_CONNECT:
Bluetooth.connectedThread = new Bluetooth.ConnectedThread((BluetoothSocket)msg.obj);
Toast.makeText(getApplicationContext(), "Connected!", 0).show();
String s = "successfully connected";
Bluetooth.connectedThread.start();
break;
case Bluetooth.MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
String strIncom = new String(readBuf, 0, 5); // create string from bytes array
Log.d("strIncom", strIncom);
if (strIncom.indexOf('.')==2 && strIncom.indexOf('s')==0){
strIncom = strIncom.replace("s", "");
if (isFloatNumber(strIncom)){
Series.appendData(new GraphViewData(graph2LastXValue,Double.parseDouble(strIncom)),AutoScrollX);
//X-axis control
if (graph2LastXValue >= Xview && Lock == true){
Series.resetData(new GraphViewData[] {});
graph2LastXValue = 0;
}else graph2LastXValue += 0.1;
if(Lock == true)
graphView.setViewPort(0, Xview);
else
graphView.setViewPort(graph2LastXValue-Xview, Xview);
//refresh
GraphView.removeView(graphView);
GraphView.addView(graphView);
}
}
break;
}
}
public boolean isFloatNumber(String num){
//Log.d("checkfloatNum", num);
try{
Double.parseDouble(num);
} catch(NumberFormatException nfe) {
return false;
}
return true;
}
};
Но я не знаю, как изменитьс mpandroidchart.Это мой код диаграммы mpandroid:
Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg){
switch (msg.what){
case bluetooth.SUCCESS_CONNECT:
bluetooth.connectedThread = new bluetooth.connectedThread ((BluetoothSocket)msg.obj);
Toast.makeText(getApplicationContext(),"connected",LENGTH_LONG).show();
String s="successfully connected";
bluetooth.connectedThread.start();
break;
//message read case
case bluetooth.MESSAGE_READ:
byte[] readBuf =(byte[]) msg.obj;
String strIncom = new String(readBuf,0,5);
// check handler char decimal;
if (strIncom.indexOf('s')==0 && strIncom.indexOf('.')==2){
strIncom =strIncom.replace("s","");
if(isFloatNumber(strIncom)){
addEntry();
}
}
break;
}
}
// add isFloatNumber method
public boolean isFloatNumber(String num){
try {
Double.parseDouble(num);
}catch (NumberFormatException nfe){
return false;
}
return true;
}
};
private void addEntry(){
LineData data = mChart.getData();
if (data != null) {
//getDataSetByIndex
LineDataSet set = data.getDataSetByIndex(0);
if (set == null) {
//creation if null
set = createSet();
data.addDataSet(set);
}
// add a new random value
data.addXValue("");
data.addEntry(new Entry(set.getEntryCount(),0);
//notify chart data have changed
mChart.notifyDataSetChanged();
// limit number if visible entreies
mChart.setVisibleXRange(12);
//scroll to the last entry
mChart.moveViewToX(data.getXValCount()-7);
}
}
private LineDataSet createSet() {
LineDataSet set = new LineDataSet(null,"");
set.setDrawCubic(true);
set.setCubicIntensity(0.2f);
set.setAxisDependency(YAxis.AxisDependency.RIGHT);
set.setColor(ColorTemplate.getHoloBlue());
set.setCircleColor(ColorTemplate.getHoloBlue());
set.setLineWidth(2f);
set.setCircleSize(4f);
set.setFillAlpha(65);
set.setFillColor(ColorTemplate.getHoloBlue());
set.setHighLightColor(Color.rgb(244,117,177));
set.setValueTextColor(Color.DKGRAY);
set.setValueTextSize(10f);
return set;
}