Timer in Macro

edited May 2016 in Android
Hello,
I'm trying to implement a battery status indicator which would work when device is not connected and which would start on the boot. For this I'm using data processor on fromBattery signal and periodically call settingsModule.readBatteryState() (from timer or from other processors). 
All runs fine if I start the process and disconnect. Now I'm trying to make it work from Macro. When I'm programming macro - it starts, but when I'm making a soft reset - I'm not getting battery signal, while other functionality is working fine.
The first issue that I can not start timer from Macro
When I program the Macro with the code below I'm getting the single green flash followed by periodical BLUE, if I reset the device (mwBoard.getModule(Debug.class).resetDevice()) - I'm having only the single green, but no Timer events.
HW: Metawear RG FW 1.1.3), Android API 2.5.9

timerModule
.scheduleTask(new Timer.Task() {
@Override
public void commands() {
ledModule.stop(true);
ledModule.configureColorChannel(Led.ColorChannel.BLUE)
.setHighIntensity((byte) 31).setLowIntensity((byte) 0)
.setRiseTime((short) 100)
.setFallTime((short) 50)
.setHighTime((short) 100).setPulseDuration((short) 250)
.setRepeatCount((byte) 1).commit();
ledModule.play(true);

settingsModule.readBatteryState(true);

}
}, 1000, true).onComplete(new AsyncOperation.CompletionHandler<Timer.Controller>() {
@Override
public void success(Timer.Controller result) {
ledModule.stop(true);
ledModule.configureColorChannel(Led.ColorChannel.GREEN)
.setHighIntensity((byte) 31).setLowIntensity((byte) 0)
.setRiseTime((short) 100)
.setFallTime((short) 50)
.setHighTime((short) 100).setPulseDuration((short) 250)
.setRepeatCount((byte) 1).commit();
ledModule.play(true);
result.start();
}

@Override
public void failure(Throwable error) {
ledModule.stop(true);
ledModule.configureColorChannel(Led.ColorChannel.RED)
.setHighIntensity((byte) 31).setLowIntensity((byte) 0)
.setRiseTime((short) 100)
.setFallTime((short) 50)
.setHighTime((short) 100).setPulseDuration((short) 250)
.setRepeatCount((byte) 1).commit();
ledModule.play(true);
}
});

Comments

  • As a workaround I have implemented periodic calling of readBatteryState from processor of BMI accelerometer signal monitor and it starts from Macro after boot, but still the readout of the battery is not happening

    Here is my data route (I have just a LED indication to see if the signal has arrived:

                    settingsModule.routeData().fromBattery(true)
                            .process(new Counter())
                            .process(new Comparison(Comparison.Operation.GTE, 0))
                            .monitor(new DataSignal.ActivityHandler() {
                                @Override
                                public void onSignalActive(Map<String, DataProcessor> processors,
                                                           DataSignal.DataToken token) {
                                    ledModule.stop(true);
                                    ledModule.configureColorChannel(Led.ColorChannel.BLUE)
                                            .setHighIntensity((byte) 31).setLowIntensity((byte) 0)
                                            .setRiseTime((short) 100)
                                            .setFallTime((short) 50)
                                            .setHighTime((short) 100).setPulseDuration((short) 250)
                                            .setRepeatCount((byte) 1).commit();
                                    ledModule.play(true);
                                }
                            }).commit();

  • Yes, there is a bug with using the timer and macro together; I have pushed a fix for this.  Let me know if this addresses your issue.

  • Thank you for the rapid response, @Eric, that worked. Also the fromBattery signal now works in Macro. 

    Still do not understand why I was not able to call readBatteryStatus periodically from monitor sitting on accelerometer signal.
  • What is the code you were using to read battery state with the accelerometer?
  • @Eric
    I have set the acc sampling rate to 25Hz and had the handler like below and fromBattery like above.
    I was getting RED led blinks, but no BLUE ones.
    However, it looks like it might be more related to accelerometer handlers. In another application I had a feeling that too much code put in accel handler makes it unstable (some commands are skipped). I have not explored it too much since you've got timer fixed.

            bmi160AccModule.routeData().fromZAxis()
                    .process("acc_counter", new Counter())
                    .process(new Maths(Maths.Operation.MODULUS, 25))
                    .process(new Comparison(Comparison.Operation.EQ, 0))
                    .monitor(new DataSignal.ActivityHandler() {
                        @Override
                        public void onSignalActive(Map<String, DataProcessor> processors,
                                                   DataSignal.DataToken token) {
                          
                            ledModule.stop(true);
                            ledModule.configureColorChannel(Led.ColorChannel.RED)
                                    .setHighIntensity((byte) 31)
                                    .setLowIntensity((byte) 0)
                                    .setRiseTime((short) 50)
                                    .setFallTime((short) 50)
                                    .setHighTime((short) 50).setPulseDuration((short) 200)
                                    .setRepeatCount((byte) 1).commit();
                            ledModule.play(true);

    settingsModule.readBatteryState(true);
                        }
                    })
                    .commit();

This discussion has been closed.