@@ -7,14 +7,26 @@ menu with adafruit GFX
77output: 1.8" TFT 128*160 (ST7735 HW SPI)
88input: Serial + encoder
99www.r-site.net
10+
11+ alternative encoder (clickEncoder) uses:
12+ https://github.com/0xPIT/encoder
13+ https://github.com/PaulStoffregen/TimerOne
1014***/
1115
16+ #define USE_CLICK_ENCODER
17+
1218#include < SPI.h>
1319#include < Adafruit_GFX.h>
1420#include < Adafruit_ST7735.h>
1521#include < menu.h>
1622#include < menuIO/adafruitGfxOut.h>
17- #include < menuIO/encoderIn.h>
23+ #ifdef USE_CLICK_ENCODER
24+ #include < TimerOne.h>
25+ #include < ClickEncoder.h>
26+ #include < menuIO/clickEncoderIn.h>
27+ #else
28+ #include < menuIO/encoderIn.h>
29+ #endif
1830#include < menuIO/keyIn.h>
1931#include < menuIO/chainStream.h>
2032#include < menuIO/serialOut.h>
@@ -40,25 +52,6 @@ result doAlert(eventMask e, prompt &item);
4052
4153int test=55 ;
4254
43- /* result showEvent(eventMask e,navNode& nav, prompt& item) {
44- Serial.print(F("event:"));
45- Serial.print(e);
46- return proceed;
47- }
48-
49- result action1(eventMask e) {
50- Serial.print(e);
51- Serial.println(" action1 executed, proceed menu");
52- Serial.flush();
53- return proceed;
54- }
55-
56- result action2(eventMask e,navNode& nav, prompt &item) {
57- Serial.print(e);
58- Serial.println(" action2 executed, quiting menu");
59- return quit;
60- }*/
61-
6255int ledCtrl=LOW;
6356
6457result myLedOn () {
@@ -140,15 +133,21 @@ const colorDef<uint16_t> colors[] MEMMODE={
140133 {{ST7735_WHITE,ST7735_YELLOW},{ST7735_BLUE,ST7735_RED,ST7735_RED}},// titleColor
141134};
142135
143- encoderIn<encA,encB> encoder;// simple quad encoder driver
144- encoderInStream<encA,encB> encStream (encoder,4 );// simple quad encoder fake Stream
145-
146- // a keyboard with only one key as the encoder button
147- keyMap encBtn_map[]={{-encBtn,defaultNavCodes[enterCmd].ch }};// negative pin numbers use internal pull-up, this is on when low
148- keyIn<1 > encButton (encBtn_map);// 1 is the number of keys
149-
150136serialIn serial (Serial);
151- MENU_INPUTS (in,&encStream,&encButton,&serial);
137+
138+ #ifdef USE_CLICK_ENCODER
139+ ClickEncoder clickEncoder (encA,encB,encBtn);
140+ ClickEncoderStream encStream (clickEncoder,1 );
141+ MENU_INPUTS (in,&encStream,&serial);
142+ void timerIsr () {clickEncoder.service ();}
143+ #else
144+ encoderIn<encA,encB> encoder;// simple quad encoder driver
145+ encoderInStream<encA,encB> encStream (encoder,4 );// simple quad encoder fake Stream
146+ // a keyboard with only one key as the encoder button
147+ keyMap encBtn_map[]={{-encBtn,defaultNavCodes[enterCmd].ch }};// negative pin numbers use internal pull-up, this is on when low
148+ keyIn<1 > encButton (encBtn_map);// 1 is the number of keys
149+ MENU_INPUTS (in,&encStream,&encButton,&serial);
150+ #endif
152151
153152#define MAX_DEPTH 4
154153#define textScale 1
@@ -159,23 +158,6 @@ MENU_OUTPUTS(out,MAX_DEPTH
159158
160159NAVROOT (nav,mainMenu,MAX_DEPTH,in,out);
161160
162- /* result alert(menuOut& o,idleEvent e) {
163- if (e==idling) {
164- o.setCursor(0,0);
165- o.print("alert test");
166- o.setCursor(0,1);
167- o.print("press [select]");
168- o.setCursor(0,2);
169- o.print("to continue...");
170- }
171- return proceed;
172- }
173-
174- result doAlert(eventMask e, prompt &item) {
175- nav.idleOn(alert);
176- return proceed;
177- }*/
178-
179161// when menu is suspended
180162result idle (menuOut& o,idleEvent e) {
181163 if (e==idling) {
@@ -201,8 +183,13 @@ void setup() {
201183 // nav.showTitle=false;//show menu title?
202184
203185 // pinMode(encBtn, INPUT_PULLUP);
204- encButton.begin ();
205- encoder.begin ();
186+ #ifdef USE_CLICK_ENCODER
187+ Timer1.initialize (1000 );
188+ Timer1.attachInterrupt (timerIsr);
189+ #else
190+ encButton.begin ();
191+ encoder.begin ();
192+ #endif
206193
207194 SPI.begin ();
208195 gfx.initR (INITR_BLACKTAB);
0 commit comments