|
## Measuring CO₂
|
|
## Measuring CO₂
|
|
|
|
|
|
```
|
|
```
|
|
static uint32_t timer0 = 0;
|
|
|
|
static uint32_t timer1 = 0;
|
|
|
|
TIMER(timer0, 5000)
|
|
TIMER(timer0, 5000)
|
|
{
|
|
{
|
|
timer0 = millis();
|
|
timer0 = millis();
|
|
PRINT_DEBUG(F("Measured CO2 "));
|
|
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.
|
|
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
|
|
## Notifications
|
|
|
|
|
|
```
|
|
```
|
|
static uint32_t timer2 = 0;
|
|
TIMER(timer2, HIGH_PPM_TIMEOUT)
|
|
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"));
|
|
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
Asks for a long beep.
|
|
Asks for a long beep. There is no function that reads this intent.
|
|
|
|
|
|
## Update time from RTC
|
|
## Update time from RTC
|
|
|
|
|
|
```
|
|
```
|
|
static uint32_t timer3 = 0;
|
|
|
|
static DateTime DTtmp;
|
|
|
|
TIMER(timer3, 999)
|
|
TIMER(timer3, 999)
|
|
{
|
|
{
|
|
PRINT_DEBUG(F("Time updated "));
|
|
PRINT_DEBUG(F("Time updated "));
|
|
DTtmp = rtc.getTime();
|
|
…
|
|
globalVars.hours = DTtmp.hour % TIME_FORMAT;
|
|
|
|
#if(OVERFLOW_WITHOUT_ZERO)
|
|
|
|
if(globalVars.hours == 0)
|
|
|
|
globalVars.hours = TIME_FORMAT;
|
|
|
|
#endif
|
|
|
|
globalVars.minutes = DTtmp.minute;
|
|
|
|
if(globalVars.seconds != DTtmp.second)
|
|
|
|
timer3 = millis();
|
|
|
|
globalVars.seconds = DTtmp.second;
|
|
|
|
PRINTLN_DEBUG(F("succesfuly"));
|
|
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
... | @@ -74,7 +45,7 @@ TIMER(timer4, 10) |
... | @@ -74,7 +45,7 @@ TIMER(timer4, 10) |
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
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 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
|
|
## Pomodoro
|
|
|
|
|
... | @@ -82,59 +53,38 @@ This timer call _if spaghetti_ function. I'll be glad if someone will help me wi |
... | @@ -82,59 +53,38 @@ This timer call _if spaghetti_ function. I'll be glad if someone will help me wi |
|
if(globalVars.pomodoroRunning) TIMER(globalVars.pomodoroTimer, 1000)
|
|
if(globalVars.pomodoroRunning) TIMER(globalVars.pomodoroTimer, 1000)
|
|
{
|
|
{
|
|
globalVars.pomodoroTimer = millis();
|
|
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.
|
|
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
|
|
## Render
|
|
|
|
|
|
```
|
|
```
|
|
switch(globalVars.prepare)
|
|
switch(globalVars.prepare)
|
|
{
|
|
{
|
|
case 1:
|
|
…
|
|
PRINTLN_DEBUG(F("Prepared"));
|
|
|
|
screens[globalVars.currentScreen].funcPrepare();
|
|
|
|
case 2:
|
|
|
|
PRINTLN_DEBUG(F("Animated"));
|
|
|
|
animate(50);
|
|
|
|
break;
|
|
|
|
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);
|
|
|
|
break;
|
|
|
|
}
|
|
}
|
|
matrix.show();
|
|
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`.
|
|
Calls current screen's function and updates display. Calls `animate` in the transition.
|
|
|
|
|
|
## `millis()` reset
|
|
## `millis()` reset
|
|
|
|
|
... | @@ -146,16 +96,7 @@ TIMER(0, 3456000000) |
... | @@ -146,16 +96,7 @@ TIMER(0, 3456000000) |
|
timer0_millis = 0;
|
|
timer0_millis = 0;
|
|
timer0_overflow_count = 0;
|
|
timer0_overflow_count = 0;
|
|
interrupts();
|
|
interrupts();
|
|
globalVars.timer = 0;
|
|
…
|
|
globalVars.pomodoroTimer = 0;
|
|
|
|
tb.resetTimers();
|
|
|
|
timer_debug0 = 0;
|
|
|
|
timer0 = 0;
|
|
|
|
timer1 = 0;
|
|
|
|
timer2 = 0;
|
|
|
|
timer3 = 0;
|
|
|
|
timer4 = 0;
|
|
|
|
buttons(1);
|
|
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
... | | ... | |