Problem using tap detection

Hello, I am trying to make an app that uses the tap detector and the sensor fusion on the MetaWear C board. Since I cannot use both sensors at the same time, the way I am doing it is by calling tearDown() after I am done with one sensor and then set the next one.

The first time I ran the app it worked fine, but after I made some modifications, the tap detector started having some weird behavior: it did not recognize my taps, and when it did, it was just after several taps, and only recognizing one out of maybe ten of them. I tried going back to the code I had before modifications, but it still had that weird behavior.

This is my code:

  public void onClickSetBoard(View view){
        //passing a reference of the sensors to the variables
        accBosch = board.getModule(AccelerometerBosch.class);
        led = board.getModule(Led.class);

        //configuring sensors

        led.editPattern(Led.Color.BLUE, Led.PatternPreset.SOLID).commit();




        accBosch.tap().configure()
                .enableDoubleTap()
                .enableSingleTap()
                .threshold(2f)
                .shockTime(TapShockTime.TST_50_MS)
                .commit();
        accBosch.tap().addRouteAsync(new RouteBuilder() {
            @Override
            public void configure(RouteComponent source) {
                source.stream(new Subscriber() {
                    @Override
                    public void apply(Data data, Object... env) {
                        AccelerometerBosch.Tap tap = data.value(AccelerometerBosch.Tap.class);
                        switch(tap.type) {
                            case SINGLE:
                                Log.i("MainActivity", "Single tap");
                                led.stop(false);
                                break;
                            case DOUBLE:
                                setMyBoard2();
                                break;
                        }
                    }
                });
            }
        }).continueWith(new Continuation<Route, Void>() {
            @Override
            public Void then(Task<Route> task) throws Exception {
                accBosch.tap().start();
                accBosch.start();
                return null;
            }
        });



    }

    public void setMyBoard2(){
        board.tearDown();

        led.editPattern(Led.Color.BLUE, Led.PatternPreset.SOLID).commit();
        sensorFusion = board.getModule(SensorFusionBosch.class);

        sensorFusion.configure()
                .mode(SensorFusionBosch.Mode.NDOF)
                .accRange(SensorFusionBosch.AccRange.AR_16G)
                .gyroRange(SensorFusionBosch.GyroRange.GR_2000DPS)
                .commit();


        sensorFusion.eulerAngles().addRouteAsync(new RouteBuilder() {
            @Override
            public void configure(RouteComponent source) {
                source.stream(new Subscriber() {
                    @Override
                    public void apply(Data data, Object... env) {
                        Log.i("MainActivity", "Euler angles = " + data.value(EulerAngles.class));
                    }
                });
            }
        }).continueWith(new Continuation<Route, Void>() {
            @Override
            public Void then(Task<Route> task) throws Exception {
                sensorFusion.eulerAngles().start();
                sensorFusion.start();
                return null;
            }
        });

        led.play();
    }

Can someone please tell me what happened and what am I doing wrong?
Thank you!

Comments

Sign In or Register to comment.