Outside of RTOS you should be able to use printf in interrupts (generally it is not a great idea, although with a system like this, which is relative slow, it should work fine). So I dont understand why it wouldnt work with TimeOut.
There are two ways to do it (well probably more). One is to add a global variable, that is changed by a timer interrupt, and your main loop reacts to that. Option B is to use serial interrupts (serial.attach), which will directly go through the wait statement.
In this case second option is probably most effective, but first one would be something like this:
Ticker tick; //Instead of Timeout, although you can also use that
volatile bool ticked;
void tickFunction( void ) {
ticked = true;
}
int main( void ) {
ticked = false;
tick.attach(&tickFunction, 10);
while(1) {
if (ticked) {
pingBaseStation();
ticked = false;
}
if (pc.readable())
pc.printf("GOCHA!");
}
}
Hi all,
I tried Timeout, but strayed away from using that after I realized printf does not work well. Now I am using a while loop with wait(10). That works; however, as my code stands, I am not able to break the wait. I basically need the ability to break a timeout when pc.readable() is true. If pc.readable() is false I need to execute the pingBaseStation() function every 10 seconds until pc.readable() equals true. Will RTOS work with printf? What are other ways that I can approach this?