Measuring CO₂
TIMER(timer0, 5000)
{
timer0 = millis();
PRINT_DEBUG(F("Measured CO2 "));
…
}
Reads PPM and writes it into the global array. To save time, it don't shifts array, but increments element counter that points to the fresh ppm value. Values which measured at first 3 minutes after boot are ignored.
Notifications
TIMER(timer2, HIGH_PPM_TIMEOUT)
{
…
}
Asks for a long beep. There is no function that reads this intent.
Update time from RTC
TIMER(timer3, 999)
{
PRINT_DEBUG(F("Time updated "));
…
}
Every last millisecond it continuously updates time every cycle pass until seconds
variable changes. Also formats it to the defined time format.
Swipe panel poll
static uint32_t timer4 = 0;
TIMER(timer4, 10)
{
timer4 = millis();
PRINTLN_DEBUG(F("Buttons readed"));
buttons(0);
}
This timer calls if spaghetti function. I'll be glad if someone will help me with tidying it. Function detects the event and writes it to the global variables. Screens have to null every event's boolean after reading (or rendering to ignore input).
Pomodoro
if(globalVars.pomodoroRunning) TIMER(globalVars.pomodoroTimer, 1000)
{
globalVars.pomodoroTimer = millis();
…
}
Updates pomodoro timer every second and changes work/break states. Not depends on RTC.
Sleep
TIMER(timer5, 30000)
{
if(!globalVars.noAutoChangeScreen && globalVars.currentScreen != homeScreen)
{
matrix.clear();
globalVars.currentScreen = homeScreen;
globalVars.currentState = 0;
}
}
else globalVars.sleep = false;
Render
switch(globalVars.prepare)
{
…
}
matrix.show();
Calls current screen's function and updates display. Calls animate
in the transition.
millis()
reset
TIMER(0, 3456000000)
{
PRINTLN_DEBUG(F("Timers reset"));
noInterrupts();
timer0_millis = 0;
timer0_overflow_count = 0;
interrupts();
…
}
Classical timer realization implies that millis() always greater than last memorized time. But system timer0_millis
is not infinite, it nulls after UINT32_MAX, which means it will work 1 month 19 days 17 hours 2 minutes 47 seconds 295 milliseconds. This timer resets all timers every month.