此应用程序显示EEG设备OSC数据。到目前为止,它可以显示它从设备接收的信息。
@Override
public void receiveDataPacket(DataPacket p) {
switch (p.getPacketType()) {
case EEG:
updateEeg(p.getValues());
break;
case ACCELEROMETER:
updateAccelerometer(p.getValues());
break;
case ALPHA_RELATIVE:
updateAlphaRelative(p.getValues());
break;
case BATTERY:
fileWriter.addDataPacket(1, p);
// It's library client responsibility to flush the buffer,
// otherwise you may get memory overflow.
if (fileWriter.getBufferedMessagesSize() > 8096)
fileWriter.flush();
break;
default:
break;
}
}
private void updateEeg(final ArrayList<Double> data) {
Activity activity = activityRef.get();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
TextView tp9 = (TextView) findViewById(R.id.eeg_tp9);
TextView fp1 = (TextView) findViewById(R.id.eeg_fp1);
TextView fp2 = (TextView) findViewById(R.id.eeg_fp2);
TextView tp10 = (TextView) findViewById(R.id.eeg_tp10);
tp9.setText(String.format(
"%6.2f", data.get(Eeg.TP9.ordinal())));
fp1.setText(String.format(
"%6.2f", data.get(Eeg.FP1.ordinal())));
fp2.setText(String.format(
"%6.2f", data.get(Eeg.FP2.ordinal())));
tp10.setText(String.format(
"%6.2f", data.get(Eeg.TP10.ordinal())));
}
});
}
}
我想创建一个数组来保存和记录来自不同位置的EEG值。我想填充此列表并启用一个可以显示数据图形表示的按钮。
我可以在recieveDataPacket(Datapacket p)案例EEG中创建一个数组并填充它吗?我的问题是通过刷新功能更新数据,刷新功能刷新并获取新数据。有4个位置,我想至少有一个数组中每个位置的5-10个值来填充折线图。
EEGData[] eegData = new EEGData[]
for(int i = 0; i<eegData.length; i++){
eegData[i] = new EEGData();}
刷新功能:
public void onClick(View v) {
Spinner Spinner = (Spinner) findViewById(R.id.spinner);
if (v.getId() == R.id.refresh) {
MuManager.refreshPaired();
List<Device> pairedDevice = MManager.getPaired();
List<String> spinnerItems = new ArrayList<String>();
for (Device m: pairedDevice) {
String dev_id = m.getName() + "-" + m.getMacAddress();
Log.i("Device", dev_id);
spinnerItems.add(dev_id);
}
ArrayAdapter<String> adapterArray = new ArrayAdapter<String> (
this, android.R.layout.simple_spinner_item, spinnerItems);
Spinner.setAdapter(adapterArray);
}
我知道数据不断变化,我可以为每个位置保留前15个值的计数器,然后填充图表可以从中提取数据的数组。