Browse Source

stashed changes: show connection info on display at start

Thomas Buck 1 month ago
parent
commit
52792b4bed
4 changed files with 91 additions and 17 deletions
  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 View File

27
 
27
 
28
 extern struct ui_status ui_status;
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
 void ui_init(void);
38
 void ui_init(void);
31
 void ui_draw_menu(void);
39
 void ui_draw_menu(void);
32
 void ui_run(void);
40
 void ui_run(void);
33
 
41
 
42
+void ui_progress(enum ui_state state);
43
+
34
 #endif // __UI_H__
44
 #endif // __UI_H__

+ 1
- 0
platformio.ini View File

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

+ 28
- 1
src/main.cpp View File

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

+ 52
- 16
src/ui.cpp View File

57
 
57
 
58
 struct ui_status ui_status = {0};
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
     UI_LIVINGROOM1,
62
     UI_LIVINGROOM1,
63
     UI_LIVINGROOM2,
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
 static TS_Point touchToScreen(TS_Point p) {
70
 static TS_Point touchToScreen(TS_Point p) {
71
     p.x = map(p.x, TOUCH_LEFT, TOUCH_RIGHT, 0, LCD_WIDTH);
71
     p.x = map(p.x, TOUCH_LEFT, TOUCH_RIGHT, 0, LCD_WIDTH);
115
     ledcAttachPin(TFT_BL, LEDC_CHANNEL_0);
115
     ledcAttachPin(TFT_BL, LEDC_CHANNEL_0);
116
     ledcAnalogWrite(LEDC_CHANNEL_0, 255);
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
 void ui_draw_menu(void) {
163
 void ui_draw_menu(void) {
128
-    switch (ui_state) {
129
-        case UI_INIT:
164
+    switch (ui_page) {
165
+        case UI_START:
130
             tft.fillScreen(TFT_BLACK);
166
             tft.fillScreen(TFT_BLACK);
131
-            ui_state = UI_LIVINGROOM1;
167
+            ui_page = UI_LIVINGROOM1;
132
             // fall-through
168
             // fall-through
133
 
169
 
134
         case UI_LIVINGROOM1:
170
         case UI_LIVINGROOM1:
140
             break;
176
             break;
141
 
177
 
142
         default:
178
         default:
143
-            ui_state = UI_INIT;
179
+            ui_page = UI_START;
144
     }
180
     }
145
 
181
 
146
     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);
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
             // TODO should act on both TV lights (box and amp)
198
             // TODO should act on both TV lights (box and amp)
163
         } 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))) {
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
             // switch to next page
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
                 // skip init screen
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
             tft.fillScreen(TFT_BLACK);
206
             tft.fillScreen(TFT_BLACK);
171
         }
207
         }

Loading…
Cancel
Save