如果有人了解 NeuroSky 产品......
是否可以从Mindwave移动耳机访问原始数据?
我问我想要访问那些数据(即theta,gamma wave等)以便对其进行计算。
以下是NeuroSky提供的 android 示例代码:
与原始eeg数据相关的代码部分:(如您所见,访问原始数据没有做任何事情)
case TGDevice.MSG_RAW_DATA:
/* Handle raw EEG/EKG data here */
break;
完整的示例代码活动:
package com.test.helloeeg;
import android.app.Activity;
import android.bluetooth.*;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.neurosky.thinkgear.*;
public class HelloEEGActivity extends Activity {
private static final String TAG = "HelloEEG"; //??
BluetoothAdapter bluetoothAdapter; //BluetoothAdapter lets you perform fundamental Bluetooth tasks
TGDevice device; //used to manage a single connection to a single hardware device
final boolean rawEnabled = true; //??
//references to the layout
ScrollView sv;
TextView tv;
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//set up the scroll views and text boxes
sv = (ScrollView) findViewById(R.id.scrollView1);
tv = (TextView) findViewById(R.id.textView1);
tv.setText("");
//display what android version is being used
tv.append("Android version: " + Integer.valueOf(android.os.Build.VERSION.SDK) + "\n");
// Check if Blue tooth is available on the Android device
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
// Alert user that Bluetooth is not available
Toast.makeText(this, "Bluetooth not available", Toast.LENGTH_LONG)
.show();
// finish();
return;
} else {
// create the TGDevice
//Android app is connecting to hardware device using the standard constructor
device = new TGDevice(bluetoothAdapter, handler);
}
tv.append("NeuroSky: " + TGDevice.version + " " + TGDevice.build_title);
tv.append("\n");
}
/* end onCreate() */
// turn off app when touch return button of phone
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
device.close();
this.finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onStart() {
super.onStart();
// If BT is not on, request that it be enabled.
// if (!bluetoothAdapter.isEnabled()) {
// Intent enableIntent = new
// Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
// startActivityForResult(enableIntent, 1);
// }
}
@Override
public void onPause() {
// device.close();
super.onPause();
}
@Override
public void onStop() {
device.close();
super.onStop();
}
@Override
public void onDestroy() {
// device.close();
super.onDestroy();
}
/**
* Handles messages from TGDevice
*
*/
final Handler handler = new Handler() { //Note: TGdevice communicates with app messages sent to handler object
//A handler object processes incoming data
@Override
public void handleMessage(Message msg) {
//msg.what determines the type of each message
switch (msg.what) {
case TGDevice.MSG_STATE_CHANGE:
//actual value of the message is determined by msg.arg1
switch (msg.arg1) {
case TGDevice.STATE_IDLE:
break;
case TGDevice.STATE_CONNECTING:
tv.append("Connecting...\n");
break;
case TGDevice.STATE_CONNECTED:
tv.append("Connected.\n");
device.start();
break;
case TGDevice.STATE_NOT_FOUND:
tv.append("Could not connect any of the paired BT devices. Turn them on and try again.\n");
break;
case TGDevice.STATE_ERR_NO_DEVICE:
tv.append("No Bluetooth devices paired. Pair your device and try again.\n");
break;
case TGDevice.STATE_ERR_BT_OFF:
tv.append("Bluetooth is off. Turn on Bluetooth and try again.");
break;
case TGDevice.STATE_DISCONNECTED:
tv.append("Disconnected.\n");
} /* end switch on msg.arg1 */
break;
case TGDevice.MSG_POOR_SIGNAL:
tv.append("PoorSignal: " + msg.arg1 + "\n");
break;
case TGDevice.MSG_HEART_RATE:
tv.append("Heart rate: " + msg.arg1 + "\n");
break;
case TGDevice.MSG_RAW_DATA:
/* Handle raw EEG/EKG data here */
break;
case TGDevice.MSG_ATTENTION:
tv.append("Attention: " + msg.arg1 + "\n");
//Example code to see modifications
if(msg.arg1>=30){
tv.append("getting nearer!!");
}
break;
case TGDevice.MSG_MEDITATION:
tv.append("Meditation: " + msg.arg1 + "\n");
break;
case TGDevice.MSG_BLINK:
tv.append("Blink: " + msg.arg1 + "\n");
break;
default:
break;
} /* end switch on msg.what */
sv.fullScroll(View.FOCUS_DOWN);
} /* end handleMessage() */
}; /* end Handler */
/**
* This method is called when the user clicks on the "Connect" button.
*
* @param view
*/
public void doStuff(View view) {
//if the device is not currently connecting and is not already connected
if (device.getState() != TGDevice.STATE_CONNECTING
&& device.getState() != TGDevice.STATE_CONNECTED) {
//Connect the device to the Neurosky Headset (starting connection process)
device.connect(rawEnabled); //note: rawEnabled allows raw sample data to be sent to device
}
} /* end doStuff() */
} /* end HelloEEGActivity() */
答案 0 :(得分:0)
private final Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
switch (msg.what)
{
case TGDevice.MSG_RAW_MULTI:
TGRawMulti eegRaw = (TGRawMulti) msg.obj;
double ch1 = eegRaw.ch1;
double ch2 = eegRaw.ch2;
double ch3 = eegRaw.ch3;
double ch4 = eegRaw.ch4;
double ch5 = eegRaw.ch5;
double ch6 = eegRaw.ch6;
double ch7 = eegRaw.ch7;
double ch8 = eegRaw.ch8;
break;
}
}
}