Skip to content
Snippets Groups Projects
Commit 7a379b81 authored by egorguslyan's avatar egorguslyan
Browse files

animations

parent 03e622b4
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
/*************Marcos*************/ /*************Marcos*************/
#define timer(tim, del) if(millis() - (tim) > (del)) #define timer(tim, del) if(millis() - (tim) > (del))
#define numLeds (WIDTH * HEIGHT) #define numLeds(WIDTH * HEIGHT)
/********************************/ /********************************/
// Unified arguments for screen functions // Unified arguments for screen functions
...@@ -45,13 +45,24 @@ typedef union ...@@ -45,13 +45,24 @@ typedef union
// Screen entity with transition table // Screen entity with transition table
typedef struct typedef struct
{ {
void (*func)(const Arg *); void (*func)(Arg *);
const Arg arg; const Arg arg;
void (*funcPrepare)(void);
const uint8_t nextScreen0; const uint8_t nextScreen0;
const uint8_t nextScreen1; const uint8_t nextScreen1;
const uint8_t nextScreen2; const uint8_t nextScreen2;
} Screen; } 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 // It will be stored in EEPROM with a special key
enum PANEL_ORIENTATION enum PANEL_ORIENTATION
{ {
...@@ -61,12 +72,16 @@ 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) 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 // Structure for all global variables
struct struct
{ {
uint8_t panelOrientation : 2; // Swipe panel orientation uint8_t panelOrientation : 2; // Swipe panel orientation
uint8_t currentScreen; uint8_t currentScreen;
uint8_t currentState; uint8_t currentState;
uint8_t animation : 4;
uint8_t prepare : 2;
uint64_t timer; uint64_t timer;
uint8_t tapLeft : 1; uint8_t tapLeft : 1;
uint8_t tapRight : 1; uint8_t tapRight : 1;
...@@ -74,10 +89,10 @@ struct ...@@ -74,10 +89,10 @@ struct
uint8_t swipeRight : 1; uint8_t swipeRight : 1;
uint8_t holdLeft : 1; uint8_t holdLeft : 1;
uint8_t holdRight : 1; uint8_t holdRight : 1;
mData leds[numLeds];
} globalVars; } 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" #include "textbox.h"
textbox tb; textbox tb;
#include "configScreens.h" #include "configScreens.h"
...@@ -105,6 +120,9 @@ void setup() ...@@ -105,6 +120,9 @@ void setup()
// Set start screen // Set start screen
globalVars.currentScreen = startWith; globalVars.currentScreen = startWith;
// Start without animation
globalVars.animation = NO_ANIMATION;
globalVars.prepare = true;
delay(500); delay(500);
} }
...@@ -125,30 +143,17 @@ void loop() ...@@ -125,30 +143,17 @@ void loop()
Serial.end(); Serial.end();
} }
static uint64_t timer0 = 0; switch(prepare)
timer(timer0, 3000)
{ {
timer0 = millis(); case true:
uint16_t CO2 = co2.getPPM(); screens[globalVars.currentScreen].funcPrepare();
Serial.print(CO2); case 2:
Serial.print(" "); animate();
Serial.print(digitalRead(LBTN)); break;
Serial.print(" "); case false:
Serial.println(digitalRead(RBTN)); screens[globalVars.currentScreen].func(screens[globalVars.currentScreen].arg);
break;
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));
}
} }
static uint64_t timer1 = 0;
timer(timer1, 99)
if(tb.render()) timer1 = millis();
matrix.show(); matrix.show();
} }
\ No newline at end of file
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
/* Welcome screen with greetings /* Welcome screen with greetings
Swipe left when prompts to continue (nextScreeen0) */ Swipe left when prompts to continue (nextScreeen0) */
void welcome(Arg *arg); void welcome(Arg *arg);
void welcomePrepare();
/* Main screen with clock and CO2 bar */ /* Main screen with clock and CO2 bar */
void dashboard(Arg *arg); void dashboard(Arg *arg);
void dashboardPrepare();
// Links // Links
enum SCREENS enum SCREENS
...@@ -18,8 +20,8 @@ enum SCREENS ...@@ -18,8 +20,8 @@ enum SCREENS
}; };
const Screen screens[] = { const Screen screens[] = {
{ welcome, {.ui8 = globalVars.panelOrientation}, SCREEN_DASHBOARD, NONE, NONE }, { welcome, {0}, welcomePrepare, SCREEN_DASHBOARD, NONE, NONE },
{ dashboard, {.ui8 = globalVars.panelOrientation}, SCREEN_DASHBOARD, NONE, NONE }, { dashboard, {0}, dashboardPrepare, SCREEN_DASHBOARD, NONE, NONE },
}; };
#include "screens.h" #include "screens.h"
\ No newline at end of file
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
void unhandle(); void unhandle();
// Change screen // Change screen
void changeScreen(uint8_t current, uint8_t next); void changeScreen(uint8_t current, uint8_t next);
// Animate
void animate(uint16_t reciprocal_speed);
void unhandle() void unhandle()
{ {
...@@ -17,16 +19,28 @@ void changeScreen(uint8_t current, uint8_t next) ...@@ -17,16 +19,28 @@ void changeScreen(uint8_t current, uint8_t next)
uint8_t ns = *(&(screens[current].nextScreen0) + sizeof(uint8_t) * next); uint8_t ns = *(&(screens[current].nextScreen0) + sizeof(uint8_t) * next);
if(ns == NONE) return; if(ns == NONE) return;
globalVars.currentScreen = ns; 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) void welcome(Arg *arg)
{ {
const uint16_t delayMap[] = {0, 50, 0, 99}; const uint16_t delayMap[] PROGMEM = {0, 50, 0, 99};
// Local vars // Local vars
static uint8_t counter = 0; 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) switch(globalVars.currentState)
{ {
...@@ -34,6 +48,7 @@ void welcome(Arg *arg) ...@@ -34,6 +48,7 @@ void welcome(Arg *arg)
case 0: case 0:
if(globalVars.panelOrientation != PANEL_UNKNOWN) if(globalVars.panelOrientation != PANEL_UNKNOWN)
{ {
globalVars.animation = NO_ANIMATION;
changeScreen(SCREEN_WELCOME, 0); changeScreen(SCREEN_WELCOME, 0);
break; break;
} }
...@@ -66,13 +81,22 @@ void welcome(Arg *arg) ...@@ -66,13 +81,22 @@ void welcome(Arg *arg)
break; break;
case 3: case 3:
if(tb.render()) globalVars.timer = millis(); 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; break;
} }
unhandle(); unhandle();
} }
} }
void welcomePrepare()
{
memset(globalVars.leds, mBlack, sizeof(mData) * numLeds);
}
void dashboard(Arg *arg) void dashboard(Arg *arg)
{ {
const uint16_t delayMap[] = {50}; const uint16_t delayMap[] = {50};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment