Sfoglia il codice sorgente

draw rudimentary buttons

Thomas Buck 1 anno fa
parent
commit
0ee0bd3ba3
1 ha cambiato i file con 22 aggiunte e 4 eliminazioni
  1. 22
    4
      src/ui.cpp

+ 22
- 4
src/ui.cpp Vedi File

@@ -36,6 +36,18 @@
36 36
 #define LEDC_TIMER_12_BIT 12
37 37
 #define LEDC_BASE_FREQ 5000
38 38
 
39
+#define TOUCH_LEFT 180
40
+#define TOUCH_RIGHT 3750
41
+
42
+#define TOUCH_TOP 230
43
+#define TOUCH_BOTTOM 3800
44
+
45
+TS_Point touchToScreen(TS_Point p) {
46
+    p.x = map(p.x, TOUCH_LEFT, TOUCH_RIGHT, 0, LCD_WIDTH);
47
+    p.y = map(p.y, TOUCH_TOP, TOUCH_BOTTOM, 0, LCD_HEIGHT);
48
+    return p;
49
+}
50
+
39 51
 void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) {
40 52
     uint32_t duty = (4095 / valueMax) * min(value, valueMax);
41 53
     ledcWrite(channel, duty);
@@ -69,6 +81,10 @@ void ui_init(void) {
69 81
 
70 82
 void printTouchToDisplay(TS_Point p) {
71 83
     tft.fillScreen(TFT_BLACK);
84
+
85
+    tft.fillRect(0, 0, 100, LCD_HEIGHT, TFT_RED);
86
+    tft.fillRect(LCD_WIDTH - 100, 0, 100, LCD_HEIGHT, TFT_GREEN);
87
+
72 88
     tft.setTextColor(TFT_WHITE, TFT_BLACK);
73 89
 
74 90
     int x = LCD_WIDTH / 2;
@@ -89,16 +105,18 @@ void printTouchToDisplay(TS_Point p) {
89 105
 
90 106
 void ui_run(void) {
91 107
     if (ts.tirqTouched() && ts.touched()) {
92
-        TS_Point p = ts.getPoint();
108
+        TS_Point p = touchToScreen(ts.getPoint());
93 109
         printTouchToDisplay(p);
94 110
 
95
-        if (p.x < 1000) {
111
+        if (p.x < 100) {
96 112
             writeMQTTtopic("livingroom/light_kitchen", "off");
97
-        } else if (p.x > 3000) {
113
+            tft.drawCentreString("Off", LCD_WIDTH / 2, 100 + 4 * 16, 2);
114
+        } else if (p.x > (LCD_WIDTH - 100)) {
98 115
             writeMQTTtopic("livingroom/light_kitchen", "on");
116
+            tft.drawCentreString("On", LCD_WIDTH / 2, 100 + 4 * 16, 2);
99 117
         }
100 118
 
101
-        delay(1000);
119
+        delay(100);
102 120
     }
103 121
 }
104 122
 

Loading…
Annulla
Salva