ソースを参照

add ui for bathroom lights

Thomas Buck 5ヶ月前
コミット
dac8960c39
3個のファイルの変更78行の追加0行の削除
  1. 8
    0
      include/ui.h
  2. 31
    0
      src/mqtt.cpp
  3. 39
    0
      src/ui.cpp

+ 8
- 0
include/ui.h ファイルの表示

@@ -14,6 +14,13 @@
14 14
 #ifndef __UI_H__
15 15
 #define __UI_H__
16 16
 
17
+enum bathroom_light_states {
18
+    BATH_LIGHT_OFF,
19
+    BATH_LIGHT_NONE,
20
+    BATH_LIGHT_BIG,
21
+    BATH_LIGHT_SMALL,
22
+};
23
+
17 24
 struct ui_status {
18 25
     bool light_corner;
19 26
     bool light_workspace;
@@ -23,6 +30,7 @@ struct ui_status {
23 30
     bool light_pc;
24 31
     bool light_amp;
25 32
     bool light_box;
33
+    enum bathroom_light_states bathroom_lights;
26 34
 };
27 35
 
28 36
 extern struct ui_status ui_status;

+ 31
- 0
src/mqtt.cpp ファイルの表示

@@ -110,6 +110,12 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
110 110
         state = 1;
111 111
     } else if (ps.indexOf("off") != -1) {
112 112
         state = 0;
113
+    } else if (ps.indexOf("big") != -1) {
114
+        state = 3;
115
+    } else if (ps.indexOf("small") != -1) {
116
+        state = 2;
117
+    } else if (ps.indexOf("none") != -1) {
118
+        state = 4;
113 119
     } else {
114 120
         return;
115 121
     }
@@ -179,6 +185,19 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
179 185
     } else if (ts == "livingroom/amp/cmnd/POWER") {
180 186
         ui_status.sound_amplifier = state ? true : false;
181 187
         ui_progress(UI_UPDATE);
188
+    } else if (ts == "bathroom/force_light") {
189
+        if (state == 0) {
190
+            ui_status.bathroom_lights = BATH_LIGHT_OFF;
191
+        } else if (state == 1) {
192
+            ui_status.bathroom_lights = BATH_LIGHT_NONE;
193
+        } else if (state == 2) {
194
+            ui_status.bathroom_lights = BATH_LIGHT_SMALL;
195
+        } else if (state == 3) {
196
+            ui_status.bathroom_lights = BATH_LIGHT_BIG;
197
+        } else if (state == 4) {
198
+            ui_status.bathroom_lights = BATH_LIGHT_NONE;
199
+        }
200
+        ui_progress(UI_UPDATE);
182 201
     }
183 202
 #endif // FEATURE_UI
184 203
 }
@@ -213,6 +232,7 @@ static void mqttReconnect() {
213 232
         mqtt.subscribe("livingroom/light_corner/cmnd/POWER");
214 233
         mqtt.subscribe("livingroom/workbench/cmnd/POWER");
215 234
         mqtt.subscribe("livingroom/amp/cmnd/POWER");
235
+        mqtt.subscribe("bathroom/force_light");
216 236
 #endif // FEATURE_UI
217 237
     }
218 238
 }
@@ -277,6 +297,17 @@ void writeMQTT_UI(void) {
277 297
     if (curr_status.sound_amplifier != prev_status.sound_amplifier) {
278 298
         mqttPublish("livingroom/amp/cmnd/POWER", curr_status.sound_amplifier ? "on" : "off", true);
279 299
     }
300
+    if (curr_status.bathroom_lights != prev_status.bathroom_lights) {
301
+        if (curr_status.bathroom_lights == BATH_LIGHT_BIG) {
302
+            mqttPublish("bathroom/force_light", "big", true);
303
+        } else if (curr_status.bathroom_lights == BATH_LIGHT_SMALL) {
304
+            mqttPublish("bathroom/force_light", "small", true);
305
+        } else if (curr_status.bathroom_lights == BATH_LIGHT_OFF) {
306
+            mqttPublish("bathroom/force_light", "off", true);
307
+        } else {
308
+            mqttPublish("bathroom/force_light", "none", true);
309
+        }
310
+    }
280 311
 
281 312
     prev_status = curr_status;
282 313
 }

+ 39
- 0
src/ui.cpp ファイルの表示

@@ -61,6 +61,7 @@ enum ui_pages {
61 61
     UI_START = 0,
62 62
     UI_LIVINGROOM1,
63 63
     UI_LIVINGROOM2,
64
+    UI_BATHROOM,
64 65
 
65 66
     UI_NUM_PAGES
66 67
 };
@@ -143,6 +144,32 @@ static void draw_livingroom2(void) {
143 144
                 ui_status.light_box ? TFT_GREEN : TFT_RED);
144 145
 }
145 146
 
147
+static void draw_bathroom(void) {
148
+    // 1
149
+    draw_button("Bath Lights Auto",
150
+                BTNS_OFF_X + BTN_W / 2,
151
+                BTNS_OFF_Y + BTN_H / 2,
152
+                ui_status.bathroom_lights == BATH_LIGHT_NONE ? TFT_GREEN : TFT_RED);
153
+
154
+    // 2
155
+    draw_button("Bath Lights Big",
156
+                BTNS_OFF_X + BTN_W / 2,
157
+                BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP,
158
+                ui_status.bathroom_lights == BATH_LIGHT_BIG ? TFT_GREEN : TFT_RED);
159
+
160
+    // 4
161
+    draw_button("Bath Lights Off",
162
+                BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP,
163
+                BTNS_OFF_Y + BTN_H / 2,
164
+                ui_status.bathroom_lights == BATH_LIGHT_OFF ? TFT_GREEN : TFT_RED);
165
+
166
+    // 5
167
+    draw_button("Bath Lights Small",
168
+                BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP,
169
+                BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP,
170
+                ui_status.bathroom_lights == BATH_LIGHT_SMALL ? TFT_GREEN : TFT_RED);
171
+}
172
+
146 173
 void ui_init(void) {
147 174
     mySpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
148 175
     ts.begin(mySpi);
@@ -173,6 +200,10 @@ static void ui_draw_menu(void) {
173 200
             draw_livingroom2();
174 201
             break;
175 202
 
203
+        case UI_BATHROOM:
204
+            draw_bathroom();
205
+            break;
206
+
176 207
         default:
177 208
             ui_page = UI_START;
178 209
             ui_draw_menu();
@@ -237,6 +268,8 @@ void ui_run(void) {
237 268
                 INVERT_BOOL(ui_status.light_corner);
238 269
             } else if (ui_page == UI_LIVINGROOM2) {
239 270
                 INVERT_BOOL(ui_status.light_pc);
271
+            } else if (ui_page == UI_BATHROOM) {
272
+                ui_status.bathroom_lights = BATH_LIGHT_NONE;
240 273
             }
241 274
             writeMQTT_UI();
242 275
         } 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))) {
@@ -245,6 +278,8 @@ void ui_run(void) {
245 278
                 INVERT_BOOL(ui_status.light_workspace);
246 279
             } else if (ui_page == UI_LIVINGROOM2) {
247 280
                 INVERT_BOOL(ui_status.light_bench);
281
+            } else if (ui_page == UI_BATHROOM) {
282
+                ui_status.bathroom_lights = BATH_LIGHT_BIG;
248 283
             }
249 284
             writeMQTT_UI();
250 285
         } 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))) {
@@ -259,6 +294,8 @@ void ui_run(void) {
259 294
                 INVERT_BOOL(ui_status.sound_amplifier);
260 295
             } else if (ui_page == UI_LIVINGROOM2) {
261 296
                 INVERT_BOOL(ui_status.light_amp);
297
+            } else if (ui_page == UI_BATHROOM) {
298
+                ui_status.bathroom_lights = BATH_LIGHT_OFF;
262 299
             }
263 300
             writeMQTT_UI();
264 301
         } 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))) {
@@ -273,6 +310,8 @@ void ui_run(void) {
273 310
                 ui_status.light_box = false;
274 311
             } else if (ui_page == UI_LIVINGROOM2) {
275 312
                 INVERT_BOOL(ui_status.light_box);
313
+            } else if (ui_page == UI_BATHROOM) {
314
+                ui_status.bathroom_lights = BATH_LIGHT_SMALL;
276 315
             }
277 316
             writeMQTT_UI();
278 317
         } 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))) {

読み込み中…
キャンセル
保存