|
@@ -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
|
}
|