A class to call a function at the main function at regular intervals (using Ticker class)
Dependents: GPS_0002 optWingforHAPS_Eigen hexaTest_Eigen
Diff: LoopTicker.cpp
- Revision:
- 0:d9fd30e1ebe4
diff -r 000000000000 -r d9fd30e1ebe4 LoopTicker.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LoopTicker.cpp Thu Jan 21 15:45:43 2021 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" +#include "LoopTicker.hpp" + +LoopTicker::LoopTicker() +{ + fptr = NULL; + time = 0.0f; + updated = false; +} + +void LoopTicker::attach(void (*fptr_)(), float time_) +{ + fptr = fptr_; + time = time_; + ticker_.attach(this, &LoopTicker::interrupt, time); +} + +void LoopTicker::detach() +{ + fptr = NULL; + time = 0.0f; + updated = false; + ticker_.detach(); +} + +void LoopTicker::loop() +{ + if (updated) + { + fptr(); + updated = false; + } +} + +void LoopTicker::interrupt() +{ + updated = true; +} \ No newline at end of file