... | @@ -2,57 +2,132 @@ |
... | @@ -2,57 +2,132 @@ |
|
|
|
|
|
```
|
|
```
|
|
static uint32_t timer0 = 0;
|
|
static uint32_t timer0 = 0;
|
|
|
|
static uint32_t timer1 = 0;
|
|
TIMER(timer0, 5000)
|
|
TIMER(timer0, 5000)
|
|
{
|
|
{
|
|
timer0 = millis();
|
|
timer0 = millis();
|
|
globalVars.ppm = co2.getPPM();
|
|
PRINT_DEBUG(F("Measured CO2 "));
|
|
|
|
TIMER(timer1, GRAPH_UPDATE_TIME)
|
|
|
|
{
|
|
|
|
timer1 = millis();
|
|
|
|
globalVars.freshPPM++;
|
|
|
|
if(globalVars.freshPPM == WIDTH) globalVars.freshPPM = 0;
|
|
|
|
PRINT_DEBUG(F("and shifted array "));
|
|
|
|
}
|
|
|
|
globalVars.ppm[globalVars.freshPPM] = co2.getPPM();
|
|
|
|
if(globalVars.ppm[globalVars.freshPPM] > globalVars.maxPPM) globalVars.maxPPM = globalVars.ppm[globalVars.freshPPM];
|
|
|
|
if(globalVars.ppm[globalVars.freshPPM] < globalVars.minPPM) globalVars.minPPM = globalVars.ppm[globalVars.freshPPM];
|
|
|
|
PRINTLN_DEBUG(globalVars.ppm[globalVars.freshPPM]);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
## Notifications
|
|
|
|
|
|
|
|
```
|
|
|
|
static uint32_t timer2 = 0;
|
|
|
|
static uint8_t ppmFlag = false;
|
|
|
|
if(globalVars.ppm[globalVars.freshPPM] <= globalVars.maxPPM - CO2WINDOW) ppmFlag = true;
|
|
|
|
if(ppmFlag && (globalVars.ppm[globalVars.freshPPM] > globalVars.maxPPM - CO2WINDOW)) TIMER(timer2, HIGH_PPM_TIMEOUT)
|
|
|
|
{
|
|
|
|
globalVars.longBeep = true;
|
|
|
|
PRINTLN_DEBUG(F("Notified"));
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
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.
|
|
Asks for a long beep.
|
|
|
|
|
|
## Update time from RTC
|
|
## Update time from RTC
|
|
|
|
|
|
```
|
|
```
|
|
static uint32_t timer1 = 0;
|
|
static uint32_t timer3 = 0;
|
|
static DateTime DTtmp;
|
|
static DateTime DTtmp;
|
|
TIMER(timer1, 999)
|
|
TIMER(timer3, 999)
|
|
{
|
|
{
|
|
|
|
PRINT_DEBUG(F("Time updated "));
|
|
DTtmp = rtc.getTime();
|
|
DTtmp = rtc.getTime();
|
|
globalVars.hours = DTtmp.hour;
|
|
globalVars.hours = DTtmp.hour % TIME_FORMAT;
|
|
|
|
#if(OVERFLOW_WITHOUT_ZERO)
|
|
|
|
if(globalVars.hours == 0)
|
|
|
|
globalVars.hours = TIME_FORMAT;
|
|
|
|
#endif
|
|
globalVars.minutes = DTtmp.minute;
|
|
globalVars.minutes = DTtmp.minute;
|
|
if(globalVars.seconds != DTtmp.second)
|
|
if(globalVars.seconds != DTtmp.second)
|
|
timer1 = millis();
|
|
timer3 = millis();
|
|
globalVars.seconds = DTtmp.second;
|
|
globalVars.seconds = DTtmp.second;
|
|
|
|
PRINTLN_DEBUG(F("succesfuly"));
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
Every last millisecond it continuously updates time every cycle pass until `seconds` variable changes.
|
|
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
|
|
## Swipe panel poll
|
|
|
|
|
|
```
|
|
```
|
|
static uint32_t timer2 = 0;
|
|
static uint32_t timer4 = 0;
|
|
TIMER(timer2, 10)
|
|
TIMER(timer4, 10)
|
|
{
|
|
{
|
|
timer2 = millis();
|
|
timer4 = millis();
|
|
buttons();
|
|
PRINTLN_DEBUG(F("Buttons readed"));
|
|
|
|
buttons(0);
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
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).
|
|
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).
|
|
|
|
|
|
|
|
## Pomodoro
|
|
|
|
|
|
|
|
```
|
|
|
|
if(globalVars.pomodoroRunning) TIMER(globalVars.pomodoroTimer, 1000)
|
|
|
|
{
|
|
|
|
globalVars.pomodoroTimer = millis();
|
|
|
|
PRINT_DEBUG(F("Updated pomodoro "));
|
|
|
|
PRINT_DEBUG(globalVars.pomodoroMinutes);
|
|
|
|
PRINT_DEBUG(F(" "));
|
|
|
|
PRINT_DEBUG(globalVars.pomodoroSeconds);
|
|
|
|
if(globalVars.pomodoroSeconds == 0)
|
|
|
|
{
|
|
|
|
if(globalVars.pomodoroMinutes == 0)
|
|
|
|
{
|
|
|
|
globalVars.pomodoroState = !globalVars.pomodoroState;
|
|
|
|
globalVars.pomodoroMinutes = globalVars.pomodoroState ? globalVars.pomodoroSavedBreak : globalVars.pomodoroSavedWork;
|
|
|
|
globalVars.pomodoroSeconds = 0;
|
|
|
|
globalVars.shortBeep = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
globalVars.pomodoroMinutes--;
|
|
|
|
globalVars.pomodoroSeconds = 59;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else globalVars.pomodoroSeconds--;
|
|
|
|
PRINT_DEBUG(F(" to "));
|
|
|
|
PRINT_DEBUG(globalVars.pomodoroMinutes);
|
|
|
|
PRINT_DEBUG(F(" "));
|
|
|
|
PRINTLN_DEBUG(globalVars.pomodoroSeconds);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Updates pomodoro timer every second and changes work/break states. Not depends on RTC.
|
|
|
|
|
|
## Render
|
|
## Render
|
|
|
|
|
|
```
|
|
```
|
|
switch(globalVars.prepare)
|
|
switch(globalVars.prepare)
|
|
{
|
|
{
|
|
case 1:
|
|
case 1:
|
|
|
|
PRINTLN_DEBUG(F("Prepared"));
|
|
screens[globalVars.currentScreen].funcPrepare();
|
|
screens[globalVars.currentScreen].funcPrepare();
|
|
case 2:
|
|
case 2:
|
|
|
|
PRINTLN_DEBUG(F("Animated"));
|
|
animate(50);
|
|
animate(50);
|
|
break;
|
|
break;
|
|
case 0:
|
|
case 0:
|
|
|
|
PRINT_DEBUG(F("Screen "));
|
|
|
|
PRINT_DEBUG(globalVars.currentScreen);
|
|
|
|
PRINT_DEBUG(F(" state "));
|
|
|
|
PRINT_DEBUG(globalVars.currentState);
|
|
screens[globalVars.currentScreen].func(&screens[globalVars.currentScreen].arg);
|
|
screens[globalVars.currentScreen].func(&screens[globalVars.currentScreen].arg);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
... | @@ -66,16 +141,21 @@ Calls current screen's function and updates display. Calls `animate` in the tran |
... | @@ -66,16 +141,21 @@ Calls current screen's function and updates display. Calls `animate` in the tran |
|
```
|
|
```
|
|
TIMER(0, 3456000000)
|
|
TIMER(0, 3456000000)
|
|
{
|
|
{
|
|
|
|
PRINTLN_DEBUG(F("Timers reset"));
|
|
noInterrupts();
|
|
noInterrupts();
|
|
timer0_millis = 0;
|
|
timer0_millis = 0;
|
|
timer0_overflow_count = 0;
|
|
timer0_overflow_count = 0;
|
|
interrupts();
|
|
interrupts();
|
|
globalVars.timer = 0;
|
|
globalVars.timer = 0;
|
|
|
|
globalVars.pomodoroTimer = 0;
|
|
tb.resetTimers();
|
|
tb.resetTimers();
|
|
timer_debug0 = 0;
|
|
timer_debug0 = 0;
|
|
timer0 = 0;
|
|
timer0 = 0;
|
|
timer1 = 0;
|
|
timer1 = 0;
|
|
timer2 = 0;
|
|
timer2 = 0;
|
|
|
|
timer3 = 0;
|
|
|
|
timer4 = 0;
|
|
|
|
buttons(1);
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
... | | ... | |