diff --git a/Dashboard/Dashboard.ino b/Dashboard/Dashboard.ino index f03a8026d83471cb837c9fd04b6845264b6a258a..6619949b5476c80851942b4e3231f6226fc35906 100644 --- a/Dashboard/Dashboard.ino +++ b/Dashboard/Dashboard.ino @@ -22,21 +22,17 @@ Service Desk: gitlab+egorguslyan-dashboard-851-issue-@edugit.org */ -#define DEBUG 1 +#define DEBUG 0 +// Serial helps to slow down +#define START_DEBUGGING Serial.begin(9600) +#define PRINT_DEBUG(x) Serial.print(x) +#define PRINTLN_DEBUG(x) Serial.println(x) +#define STOP_DEBUGGING Serial.end() #if(DEBUG) - #define START_DEBUGGING Serial.begin(9600) - #define PRINT_DEBUG(x) Serial.print(x) - #define PRINTLN_DEBUG(x) Serial.println(x) - #define STOP_DEBUGGING Serial.end() #define WAIT_DEBUGGER while(!Serial.available()) {} #else - #define START_DEBUGGING - #define PRINT_DEBUG(x) - #define PRINTLN_DEBUG(x) - #define STOP_DEBUGGING #define WAIT_DEBUGGER #endif - /*******microLED library*********/ #define COLOR_DEBTH 3 #include <color_utility.h> @@ -64,15 +60,16 @@ /********************************/ // Unified arguments for screen functions -typedef union +union Arg { int8_t i; uint8_t ui; const void *v; -} Arg; +}; + // Screen entity with transition table -typedef struct +struct Screen { void (*func)(const Arg *); const Arg arg; @@ -80,7 +77,7 @@ typedef struct const uint8_t nextScreen0; const uint8_t nextScreen1; const uint8_t nextScreen2; -} Screen; +}; // Animation types enum ANIMATION : uint8_t @@ -160,11 +157,16 @@ extern volatile uint32_t timer0_overflow_count; extern volatile uint32_t timer0_millis; // Spaghetti -void buttons() +void buttons(uint8_t resetTimers = 0) { static uint32_t timer_btnl = 0; static uint32_t timer_btnr = 0; static uint8_t btn_flags = 0; + if(resetTimers) + { + timer_btnl = timer_btnr = 0; + return; + } uint8_t btnl, btnr; if(globalVars.panelOrientation == PANEL_REVERSE) { @@ -177,9 +179,14 @@ void buttons() btnr = digitalRead(RBTN); } - if(btnl || bitRead(btn_flags, 0)) + PRINT_DEBUG(F("Buttons: ")); + PRINT_DEBUG(btnl); + PRINT_DEBUG(F(" ")); + PRINTLN_DEBUG(btnr); + + if((btnl && !bitRead(btn_flags, 2)) || bitRead(btn_flags, 0)) { - if(bitRead(btn_flags, 1)) + if(!bitRead(btn_flags, 1)) { if(!bitRead(btn_flags, 0)) { @@ -188,8 +195,9 @@ void buttons() } if((millis() - timer_btnl <= BOTH_DELAY) && btnr) bitWrite(btn_flags, 1, 1); - else if((millis() - timer_btnl <= SWIPE_DELAY) && btnr) + else if((millis() - timer_btnl <= SWIPE_DELAY) && btnr && !btnl) { + PRINTLN_DEBUG(F("Swipe right")); globalVars.swipeRight = 1; bitWrite(btn_flags, 1, 1); } @@ -197,30 +205,33 @@ void buttons() bitWrite(btn_flags, 1, 1); else if(!(millis() - timer_btnl <= SWIPE_DELAY) && !btnl) { + PRINTLN_DEBUG(F("Tap left")); globalVars.tapLeft = 1; bitWrite(btn_flags, 1, 1); } else if(millis() - timer_btnl > HOLD_DELAY) { + PRINTLN_DEBUG(F("Hold left")); globalVars.holdLeft = 1; bitWrite(btn_flags, 1, 1); } } else if(!btnl && !btnr) btn_flags = 0; } - else if(btnr || bitRead(btn_flags, 0)) + if((btnr && !bitRead(btn_flags, 0)) || bitRead(btn_flags, 2)) { - if(bitRead(btn_flags, 1)) + if(!bitRead(btn_flags, 1)) { - if(!bitRead(btn_flags, 0)) + if(!bitRead(btn_flags, 2)) { - bitWrite(btn_flags, 0, 1); + bitWrite(btn_flags, 2, 1); timer_btnl = millis(); } if((millis() - timer_btnl <= BOTH_DELAY) && btnl) bitWrite(btn_flags, 1, 1); - else if((millis() - timer_btnl <= SWIPE_DELAY) && btnl) + else if((millis() - timer_btnl <= SWIPE_DELAY) && btnl && !btnr) { + PRINTLN_DEBUG(F("Swipe left")); globalVars.swipeLeft = 1; bitWrite(btn_flags, 1, 1); } @@ -228,11 +239,13 @@ void buttons() bitWrite(btn_flags, 1, 1); else if(!(millis() - timer_btnl <= SWIPE_DELAY) && !btnr) { + PRINTLN_DEBUG(F("Tap right")); globalVars.tapRight = 1; bitWrite(btn_flags, 1, 1); } else if(millis() - timer_btnl > HOLD_DELAY) { + PRINTLN_DEBUG(F("Hold right")); globalVars.holdRight = 1; bitWrite(btn_flags, 1, 1); } @@ -255,26 +268,35 @@ void setup() START_DEBUGGING; // For safe debugging WAIT_DEBUGGER; - PRINTLN_DEBUG("Hello"); + PRINTLN_DEBUG(F("Hello")); // Reading settings from nonvolatile memory uint8_t eepromData; eepromData = EEPROM.read(0); - if((eepromData & 0b11111100 == special_key) && (eepromData & 0b00000011 < 3)) - globalVars.panelOrientation = eepromData & 0b00000011; + PRINTLN_DEBUG(eepromData & 0b11111100); + PRINTLN_DEBUG(special_key); + PRINTLN_DEBUG(eepromData & 0b00000011); + if(((eepromData & 0b11111100) == special_key) && ((eepromData & 0b00000011) < 3)) + globalVars.panelOrientation = (PANEL_ORIENTATION)(eepromData & 0b00000011); else globalVars.panelOrientation = PANEL_UNKNOWN; eepromData = EEPROM.read(1); + PRINTLN_DEBUG(eepromData); if(!(eepromData == special_key)) { + PRINTLN_DEBUG(F("RTC UPDATED")); EEPROM.write(1, special_key); rtc.setTime(COMPILE_TIME); } + PRINTLN_DEBUG(globalVars.panelOrientation); // Set start screen globalVars.currentScreen = startWith; // Start without animation globalVars.animation = NO_ANIMATION; globalVars.prepare = true; + // Write default pomodoro times + globalVars.pomodoroSavedWork = POMODORO_WORK; + globalVars.pomodoroSavedBreak = POMODORO_BREAK; delay(500); // Measure PPM @@ -305,25 +327,25 @@ void loop() TIMER(timer0, 5000) { timer0 = millis(); - PRINT_DEBUG(F("Measured CO2")); - TIMER(timer1, 1800000) + 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")); + PRINT_DEBUG(F("and shifted array ")); } globalVars.ppm[globalVars.freshPPM] = co2.getPPM(); - if(globalVars.ppm[globalVars.freshPPM] > globalVars.maxPPM) globalVars.maxPPM = globalVars.ppm; - if(globalVars.ppm[globalVars.freshPPM] < globalVars.minPPM) globalVars.minPPM = globalVars.ppm; - PRINTLN_DEBUG(); + 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]); } // Notify when ppm is high static uint32_t timer2 = 0; static uint8_t ppmFlag = false; - if(globalVars.ppm <= globalVars.maxPPM - 100) ppmFlag = true; - if(ppmFlag && (globalVars.ppm > globalVars.maxPPM - 100)) TIMER(timer2, HIGH_PPM_TIMEOUT) + 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")); @@ -334,7 +356,7 @@ void loop() static DateTime DTtmp; TIMER(timer3, 999) { - PRINTLN_DEBUG(F("Time updated")); + PRINT_DEBUG(F("Time updated ")); DTtmp = rtc.getTime(); globalVars.hours = DTtmp.hour % TIME_FORMAT; #if(OVERFLOW_WITHOUT_ZERO) @@ -345,6 +367,7 @@ void loop() if(globalVars.seconds != DTtmp.second) timer3 = millis(); globalVars.seconds = DTtmp.second; + PRINTLN_DEBUG(F("succesfuly")); } // Detect taps and swipes @@ -353,14 +376,17 @@ void loop() { timer4 = millis(); PRINTLN_DEBUG(F("Buttons readed")); - buttons(); + buttons(0); } // Update pomodoro timer if(globalVars.pomodoroRunning) TIMER(globalVars.pomodoroTimer, 1000) { globalVars.pomodoroTimer = millis(); - PRINTLN_DEBUG(F("Updated pomodoro")); + PRINT_DEBUG(F("Updated pomodoro ")); + PRINT_DEBUG(globalVars.pomodoroMinutes); + PRINT_DEBUG(F(" ")); + PRINT_DEBUG(globalVars.pomodoroSeconds); if(globalVars.pomodoroSeconds == 0) { if(globalVars.pomodoroMinutes == 0) @@ -373,10 +399,14 @@ void loop() else { globalVars.pomodoroMinutes--; - globalVars.seconds = 59; + globalVars.pomodoroSeconds = 59; } } else globalVars.pomodoroSeconds--; + PRINT_DEBUG(F(" to ")); + PRINT_DEBUG(globalVars.pomodoroMinutes); + PRINT_DEBUG(F(" ")); + PRINTLN_DEBUG(globalVars.pomodoroSeconds); } // Display @@ -390,7 +420,10 @@ void loop() animate(50); break; case 0: - PRINTLN_DEBUG(F("Screen")); + 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; } @@ -413,5 +446,6 @@ void loop() timer2 = 0; timer3 = 0; timer4 = 0; + buttons(1); } } \ No newline at end of file diff --git a/Dashboard/config.h b/Dashboard/config.h index aa20e85b38bb433ded0ebc3a38dc95c6fc910ea5..7820e53d46820a65687d8098f9abfcddfdda01f3 100644 --- a/Dashboard/config.h +++ b/Dashboard/config.h @@ -1,3 +1,4 @@ +#pragma once // Native Language #define LANG_RU_RU // Time format (24, 12 and also every number) @@ -22,11 +23,13 @@ #define CONNECTION_TYPE ZIGZAG // Direction (DIR_RIGHT, DIR_UP, DIR_LEFT, DIR_DOWN) #define DIRECTION DIR_LEFT +// Delay between textboxes frames (greater => slower) +#define TB_FRAMES_DELAY 100 // Favorite colors // Breeze -// #define COLOR1 mHEX(0x3daee9) -// #define COLOR2 mHEX(0x27ae60) +#define COLOR1 mHEX(0x3daee9) +#define COLOR2 mHEX(0x27ae60) // Dracula // #define COLOR1 mHEX(0xff79c6) // #define COLOR2 mHEX(0x50fa7b) @@ -34,13 +37,23 @@ // #define COLOR1 mHEX(0xb8bb26) // #define COLOR2 mHEX(0xcc241d) // Custom -#define COLOR1 mHEX(0x9aa100) -#define COLOR2 mHEX(0x000aa0) +// #define COLOR1 mHEX(0x9aa100) +// #define COLOR2 mHEX(0x000aa0) // Delay between button fronts _|¯ have to be greater than BOTH_DELAY and less than SWIPE_DELAY (milliseconds) #define BOTH_DELAY 30 -#define SWIPE_DELAY 700 +#define SWIPE_DELAY 500 #define HOLD_DELAY 2000 // High ppm notification timeout (milliseconds) -#define HIGH_PPM_TIMEOUT 300000 \ No newline at end of file +#define HIGH_PPM_TIMEOUT 300000 + +// COâ‚‚ min-max window +#define CO2WINDOW 50 + +// COâ‚‚ graph update time +#define GRAPH_UPDATE_TIME 180000 + +// Pomodoro defaults +#define POMODORO_WORK 25 +#define POMODORO_BREAK 5 \ No newline at end of file diff --git a/Dashboard/configScreens.h b/Dashboard/configScreens.h index 7b33f0261267ccfa6431dc50e0f768150f7dbb58..06d2e02963b4182cd4f2dbd793be96c413c6979d 100644 --- a/Dashboard/configScreens.h +++ b/Dashboard/configScreens.h @@ -1,5 +1,6 @@ -#define startWith SCREEN_WELCOME +#pragma once +#define startWith SCREEN_WELCOME // Screens /* Welcome screen with greetings Swipe left when prompts to continue (nextScreeen0) */ @@ -14,6 +15,9 @@ extern void graphPrepare(); /* Pomodoro timer */ extern void pomodoro(Arg *arg); extern void pomodoroPrepare(); +/* Service desk email */ +extern void settings(Arg *arg); +extern void settingsPrepare(); // Links enum SCREEN : uint8_t @@ -23,12 +27,13 @@ enum SCREEN : uint8_t SCREEN_DASHBOARD, SCREEN_GRAPH, SCREEN_POMODORO, - SCREEN_SETTINGS, + SCREEN_SETTINGS, // For now it's just service desk }; const Screen screens[] = { { welcome, {0}, welcomePrepare, SCREEN_DASHBOARD, NONE, NONE }, - { dashboard, {0}, dashboardPrepare, SCREEN_GRAPH, NONE, NONE }, + { dashboard, {0}, dashboardPrepare, SCREEN_GRAPH, SCREEN_POMODORO, NONE }, { graph, {0}, graphPrepare, SCREEN_DASHBOARD, NONE, NONE }, { pomodoro, {0}, pomodoroPrepare, SCREEN_DASHBOARD, SCREEN_SETTINGS, NONE }, + { settings, {0}, settingsPrepare, SCREEN_POMODORO, NONE, NONE }, }; \ No newline at end of file diff --git a/Dashboard/font.h b/Dashboard/font.h index 417f39d2784d96a7b7f63c3f0a10e89b30a78888..c20e91d42cdd7a59c95d3d902c56e9cf5c38071b 100644 --- a/Dashboard/font.h +++ b/Dashboard/font.h @@ -19,9 +19,9 @@ const uint8_t font_bracketO[] PROGMEM = {cords(2, 0, 2), 0b01101010, 0b10100 const uint8_t font_bracketC[] PROGMEM = {cords(2, 0, 2), 0b10010101, 0b01011000}; const uint8_t font_multiply[] PROGMEM = {cords(3, 2, 2), 0b10101010, 0b10000000}; const uint8_t font_plus[] PROGMEM = {cords(3, 2, 1), 0b01011101}; -const uint8_t font_comma[] PROGMEM = {cords(2, 4, 1), 0b11011001}; +const uint8_t font_comma[] PROGMEM = {cords(3, 4, 1), 0b11011001}; const uint8_t font_minus[] PROGMEM = {cords(3, 3, 1), 0b11100000}; -const uint8_t font_dot[] PROGMEM = {cords(2, 4, 1), 0b11011000}; +const uint8_t font_dot[] PROGMEM = {cords(3, 4, 1), 0b11011000}; const uint8_t font_slash[] PROGMEM = {cords(3, 0, 3), 0b00100101, 0b00100101, 0b00100000}; const uint8_t font_colon[] PROGMEM = {cords(1, 2, 1), 0b10100000}; const uint8_t font_semicolon[] PROGMEM = {cords(2, 2, 1), 0b01000110}; @@ -141,7 +141,7 @@ const uint8_t font_ru_ru_k[] PROGMEM = {cords(4, 2, 3), 0b10011010, 0b11 const uint8_t font_ru_ru_l[] PROGMEM = {cords(4, 2, 3), 0b00110101, 0b01010101, 0b10010000}; const uint8_t font_ru_ru_m[] PROGMEM = {cords(5, 2, 4), 0b01010101, 0b01101011, 0b01011010, 0b10000000}; const uint8_t font_ru_ru_n[] PROGMEM = {cords(4, 2, 3), 0b10011001, 0b11111001, 0b10010000}; -const uint8_t font_ru_ru_p[] PROGMEM = {cords(4, 0, 3), 0b11111001, 0b10011001, 0b10010000}; +const uint8_t font_ru_ru_p[] PROGMEM = {cords(4, 2, 3), 0b11111001, 0b10011001, 0b10010000}; const uint8_t font_ru_ru_t[] PROGMEM = {cords(3, 2, 2), 0b11101001, 0b00100100}; const uint8_t font_ru_ru_f[] PROGMEM = {cords(5, 2, 3), 0b00100011, 0b10101010, 0b11100010}; const uint8_t font_ru_ru_c[] PROGMEM = {cords(4, 2, 3), 0b10101010, 0b10101111, 0b00010000}; @@ -369,5 +369,5 @@ const uint16_t small_num7 PROGMEM = 0b1110010010010010; const uint16_t small_num8 PROGMEM = 0b1111011111011110; const uint16_t small_num9 PROGMEM = 0b1111011110011110; -const uint16_t* const small_nums[] = { small_num0, small_num1, small_num2, small_num3, small_num4, - small_num5, small_num6, small_num7, small_num8, small_num9 }; \ No newline at end of file +const uint16_t* const small_nums[] = { &small_num0, &small_num1, &small_num2, &small_num3, &small_num4, + &small_num5, &small_num6, &small_num7, &small_num8, &small_num9 }; \ No newline at end of file diff --git a/Dashboard/screens.h b/Dashboard/screens.h index 9c0310a73c9adfcf719150295558f9c2f6f29f7f..a050f3e9550131afa55dd1d63aa176fdfb0f2855 100644 --- a/Dashboard/screens.h +++ b/Dashboard/screens.h @@ -1,3 +1,4 @@ +#pragma once #include "strings.h" // Clear touch panel bools @@ -47,17 +48,23 @@ void animate(uint16_t reciprocal_speed) void welcome(Arg *arg) { - const uint16_t delayMap[] PROGMEM = {0, 50, 0, 99, 0, 99}; + const uint16_t delayMap[] = {0, TB_FRAMES_DELAY / 2, 0, TB_FRAMES_DELAY - 1, 0, TB_FRAMES_DELAY - 1}; // Local vars static uint8_t counter = 0; - TIMER(globalVars.timer, (uint16_t)pgm_read_word(&delayMap[globalVars.currentState])) + PRINT_DEBUG(F(" delay ")); + PRINT_DEBUG(delayMap[globalVars.currentState]); + PRINT_DEBUG(F(" time ")); + PRINTLN_DEBUG(millis() - globalVars.timer); + + TIMER(globalVars.timer, delayMap[globalVars.currentState]) { switch(globalVars.currentState) { // Init case 0: + { if(globalVars.panelOrientation != PANEL_UNKNOWN) { changeScreen(SCREEN_WELCOME, 0, NO_ANIMATION); @@ -66,43 +73,62 @@ void welcome(Arg *arg) counter = 0; globalVars.currentState++; globalVars.timer = millis(); + PRINTLN_DEBUG(F("0Init")); + } break; // Fill borders case 1: + { uint8_t x = counter < WIDTH ? (counter) : (counter < WIDTH + HEIGHT - 1 ? (WIDTH - 1) - : (counter < 2 * WIDTH + HEIGHT - 2 ? (2 * WIDTH - counter + HEIGHT - 2) + : (counter < 2 * WIDTH + HEIGHT - 2 ? (2 * WIDTH - counter + HEIGHT - 3) : (0))); uint8_t y = counter < WIDTH ? (0) : (counter < WIDTH + HEIGHT - 1 ? (counter - WIDTH + 1) : (counter < 2 * WIDTH + HEIGHT - 2 ? (HEIGHT - 1) - : (2 * HEIGHT - counter + 2 * WIDTH - 3))); + : (2 * HEIGHT - counter + 2 * WIDTH - 4))); matrix.set(x, y, COLOR1); - matrix.show(); + PRINT_DEBUG(F("1 ")); + PRINT_DEBUG(counter); + PRINT_DEBUG(F(" ")); + PRINTLN_DEBUG(counter < WIDTH ? (F("->")) + : (counter < WIDTH + HEIGHT - 1 ? (F("/\\")) + : (counter < 2 * WIDTH + HEIGHT - 2 ? (F("<-")) + : (F("\\/"))))); counter += 1; - if(counter == 2 * (WIDTH + HEIGHT) - 4) + if(counter == (2 * (WIDTH + HEIGHT) - 4)) globalVars.currentState++; globalVars.timer = millis(); + } break; // Setup textbox case 2: - strcpy_P(globalVars.S, pgm_read_word(strings[0])); - tb.setup(globalVars.S, LANGMASK(0), COLOR2, TB_REPEAT, 1, 1, 14, 100); + { + PRINT_DEBUG(F("2Textbox ")); + strcpy_P(globalVars.S, strings[0]); + PRINTLN_DEBUG(globalVars.S); + tb.setup(globalVars.S, LANGMASK(0), COLOR2, TB_REPEAT, 1, 1, 14, TB_FRAMES_DELAY); globalVars.currentState++; + } break; // Render until it disappears case 3: + { uint8_t tbr = tb.render(); if(tbr) globalVars.timer = millis(); if(tbr == 2) globalVars.currentState++; + } break; // Setup textbox again case 4: - strcpy_P(globalVars.S, pgm_read_word(strings[1])); - tb.setup(globalVars.S, LANGMASK(1), COLOR2, TB_REPEAT, 1, 1, 14, 100); + { + strcpy_P(globalVars.S, strings[1]); + tb.setup(globalVars.S, LANGMASK(1), COLOR2, TB_REPEAT, 1, 1, 14, TB_FRAMES_DELAY); globalVars.currentState++; + } break; case 5: + { if(tb.render()) globalVars.timer = millis(); if(globalVars.swipeLeft) { @@ -116,6 +142,7 @@ void welcome(Arg *arg) EEPROM.write(0, special_key | PANEL_REVERSE); changeScreen(SCREEN_WELCOME, 0, ANIMATION_SHIFT_LEFT); } + } break; } unhandle(); @@ -130,40 +157,46 @@ void welcomePrepare() void drawSmallNumber(uint8_t x, uint8_t y, uint8_t num, mData color) { - uint16_t numBitmap = small_nums[num]; + uint16_t numBitmap = pgm_read_word(small_nums[num]); // Run througth bits for(uint8_t i = 0; i < 15; i++) matrix.set(x + (i % 3), y + 4 - (i / 3), bitRead(numBitmap, 15 - i) ? color : mBlack); } // Gradient for COâ‚‚ bars -const mGradient<2> barGrad = {{mGreen, mRed}}; +mGradient<2> barGrad = {{COLOR2, COLOR1}}; void dashboard(Arg *arg) { - const uint16_t delayMap[] PROGMEM = {30}; + const uint16_t delayMap[] = {TB_FRAMES_DELAY / 3}; + + PRINT_DEBUG(F(" delay ")); + PRINT_DEBUG(delayMap[globalVars.currentState]); + PRINT_DEBUG(F(" time ")); + PRINTLN_DEBUG(millis() - globalVars.timer); - TIMER(globalVars.timer, (uint16_t)pgm_read_word(&delayMap[globalVars.currentState])) + TIMER(globalVars.timer, delayMap[globalVars.currentState]) { switch(globalVars.currentState) { case 0: + { globalVars.timer = millis(); // Draw COâ‚‚ bar // Drawing critical ppm is more important - if(globalVars.ppm[globalVars.freshPPM] >= globalVars.maxPPM - 100) + if(globalVars.ppm[globalVars.freshPPM] >= globalVars.maxPPM - CO2WINDOW) for(uint8_t i = 0; i < HEIGHT; i++) { - matrix.set(0, i, mRed); - matrix.fade(0, i, (millis() / 32) % 128); + matrix.set(0, i, COLOR2); + matrix.fade(0, i, abs((int16_t)((millis() / 16) % 256) - 128)); } // Fresh room blinking - else if(globalVars.ppm[globalVars.freshPPM] <= globalVars.minPPM + 100) + else if(globalVars.ppm[globalVars.freshPPM] <= globalVars.minPPM + CO2WINDOW) for(uint8_t i = 0; i < HEIGHT; i++) { - matrix.set(0, i, mGreen); - matrix.fade(0, i, (millis() / 32) % 128); + matrix.set(0, i, COLOR1); + matrix.fade(0, i, abs((int16_t)((millis() / 16) % 256) - 128)); } // Else show progress bar else @@ -202,6 +235,7 @@ void dashboard(Arg *arg) changeScreen(SCREEN_DASHBOARD, 0, ANIMATION_SHIFT_RIGHT); if(globalVars.swipeLeft) changeScreen(SCREEN_DASHBOARD, 1, ANIMATION_SHIFT_LEFT); + } break; } unhandle(); @@ -226,7 +260,7 @@ void graphPrepare() // Working with the main buffer cause there are no memory for additional matrix.clear(); uint8_t x = WIDTH - 1; - for(uint8_t f = globalVars.freshPPM; (f != globalVars.freshPPM) || (x == WIDTH - 1); f = (f == WIDTH - 1) ? 0 : (f+1)) + for(uint8_t f = globalVars.freshPPM; (f != globalVars.freshPPM) || (x == WIDTH - 1); f = (f == 0) ? WIDTH - 1 : (f-1)) { uint8_t ppmMapped = map(globalVars.ppm[f], globalVars.minPPM, globalVars.maxPPM, 0, HEIGHT); if(ppmMapped >= HEIGHT) ppmMapped = HEIGHT - 1; @@ -242,34 +276,38 @@ void graphPrepare() void drawTomato(/*mData* buffer*/) { uint8_t x, y; - for(x = 3; x < 6; x++) - { - matrix.set(x, 7, mGreen); - } for(x = 1; x < 8; x++) { for(y = 1; y < 7; y++) { - matrix.set(x, y, ((x == 1 || x == 7) && (y == 1 || y == 6)) ? mBlack : mRed); + matrix.set(x + 3, y, ((x == 1 || x == 7) && (y == 1 || y == 6)) ? mBlack : mRed); } } + for(x = 3; x < 6; x++) + { + matrix.set(x + 3, 7, mGreen); + } + matrix.set(4 + 3, 6, mGreen); } void pomodoro(Arg *arg) { // Only 16x9 - const uint16_t delayMap[] PROGMEM = {2000, 99, 100}; + const uint16_t delayMap[] = {2000, TB_FRAMES_DELAY - 1, TB_FRAMES_DELAY - 1}; - TIMER(globalVars.timer, (uint16_t)pgm_read_word(&delayMap[globalVars.currentState])) + TIMER(globalVars.timer, delayMap[globalVars.currentState]) { switch(globalVars.currentState) { case 0: - strcpy_P(globalVars.S, pgm_read_word(strings[2])); - tb.setup(globalVars.S, LANGMASK(2), COLOR2, TB_REPEAT, 1, 1, 14, 100); + { + strcpy_P(globalVars.S, strings[2]); + tb.setup(globalVars.S, LANGMASK(2), COLOR2, TB_REPEAT, 0, 1, 16, TB_FRAMES_DELAY); globalVars.currentState++; + } break; case 1: + { switch(tb.render()) { case 1: @@ -281,15 +319,26 @@ void pomodoro(Arg *arg) globalVars.currentState = 0; break; } + } break; case 2: + { // Work minutes + for(uint8_t x = 0; (x < 6) && !(globalVars.pomodoroState); x++) + { + matrix.set(x + 2, 7, COLOR1); + } drawSmallNumber(2, 1, globalVars.pomodoroMinutes / 10, COLOR1); drawSmallNumber(5, 1, globalVars.pomodoroMinutes % 10, COLOR1); // Break minutes + for(uint8_t x = 0; (x < 6) && (globalVars.pomodoroState); x++) + { + matrix.set(x + 8, 7, COLOR1); + } drawSmallNumber(8, 1, globalVars.pomodoroSeconds / 10, COLOR2); drawSmallNumber(11, 1, globalVars.pomodoroSeconds % 10, COLOR2); globalVars.timer = millis(); + } break; } if(globalVars.currentState == 2) @@ -318,6 +367,7 @@ void pomodoro(Arg *arg) globalVars.pomodoroMinutes = globalVars.pomodoroSavedWork; globalVars.pomodoroSeconds = 0; globalVars.pomodoroRunning = true; + changeScreen(SCREEN_POMODORO, 0, ANIMATION_SHIFT_UP); } } else @@ -328,6 +378,7 @@ void pomodoro(Arg *arg) changeScreen(SCREEN_POMODORO, 1, ANIMATION_SHIFT_LEFT); if(globalVars.tapRight) { + matrix.clear(); globalVars.currentState = 2; globalVars.pomodoroRunning = false; globalVars.pomodoroMinutes = globalVars.pomodoroSavedWork; @@ -336,8 +387,8 @@ void pomodoro(Arg *arg) } if(globalVars.tapLeft) { - strcpy_P(globalVars.S, pgm_read_word(strings[3])); - tb.setup(globalVars.S, LANGMASK(3), COLOR2, TB_REPEAT, 1, 1, 14, 100); + strcpy_P(globalVars.S, strings[3]); + tb.setup(globalVars.S, LANGMASK(3), COLOR2, TB_REPEAT, 0, 1, 16, 80); globalVars.pomodoroRunning = false; globalVars.currentState = 1; } @@ -352,4 +403,32 @@ void pomodoroPrepare() // Only 16x9 matrix.clear(); drawTomato(); +} + +void settings(Arg *arg) +{ + if(globalVars.swipeRight) + changeScreen(SCREEN_SETTINGS, 0, ANIMATION_SHIFT_RIGHT); + if(globalVars.tapLeft && (globalVars.currentState != 0)) + { + globalVars.currentState--; + strcpy_P(globalVars.S, strings[4] + sizeof(char) * globalVars.currentState); + tb.setup(globalVars.S, LANGMASK(4), COLOR2, TB_STATIC, 0, 1, 16, 0); + tb.render(); + } + if(globalVars.tapRight && (globalVars.currentState != strlen_P(strings[4]) - 1)) + { + globalVars.currentState++; + strcpy_P(globalVars.S, strings[4] + sizeof(char) * globalVars.currentState); + tb.setup(globalVars.S, LANGMASK(4), COLOR2, TB_STATIC, 0, 1, 16, 0); + tb.render(); + } + unhandle(); +} + +void settingsPrepare() +{ + strcpy_P(globalVars.S, strings[4]); + tb.setup(globalVars.S, LANGMASK(4), COLOR2, TB_STATIC, 0, 1, 16, 0); + tb.render(); } \ No newline at end of file diff --git a/Dashboard/strings.h b/Dashboard/strings.h index c60da9d8032d90e91f338830968a5328c936782d..aa27f91a1ef5e2adf58d33061f0605ec3ed31e2b 100644 --- a/Dashboard/strings.h +++ b/Dashboard/strings.h @@ -1,11 +1,14 @@ +#pragma once + #ifdef LANG_RU_RU #define LANGMASK(n) langmask[n] const char string_hello[] PROGMEM = "Ghbdtn"; // Привет const char string_start_prompt[] PROGMEM = "<- Cdfqgyb dktdj"; // Свайпни влево const char string_pomodoro[] PROGMEM = "Gjvbljh"; // Помидор const char string_stopped[] PROGMEM = "Jcnfyjdktyyj"; // ОÑтановленно +const char string_service_desk[] PROGMEM = "gitlab+egorguslyan-dashboard-851-issue-@edugit.org"; // Need to make it PROGMEM -const uint64_t langmask[] = {0xFF, 0xFFFC, 0xFF, 0xFFFF}; +const uint64_t langmask[] = {0xFF, 0xFFFC, 0xFF, 0xFFFF, 0}; #else #define LANGMASK(n) 0 const char string_hello[] PROGMEM = "Hello"; @@ -14,4 +17,4 @@ const char string_pomodoro[] PROGMEM = "Pomodoro"; const char string_stopped[] PROGMEM = "Stopped"; #endif -const char* const strings[] = {string_hello, string_start_prompt, string_pomodoro, string_stopped}; \ No newline at end of file +const char* const strings[] = {string_hello, string_start_prompt, string_pomodoro, string_stopped, string_service_desk}; \ No newline at end of file