|
@@ -36,6 +36,8 @@
|
36
|
36
|
#define LEDC_TIMER_12_BIT 12
|
37
|
37
|
#define LEDC_BASE_FREQ 5000
|
38
|
38
|
|
|
39
|
+#define LDR_PIN 34
|
|
40
|
+
|
39
|
41
|
#define TOUCH_LEFT 180
|
40
|
42
|
#define TOUCH_RIGHT 3750
|
41
|
43
|
|
|
@@ -51,6 +53,8 @@
|
51
|
53
|
|
52
|
54
|
#define INVERT_BOOL(x) (x) = !(x);
|
53
|
55
|
|
|
56
|
+#define LDR_CHECK_MS 1000
|
|
57
|
+
|
54
|
58
|
static SPIClass mySpi = SPIClass(HSPI);
|
55
|
59
|
static XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);
|
56
|
60
|
static TFT_eSPI tft = TFT_eSPI();
|
|
@@ -62,12 +66,15 @@ enum ui_pages {
|
62
|
66
|
UI_LIVINGROOM1,
|
63
|
67
|
UI_LIVINGROOM2,
|
64
|
68
|
UI_BATHROOM,
|
|
69
|
+ UI_INFO,
|
65
|
70
|
|
66
|
71
|
UI_NUM_PAGES
|
67
|
72
|
};
|
68
|
73
|
|
69
|
74
|
static enum ui_pages ui_page = UI_START;
|
70
|
75
|
static bool is_touched = false;
|
|
76
|
+static unsigned long last_ldr = 0;
|
|
77
|
+static int ldr_value = 0;
|
71
|
78
|
|
72
|
79
|
static TS_Point touchToScreen(TS_Point p) {
|
73
|
80
|
p.x = map(p.x, TOUCH_LEFT, TOUCH_RIGHT, 0, LCD_WIDTH);
|
|
@@ -171,6 +178,22 @@ static void draw_bathroom(void) {
|
171
|
178
|
ui_status.bathroom_lights == BATH_LIGHT_SMALL ? TFT_GREEN : TFT_RED);
|
172
|
179
|
}
|
173
|
180
|
|
|
181
|
+static void draw_info(void) {
|
|
182
|
+ tft.fillScreen(TFT_BLACK);
|
|
183
|
+
|
|
184
|
+ tft.setTextDatum(TC_DATUM); // top center
|
|
185
|
+ tft.drawString(ESP_PLATFORM_NAME " " NAME_OF_FEATURE " V" ESP_ENV_VERSION, LCD_WIDTH / 2, 0, 2);
|
|
186
|
+ tft.drawString("by xythobuz.de", LCD_WIDTH / 2, 16, 2);
|
|
187
|
+
|
|
188
|
+ tft.setTextDatum(TL_DATUM); // top left
|
|
189
|
+ tft.drawString("Build Date: " __DATE__, 0, 40 + 16 * 0, 1);
|
|
190
|
+ tft.drawString("Build Time: " __TIME__, 0, 40 + 16 * 1, 1);
|
|
191
|
+ tft.drawString("Location: " SENSOR_LOCATION, 0, 40 + 16 * 2, 1);
|
|
192
|
+ tft.drawString("ID: " SENSOR_ID, 0, 40 + 16 * 3, 1);
|
|
193
|
+
|
|
194
|
+ tft.drawString("LDR: " + String(ldr_value), 0, 40 + 16 * 5, 1);
|
|
195
|
+}
|
|
196
|
+
|
174
|
197
|
void ui_init(void) {
|
175
|
198
|
mySpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
|
176
|
199
|
ts.begin(mySpi);
|
|
@@ -183,6 +206,12 @@ void ui_init(void) {
|
183
|
206
|
ledcAttachPin(TFT_BL, LEDC_CHANNEL_0);
|
184
|
207
|
ledcAnalogWrite(LEDC_CHANNEL_0, 255);
|
185
|
208
|
|
|
209
|
+ pinMode(LDR_PIN, ANALOG);
|
|
210
|
+ analogSetAttenuation(ADC_0db);
|
|
211
|
+ analogReadResolution(12);
|
|
212
|
+ analogSetPinAttenuation(LDR_PIN, ADC_0db);
|
|
213
|
+ ldr_value = analogRead(LDR_PIN);
|
|
214
|
+
|
186
|
215
|
ui_progress(UI_INIT);
|
187
|
216
|
}
|
188
|
217
|
|
|
@@ -205,6 +234,10 @@ static void ui_draw_menu(void) {
|
205
|
234
|
draw_bathroom();
|
206
|
235
|
break;
|
207
|
236
|
|
|
237
|
+ case UI_INFO:
|
|
238
|
+ draw_info();
|
|
239
|
+ return; // no next button
|
|
240
|
+
|
208
|
241
|
default:
|
209
|
242
|
ui_page = UI_START;
|
210
|
243
|
ui_draw_menu();
|
|
@@ -260,11 +293,44 @@ void ui_progress(enum ui_state state) {
|
260
|
293
|
}
|
261
|
294
|
|
262
|
295
|
void ui_run(void) {
|
|
296
|
+ unsigned long now = millis();
|
|
297
|
+ if (now >= (last_ldr + LDR_CHECK_MS)) {
|
|
298
|
+ last_ldr = now;
|
|
299
|
+ int ldr = analogRead(LDR_PIN);
|
|
300
|
+ //ldr_value = (ldr_value * 0.9f) + (ldr * 0.1f);
|
|
301
|
+ ldr_value = ldr;
|
|
302
|
+ if (ui_page == UI_INFO) {
|
|
303
|
+ ui_draw_menu();
|
|
304
|
+ }
|
|
305
|
+ }
|
|
306
|
+
|
263
|
307
|
bool touched = ts.tirqTouched() && ts.touched();
|
|
308
|
+ TS_Point p;
|
|
309
|
+
|
|
310
|
+ if (touched) {
|
|
311
|
+ p = touchToScreen(ts.getPoint());
|
|
312
|
+
|
|
313
|
+ // minimum pressure
|
|
314
|
+ if (p.z < 100) {
|
|
315
|
+ touched = false;
|
|
316
|
+ }
|
|
317
|
+ }
|
264
|
318
|
|
265
|
319
|
if (touched && (!is_touched)) {
|
266
|
320
|
is_touched = true;
|
267
|
|
- TS_Point p = touchToScreen(ts.getPoint());
|
|
321
|
+
|
|
322
|
+ if (ui_page == UI_INFO) {
|
|
323
|
+ // switch to next page
|
|
324
|
+ ui_page = (enum ui_pages)((ui_page + 1) % UI_NUM_PAGES);
|
|
325
|
+ if (ui_page == UI_START) {
|
|
326
|
+ // skip init screen
|
|
327
|
+ ui_page = (enum ui_pages)((ui_page + 1) % UI_NUM_PAGES);
|
|
328
|
+ }
|
|
329
|
+ tft.fillScreen(TFT_BLACK);
|
|
330
|
+
|
|
331
|
+ ui_draw_menu();
|
|
332
|
+ return;
|
|
333
|
+ }
|
268
|
334
|
|
269
|
335
|
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)) {
|
270
|
336
|
// 1
|