Bläddra i källkod

stashed changes: show connection info on display at start

Thomas Buck 5 månader sedan
förälder
incheckning
52792b4bed
4 ändrade filer med 91 tillägg och 17 borttagningar
  1. 10
    0
      include/ui.h
  2. 1
    0
      platformio.ini
  3. 28
    1
      src/main.cpp
  4. 52
    16
      src/ui.cpp

+ 10
- 0
include/ui.h Visa fil

@@ -27,8 +27,18 @@ struct ui_status {
27 27
 
28 28
 extern struct ui_status ui_status;
29 29
 
30
+enum ui_state {
31
+    UI_INIT = 0,
32
+    UI_WIFI_CONNECT,
33
+    UI_WIFI_CONNECTING,
34
+    UI_WIFI_CONNECTED,
35
+    UI_READY,
36
+};
37
+
30 38
 void ui_init(void);
31 39
 void ui_draw_menu(void);
32 40
 void ui_run(void);
33 41
 
42
+void ui_progress(enum ui_state state);
43
+
34 44
 #endif // __UI_H__

+ 1
- 0
platformio.ini Visa fil

@@ -27,6 +27,7 @@ build_flags =
27 27
   -DFEATURE_UI
28 28
   -DUSER_SETUP_LOADED=1
29 29
   -include include/User_Setup.h
30
+  -DDISABLE_ALL_LIBRARY_WARNINGS
30 31
 lib_ldf_mode = deep
31 32
 lib_deps =
32 33
     https://github.com/knolleary/pubsubclient.git#2d228f2f862a95846c65a8518c79f48dfc8f188c

+ 28
- 1
src/main.cpp Visa fil

@@ -95,6 +95,9 @@ void setup() {
95 95
 
96 96
     // Connect to WiFi AP
97 97
     debug.print(F("Connecting WiFi"));
98
+#ifdef FEATURE_UI
99
+    ui_progress(UI_WIFI_CONNECT);
100
+#endif // FEATURE_UI
98 101
     WiFi.hostname(hostname);
99 102
     WiFi.mode(WIFI_STA);
100 103
     WiFi.hostname(hostname);
@@ -103,8 +106,14 @@ void setup() {
103 106
         delay(LED_CONNECT_BLINK_INTERVAL);
104 107
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
105 108
         debug.print(F("."));
109
+#ifdef FEATURE_UI
110
+        ui_progress(UI_WIFI_CONNECTING);
111
+#endif // FEATURE_UI
106 112
     }
107 113
     debug.println(F("\nWiFi connected!"));
114
+#ifdef FEATURE_UI
115
+    ui_progress(UI_WIFI_CONNECTED);
116
+#endif // FEATURE_UI
108 117
 
109 118
     disconnectHandler = WiFi.onStationModeDisconnected(onDisconnected);
110 119
 
@@ -137,6 +146,9 @@ void setup() {
137 146
 
138 147
     // Connect to WiFi AP
139 148
     debug.print(F("Connecting WiFi"));
149
+#ifdef FEATURE_UI
150
+    ui_progress(UI_WIFI_CONNECT);
151
+#endif // FEATURE_UI
140 152
     WiFi.mode(WIFI_STA);
141 153
     WiFi.setHostname(hostname.c_str());
142 154
     WiFi.begin(WIFI_SSID, WIFI_PASS);
@@ -144,8 +156,14 @@ void setup() {
144 156
         delay(LED_CONNECT_BLINK_INTERVAL);
145 157
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
146 158
         debug.print(F("."));
159
+#ifdef FEATURE_UI
160
+        ui_progress(UI_WIFI_CONNECTING);
161
+#endif // FEATURE_UI
147 162
     }
148 163
     debug.println(F("\nWiFi connected!"));
164
+#ifdef FEATURE_UI
165
+    ui_progress(UI_WIFI_CONNECTED);
166
+#endif // FEATURE_UI
149 167
 
150 168
     // Set hostname workaround
151 169
     WiFi.setHostname(hostname.c_str());
@@ -157,13 +175,22 @@ void setup() {
157 175
     WiFi.init(&Serial1);
158 176
 
159 177
     debug.print(F("Connecting WiFi"));
178
+#ifdef FEATURE_UI
179
+    ui_progress(UI_WIFI_CONNECT);
180
+#endif // FEATURE_UI
160 181
     WiFi.begin(WIFI_SSID, WIFI_PASS);
161 182
     while (WiFi.status() != WL_CONNECTED) {
162 183
         delay(LED_CONNECT_BLINK_INTERVAL);
163 184
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
164 185
         debug.print(F("."));
186
+#ifdef FEATURE_UI
187
+        ui_progress(UI_WIFI_CONNECTING);
188
+#endif // FEATURE_UI
165 189
     }
166 190
     debug.println(F("\nWiFi connected!"));
191
+#ifdef FEATURE_UI
192
+    ui_progress(UI_WIFI_CONNECTED);
193
+#endif // FEATURE_UI
167 194
 
168 195
 #endif
169 196
 
@@ -183,7 +210,7 @@ void setup() {
183 210
 
184 211
 #ifdef FEATURE_UI
185 212
     debug.println(F("UI Go"));
186
-    ui_draw_menu();
213
+    ui_progress(UI_READY);
187 214
 #endif // FEATURE_UI
188 215
 }
189 216
 

+ 52
- 16
src/ui.cpp Visa fil

@@ -57,15 +57,15 @@ static TFT_eSPI tft = TFT_eSPI();
57 57
 
58 58
 struct ui_status ui_status = {0};
59 59
 
60
-enum ui_states {
61
-    UI_INIT = 0,
60
+enum ui_pages {
61
+    UI_START = 0,
62 62
     UI_LIVINGROOM1,
63 63
     UI_LIVINGROOM2,
64 64
 
65
-    UI_NUM_STATES
65
+    UI_NUM_PAGES
66 66
 };
67 67
 
68
-static enum ui_states ui_state = UI_INIT;
68
+static enum ui_pages ui_page = UI_START;
69 69
 
70 70
 static TS_Point touchToScreen(TS_Point p) {
71 71
     p.x = map(p.x, TOUCH_LEFT, TOUCH_RIGHT, 0, LCD_WIDTH);
@@ -115,20 +115,56 @@ void ui_init(void) {
115 115
     ledcAttachPin(TFT_BL, LEDC_CHANNEL_0);
116 116
     ledcAnalogWrite(LEDC_CHANNEL_0, 255);
117 117
 
118
-    tft.fillScreen(TFT_BLACK);
118
+    ui_progress(UI_INIT);
119
+}
119 120
 
120
-    tft.setTextDatum(MC_DATUM); // middle center
121
-    tft.drawString("Initializing ESP-ENV", LCD_WIDTH / 2, LCD_HEIGHT / 2 - 16, 2);
122
-    tft.drawString("xythobuz.de", LCD_WIDTH / 2, LCD_HEIGHT / 2 + 16, 2);
121
+void ui_progress(enum ui_state state) {
122
+    int x = LCD_WIDTH / 2;
123
+    int y = LCD_HEIGHT / 2;
124
+    int fontSize = 2;
125
+
126
+    switch (state) {
127
+        case UI_INIT: {
128
+            tft.fillScreen(TFT_BLACK);
129
+            tft.setTextDatum(MC_DATUM); // middle center
130
+            tft.drawString("Initializing ESP-ENV", x, y - 32, fontSize);
131
+            tft.drawString("xythobuz.de", x, y, fontSize);
132
+        } break;
133
+
134
+        case UI_WIFI_CONNECT: {
135
+            tft.setTextDatum(MC_DATUM); // middle center
136
+            tft.drawString("Connecting to '" WIFI_SSID "'", x, y + 32, fontSize);
137
+        } break;
138
+
139
+        case UI_WIFI_CONNECTING: {
140
+            static int n = 0;
141
+            const char anim[] = { '\\', '|', '/', '-' };
142
+            n++;
143
+            if (n >= sizeof(anim)) {
144
+                n = 0;
145
+            }
146
+            char s[2] = { anim[n], '\0' };
147
+            tft.drawCentreString(s, x, y + 64, fontSize);
148
+        } break;
149
+
150
+        case UI_WIFI_CONNECTED: {
151
+            tft.setTextDatum(MC_DATUM); // middle center
152
+            tft.drawString("Connected!", x, y + 64, fontSize);
153
+        } break;
123 154
 
124
-    ui_state = UI_INIT;
155
+        case UI_READY: {
156
+            tft.fillScreen(TFT_BLACK);
157
+            tft.setTextDatum(MC_DATUM); // middle center
158
+            tft.drawString("Ready", x, y, fontSize);
159
+        } break;
160
+    }
125 161
 }
126 162
 
127 163
 void ui_draw_menu(void) {
128
-    switch (ui_state) {
129
-        case UI_INIT:
164
+    switch (ui_page) {
165
+        case UI_START:
130 166
             tft.fillScreen(TFT_BLACK);
131
-            ui_state = UI_LIVINGROOM1;
167
+            ui_page = UI_LIVINGROOM1;
132 168
             // fall-through
133 169
 
134 170
         case UI_LIVINGROOM1:
@@ -140,7 +176,7 @@ void ui_draw_menu(void) {
140 176
             break;
141 177
 
142 178
         default:
143
-            ui_state = UI_INIT;
179
+            ui_page = UI_START;
144 180
     }
145 181
 
146 182
     draw_button("Next...", BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP, BTNS_OFF_Y + BTN_H / 2 + (BTN_H + BTN_GAP) * 2, TFT_MAGENTA);
@@ -162,10 +198,10 @@ void ui_run(void) {
162 198
             // TODO should act on both TV lights (box and amp)
163 199
         } else if ((p.x >= BTNS_OFF_X + BTN_W + BTN_GAP) && (p.x <= BTNS_OFF_X + BTN_W + BTN_GAP + BTN_W) && (p.y >= (BTNS_OFF_Y + BTN_H * 2 + BTN_GAP * 2)) && (p.y <= (BTNS_OFF_Y + BTN_H * 2 + BTN_GAP * 2 + BTN_H))) {
164 200
             // switch to next page
165
-            ui_state = (enum ui_states)((ui_state + 1) % UI_NUM_STATES);
166
-            if (ui_state == UI_INIT) {
201
+            ui_page = (enum ui_pages)((ui_page + 1) % UI_NUM_PAGES);
202
+            if (ui_page == UI_START) {
167 203
                 // skip init screen
168
-                ui_state = (enum ui_states)((ui_state + 1) % UI_NUM_STATES);
204
+                ui_page = (enum ui_pages)((ui_page + 1) % UI_NUM_PAGES);
169 205
             }
170 206
             tft.fillScreen(TFT_BLACK);
171 207
         }

Laddar…
Avbryt
Spara