source.count() reset and timed reset
Hi,
I'm trying to use a Metamotion R switch to send out a message.
I'd like to send it out after pressing two times and then reset the counter; so far I managed to send message out after pushing two times but I cannot figure out how to reset the count, below a snippet of my code:
I'd like to send it out after pressing two times and then reset the counter; so far I managed to send message out after pushing two times but I cannot figure out how to reset the count, below a snippet of my code:
public void readSwitch() {
final Switch mwSwitch = metawear.getModule(Switch.class);
mwSwitch.state().addRouteAsync(new RouteBuilder() {
@Override
public void configure(RouteComponent source) {
source.count().filter(Comparison.GTE, (byte) 4).stream(new Subscriber() {
@Override
public void apply(final Data data, Object... env) {
if (data.value(Boolean.class)) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(
MainActivity.this,
"HELLO!\nTHIS IS SWITCH MESSAGE :-)",
Toast.LENGTH_SHORT
).show();
}
});
new DataProcessor.CounterEditor() {
@Override
public void reset() {
// how to reset data count ?!?;
}
@Override
public void set(int value) { }
};
}
}
});
}
});
}
I've also tried with:
source.delay((byte) 2).limit(Passthrough.COUNT, (byte) 2).stream(new Subscriber()) ...
but of course after the second pushing it's not possible to repeat the procedure ... unless app is restarted and I'd like to avoid this behaviour.
Further I'd also like to reset data count if after pushing the first time second one doesn't come within a couple of seconds; I've tried using android countdown timer but it seems it was totally ignored, how I can achieve this "timed" data reset?
thanks
regards
This discussion has been closed.
Comments
name
component and use the edit function in the DataProcessor module to get the appropriate editor object. See the documentation and unit test:Would you please be so kind to clarify the "foggy" in my mind?
Regards