Browse Source

add pc displays to ui

Thomas Buck 5 months ago
parent
commit
f587c66e75
3 changed files with 22 additions and 2 deletions
  1. 1
    0
      include/ui.h
  2. 8
    0
      src/mqtt.cpp
  3. 13
    2
      src/ui.cpp

+ 1
- 0
include/ui.h View File

@@ -32,6 +32,7 @@ struct ui_status {
32 32
     bool light_box;
33 33
     enum bathroom_light_states bathroom_lights;
34 34
     bool light_sink;
35
+    bool pc_displays;
35 36
 };
36 37
 
37 38
 extern struct ui_status ui_status;

+ 8
- 0
src/mqtt.cpp View File

@@ -178,6 +178,10 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
178 178
         ui_status.light_sink = state ? true : false;
179 179
         prev_status.light_sink = ui_status.light_sink;
180 180
         ui_progress(UI_UPDATE);
181
+    } else if (ts == "livingroom/displays/cmnd/POWER") {
182
+        ui_status.pc_displays = state ? true : false;
183
+        prev_status.pc_displays = ui_status.pc_displays;
184
+        ui_progress(UI_UPDATE);
181 185
     }
182 186
 #endif // FEATURE_UI
183 187
 
@@ -252,6 +256,7 @@ static void mqttReconnect() {
252 256
         mqtt.subscribe("livingroom/amp/cmnd/POWER");
253 257
         mqtt.subscribe("bathroom/force_light");
254 258
         mqtt.subscribe("livingroom/light_sink/cmnd/POWER");
259
+        mqtt.subscribe("livingroom/displays/cmnd/POWER");
255 260
 #endif // FEATURE_UI
256 261
     }
257 262
 }
@@ -329,6 +334,9 @@ void writeMQTT_UI(void) {
329 334
     if (curr_status.light_sink != prev_status.light_sink) {
330 335
         mqttPublish("livingroom/light_sink/cmnd/POWER", curr_status.light_sink ? "on" : "off", true);
331 336
     }
337
+    if (curr_status.pc_displays != prev_status.pc_displays) {
338
+        mqttPublish("livingroom/displays/cmnd/POWER", curr_status.pc_displays ? "on" : "off", true);
339
+    }
332 340
 
333 341
     prev_status = curr_status;
334 342
 }

+ 13
- 2
src/ui.cpp View File

@@ -154,7 +154,7 @@ static void draw_livingroom1(void) {
154 154
     // 5
155 155
     bool on = ui_status.light_corner || ui_status.light_sink || ui_status.light_workspace
156 156
             || ui_status.light_amp || ui_status.light_bench || ui_status.light_box
157
-            || ui_status.light_kitchen || ui_status.light_pc;
157
+            || ui_status.light_kitchen || ui_status.light_pc || ui_status.pc_displays;
158 158
     draw_button(on ? "All Lights Off" : "Wake Up Lights",
159 159
                 BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP,
160 160
                 BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP,
@@ -206,6 +206,13 @@ static void draw_bathroom(void) {
206 206
                 BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP,
207 207
                 ui_status.bathroom_lights == BATH_LIGHT_BIG ? TFT_GREEN : TFT_RED);
208 208
 
209
+    // 3
210
+    // TODO own page?
211
+    draw_button("PC Displays",
212
+                BTNS_OFF_X + BTN_W / 2,
213
+                BTNS_OFF_Y + BTN_H / 2 + (BTN_H + BTN_GAP) * 2,
214
+                ui_status.pc_displays ? TFT_GREEN : TFT_RED);
215
+
209 216
     // 4
210 217
     draw_button("Bath Lights Off",
211 218
                 BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP,
@@ -585,6 +592,8 @@ void ui_run(void) {
585 592
                 INVERT_BOOL(ui_status.light_sink);
586 593
             } else if (ui_page == UI_LIVINGROOM2) {
587 594
                 INVERT_BOOL(ui_status.light_kitchen);
595
+            } else if (ui_page == UI_BATHROOM) {
596
+                INVERT_BOOL(ui_status.pc_displays);
588 597
             }
589 598
             writeMQTT_UI();
590 599
         } 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)) {
@@ -602,7 +611,7 @@ void ui_run(void) {
602 611
             if (ui_page == UI_LIVINGROOM1) {
603 612
                 bool on = ui_status.light_corner || ui_status.light_sink || ui_status.light_workspace
604 613
                         || ui_status.light_amp || ui_status.light_bench || ui_status.light_box
605
-                        || ui_status.light_kitchen || ui_status.light_pc;
614
+                        || ui_status.light_kitchen || ui_status.light_pc || ui_status.pc_displays;
606 615
                 if (on) {
607 616
                     ui_status.light_amp = false;
608 617
                     ui_status.light_kitchen = false;
@@ -612,9 +621,11 @@ void ui_run(void) {
612 621
                     ui_status.light_corner = false;
613 622
                     ui_status.light_box = false;
614 623
                     ui_status.light_sink = false;
624
+                    ui_status.pc_displays = false;
615 625
                 } else {
616 626
                     ui_status.light_corner = true;
617 627
                     ui_status.light_sink = true;
628
+                    ui_status.pc_displays = true;
618 629
                 }
619 630
             } else if (ui_page == UI_LIVINGROOM2) {
620 631
                 INVERT_BOOL(ui_status.light_box);

Loading…
Cancel
Save