diff --git a/Dashboard/Dashboard.ino b/Dashboard/Dashboard.ino index e8774efec2bfe71939faa9f2f9d3b118e4715d28..58008a185b3ddd7972cf013ddcb65aa617b1d1b5 100644 --- a/Dashboard/Dashboard.ino +++ b/Dashboard/Dashboard.ino @@ -31,7 +31,7 @@ /*************Marcos*************/ #define timer(tim, del) if(millis() - (tim) > (del)) -#define numLeds (WIDTH * HEIGHT) +#define numLeds(WIDTH * HEIGHT) /********************************/ // Unified arguments for screen functions @@ -45,13 +45,24 @@ typedef union // Screen entity with transition table typedef struct { - void (*func)(const Arg *); + void (*func)(Arg *); const Arg arg; + void (*funcPrepare)(void); const uint8_t nextScreen0; const uint8_t nextScreen1; const uint8_t nextScreen2; } Screen; +// Animation types +enum ANIMATIONS +{ + NO_ANIMATION, + SHIFT_LEFT, + SHIFT_RIGHT, + SHIFT_UP, + SHIFT_DOWN, +}; + // It will be stored in EEPROM with a special key enum PANEL_ORIENTATION { @@ -61,12 +72,16 @@ enum PANEL_ORIENTATION }; const uint8_t special_key = 0b11011100; // Just a random number (it's actually the voltage from the outlet) +#include "config.h" + // Structure for all global variables struct { uint8_t panelOrientation : 2; // Swipe panel orientation uint8_t currentScreen; uint8_t currentState; + uint8_t animation : 4; + uint8_t prepare : 2; uint64_t timer; uint8_t tapLeft : 1; uint8_t tapRight : 1; @@ -74,10 +89,10 @@ struct uint8_t swipeRight : 1; uint8_t holdLeft : 1; uint8_t holdRight : 1; + mData leds[numLeds]; } globalVars; -#include "config.h" -microLED<numLeds, LEDsPin, MLED_NO_CLOCK, LED_WS2812, ORDER_GRB, CLI_AVER/*, SAVE_MILLIS*/> matrix(WIDTH, HEIGHT, ZIGZAG, RIGHT_TOP, DIR_LEFT); +microLED<numLeds, LEDsPin, MLED_NO_CLOCK, LED_WS2812, ORDER_GRB, CLI_AVER, SAVE_MILLIS> matrix(WIDTH, HEIGHT, ZIGZAG, RIGHT_TOP, DIR_LEFT); #include "textbox.h" textbox tb; #include "configScreens.h" @@ -105,6 +120,9 @@ void setup() // Set start screen globalVars.currentScreen = startWith; + // Start without animation + globalVars.animation = NO_ANIMATION; + globalVars.prepare = true; delay(500); } @@ -125,30 +143,17 @@ void loop() Serial.end(); } - static uint64_t timer0 = 0; - timer(timer0, 3000) + switch(prepare) { - timer0 = millis(); - uint16_t CO2 = co2.getPPM(); - Serial.print(CO2); - Serial.print(" "); - Serial.print(digitalRead(LBTN)); - Serial.print(" "); - Serial.println(digitalRead(RBTN)); - - CO2 = map(CO2, 300, 1500, 0, 9); - for (uint8_t i = 0; i < 9; i++) - { - matrix.set(matrix.getPixNumber(15, i), mHEX(0)); - } - for (uint8_t i = 0; i < CO2; i++) - { - matrix.set(15, i, mHEX(0x0aa100)); - } + case true: + screens[globalVars.currentScreen].funcPrepare(); + case 2: + animate(); + break; + case false: + screens[globalVars.currentScreen].func(screens[globalVars.currentScreen].arg); + break; } - static uint64_t timer1 = 0; - timer(timer1, 99) - if(tb.render()) timer1 = millis(); matrix.show(); -} +} \ No newline at end of file diff --git a/Dashboard/configScreens.h b/Dashboard/configScreens.h index bb8685357be1e33665beefba4d3a4a5eb3e2bb2e..ae2a9cf2ca24de5b18b3a8a3e4a4452aeaffd658 100644 --- a/Dashboard/configScreens.h +++ b/Dashboard/configScreens.h @@ -4,8 +4,10 @@ /* Welcome screen with greetings Swipe left when prompts to continue (nextScreeen0) */ void welcome(Arg *arg); +void welcomePrepare(); /* Main screen with clock and CO2 bar */ void dashboard(Arg *arg); +void dashboardPrepare(); // Links enum SCREENS @@ -18,8 +20,8 @@ enum SCREENS }; const Screen screens[] = { - { welcome, {.ui8 = globalVars.panelOrientation}, SCREEN_DASHBOARD, NONE, NONE }, - { dashboard, {.ui8 = globalVars.panelOrientation}, SCREEN_DASHBOARD, NONE, NONE }, + { welcome, {0}, welcomePrepare, SCREEN_DASHBOARD, NONE, NONE }, + { dashboard, {0}, dashboardPrepare, SCREEN_DASHBOARD, NONE, NONE }, }; #include "screens.h" \ No newline at end of file diff --git a/Dashboard/screens.h b/Dashboard/screens.h index 084079d824496e8e05779be6462c35dab56a4af0..9ed24231f140c9b4de5767b98854fbb0082ee30d 100644 --- a/Dashboard/screens.h +++ b/Dashboard/screens.h @@ -4,6 +4,8 @@ void unhandle(); // Change screen void changeScreen(uint8_t current, uint8_t next); +// Animate +void animate(uint16_t reciprocal_speed); void unhandle() { @@ -17,16 +19,28 @@ void changeScreen(uint8_t current, uint8_t next) uint8_t ns = *(&(screens[current].nextScreen0) + sizeof(uint8_t) * next); if(ns == NONE) return; globalVars.currentScreen = ns; + globalVars.timer = millis(); + globalVars.prepare = true; +} + +void animate(uint16_t reciprocal_speed) +{ + static uint8_t counter = 0; + timer(globalVars.timer, reciprocal_speed) + { + globalVars.timer = millis(); + + } } void welcome(Arg *arg) { - const uint16_t delayMap[] = {0, 50, 0, 99}; + const uint16_t delayMap[] PROGMEM = {0, 50, 0, 99}; // Local vars static uint8_t counter = 0; - if(millis() - globalVars.timer > delayMap[globalVars.currentState]) + timer(globalVars.timer, (uint16_t)pgm_read_word(&delayMap[globalVars.currentState])) { switch(globalVars.currentState) { @@ -34,6 +48,7 @@ void welcome(Arg *arg) case 0: if(globalVars.panelOrientation != PANEL_UNKNOWN) { + globalVars.animation = NO_ANIMATION; changeScreen(SCREEN_WELCOME, 0); break; } @@ -66,13 +81,22 @@ void welcome(Arg *arg) break; case 3: if(tb.render()) globalVars.timer = millis(); - if(globalVars.swipeLeft) changeScreen(SCREEN_WELCOME, 0); + if(globalVars.swipeLeft) + { + globalVars.animation = SHIFT_LEFT; + changeScreen(SCREEN_WELCOME, 0); + } break; } unhandle(); } } +void welcomePrepare() +{ + memset(globalVars.leds, mBlack, sizeof(mData) * numLeds); +} + void dashboard(Arg *arg) { const uint16_t delayMap[] = {50};