@@ -73,12 +73,6 @@ void _setup_gpio() {
7373 if (!touch.begin (Wire, GT911_SLAVE_ADDRESS_L)) {
7474 Serial.println (" Failed to find GT911 - check your wiring!" );
7575 }
76- // Set touch max xy
77- touch.setMaxCoordinates (320 , 240 );
78- // Set swap xy
79- touch.setSwapXY (true );
80- // Set mirror xy
81- touch.setMirrorXY (false , true );
8276
8377 pinMode (9 , OUTPUT); // LoRa Radio CS Pin to HIGH (Inhibit the SPI Communication for this module)
8478 digitalWrite (9 , HIGH);
@@ -129,30 +123,42 @@ void _setBrightness(uint8_t brightval) {
129123**********************************************************************/
130124void InputHandler (void ) {
131125 char keyValue = 0 ;
132- static unsigned long _tmptmp ;
126+ static unsigned long tm = millis () ;
133127 TouchPointPro t;
134128 uint8_t touched = 0 ;
135- touched = touch.getPoint (&t.x , &t.y );
136- if ((millis () - _tmptmp) > 190 || LongPress) { // one reading each 190ms
137- // Serial.printf("\nPressed x=%d , y=%d, rot: %d",t.x, t.y, rotation);
138- if (touched) {
139-
140- // Serial.printf("\nPressed x=%d , y=%d, rot: %d, millis=%d, tmp=%d",t.x, t.y, rotation, millis(),
141- // _tmptmp);
142- _tmptmp = millis ();
143-
144- if (!wakeUpScreen ()) AnyKeyPress = true ;
145- else return ;
146-
147- // Touch point global variable
148- touchPoint.x = t.x ;
149- touchPoint.y = t.y ;
150- touchPoint.pressed = true ;
151- touchHeatMap (touchPoint);
152- touched = 0 ;
153- return ;
129+ uint8_t rot = 5 ;
130+ if (rot != rotation) {
131+ if (rotation == 1 ) {
132+ touch.setMaxCoordinates (320 , 240 );
133+ touch.setSwapXY (true );
134+ touch.setMirrorXY (true , true );
135+ }
136+ if (rotation == 3 ) {
137+ touch.setMaxCoordinates (320 , 240 );
138+ touch.setSwapXY (true );
139+ touch.setMirrorXY (false , false );
140+ }
141+ if (rotation == 0 ) {
142+ touch.setMaxCoordinates (240 , 320 );
143+ touch.setSwapXY (false );
144+ touch.setMirrorXY (false , true );
145+ }
146+ if (rotation == 2 ) {
147+ touch.setMaxCoordinates (240 , 320 );
148+ touch.setSwapXY (false );
149+ touch.setMirrorXY (true , false );
154150 }
151+ rot = rotation;
155152 }
153+ touched = touch.getPoint (&t.x , &t.y );
154+ delay (1 );
155+ Wire.requestFrom (LILYGO_KB_SLAVE_ADDRESS, 1 );
156+ while (Wire.available () > 0 ) {
157+ keyValue = Wire.read ();
158+ delay (1 );
159+ }
160+ if (millis () - tm < 200 && !LongPress) return ;
161+
156162 // 0 - UP
157163 // 1 - Down
158164 // 2 - Left
@@ -168,7 +174,7 @@ void InputHandler(void) {
168174 ISR_rst ();
169175 } else {
170176 if (!wakeUpScreen ()) AnyKeyPress = true ;
171- else goto END ;
177+ else return ;
172178 }
173179 delay (50 );
174180 // Print "bot - xx - yy", 1 is normal value for xx and yy 0 and 2 means movement on the axis
@@ -183,34 +189,48 @@ void InputHandler(void) {
183189 } // right, Down
184190 }
185191
186- delay (1 );
187- Wire.requestFrom (LILYGO_KB_SLAVE_ADDRESS, 1 );
188- while (Wire.available () > 0 ) { keyValue = Wire.read (); }
189192 if (keyValue != (char )0x00 ) {
193+ if (!wakeUpScreen ()) {
194+ AnyKeyPress = true ;
195+ } else return ;
190196 KeyStroke.Clear ();
191197 KeyStroke.hid_keys .push_back (keyValue);
192198 if (keyValue == ' ' ) KeyStroke.exit_key = true ; // key pressed to try to exit
193199 if (keyValue == (char )0x08 ) KeyStroke.del = true ;
194200 if (keyValue == (char )0x0D ) KeyStroke.enter = true ;
195201 if (digitalRead (SEL_BTN) == BTN_ACT) KeyStroke.fn = true ;
196202 KeyStroke.word .push_back (keyValue);
203+ if (KeyStroke.del ) EscPress = true ;
204+ if (KeyStroke.enter ) SelPress = true ;
197205 KeyStroke.pressed = true ;
198- } else KeyStroke.Clear ();
206+ tm = millis ();
207+ } else KeyStroke.pressed = false ;
199208
200- if (digitalRead (SEL_BTN) == BTN_ACT || KeyStroke.enter ) {
209+ if (digitalRead (SEL_BTN) == BTN_ACT) {
210+ tm = millis ();
201211 if (!wakeUpScreen ()) {
202- SelPress = true ;
203212 AnyKeyPress = true ;
204- } else goto END;
205- }
206- if (keyValue == 0x08 ) {
207- EscPress = true ;
208- AnyKeyPress = true ;
213+ } else return ;
214+ SelPress = true ;
209215 }
210- END:
211- if (AnyKeyPress) {
212- long tmp = millis ();
213- while ((millis () - tmp) < 200 && (digitalRead (SEL_BTN) == BTN_ACT));
216+
217+ if ((millis () - tm) > 190 || LongPress) { // one reading each 190ms
218+ if (touched) {
219+
220+ // Serial.printf("\nPressed x=%d , y=%d, rot: %d", t.x, t.y, rotation);
221+ tm = millis ();
222+
223+ if (!wakeUpScreen ()) AnyKeyPress = true ;
224+ else return ;
225+
226+ // Touch point global variable
227+ touchPoint.x = t.x ;
228+ touchPoint.y = t.y ;
229+ touchPoint.pressed = true ;
230+ touchHeatMap (touchPoint);
231+ touched = 0 ;
232+ return ;
233+ }
214234 }
215235}
216236
0 commit comments