From 5ad8cc9a17d9330326b76e41cd2595e5369a13f2 Mon Sep 17 00:00:00 2001
From: egorguslyan <egorguslyan@gmail.com>
Date: Sun, 26 Dec 2021 23:17:39 +0300
Subject: [PATCH] Screens pt.2

---
 Dashboard/Dashboard.ino   | 18 ++++++++++++++----
 Dashboard/config.h        | 21 +--------------------
 Dashboard/configScreens.h | 24 ++++++++++++++++++++++++
 Dashboard/screens.h       | 31 +++++++++++++++++++++++++------
 Dashboard/strings.h       |  5 +++--
 5 files changed, 67 insertions(+), 32 deletions(-)
 create mode 100644 Dashboard/configScreens.h

diff --git a/Dashboard/Dashboard.ino b/Dashboard/Dashboard.ino
index 84b156f..e8774ef 100644
--- a/Dashboard/Dashboard.ino
+++ b/Dashboard/Dashboard.ino
@@ -47,9 +47,9 @@ typedef struct
 {
   void (*func)(const Arg *);
   const Arg arg;
-  const uint8_t nextFunc0;
-  const uint8_t nextFunc1;
-  const uint8_t nextFunc2;
+  const uint8_t nextScreen0;
+  const uint8_t nextScreen1;
+  const uint8_t nextScreen2;
 } Screen;
 
 // It will be stored in EEPROM with a special key
@@ -68,12 +68,19 @@ struct
   uint8_t currentScreen;
   uint8_t currentState;
   uint64_t timer;
+  uint8_t tapLeft : 1;
+  uint8_t tapRight : 1;
+  uint8_t swipeLeft : 1;
+  uint8_t swipeRight : 1;
+  uint8_t holdLeft : 1;
+  uint8_t holdRight : 1;
 } globalVars;
 
-microLED<numLeds, LEDsPin, MLED_NO_CLOCK, LED_WS2812, ORDER_GRB, CLI_AVER/*, SAVE_MILLIS*/> matrix(WIDTH, HEIGHT, ZIGZAG, RIGHT_TOP, DIR_LEFT);
 #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);
 #include "textbox.h"
 textbox tb;
+#include "configScreens.h"
 MHZ19_uart co2;
 
 void setup()
@@ -96,6 +103,9 @@ void setup()
     globalVars.panelOrientation = eepromData & 0b00000011;
   else globalVars.panelOrientation = PANEL_UNKNOWN;
 
+  // Set start screen
+  globalVars.currentScreen = startWith;
+
   delay(500);
 }
 
diff --git a/Dashboard/config.h b/Dashboard/config.h
index 76c5373..f8ffa54 100644
--- a/Dashboard/config.h
+++ b/Dashboard/config.h
@@ -9,23 +9,4 @@
 #define HEIGHT 9
 
 #define COLOR1 mHEX(0x9aa100)
-#define COLOR2 mHEX(0x000aa0)
-
-#define startWith SCREEN_WELCOME
-
-#include "screens.h"
-
-// Links
-enum SCREENS
-{
-    NONE = 255,
-    SCREEN_WELCOME = 0,
-    SCREEN_DASHBOARD,
-    SCREEN_GRAPH,
-    SCREEN_POMODORO,
-};
-
-const Screen screens[] = {
-    { welcome,      {.ui8 = globalVars.panelOrientation},       SCREEN_DASHBOARD,      NONE,                NONE },
-    { dashboard,    {.ui8 = globalVars.panelOrientation},       SCREEN_DASHBOARD,      NONE,                NONE },
-};
\ No newline at end of file
+#define COLOR2 mHEX(0x000aa0)
\ No newline at end of file
diff --git a/Dashboard/configScreens.h b/Dashboard/configScreens.h
new file mode 100644
index 0000000..98b8249
--- /dev/null
+++ b/Dashboard/configScreens.h
@@ -0,0 +1,24 @@
+#define startWith SCREEN_WELCOME
+
+// Screens
+// Welcome screen with greetings
+void welcome(Arg *arg);
+// Main screen with clock and CO2 bar
+void dashboard(Arg *arg);
+
+// Links
+enum SCREENS
+{
+    NONE = 255,
+    SCREEN_WELCOME = 0,
+    SCREEN_DASHBOARD,
+    SCREEN_GRAPH,
+    SCREEN_POMODORO,
+};
+
+const Screen screens[] = {
+    { welcome,      {.ui8 = globalVars.panelOrientation},       SCREEN_DASHBOARD,      NONE,                NONE },
+    { dashboard,    {.ui8 = globalVars.panelOrientation},       SCREEN_DASHBOARD,      NONE,                NONE },
+};
+
+#include "screens.h"
\ No newline at end of file
diff --git a/Dashboard/screens.h b/Dashboard/screens.h
index e14f561..cb60522 100644
--- a/Dashboard/screens.h
+++ b/Dashboard/screens.h
@@ -1,24 +1,36 @@
 #include "strings.h"
 
-void welcome(Arg *arg);
-void dashboard(Arg *arg);
+// Clear touch panel bools
+void unhandle();
+
+void unhandle()
+{
+    globalVars.tapLeft = globalVars.tapRight =
+    globalVars.holdLeft = globalVars.holdRight =
+    globalVars.swipeLeft = globalVars.swipeRight = 0;
+}
 
 void welcome(Arg *arg)
 {
-    const uint16_t delayMap[] = {50};
+    const uint16_t delayMap[] = {0, 50, 0, 99};
 
     // Local vars
     static uint8_t counter = 0;
 
     if(millis() - globalVars.timer > delayMap[globalVars.currentState])
     {
-        globalVars.timer = millis();
         switch(globalVars.currentState)
         {
             // Init
             case 0:
+                if(globalVars.panelOrientation != PANEL_UNKNOWN)
+                {
+                    globalVars.currentScreen = screens[SCREEN_WELCOME].nextScreen0;
+                    break;
+                }
                 counter = 0;
                 globalVars.currentState++;
+                globalVars.timer = millis();
             break;
             // Fill borders
             case 1:
@@ -35,13 +47,20 @@ void welcome(Arg *arg)
                 counter += 1;
                 if(counter == 2 * (WIDTH + HEIGHT) - 4)
                     globalVars.currentState++;
+                globalVars.timer = millis();
             break;
             case 2:
-                // EEPROM read here
-                tb.setup(, COLOR2, TB_REPEAT, 1, 1, 14, 100);
+                char S[20];
+                strcpy_P(S, pgm_read_word(strings[0]));
+                tb.setup(S, LANGMASK(0), COLOR2, TB_REPEAT, 1, 1, 14, 100);
                 globalVars.currentState++;
             break;
+            case 3:
+                if(tb.render()) globalVars.timer = millis();
+                if(globalVars.swipeLeft) globalVars.currentScreen = screens[SCREEN_WELCOME].nextScreen0;
+            break;
         }
+        unhandle();
     }
 }
 
diff --git a/Dashboard/strings.h b/Dashboard/strings.h
index 7606fe6..a951e43 100644
--- a/Dashboard/strings.h
+++ b/Dashboard/strings.h
@@ -1,10 +1,11 @@
-#if LANG_RU_RU
+#ifdef LANG_RU_RU
 #define LANGMASK(n) langmask[n]
 const char hello[] PROGMEM = "Привет";
 const char start_prompt[] PROGMEM = "<- Свайпни влево";
 const char pomodoro[] PROGMEM = "Помидор";
 const char set_time[] PROGMEM = "Установи время";
-const uint64_t langmask[] PROGMEM = {0xFF, 0x1FFF, 0xFF, 0xFFFF}; 
+// Need to make it PROGMEM
+const uint64_t langmask[] = {0xFF, 0x1FFF, 0xFF, 0xFFFF}; 
 #else
 #define LANGMASK(n) 0
 const char hello[] PROGMEM = "Hello";
-- 
GitLab