Android Heart Rate App

This discussion was created from comments split from: How to integrate heartbeat sensor into metawear.

Comments

  • Hi Guys, I am trying to read heartrate data from Android with below code snippet, but its not working. Heartrate sensor light is not switching ON, any help would be grateful.
    public void startHeartRate(View view) {
    try {
    gpio = mwBoard.getModule(Gpio.class);
    gpio.routeData().fromAnalogIn(GPIO_PIN, Gpio.AnalogReadMode.ADC).stream(HEART_RATE)
    .commit().onComplete(gpioHandler);
    } catch (UnsupportedModuleException e) {
    Log.e("HeartRateSensorFragment", e.toString());
    }
    }

    private final AsyncOperation.CompletionHandler<RouteManager> gpioHandler = new AsyncOperation.CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    result.subscribe(HEART_RATE, dataHandler);
    try {
    AsyncOperation<Timer.Controller> taskResult = mwBoard.getModule(Timer.class).scheduleTask(
    new Timer.Task() {
    @Override
    public void commands() {
    gpio.readAnalogIn(GPIO_PIN, Gpio.AnalogReadMode.ADC);
    }
    }, 5000, false);
    taskResult.onComplete(
    new AsyncOperation.CompletionHandler<Timer.Controller>() {
    @Override
    public void success(Timer.Controller result) {
    result.start();
    }
    }
    );
    } catch (UnsupportedModuleException e) {
    Log.e("HeartRateSensorFragment", e.toString());
    }
    }

    };

    private final RouteManager.MessageHandler dataHandler = new RouteManager.MessageHandler() {
    @Override
    public void process(Message message) {
    short rawValue = message.getData(Short.class);
    Log.i(TAG, "!raw data from heart rate sensor: " + String.valueOf(rawValue));
    }
    };
  • Looks like the Android app does not clear digital out on pin 1 i.e. the equivalent of this code from the iOS app needs to be added.

This discussion has been closed.