Simon,
Take a look at this:-
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Ticker t3;
bool doOnceFlag = false;
void callback(void) {
led2 = !led2;
if (!doOnceFlag) {
// re-task ticker flash rate
t3.detach();
t3.attach(&callback, 5);
doOnceFlag = true;
}
}
int main() {
t3.attach(&callback, 5);
wait(1);
while(1) {
led1 = 1;
wait(0.05);
led1 = 0;
wait(0.95);
}
}
In the above code led1 is just setup to flash one per second as a "marker".
Led2 is switched on and off via the Ticker callback. Now, one thing I wanted to do was to alter the flash rate of led2. So, in the callback I "re-tasked" the Ticker to a new rate by detaching and then attaching again. Now, In the example above I'm actually setting it to 5seconds. But is doesn't matter what you set, just that 5 seconds happen to show this odd behaviour.
Try in on an Mbed. What happens is when the Ticker is reassigned the next flash doesn't happen 5seconds later, it happens 10 seconds later! In fact, experiement shows that whenever you re-task the Ticker the next callback is always twice the value you specify. After that it returns to normal 5second period.
So I'm curious, have I missed something obvious? Or is that a possible edge case bug?
Simon,
Take a look at this:-
In the above code led1 is just setup to flash one per second as a "marker".
Led2 is switched on and off via the Ticker callback. Now, one thing I wanted to do was to alter the flash rate of led2. So, in the callback I "re-tasked" the Ticker to a new rate by detaching and then attaching again. Now, In the example above I'm actually setting it to 5seconds. But is doesn't matter what you set, just that 5 seconds happen to show this odd behaviour.
Try in on an Mbed. What happens is when the Ticker is reassigned the next flash doesn't happen 5seconds later, it happens 10 seconds later! In fact, experiement shows that whenever you re-task the Ticker the next callback is always twice the value you specify. After that it returns to normal 5second period.
So I'm curious, have I missed something obvious? Or is that a possible edge case bug?