Exemple #1
0
  @Override
  protected void onStart() {
    super.onStart();
    // in order to receive broadcasted intents we need to register our receiver
    registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED));

    // this is how you tell Amarino to connect to a specific BT device from within your own code
    Amarino.connect(this, DEVICE_ADDRESS);
  }
Exemple #2
0
  @Override
  protected void onStop() {
    super.onStop();

    // if you connect in onStart() you must not forget to disconnect when your app is closed
    Amarino.disconnect(this, DEVICE_ADDRESS);

    // do never forget to unregister a registered receiver
    unregisterReceiver(arduinoReceiver);
  }
  @Override
  public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {

      if (ignoreCounter >= ignoreThreshold) {
        ignoreCounter = 0;

        if (DEBUG)
          Log.d(
              TAG,
              "send: x:" + event.values[0] + " y:" + event.values[1] + " z: " + event.values[2]);
        Amarino.sendDataFromPlugin(this, pluginId, event.values.clone());
      } else {
        ignoreCounter++;
      }
    }
  }