|
@@ -42,11 +42,31 @@
|
42
|
42
|
#define TOUCH_TOP 230
|
43
|
43
|
#define TOUCH_BOTTOM 3800
|
44
|
44
|
|
|
45
|
+#define BTN_W 120
|
|
46
|
+#define BTN_H 60
|
|
47
|
+#define BTN_GAP 20
|
|
48
|
+
|
|
49
|
+#define BTNS_OFF_X ((LCD_WIDTH - (2 * BTN_W) - (1 * BTN_GAP)) / 2)
|
|
50
|
+#define BTNS_OFF_Y ((LCD_HEIGHT - (3 * BTN_H) - (2 * BTN_GAP)) / 2)
|
|
51
|
+
|
|
52
|
+#define INVERT_BOOL(x) (x) = !(x);
|
|
53
|
+
|
45
|
54
|
static SPIClass mySpi = SPIClass(HSPI);
|
46
|
55
|
static XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);
|
47
|
|
-
|
48
|
56
|
static TFT_eSPI tft = TFT_eSPI();
|
49
|
57
|
|
|
58
|
+struct ui_status ui_status = {0};
|
|
59
|
+
|
|
60
|
+enum ui_states {
|
|
61
|
+ UI_INIT = 0,
|
|
62
|
+ UI_LIVINGROOM1,
|
|
63
|
+ UI_LIVINGROOM2,
|
|
64
|
+
|
|
65
|
+ UI_NUM_STATES
|
|
66
|
+};
|
|
67
|
+
|
|
68
|
+static enum ui_states ui_state = UI_INIT;
|
|
69
|
+
|
50
|
70
|
static TS_Point touchToScreen(TS_Point p) {
|
51
|
71
|
p.x = map(p.x, TOUCH_LEFT, TOUCH_RIGHT, 0, LCD_WIDTH);
|
52
|
72
|
p.y = map(p.y, TOUCH_TOP, TOUCH_BOTTOM, 0, LCD_HEIGHT);
|
|
@@ -58,30 +78,29 @@ static void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax =
|
58
|
78
|
ledcWrite(channel, duty);
|
59
|
79
|
}
|
60
|
80
|
|
61
|
|
-#define BTN_W 120
|
62
|
|
-#define BTN_H 60
|
63
|
|
-#define BTN_GAP 20
|
64
|
|
-
|
65
|
|
-#define BTNS_OFF_X ((LCD_WIDTH - (2 * BTN_W) - (1 * BTN_GAP)) / 2)
|
66
|
|
-#define BTNS_OFF_Y ((LCD_HEIGHT - (3 * BTN_H) - (2 * BTN_GAP)) / 2)
|
67
|
|
-
|
68
|
|
-static void draw_button(const char *name, uint32_t x, uint32_t y, bool state) {
|
69
|
|
- tft.fillRect(x - BTN_W / 2, y - BTN_H / 2, BTN_W, BTN_H, state ? TFT_GREEN : TFT_RED);
|
|
81
|
+static void draw_button(const char *name, uint32_t x, uint32_t y, uint32_t color) {
|
|
82
|
+ tft.fillRect(x - BTN_W / 2, y - BTN_H / 2, BTN_W, BTN_H, color);
|
70
|
83
|
|
71
|
84
|
tft.setTextDatum(MC_DATUM); // middle center
|
72
|
85
|
tft.drawString(name, x, y, 2);
|
73
|
86
|
}
|
74
|
87
|
|
75
|
|
-static bool lc, lw, lk, sa, lt, lp;
|
|
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);
|
76
|
92
|
|
77
|
|
-static void draw_livingroom(void) {
|
78
|
|
- draw_button("Lights Corner", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2, lc);
|
79
|
|
- draw_button("Lights Workspace", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP, lw);
|
80
|
|
- draw_button("Lights Kitchen", BTNS_OFF_X + BTN_W / 2, BTNS_OFF_Y + BTN_H / 2 + (BTN_H + BTN_GAP) * 2, lk);
|
|
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);
|
|
95
|
+}
|
|
96
|
+
|
|
97
|
+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);
|
81
|
101
|
|
82
|
|
- draw_button("Sound Amp.", BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP, BTNS_OFF_Y + BTN_H / 2, sa);
|
83
|
|
- draw_button("Lights TV", BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP, BTNS_OFF_Y + BTN_H / 2 + BTN_H + BTN_GAP, lt);
|
84
|
|
- draw_button("Lights PC", BTNS_OFF_X + BTN_W / 2 + BTN_W + BTN_GAP, BTNS_OFF_Y + BTN_H / 2 + (BTN_H + BTN_GAP) * 2, lp);
|
|
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
|
85
|
104
|
}
|
86
|
105
|
|
87
|
106
|
void ui_init(void) {
|
|
@@ -101,11 +120,30 @@ void ui_init(void) {
|
101
|
120
|
tft.setTextDatum(MC_DATUM); // middle center
|
102
|
121
|
tft.drawString("Initializing ESP-ENV", LCD_WIDTH / 2, LCD_HEIGHT / 2 - 16, 2);
|
103
|
122
|
tft.drawString("xythobuz.de", LCD_WIDTH / 2, LCD_HEIGHT / 2 + 16, 2);
|
|
123
|
+
|
|
124
|
+ ui_state = UI_INIT;
|
104
|
125
|
}
|
105
|
126
|
|
106
|
127
|
void ui_draw_menu(void) {
|
107
|
|
- tft.fillScreen(TFT_BLACK);
|
108
|
|
- draw_livingroom();
|
|
128
|
+ switch (ui_state) {
|
|
129
|
+ case UI_INIT:
|
|
130
|
+ tft.fillScreen(TFT_BLACK);
|
|
131
|
+ ui_state = UI_LIVINGROOM1;
|
|
132
|
+ // fall-through
|
|
133
|
+
|
|
134
|
+ case UI_LIVINGROOM1:
|
|
135
|
+ draw_livingroom1();
|
|
136
|
+ break;
|
|
137
|
+
|
|
138
|
+ case UI_LIVINGROOM2:
|
|
139
|
+ draw_livingroom2();
|
|
140
|
+ break;
|
|
141
|
+
|
|
142
|
+ default:
|
|
143
|
+ ui_state = UI_INIT;
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ 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);
|
109
|
147
|
}
|
110
|
148
|
|
111
|
149
|
void ui_run(void) {
|
|
@@ -113,22 +151,27 @@ void ui_run(void) {
|
113
|
151
|
TS_Point p = touchToScreen(ts.getPoint());
|
114
|
152
|
|
115
|
153
|
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)) {
|
116
|
|
- lc = !lc;
|
|
154
|
+ INVERT_BOOL(ui_status.light_corner);
|
117
|
155
|
} 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))) {
|
118
|
|
- lw = !lw;
|
|
156
|
+ INVERT_BOOL(ui_status.light_workspace);
|
119
|
157
|
} 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))) {
|
120
|
|
- lk = !lk;
|
|
158
|
+ INVERT_BOOL(ui_status.light_kitchen);
|
121
|
159
|
} 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)) {
|
122
|
|
- sa = !sa;
|
|
160
|
+ INVERT_BOOL(ui_status.sound_amplifier);
|
123
|
161
|
} 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))) {
|
124
|
|
- lt = !lt;
|
|
162
|
+ // TODO should act on both TV lights (box and amp)
|
125
|
163
|
} 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))) {
|
126
|
|
- lp = !lp;
|
|
164
|
+ // switch to next page
|
|
165
|
+ ui_state = (enum ui_states)((ui_state + 1) % UI_NUM_STATES);
|
|
166
|
+ if (ui_state == UI_INIT) {
|
|
167
|
+ // skip init screen
|
|
168
|
+ ui_state = (enum ui_states)((ui_state + 1) % UI_NUM_STATES);
|
|
169
|
+ }
|
|
170
|
+ tft.fillScreen(TFT_BLACK);
|
127
|
171
|
}
|
128
|
172
|
|
129
|
|
- // TODO
|
130
|
|
- draw_livingroom();
|
131
|
|
- delay(100);
|
|
173
|
+ ui_draw_menu();
|
|
174
|
+ delay(100); // TODO
|
132
|
175
|
}
|
133
|
176
|
}
|
134
|
177
|
|