Explorar el Código

add ui for bathroom lights

Thomas Buck hace 11 meses
padre
commit
dac8960c39
Se han modificado 3 ficheros con 78 adiciones y 0 borrados
  1. 8
    0
      include/ui.h
  2. 31
    0
      src/mqtt.cpp
  3. 39
    0
      src/ui.cpp

+ 8
- 0
include/ui.h Ver fichero

14
 #ifndef __UI_H__
14
 #ifndef __UI_H__
15
 #define __UI_H__
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
 struct ui_status {
24
 struct ui_status {
18
     bool light_corner;
25
     bool light_corner;
19
     bool light_workspace;
26
     bool light_workspace;
23
     bool light_pc;
30
     bool light_pc;
24
     bool light_amp;
31
     bool light_amp;
25
     bool light_box;
32
     bool light_box;
33
+    enum bathroom_light_states bathroom_lights;
26
 };
34
 };
27
 
35
 
28
 extern struct ui_status ui_status;
36
 extern struct ui_status ui_status;

+ 31
- 0
src/mqtt.cpp Ver fichero

110
         state = 1;
110
         state = 1;
111
     } else if (ps.indexOf("off") != -1) {
111
     } else if (ps.indexOf("off") != -1) {
112
         state = 0;
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
     } else {
119
     } else {
114
         return;
120
         return;
115
     }
121
     }
179
     } else if (ts == "livingroom/amp/cmnd/POWER") {
185
     } else if (ts == "livingroom/amp/cmnd/POWER") {
180
         ui_status.sound_amplifier = state ? true : false;
186
         ui_status.sound_amplifier = state ? true : false;
181
         ui_progress(UI_UPDATE);
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
 #endif // FEATURE_UI
202
 #endif // FEATURE_UI
184
 }
203
 }
213
         mqtt.subscribe("livingroom/light_corner/cmnd/POWER");
232
         mqtt.subscribe("livingroom/light_corner/cmnd/POWER");
214
         mqtt.subscribe("livingroom/workbench/cmnd/POWER");
233
         mqtt.subscribe("livingroom/workbench/cmnd/POWER");
215
         mqtt.subscribe("livingroom/amp/cmnd/POWER");
234
         mqtt.subscribe("livingroom/amp/cmnd/POWER");
235
+        mqtt.subscribe("bathroom/force_light");
216
 #endif // FEATURE_UI
236
 #endif // FEATURE_UI
217
     }
237
     }
218
 }
238
 }
277
     if (curr_status.sound_amplifier != prev_status.sound_amplifier) {
297
     if (curr_status.sound_amplifier != prev_status.sound_amplifier) {
278
         mqttPublish("livingroom/amp/cmnd/POWER", curr_status.sound_amplifier ? "on" : "off", true);
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
     prev_status = curr_status;
312
     prev_status = curr_status;
282
 }
313
 }

+ 39
- 0
src/ui.cpp Ver fichero

61
     UI_START = 0,
61
     UI_START = 0,
62
     UI_LIVINGROOM1,
62
     UI_LIVINGROOM1,
63
     UI_LIVINGROOM2,
63
     UI_LIVINGROOM2,
64
+    UI_BATHROOM,
64
 
65
 
65
     UI_NUM_PAGES
66
     UI_NUM_PAGES
66
 };
67
 };
143
                 ui_status.light_box ? TFT_GREEN : TFT_RED);
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
 void ui_init(void) {
173
 void ui_init(void) {
147
     mySpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
174
     mySpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
148
     ts.begin(mySpi);
175
     ts.begin(mySpi);
173
             draw_livingroom2();
200
             draw_livingroom2();
174
             break;
201
             break;
175
 
202
 
203
+        case UI_BATHROOM:
204
+            draw_bathroom();
205
+            break;
206
+
176
         default:
207
         default:
177
             ui_page = UI_START;
208
             ui_page = UI_START;
178
             ui_draw_menu();
209
             ui_draw_menu();
237
                 INVERT_BOOL(ui_status.light_corner);
268
                 INVERT_BOOL(ui_status.light_corner);
238
             } else if (ui_page == UI_LIVINGROOM2) {
269
             } else if (ui_page == UI_LIVINGROOM2) {
239
                 INVERT_BOOL(ui_status.light_pc);
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
             writeMQTT_UI();
274
             writeMQTT_UI();
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))) {
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
                 INVERT_BOOL(ui_status.light_workspace);
278
                 INVERT_BOOL(ui_status.light_workspace);
246
             } else if (ui_page == UI_LIVINGROOM2) {
279
             } else if (ui_page == UI_LIVINGROOM2) {
247
                 INVERT_BOOL(ui_status.light_bench);
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
             writeMQTT_UI();
284
             writeMQTT_UI();
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))) {
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
                 INVERT_BOOL(ui_status.sound_amplifier);
294
                 INVERT_BOOL(ui_status.sound_amplifier);
260
             } else if (ui_page == UI_LIVINGROOM2) {
295
             } else if (ui_page == UI_LIVINGROOM2) {
261
                 INVERT_BOOL(ui_status.light_amp);
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
             writeMQTT_UI();
300
             writeMQTT_UI();
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))) {
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
                 ui_status.light_box = false;
310
                 ui_status.light_box = false;
274
             } else if (ui_page == UI_LIVINGROOM2) {
311
             } else if (ui_page == UI_LIVINGROOM2) {
275
                 INVERT_BOOL(ui_status.light_box);
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
             writeMQTT_UI();
316
             writeMQTT_UI();
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))) {
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))) {

Loading…
Cancelar
Guardar