mitra42 / frugal-iot

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

Add a system clock #10

Closed mitra42 closed 1 week ago

mitra42 commented 1 week ago

The demo version of actuator_blinken uses a delay(2000) which is obviously a bad idea.

Instead it should be using some kind of system clock

mitra42 commented 1 week ago

First thoughts are a function like delay that uses a local variable specific to a actuator or sensor e.g. (and this is not correct or optimal C++, its just an example of what actuator_blinken might look like)

int foo; bool state;
foo = clock_now; state=HIGH;
if (state == HIGH && clock_waited(foo, 2000)) {
  digitalWrite(BUILTIN_LED, LOW);   // set the LED LOW if its been 2000
  foo = clock_now();  
  state = LOW;
} else if (state == LOW && clock_waited(foo, 2000)) {
  digitalWrite(BUILTIN_LED, HIGH);   // set the LED HIGH if its been 2000 at LOW
  foo = clock_now();  
  state = HIGH;
}
mitra42 commented 1 week ago

Thanks @janandrzejewski for the pull-request, note that this surfaced a need for a new section called system_clock as I'm envisioning logic for application dependent stuff, for example an application might decide that when a sensor exceeded some threshhold that the light gets blinked, and I see that happening in the logic_xxx area.