Measuring CO₂
static uint32_t timer0 = 0;
TIMER(timer0, 5000)
{
globalVars.ppm = co2.getPPM();
}
Reads PPM and writes it into the global memory. ppm
can't be more than 2¹³ - 1, I don't think it's possible under normal conditions.
Update time from RTC
static uint32_t timer1 = 0;
static DateTime DTtmp;
TIMER(timer1, 999)
{
DTtmp = rtc.getTime();
globalVars.hours = DTtmp.hour;
globalVars.minutes = DTtmp.minute;
if(globalVars.seconds != DTtmp.second)
timer1 = millis();
globalVars.seconds = DTtmp.second;
}
Every last millisecond it continuously updates time every cycle pass until seconds
variable changes.
Swipe panel poll
static uint32_t timer2 = 0;
TIMER(timer2, 10)
{
buttons();
}
This timer call 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).
Render
switch(globalVars.prepare)
{
case 1:
screens[globalVars.currentScreen].funcPrepare();
case 2:
animate(50);
break;
case 0:
screens[globalVars.currentScreen].func(&screens[globalVars.currentScreen].arg);
break;
}
matrix.show();
Calls current screen's function and updates display. Calls animate
in the transition. Currently there are no enough memory to store two matrix buffers, so animate
function just nulls prepare
.
millis()
reset
TIMER(0, 3456000000)
{
noInterrupts();
timer0_millis = 0;
timer0_overflow_count = 0;
interrupts();
globalVars.timer = 0;
tb.resetTimers();
timer_debug0 = 0;
timer0 = 0;
timer1 = 0;
timer2 = 0;
}
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.