예제 #1
0
 /*
  * Simple example of getting data from the "*.muse" file
  */
 private void playMuseFile(String name) {
   File dir = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
   File file = new File(dir, name);
   final String tag = "Muse File Reader";
   if (!file.exists()) {
     Log.w(tag, "file doesn't exist");
     return;
   }
   MuseFileReader fileReader = MuseFileFactory.getMuseFileReader(file);
   while (fileReader.gotoNextMessage()) {
     MessageType type = fileReader.getMessageType();
     int id = fileReader.getMessageId();
     long timestamp = fileReader.getMessageTimestamp();
     Log.i(
         tag,
         "type: "
             + type.toString()
             + " id: "
             + Integer.toString(id)
             + " timestamp: "
             + String.valueOf(timestamp));
     switch (type) {
       case EEG:
       case BATTERY:
       case ACCELEROMETER:
       case QUANTIZATION:
         MuseDataPacket packet = fileReader.getDataPacket();
         Log.i(tag, "data packet: " + packet.getPacketType().toString());
         break;
       case VERSION:
         MuseVersion version = fileReader.getVersion();
         Log.i(tag, "version" + version.getFirmwareType());
         break;
       case CONFIGURATION:
         MuseConfiguration config = fileReader.getConfiguration();
         Log.i(tag, "config" + config.getBluetoothMac());
         break;
       case ANNOTATION:
         AnnotationData annotation = fileReader.getAnnotation();
         Log.i(tag, "annotation" + annotation.getData());
         break;
       default:
         break;
     }
   }
 }
예제 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button refreshButton = (Button) findViewById(R.id.refresh);
    refreshButton.setOnClickListener(this);
    Button connectButton = (Button) findViewById(R.id.connect);
    connectButton.setOnClickListener(this);
    Button disconnectButton = (Button) findViewById(R.id.disconnect);
    disconnectButton.setOnClickListener(this);
    Button pauseButton = (Button) findViewById(R.id.pause);
    pauseButton.setOnClickListener(this);
    // // Uncommet to test Muse File Reader
    //
    // // file can be big, read it in a separate thread
    // Thread thread = new Thread(new Runnable() {
    //     public void run() {
    //         playMuseFile("testfile.muse");
    //     }
    // });
    // thread.start();

    // kt: start the audio feedback thread
    Thread thread =
        new Thread(
            new Runnable() {
              public void run() {
                stopSounds = 0;
                playAudioFeedback(0);
              }
            });
    thread.start();

    File dir = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
    fileWriter = MuseFileFactory.getMuseFileWriter(new File(dir, "new_muse_file.muse"));
    Log.i("Muse Headband", "libmuse version=" + LibMuseVersion.SDK_VERSION);
    fileWriter.addAnnotationString(1, "MainActivity onCreate");
    dataListener.setFileWriter(fileWriter);

    boolean append_to_file = false;
    // GettingCurrentDate gcd = new GettingCurrentDate();
    // DateFormat df = new SimpleDateFormat("dd-MM-yy_HH:mm:ss");
    DateFormat df = new SimpleDateFormat("yy-MM-dd_HH:mm:ss");
    Date dateobj = new Date();
    // System.out.println(df.format(dateobj));
    String ldt = df.format(dateobj);
    // String ldt = gcd.getCurrentDateTime();
    try {
      String fdname = dir + "/muse_data_file" + ldt + ".csv";
      writeData = new FileWriter(fdname, append_to_file);
    } catch (Exception e) {
      Log.e("Muse Headband", e.toString());
    }
    print_line = new PrintWriter(writeData);
    // fileWriterData.addAnnotationString(1, "alpha, beta, delta, gamma, theta,");

    // String strData = "Time ms,AlphaAbs0,AlphaAbs1,AlphaAbs2,AlphaAbs3, BetaAbs0, BetaAbs1,
    // BetaAbs2, BetaAbs3, DeltaAbs0, DeltaAbs1, DeltaAbs2, DeltaAbs3, GammaAbs0, GammaAbs1,
    // GammaAbs2, GammaAbs3, ThetaAbs0, ThetaAbs1, ThetaAbs2, ThetaAbs3, Horseshoe0, Horseshoe1,
    // Horseshoe2, Horseshoe4 " + "\r\n";
    // Sensor1, Sensor2, Sensor3, Sensor4 " + "\r\n";
    // old setup: all sensors
    // String strData = "Packet time,Time ms,Eeg TP9,Eeg TP10,Eeg FP1,Eeg FP2,AlphaAbs TP9,AlphaAbs
    // TP10,AlphaAbs FP1,AlphaAbs FP2,BetaAbs TP9,BetaAbs TP10,BetaAbs FP1,BetaAbs FP2,Delta
    // TP9,Delta TP10,Delta FP1,Delta FP2,GammaAbs TP9,GammaAbs TP10,GammaAbs FP1,GammaAbs
    // FP2,ThetaAbs TP9,ThetaAbs TP10,ThetaAbs FP1,ThetaAbs FP2,Horseshoe tp9,Horseshoe
    // TP10,Horseshoe FP1,Horseshoe FP2 " + "\r\n";

    // new setu[p : only fp1, fp2 eeg sensors
    String strData =
        "Packet time,Time ms,Eeg FP1,Eeg FP2,AlphaAbs FP1,AlphaAbs FP2,BetaAbs FP1,BetaAbs FP2,Delta FP1,Delta FP2,GammaAbs FP1,GammaAbs FP2,ThetaAbs FP1,ThetaAbs FP2,,Horseshoe FP1,Horseshoe FP2 "
            + "\r\n";

    print_line.printf(strData);
  }