1- #include " configuration.h"
2-
3- #ifdef T5_S3_EPAPER_PRO
4-
5- #include " Observer.h"
6- #include " TouchDrvGT911.hpp"
7- #include " Wire.h"
8- #include " input/InputBroker.h"
9- #include " input/TouchScreenImpl1.h"
10- #include " sleep.h"
11-
12- #ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
13- #include " graphics/niche/InkHUD/InkHUD.h"
14- #include " graphics/niche/InkHUD/SystemApplet.h"
15-
16- // Bridges touch events from TouchScreenImpl1 directly into InkHUD,
17- // bypassing the InputBroker (which is excluded in InkHUD builds).
18- // Routing mirrors the mini-epaper-s3 two-way rocker pattern:
19- // - Nav left/right: prevApplet/nextApplet when idle, navUp/Down when a system applet has focus (e.g. menu)
20- // - Nav up/down: navUp/navDown always (menu scroll)
21- // - Tap: shortpress (cycle applets / confirm in menu)
22- // - Long press: longpress (open menu / back)
23- class TouchInkHUDBridge : public Observer <const InputEvent *>
24- {
25- int onNotify (const InputEvent *e) override
26- {
27- auto *inkhud = NicheGraphics::InkHUD::InkHUD::getInstance ();
28-
29- // Keep alignment in sync with the current rotation so that visual-frame gestures
30- // always pass through nav functions without remapping: (rotation + alignment) % 4 == 0.
31- inkhud->persistence ->settings .joystick .alignment = (4 - inkhud->persistence ->settings .rotation ) % 4 ;
32-
33- // Check whether a system applet (e.g. menu) is currently handling input
34- bool systemHandlingInput = false ;
35- for (NicheGraphics::InkHUD::SystemApplet *sa : inkhud->systemApplets ) {
36- if (sa->handleInput ) {
37- systemHandlingInput = true ;
38- break ;
39- }
40- }
41-
42- switch (e->inputEvent ) {
43- case INPUT_BROKER_USER_PRESS:
44- inkhud->shortpress ();
45- break ;
46- case INPUT_BROKER_SELECT:
47- inkhud->longpress ();
48- break ;
49- case INPUT_BROKER_LEFT:
50- if (systemHandlingInput)
51- inkhud->navUp ();
52- else
53- inkhud->prevApplet ();
54- break ;
55- case INPUT_BROKER_RIGHT:
56- if (systemHandlingInput)
57- inkhud->navDown ();
58- else
59- inkhud->nextApplet ();
60- break ;
61- case INPUT_BROKER_UP:
62- inkhud->navUp ();
63- break ;
64- case INPUT_BROKER_DOWN:
65- inkhud->navDown ();
66- break ;
67- default :
68- break ;
69- }
70- return 0 ;
71- }
72- };
73-
74- static TouchInkHUDBridge touchBridge;
75- #endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS
76-
77- TouchDrvGT911 touch;
78-
79- // Commands the GT911 into standby before the Wire bus is torn down.
80- // notifyDeepSleep fires before Wire.end() in doDeepSleep(), so I2C is still available here.
81- struct TouchDeepSleepObserver {
82- int onDeepSleep (void *)
83- {
84- touch.sleep ();
85- return 0 ;
86- }
87- CallbackObserver<TouchDeepSleepObserver, void *> observer{this , &TouchDeepSleepObserver::onDeepSleep};
88- } static touchDeepSleepObserver;
89-
90- bool readTouch (int16_t *x, int16_t *y)
91- {
92- if (!digitalRead (GT911_PIN_INT)) {
93- int16_t raw_x;
94- int16_t raw_y;
95- if (touch.getPoint (&raw_x, &raw_y)) {
96- #ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
97- // Transform raw GT911 axes to visual-frame coordinates for the current display rotation.
98- // rotation=3 is the physical identity (device's default orientation).
99- switch (NicheGraphics::InkHUD::InkHUD::getInstance ()->persistence ->settings .rotation ) {
100- default :
101- case 3 :
102- *x = raw_x;
103- *y = raw_y;
104- break ; // identity
105- case 2 :
106- *x = (EPD_WIDTH - 1 ) - raw_y;
107- *y = raw_x;
108- break ; // 90° CW tilt
109- case 1 :
110- *x = (EPD_HEIGHT - 1 ) - raw_x;
111- *y = (EPD_WIDTH - 1 ) - raw_y;
112- break ; // 180° flip
113- case 0 :
114- *x = raw_y;
115- *y = (EPD_HEIGHT - 1 ) - raw_x;
116- break ; // 90° CCW tilt
117- }
118- #else
119- *x = raw_x;
120- *y = raw_y;
121- #endif
122- LOG_DEBUG (" touched(%d/%d)" , *x, *y);
123- return true ;
124- }
125- }
126- return false ;
127- }
1+ #include " variant.h"
2+ #include " Arduino.h"
3+ #include " pins_arduino.h"
1284
1295void earlyInitVariant ()
1306{
@@ -161,20 +37,3 @@ void variant_shutdown()
16137 // Ensure frontlight is off during deep sleep
16238 digitalWrite (BOARD_BL_EN, LOW);
16339}
164-
165- // T5-S3-ePaper Pro specific (late-) init
166- void lateInitVariant (void )
167- {
168- touch.setPins (GT911_PIN_RST, GT911_PIN_INT);
169- if (touch.begin (Wire, GT911_SLAVE_ADDRESS_H, GT911_PIN_SDA, GT911_PIN_SCL)) {
170- touchDeepSleepObserver.observer .observe (¬ifyDeepSleep);
171- touchScreenImpl1 = new TouchScreenImpl1 (EPD_WIDTH, EPD_HEIGHT, readTouch);
172- touchScreenImpl1->init ();
173- #ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
174- touchBridge.observe (touchScreenImpl1);
175- #endif
176- } else {
177- LOG_ERROR (" Failed to find touch controller!" );
178- }
179- }
180- #endif
0 commit comments