Browse Source

draw rudimentary buttons

Thomas Buck 6 months ago
parent
commit
0ee0bd3ba3
1 changed files with 22 additions and 4 deletions
  1. 22
    4
      src/ui.cpp

+ 22
- 4
src/ui.cpp View File

36
 #define LEDC_TIMER_12_BIT 12
36
 #define LEDC_TIMER_12_BIT 12
37
 #define LEDC_BASE_FREQ 5000
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
 void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) {
51
 void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) {
40
     uint32_t duty = (4095 / valueMax) * min(value, valueMax);
52
     uint32_t duty = (4095 / valueMax) * min(value, valueMax);
41
     ledcWrite(channel, duty);
53
     ledcWrite(channel, duty);
69
 
81
 
70
 void printTouchToDisplay(TS_Point p) {
82
 void printTouchToDisplay(TS_Point p) {
71
     tft.fillScreen(TFT_BLACK);
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
     tft.setTextColor(TFT_WHITE, TFT_BLACK);
88
     tft.setTextColor(TFT_WHITE, TFT_BLACK);
73
 
89
 
74
     int x = LCD_WIDTH / 2;
90
     int x = LCD_WIDTH / 2;
89
 
105
 
90
 void ui_run(void) {
106
 void ui_run(void) {
91
     if (ts.tirqTouched() && ts.touched()) {
107
     if (ts.tirqTouched() && ts.touched()) {
92
-        TS_Point p = ts.getPoint();
108
+        TS_Point p = touchToScreen(ts.getPoint());
93
         printTouchToDisplay(p);
109
         printTouchToDisplay(p);
94
 
110
 
95
-        if (p.x < 1000) {
111
+        if (p.x < 100) {
96
             writeMQTTtopic("livingroom/light_kitchen", "off");
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
             writeMQTTtopic("livingroom/light_kitchen", "on");
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…
Cancel
Save