1
1
#include < M5OnScreenKeyboard.h>
2
2
3
3
#include < M5PLUSEncoder.h>
4
+ #include < M5FACESEncoder.h>
4
5
#include < M5JoyStick.h>
5
6
6
7
bool M5OnScreenKeyboard::useTextbox = true ;
@@ -9,6 +10,7 @@ bool M5OnScreenKeyboard::useFACES = false;
9
10
bool M5OnScreenKeyboard::useCardKB = false ;
10
11
bool M5OnScreenKeyboard::useJoyStick = false ;
11
12
bool M5OnScreenKeyboard::usePLUSEncoder = false ;
13
+ bool M5OnScreenKeyboard::useFACESEncoder = false ;
12
14
bool M5OnScreenKeyboard::swapBtnBC = false ;
13
15
14
16
uint16_t M5OnScreenKeyboard::fontColor[2 ] = {0xFFFF , 0xFFFF };
@@ -128,8 +130,13 @@ void M5OnScreenKeyboard::clearString() {
128
130
}
129
131
130
132
void M5OnScreenKeyboard::setup (const String& value) {
133
+ #ifdef ARDUINO_ODROID_ESP32
134
+ _btnHeight = 0 ;
135
+ #else
136
+ _btnHeight = M5ButtonDrawer::height;
131
137
_btnDrawer.setText (" " ," " ," " );
132
138
_btnDrawer.draw (true );
139
+ #endif
133
140
setString (value);
134
141
_tbl = 0 ;
135
142
_col = 0 ;
@@ -156,6 +163,27 @@ bool M5OnScreenKeyboard::loop() {
156
163
bool canRepeat = _repeat == 0 || (_msec - _msecLast) >= (1 < _repeat ? msecRepeat : msecHold);
157
164
158
165
bool press = false ;
166
+
167
+ #ifdef ARDUINO_ODROID_ESP32
168
+ if (M5.BtnStart .wasPressed ()) { return false ; }
169
+ if (M5.BtnSelect .wasPressed ()) { press = true ; switchTable (); }
170
+ if (M5.BtnA .isPressed ()) { press = true ; if (canRepeat) { ++_repeat; pressKey (); } }
171
+ if (M5.BtnB .isPressed ()) { press = true ; if (canRepeat) { ++_repeat; pressKey (BS); } }
172
+ if (M5.JOY_X .isAxisPressed () != DPAD_V_NONE) {
173
+ press = true ;
174
+ if (canRepeat) {
175
+ ++_repeat;
176
+ _col += (M5.JOY_X .isAxisPressed () == DPAD_V_HALF) ? 1 : -1 ;
177
+ }
178
+ }
179
+ if (M5.JOY_Y .isAxisPressed () != DPAD_V_NONE) {
180
+ press = true ;
181
+ if (canRepeat) {
182
+ ++_repeat;
183
+ _row += (M5.JOY_Y .isAxisPressed () == DPAD_V_HALF) ? 1 : -1 ;
184
+ }
185
+ }
186
+ #else
159
187
Button& btnB (swapBtnBC ? M5.BtnC : M5.BtnB );
160
188
Button& btnC (swapBtnBC ? M5.BtnB : M5.BtnC );
161
189
@@ -193,6 +221,7 @@ bool M5OnScreenKeyboard::loop() {
193
221
switch (_state) {
194
222
case LEFTRIGHT: if (++_repeat < COLUMNCOUNT) --_col; break ;
195
223
case UPDOWN: if (++_repeat < ROWCOUNT) --_row; break ;
224
+ default : break ;
196
225
}
197
226
}
198
227
}
@@ -222,6 +251,7 @@ bool M5OnScreenKeyboard::loop() {
222
251
&& btnC.releasedFor (msecMorseInput)
223
252
&& _morseInputBuf) { ++_repeat; inputMorse (); }
224
253
break ;
254
+ default : break ;
225
255
}
226
256
}
227
257
if (useFACES && Wire.requestFrom (0x08 , 1 )) {
@@ -260,8 +290,8 @@ bool M5OnScreenKeyboard::loop() {
260
290
if (usePLUSEncoder && PLUSEncoder.update ()) {
261
291
switch (_state) {
262
292
case LEFTRIGHT: // left right moving
263
- if (PLUSEncoder.wasUp ()) { -- _col; }
264
- if (PLUSEncoder.wasDown ()) { ++ _col; }
293
+ if (PLUSEncoder.wasUp ()) { ++ _col; }
294
+ if (PLUSEncoder.wasDown ()) { -- _col; }
265
295
if (PLUSEncoder.wasHold ()) { switchTable (); break ; }
266
296
if (PLUSEncoder.wasClicked ()) { _state = UPDOWN; }
267
297
break ;
@@ -271,6 +301,26 @@ bool M5OnScreenKeyboard::loop() {
271
301
if (PLUSEncoder.wasHold ()) { _state = LEFTRIGHT; }
272
302
if (PLUSEncoder.wasClicked ()) { ++_repeat; pressKey (); _state = LEFTRIGHT; }
273
303
break ;
304
+ default : break ;
305
+ }
306
+ }
307
+ #endif
308
+ #ifdef _M5FACESENCODER_H_
309
+ if (useFACESEncoder && FACESEncoder.update ()) {
310
+ switch (_state) {
311
+ case LEFTRIGHT: // left right moving
312
+ if (FACESEncoder.wasUp ()) { ++_col; }
313
+ if (FACESEncoder.wasDown ()) { --_col; }
314
+ if (FACESEncoder.wasHold ()) { switchTable (); break ; }
315
+ if (FACESEncoder.wasClicked ()) { _state = UPDOWN; }
316
+ break ;
317
+ case UPDOWN: // up down moving
318
+ if (FACESEncoder.wasUp ()) { --_row; }
319
+ if (FACESEncoder.wasDown ()) { ++_row; }
320
+ if (FACESEncoder.wasHold ()) { _state = LEFTRIGHT; }
321
+ if (FACESEncoder.wasClicked ()) { ++_repeat; pressKey (); _state = LEFTRIGHT; }
322
+ break ;
323
+ default : break ;
274
324
}
275
325
}
276
326
#endif
@@ -289,6 +339,7 @@ bool M5OnScreenKeyboard::loop() {
289
339
if (JoyStick.wasClicked ()) { ++_repeat; pressKey (); }
290
340
if (JoyStick.wasHold ()) { switchTable (); }
291
341
}
342
+ #endif
292
343
#endif
293
344
if (oldCol != _col
294
345
|| oldRow != _row
@@ -321,19 +372,20 @@ bool M5OnScreenKeyboard::loop() {
321
372
, M5.Lcd .fontHeight (font)
322
373
, (_msec / 150 ) % 2 ? textboxBackColor : textboxFontColor);
323
374
}
375
+ #ifndef ARDUINO_ODROID_ESP32
324
376
updateButton ();
325
377
_btnDrawer.draw ();
378
+ #endif
326
379
return true ;
327
380
}
328
381
void M5OnScreenKeyboard::close () {
329
382
int y = getY (-1 );
330
383
M5.Lcd .fillRect (0 , y, M5.Lcd .width (), M5.Lcd .height () - y, 0 );
331
- _state == APPEAR;
332
384
clearString ();
333
385
}
334
386
335
387
int M5OnScreenKeyboard::getX (int col) const { return col * KEYWIDTH; }
336
- int M5OnScreenKeyboard::getY (int row) const { return M5.Lcd .height () - M5ButtonDrawer::height - (ROWCOUNT - row) * keyHeight; }
388
+ int M5OnScreenKeyboard::getY (int row) const { return M5.Lcd .height () - _btnHeight - (ROWCOUNT - row) * keyHeight; }
337
389
338
390
void M5OnScreenKeyboard::updateButton () {
339
391
if (M5.BtnA .isPressed () || _fn) {
@@ -348,11 +400,12 @@ void M5OnScreenKeyboard::updateButton() {
348
400
case LEFTRIGHT: _btnDrawer.setText (" Panel/Left" , swapBtnBC?" Right" :" Row" , swapBtnBC?" Row" :" Right" ); break ;
349
401
case UPDOWN: _btnDrawer.setText (" Panel/Up" , swapBtnBC?" Down" :" Ok" , swapBtnBC?" Ok" :" Down" ); break ;
350
402
case MORSE: _btnDrawer.setText (" Panel/Fn" , " ." , " _" ); break ;
403
+ default : break ;
351
404
}
352
405
}
353
406
}
354
407
void M5OnScreenKeyboard::switchTable () {
355
- _tbl = ++ _tbl % (TABLECOUNT - (useOver0x80Chars? 0 : 1 ));
408
+ _tbl = ( _tbl + 1 ) % (TABLECOUNT - (useOver0x80Chars ? 0 : 1 ));
356
409
}
357
410
358
411
bool M5OnScreenKeyboard::inputKB (char key)
@@ -474,16 +527,16 @@ void M5OnScreenKeyboard::drawKeyTop(int c, int r, int x, int y, int kh)
474
527
char * str = tbl;
475
528
char code = _chartbl[_tbl][r][c];
476
529
switch (code) {
477
- case ' \t ' : str = " TAB" ; break ;
478
- case ' \r ' : str = " CR" ; break ;
479
- case ' \n ' : str = " LF" ; break ;
480
- case BS : str = " BS" ; break ;
481
- case DEL : str = " DEL" ; break ;
482
- case LEFT: str = " <<" ; break ;
483
- case RIGH: str = " >>" ; break ;
530
+ case ' \t ' : str = ( char *)PROGMEM " TAB" ; break ;
531
+ case ' \r ' : str = ( char *)PROGMEM " CR" ; break ;
532
+ case ' \n ' : str = ( char *)PROGMEM " LF" ; break ;
533
+ case BS : str = ( char *)PROGMEM " BS" ; break ;
534
+ case DEL : str = ( char *)PROGMEM " DEL" ; break ;
535
+ case LEFT: str = ( char *)PROGMEM " <<" ; break ;
536
+ case RIGH: str = ( char *)PROGMEM " >>" ; break ;
484
537
}
485
538
uint16_t color = fontColor[_col == c && _row == r ? 1 : 0 ];
486
- int fy = min (y + (kh - fh + 1 ) / 2 + moffset, M5.Lcd .height () - M5ButtonDrawer::height - fh);
539
+ int fy = min (y + (kh - fh + 1 ) / 2 + moffset, M5.Lcd .height () - _btnHeight - fh);
487
540
M5.Lcd .setTextColor (color);
488
541
M5.Lcd .drawCentreString (str, x + 16 , fy, font);
489
542
if (_state == MORSE) {
@@ -542,7 +595,7 @@ void M5OnScreenKeyboard::drawTextbox() {
542
595
543
596
void M5OnScreenKeyboard::drawKeyboard (int h) {
544
597
if (h < 0 ) h = keyHeight * ROWCOUNT;
545
- int y = M5.Lcd .height () - M5ButtonDrawer::height - h;
598
+ int y = M5.Lcd .height () - _btnHeight - h;
546
599
for (int c = 0 ; c < COLUMNCOUNT; ++c) {
547
600
int x = getX (c);
548
601
drawColumn (c, x, y, h);
0 commit comments