|
@@ -86,21 +86,61 @@ static void draw_button(const char *name, uint32_t x, uint32_t y, uint32_t color
|
86
|
86
|
}
|
87
|
87
|
|
88
|
88
|
static void draw_livingroom1(void) {
|
89
|
|
- draw_button("Lights Corner", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2, ui_status.light_corner ? TFT_GREEN : TFT_RED);
|
90
|
|
- draw_button("Lights Workspace", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP, ui_status.light_workspace ? TFT_GREEN : TFT_RED);
|
91
|
|
- draw_button("Lights Kitchen", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2 + (BTN_H + BTN_GAP) * 2, ui_status.light_kitchen ? TFT_GREEN : TFT_RED);
|
92
|
|
-
|
93
|
|
- draw_button("Sound Amp.", BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP, BTNS_OFF_Y + BTN_H / 2, ui_status.sound_amplifier ? TFT_GREEN : TFT_RED);
|
94
|
|
- draw_button("All Lights Off", BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP, BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP, TFT_RED);
|
|
89
|
+ // 1
|
|
90
|
+ draw_button("Lights Corner",
|
|
91
|
+ BTNS_OFF_X + BTN_W / 2,
|
|
92
|
+ BTNS_OFF_Y + BTN_H / 2,
|
|
93
|
+ ui_status.light_corner ? TFT_GREEN : TFT_RED);
|
|
94
|
+
|
|
95
|
+ // 2
|
|
96
|
+ draw_button("Lights Workspace",
|
|
97
|
+ BTNS_OFF_X + BTN_W / 2,
|
|
98
|
+ BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP,
|
|
99
|
+ ui_status.light_workspace ? TFT_GREEN : TFT_RED);
|
|
100
|
+
|
|
101
|
+ // 3
|
|
102
|
+ draw_button("Lights Kitchen",
|
|
103
|
+ BTNS_OFF_X + BTN_W / 2,
|
|
104
|
+ BTNS_OFF_Y + BTN_H / 2 + (BTN_H + BTN_GAP) * 2,
|
|
105
|
+ ui_status.light_kitchen ? TFT_GREEN : TFT_RED);
|
|
106
|
+
|
|
107
|
+ // 4
|
|
108
|
+ draw_button("Sound Amp.",
|
|
109
|
+ BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP,
|
|
110
|
+ BTNS_OFF_Y + BTN_H / 2,
|
|
111
|
+ ui_status.sound_amplifier ? TFT_GREEN : TFT_RED);
|
|
112
|
+
|
|
113
|
+ // 5
|
|
114
|
+ draw_button("All Lights Off",
|
|
115
|
+ BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP,
|
|
116
|
+ BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP,
|
|
117
|
+ TFT_MAGENTA);
|
95
|
118
|
}
|
96
|
119
|
|
97
|
120
|
static void draw_livingroom2(void) {
|
98
|
|
- draw_button("Lights PC", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2, ui_status.light_corner ? TFT_GREEN : TFT_RED);
|
99
|
|
- draw_button("Lights Bench", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP, ui_status.light_workspace ? TFT_GREEN : TFT_RED);
|
100
|
|
- //draw_button("Lights Amp.", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2 + (BTN_H + BTN_GAP) * 2, ui_status.light_kitchen ? TFT_GREEN : TFT_RED);
|
101
|
|
-
|
102
|
|
- draw_button("Lights Amp.", BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP, BTNS_OFF_Y + BTN_H / 2, ui_status.sound_amplifier ? TFT_GREEN : TFT_RED);
|
103
|
|
- draw_button("Lights Box", BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP, BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP, TFT_RED); // TODO both
|
|
121
|
+ // 1
|
|
122
|
+ draw_button("Lights PC",
|
|
123
|
+ BTNS_OFF_X + BTN_W / 2,
|
|
124
|
+ BTNS_OFF_Y + BTN_H / 2,
|
|
125
|
+ ui_status.light_pc ? TFT_GREEN : TFT_RED);
|
|
126
|
+
|
|
127
|
+ // 2
|
|
128
|
+ draw_button("Lights Bench",
|
|
129
|
+ BTNS_OFF_X + BTN_W / 2,
|
|
130
|
+ BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP,
|
|
131
|
+ ui_status.light_bench ? TFT_GREEN : TFT_RED);
|
|
132
|
+
|
|
133
|
+ // 4
|
|
134
|
+ draw_button("Lights Amp.",
|
|
135
|
+ BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP,
|
|
136
|
+ BTNS_OFF_Y + BTN_H / 2,
|
|
137
|
+ ui_status.light_amp ? TFT_GREEN : TFT_RED);
|
|
138
|
+
|
|
139
|
+ // 5
|
|
140
|
+ draw_button("Lights Box",
|
|
141
|
+ BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP,
|
|
142
|
+ BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP,
|
|
143
|
+ ui_status.light_box ? TFT_GREEN : TFT_RED);
|
104
|
144
|
}
|
105
|
145
|
|
106
|
146
|
void ui_init(void) {
|
|
@@ -118,6 +158,30 @@ void ui_init(void) {
|
118
|
158
|
ui_progress(UI_INIT);
|
119
|
159
|
}
|
120
|
160
|
|
|
161
|
+static void ui_draw_menu(void) {
|
|
162
|
+ switch (ui_page) {
|
|
163
|
+ case UI_START:
|
|
164
|
+ tft.fillScreen(TFT_BLACK);
|
|
165
|
+ ui_page = UI_LIVINGROOM1;
|
|
166
|
+ // fall-through
|
|
167
|
+
|
|
168
|
+ case UI_LIVINGROOM1:
|
|
169
|
+ draw_livingroom1();
|
|
170
|
+ break;
|
|
171
|
+
|
|
172
|
+ case UI_LIVINGROOM2:
|
|
173
|
+ draw_livingroom2();
|
|
174
|
+ break;
|
|
175
|
+
|
|
176
|
+ default:
|
|
177
|
+ ui_page = UI_START;
|
|
178
|
+ ui_draw_menu();
|
|
179
|
+ return;
|
|
180
|
+ }
|
|
181
|
+
|
|
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_CYAN);
|
|
183
|
+}
|
|
184
|
+
|
121
|
185
|
void ui_progress(enum ui_state state) {
|
122
|
186
|
int x = LCD_WIDTH / 2;
|
123
|
187
|
int y = LCD_HEIGHT / 2;
|
|
@@ -153,33 +217,14 @@ void ui_progress(enum ui_state state) {
|
153
|
217
|
} break;
|
154
|
218
|
|
155
|
219
|
case UI_READY: {
|
156
|
|
- tft.fillScreen(TFT_BLACK);
|
157
|
|
- tft.setTextDatum(MC_DATUM); // middle center
|
158
|
|
- tft.drawString("Ready", x, y, fontSize);
|
|
220
|
+ ui_page = UI_START;
|
|
221
|
+ ui_draw_menu();
|
159
|
222
|
} break;
|
160
|
|
- }
|
161
|
|
-}
|
162
|
223
|
|
163
|
|
-void ui_draw_menu(void) {
|
164
|
|
- switch (ui_page) {
|
165
|
|
- case UI_START:
|
166
|
|
- tft.fillScreen(TFT_BLACK);
|
167
|
|
- ui_page = UI_LIVINGROOM1;
|
168
|
|
- // fall-through
|
169
|
|
-
|
170
|
|
- case UI_LIVINGROOM1:
|
171
|
|
- draw_livingroom1();
|
172
|
|
- break;
|
173
|
|
-
|
174
|
|
- case UI_LIVINGROOM2:
|
175
|
|
- draw_livingroom2();
|
176
|
|
- break;
|
177
|
|
-
|
178
|
|
- default:
|
179
|
|
- ui_page = UI_START;
|
|
224
|
+ case UI_UPDATE: {
|
|
225
|
+ ui_draw_menu();
|
|
226
|
+ } break;
|
180
|
227
|
}
|
181
|
|
-
|
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);
|
183
|
228
|
}
|
184
|
229
|
|
185
|
230
|
void ui_run(void) {
|
|
@@ -187,15 +232,49 @@ void ui_run(void) {
|
187
|
232
|
TS_Point p = touchToScreen(ts.getPoint());
|
188
|
233
|
|
189
|
234
|
if ((p.x >= BTNS_OFF_X) && (p.x <= BTNS_OFF_X + BTN_W) && (p.y >= BTNS_OFF_Y) && (p.y <= BTNS_OFF_Y + BTN_H)) {
|
190
|
|
- INVERT_BOOL(ui_status.light_corner);
|
|
235
|
+ // 1
|
|
236
|
+ if (ui_page == UI_LIVINGROOM1) {
|
|
237
|
+ INVERT_BOOL(ui_status.light_corner);
|
|
238
|
+ } else if (ui_page == UI_LIVINGROOM2) {
|
|
239
|
+ INVERT_BOOL(ui_status.light_pc);
|
|
240
|
+ }
|
|
241
|
+ writeMQTT_UI();
|
191
|
242
|
} else if ((p.x >= BTNS_OFF_X) && (p.x <= BTNS_OFF_X + BTN_W) && (p.y >= (BTNS_OFF_Y + BTN_H + BTN_GAP)) && (p.y <= (BTNS_OFF_Y + BTN_H + BTN_GAP + BTN_H))) {
|
192
|
|
- INVERT_BOOL(ui_status.light_workspace);
|
|
243
|
+ // 2
|
|
244
|
+ if (ui_page == UI_LIVINGROOM1) {
|
|
245
|
+ INVERT_BOOL(ui_status.light_workspace);
|
|
246
|
+ } else if (ui_page == UI_LIVINGROOM2) {
|
|
247
|
+ INVERT_BOOL(ui_status.light_bench);
|
|
248
|
+ }
|
|
249
|
+ writeMQTT_UI();
|
193
|
250
|
} else if ((p.x >= BTNS_OFF_X) && (p.x <= BTNS_OFF_X + 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))) {
|
194
|
|
- INVERT_BOOL(ui_status.light_kitchen);
|
|
251
|
+ // 3
|
|
252
|
+ if (ui_page == UI_LIVINGROOM1) {
|
|
253
|
+ INVERT_BOOL(ui_status.light_kitchen);
|
|
254
|
+ }
|
|
255
|
+ writeMQTT_UI();
|
195
|
256
|
} 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) && (p.y <= BTNS_OFF_Y + BTN_H)) {
|
196
|
|
- INVERT_BOOL(ui_status.sound_amplifier);
|
|
257
|
+ // 4
|
|
258
|
+ if (ui_page == UI_LIVINGROOM1) {
|
|
259
|
+ INVERT_BOOL(ui_status.sound_amplifier);
|
|
260
|
+ } else if (ui_page == UI_LIVINGROOM2) {
|
|
261
|
+ INVERT_BOOL(ui_status.light_amp);
|
|
262
|
+ }
|
|
263
|
+ writeMQTT_UI();
|
197
|
264
|
} 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 + BTN_GAP)) && (p.y <= (BTNS_OFF_Y + BTN_H + BTN_GAP + BTN_H))) {
|
198
|
|
- // TODO should act on both TV lights (box and amp)
|
|
265
|
+ // 5
|
|
266
|
+ if (ui_page == UI_LIVINGROOM1) {
|
|
267
|
+ ui_status.light_amp = false;
|
|
268
|
+ ui_status.light_kitchen = false;
|
|
269
|
+ ui_status.light_bench= false;
|
|
270
|
+ ui_status.light_workspace = false;
|
|
271
|
+ ui_status.light_pc = false;
|
|
272
|
+ ui_status.light_corner = false;
|
|
273
|
+ ui_status.light_box = false;
|
|
274
|
+ } else if (ui_page == UI_LIVINGROOM2) {
|
|
275
|
+ INVERT_BOOL(ui_status.light_box);
|
|
276
|
+ }
|
|
277
|
+ writeMQTT_UI();
|
199
|
278
|
} 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))) {
|
200
|
279
|
// switch to next page
|
201
|
280
|
ui_page = (enum ui_pages)((ui_page + 1) % UI_NUM_PAGES);
|