예제 #1
0
  private void configureLibrary() {
    muse.registerConnectionListener(connectionListener);
    muse.registerDataListener(dataListener, MuseDataPacketType.ACCELEROMETER);
    muse.registerDataListener(dataListener, MuseDataPacketType.EEG);
    muse.registerDataListener(dataListener, MuseDataPacketType.ALPHA_RELATIVE);

    muse.registerDataListener(dataListener, MuseDataPacketType.ARTIFACTS);
    muse.registerDataListener(dataListener, MuseDataPacketType.BATTERY);
    // kt start:
    muse.registerDataListener(dataListener, MuseDataPacketType.ALPHA_ABSOLUTE);
    muse.registerDataListener(dataListener, MuseDataPacketType.BETA_ABSOLUTE);
    muse.registerDataListener(dataListener, MuseDataPacketType.DELTA_ABSOLUTE);
    muse.registerDataListener(dataListener, MuseDataPacketType.GAMMA_ABSOLUTE);
    muse.registerDataListener(dataListener, MuseDataPacketType.THETA_ABSOLUTE);

    muse.registerDataListener(dataListener, MuseDataPacketType.HORSESHOE);
    // kt end

    muse.setPreset(MusePreset.PRESET_14);
    muse.enableDataTransmission(dataTransmission);
  }
예제 #2
0
  @Override
  public void onClick(View v) {
    Spinner musesSpinner = (Spinner) findViewById(R.id.muses_spinner);
    if (v.getId() == R.id.refresh) {
      MuseManager.refreshPairedMuses();
      List<Muse> pairedMuses = MuseManager.getPairedMuses();
      List<String> spinnerItems = new ArrayList<String>();
      for (Muse m : pairedMuses) {
        String dev_id = m.getName() + "-" + m.getMacAddress();
        Log.i("Muse Headband", dev_id);
        spinnerItems.add(dev_id);
      }
      ArrayAdapter<String> adapterArray =
          new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerItems);
      musesSpinner.setAdapter(adapterArray);
    } else if (v.getId() == R.id.connect) {
      List<Muse> pairedMuses = MuseManager.getPairedMuses();
      if (pairedMuses.size() < 1 || musesSpinner.getAdapter().getCount() < 1) {
        Log.w("Muse Headband", "There is nothing to connect to");
      } else {
        muse = pairedMuses.get(musesSpinner.getSelectedItemPosition());
        ConnectionState state = muse.getConnectionState();
        if (state == ConnectionState.CONNECTED || state == ConnectionState.CONNECTING) {
          Log.w("Muse Headband", "doesn't make sense to connect second time to the same muse");
          return;
        }
        configureLibrary();
        fileWriter.open();
        fileWriter.addAnnotationString(1, "Connect clicked");
        stopSounds = 0;

        /**
         * In most cases libmuse native library takes care about exceptions and recovery mechanism,
         * but native code still may throw in some unexpected situations (like bad bluetooth
         * connection). Print all exceptions here.
         */
        try {
          muse.runAsynchronously();
        } catch (Exception e) {
          Log.e("Muse Headband", e.toString());
        }
      }
    } else if (v.getId() == R.id.disconnect) {
      if (muse != null) {
        /**
         * true flag will force libmuse to unregister all listeners, BUT AFTER disconnecting and
         * sending disconnection event. If you don't want to receive disconnection event (for ex.
         * you call disconnect when application is closed), then unregister listeners first and then
         * call disconnect: muse.unregisterAllListeners(); muse.disconnect(false);
         */
        stopSounds = 1;
        muse.disconnect(true);
        fileWriter.addAnnotationString(1, "Disconnect clicked");
        fileWriter.flush();
        fileWriter.close();
        try {
          writeData.flush();
          writeData.close();
        } catch (Exception e) {
          Log.e("Muse Headband exception", e.toString());
        }
      }
    } else if (v.getId() == R.id.pause) {
      dataTransmission = !dataTransmission;
      if (muse != null) {
        muse.enableDataTransmission(dataTransmission);
      }
    }
  }