Detecting Taps - error thrown

I am trying to detect double taps and use the example from the docs. It works, but the switch statement that checks for double/single tap seems to cause an issue:

04-07 13:46:27.036 32113-32137/com.hybris.labs.fit E/MetaWear: Background task reported an error
                                                               java.util.concurrent.ExecutionException: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.mbientlab.metawear.module.Bmi160Accelerometer$TapType.ordinal()' on a null object reference
                                                                  ...
                                                                   at com.mbientlab.metawear.MetaWearBleService$3.run(MetaWearBleService.java:1263)
                                                                   at java.util.Timer$TimerImpl.run(Timer.java:284)
                                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.mbientlab.metawear.module.Bmi160Accelerometer$TapType.ordinal()' on a null object reference
                                                                   at com.hybris.labs.fit.MainActivity$7$1.process(MainActivity.java:249)
                                                                   at com.mbientlab.metawear.impl.DefaultMetaWearBoard$57.run(DefaultMetaWearBoard.java:3915)
                                                                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                             

When I remove the switch statement for checking on single/double taps, it works. Also, I start the double tap detection with bmi160AccModule.enableTapDetection(Bmi160Accelerometer.TapType.DOUBLE);
Why do I need to distinguish between single/doublel taps then?

Comments

  • What is the actual byte data that is returned in the Message class?  If a npe is being thrown, then it seems like invalid data is getting sent from the board.

    Double and single taps have different enable and interrupt bits on the accelerometer so it is possible to only detect one tap type.
  • Hi @Eric, sorry for the stupid response, but you have to tell me how I can show you these bytes :-) I have the 

    Bmi160Accelerometer.TapResponse response= msg.getData(Bmi160Accelerometer.TapResponse.class);

    response object - is there a getBytes() method or so that I don't see? How can I give you the raw data?

    Thx
    Sven
  • The Message class has a getData() function to retrieve the bytes.
  • OK, here we go. I am doing this after the "double Tap" log mesage

    Log.i("MainActivity", Arrays.toString(msg.getData()));
    I get the byte 4 and 37 sometimes. It looks like the that line:
    bmi160AccModule.enableTapDetection(Bmi160Accelerometer.TapType.DOUBLE);

    Does not work for me :-) 

    04-11 11:35:19.365 14338-14418/com.hybris.labs.fit I/MainActivity: Steps= 0
    04-11 11:35:20.861 14338-14418/com.hybris.labs.fit I/MainActivity: Double Tap
    04-11 11:35:20.862 14338-14418/com.hybris.labs.fit I/MainActivity: [4]
    04-11 11:35:20.862 14338-14418/com.hybris.labs.fit I/MainActivity: You took a step
    04-11 11:35:20.895 14338-14418/com.hybris.labs.fit I/MainActivity: Double Tap
    04-11 11:35:20.896 14338-14418/com.hybris.labs.fit I/MainActivity: [4]
    04-11 11:35:20.941 14338-14418/com.hybris.labs.fit I/MainActivity: Steps= 0
    04-11 11:35:21.976 14338-14418/com.hybris.labs.fit I/MainActivity: You took a step
    04-11 11:35:22.065 14338-14418/com.hybris.labs.fit I/MainActivity: Steps= 0
    04-11 11:35:30.718 14338-14418/com.hybris.labs.fit I/MainActivity: No motion detected.
    04-11 11:35:36.165 14338-14418/com.hybris.labs.fit I/MainActivity: Double Tap
    04-11 11:35:36.166 14338-14418/com.hybris.labs.fit I/MainActivity: [37]
    04-11 11:35:36.615 14338-14418/com.hybris.labs.fit I/MainActivity: You 
This discussion has been closed.