mitra42 / frugal-iot

A platform to enable affordable sensor networks
https://drive.google.com/drive/folders/1VRrBSEATjN9i-Fx3X48nKeh_lJCg1sto?usp=sharing
1 stars 2 forks source link

Refactor: clock should be nextTime instead of lastTime #15

Closed mitra42 closed 1 month ago

mitra42 commented 2 months ago

The clock uses a pattern like

bool hasIntervalPassed(unsigned long lastTime, unsigned long interval) {
        unsigned long currentTime = getTime();
        return (currentTime - lastTime >= interval);

and is tested with something like

if (sClock::hasIntervalPassed(lastLoopTime, ACTUATOR_BLINKEN_MS)) {

and set with

lastLoopTime = sClock::getTime();

I think this would be better if we flipped this, so we stored the next time we wanted to run, and checked if getTime() had passed it.

Two rationals for this. a: the math is simpler in the hasIntervalPassed which is executed much more frequently than the setting. b: when we get to do power management, we can do something like storing a global earliestAction time and sleeping till then.

mitra42 commented 2 months ago

@janandrzejewski would you like to take this ?

mitra42 commented 1 month ago

completed = now uses nextLoopTime and doesn't need a system_clock.cpp, may reintroduce a library as part of power management