66#include " display.h"
77
88long encOldPosition = 0 ;
9+ long enc2OldPosition = 0 ;
910int lpId = -1 ;
1011
11- #define ISPUSHBUTTONS BTN_LEFT!=255 || BTN_LEFT !=255 || BTN_RIGHT!=255 || ENC_BTNB!=255
12+ #define ISPUSHBUTTONS BTN_LEFT!=255 || BTN_CENTER !=255 || BTN_RIGHT!=255 || ENC_BTNB!= 255 || BTN_UP!= 255 || BTN_DOWN!= 255 || ENC2_BTNB !=255
1213#if ISPUSHBUTTONS
1314#include " OneButton.h"
14- OneButton button[] {{BTN_LEFT, true , BTN_INTERNALPULLUP}, {BTN_CENTER, true , BTN_INTERNALPULLUP}, {BTN_RIGHT, true , BTN_INTERNALPULLUP}, {ENC_BTNB, true , ENC_INTERNALPULLUP}};
15+ OneButton button[] {{BTN_LEFT, true , BTN_INTERNALPULLUP}, {BTN_CENTER, true , BTN_INTERNALPULLUP}, {BTN_RIGHT, true , BTN_INTERNALPULLUP}, {ENC_BTNB, true , ENC_INTERNALPULLUP}, {BTN_UP, true , BTN_INTERNALPULLUP}, {BTN_DOWN, true , BTN_INTERNALPULLUP}, {ENC2_BTNB, true , ENC2_INTERNALPULLUP} };
1516constexpr uint8_t nrOfButtons = sizeof (button) / sizeof (button[0 ]);
1617#endif
1718
18- #if ENC_BTNL!=255 && ENC_BTNR!=255
19+ #if ( ENC_BTNL!=255 && ENC_BTNR!=255) || (ENC2_BTNL!=255 && ENC2_BTNR!=255)
1920#include < ESP32Encoder.h>
21+ #if (ENC_BTNL!=255 && ENC_BTNR!=255)
2022ESP32Encoder encoder;
2123#endif
24+ #if (ENC2_BTNL!=255 && ENC2_BTNR!=255)
25+ ESP32Encoder encoder2;
26+ #endif
27+ #endif
2228
2329#if IR_PIN!=255
2430#include < assert.h>
@@ -41,17 +47,25 @@ decode_results irResults;
4147
4248void initControls () {
4349#if ENC_BTNL!=255
44- ESP32Encoder:: useInternalWeakPullResistors = ENC_INTERNALPULLUP ? UP : DOWN;
50+ encoder. useInternalWeakPullResistors = ENC_INTERNALPULLUP ? UP : DOWN;
4551 if (ENC_HALFQUARD) {
4652 encoder.attachHalfQuad (ENC_BTNL, ENC_BTNR);
4753 } else {
4854 encoder.attachFullQuad (ENC_BTNL, ENC_BTNR);
4955 }
5056#endif
57+ #if ENC2_BTNL!=255
58+ encoder2.useInternalWeakPullResistors = ENC2_INTERNALPULLUP ? UP : DOWN;
59+ if (ENC2_HALFQUARD) {
60+ encoder2.attachHalfQuad (ENC2_BTNL, ENC2_BTNR);
61+ } else {
62+ encoder2.attachFullQuad (ENC2_BTNL, ENC2_BTNR);
63+ }
64+ #endif
5165#if ISPUSHBUTTONS
5266 for (int i = 0 ; i < nrOfButtons; i++)
5367 {
54- if ((i == 0 && BTN_LEFT == 255 ) || (i == 1 && BTN_CENTER == 255 ) || (i == 2 && BTN_RIGHT == 255 ) || (i == 3 && ENC_BTNB == 255 )) continue ;
68+ if ((i == 0 && BTN_LEFT == 255 ) || (i == 1 && BTN_CENTER == 255 ) || (i == 2 && BTN_RIGHT == 255 ) || (i == 3 && ENC_BTNB == 255 ) || (i == 4 && BTN_UP == 255 ) || (i == 5 && BTN_DOWN == 255 ) || (i == 6 && ENC2_BTNB == 255 ) ) continue ;
5569 button[i].attachClick ([](void * p) {
5670 onBtnClick ((int )p);
5771 }, (void *)i);
@@ -84,14 +98,20 @@ void loopControls() {
8498#if ENC_BTNL!=255
8599 encoderLoop ();
86100#endif
101+ #if ENC2_BTNL!=255
102+ encoder2Loop ();
103+ #endif
87104#if ISPUSHBUTTONS
88105 for (unsigned i = 0 ; i < nrOfButtons; i++)
89106 {
90- if ((i == 0 && BTN_LEFT == 255 ) || (i == 1 && BTN_CENTER == 255 ) || (i == 2 && BTN_RIGHT == 255 ) || (i == 3 && ENC_BTNB == 255 )) continue ;
107+ if ((i == 0 && BTN_LEFT == 255 ) || (i == 1 && BTN_CENTER == 255 ) || (i == 2 && BTN_RIGHT == 255 ) || (i == 3 && ENC_BTNB == 255 ) || (i == 4 && BTN_UP == 255 ) || (i == 5 && BTN_DOWN == 255 ) || (i == 6 && ENC2_BTNB == 255 ) ) continue ;
91108 button[i].tick ();
92109 if (lpId >= 0 ) {
110+ if (DSP_MODEL==DSP_DUMMY && (lpId==4 || lpId==5 )) continue ;
93111 onBtnDuringLongPress (lpId);
112+ yield ();
94113 }
114+ yield ();
95115 }
96116#endif
97117#if IR_PIN!=255
@@ -111,6 +131,22 @@ void encoderLoop() {
111131}
112132#endif
113133
134+ #if ENC2_BTNL!=255
135+ void encoder2Loop () {
136+ long encNewPosition = encoder2.getCount () / 2 ;
137+ if (encNewPosition != 0 && encNewPosition != enc2OldPosition) {
138+ enc2OldPosition = encNewPosition;
139+ encoder2.setCount (0 );
140+ uint8_t bp = 2 ;
141+ if (ENC2_BTNB!=255 ){
142+ bp = digitalRead (ENC2_BTNB);
143+ }
144+ if (bp==HIGH && display.mode !=STATIONS) display.swichMode (STATIONS);
145+ controlsEvent (encNewPosition > 0 );
146+ }
147+ }
148+ #endif
149+
114150#if IR_PIN!=255
115151void irBlink () {
116152 if (player.mode == STOPPED) {
@@ -183,6 +219,7 @@ void irLoop() {
183219 }
184220 case IR_CODE_HASH: {
185221 if (display.mode == NUMBERS) {
222+ display.returnTile ();
186223 display.swichMode (PLAYER);
187224 display.numOfNextStation = 0 ;
188225 break ;
@@ -236,24 +273,28 @@ void irLoop() {
236273#endif // if IR_PIN!=255
237274
238275void onBtnLongPressStart (int id) {
239- switch (id) {
240- case 0 :
241- case 2 : {
276+ switch ((controlEvt_e)id) {
277+ case EVT_BTNLEFT:
278+ case EVT_BTNRIGHT:
279+ case EVT_BTNUP:
280+ case EVT_BTNDOWN:{
242281 lpId = id;
243282 break ;
244283 }
245- case 1 :
246- case 3 : {
284+ case EVT_BTNCENTER :
285+ case EVT_ENCBTNB : {
247286 display.swichMode (display.mode == PLAYER ? STATIONS : PLAYER);
248287 break ;
249288 }
250289 }
251290}
252291
253292void onBtnLongPressStop (int id) {
254- switch (id) {
255- case 0 :
256- case 2 : {
293+ switch ((controlEvt_e)id) {
294+ case EVT_BTNLEFT:
295+ case EVT_BTNRIGHT:
296+ case EVT_BTNUP:
297+ case EVT_BTNDOWN:{
257298 lpId = -1 ;
258299 break ;
259300 }
@@ -272,15 +313,25 @@ boolean checklpdelay(int m, unsigned long &tstamp) {
272313
273314void onBtnDuringLongPress (int id) {
274315 if (checklpdelay (BTN_LONGPRESS_LOOP_DELAY, lpdelay)) {
275- switch (id) {
276- case 0 : {
316+ switch ((controlEvt_e) id) {
317+ case EVT_BTNLEFT : {
277318 controlsEvent (false );
278319 break ;
279320 }
280- case 2 : {
321+ case EVT_BTNRIGHT : {
281322 controlsEvent (true );
282323 break ;
283324 }
325+ case EVT_BTNUP:
326+ case EVT_BTNDOWN: {
327+ if (display.mode == PLAYER) {
328+ display.swichMode (STATIONS);
329+ }
330+ if (display.mode == STATIONS) {
331+ controlsEvent (id==EVT_BTNDOWN);
332+ }
333+ break ;
334+ }
284335 }
285336 }
286337}
@@ -305,13 +356,14 @@ void controlsEvent(bool toRight) {
305356}
306357
307358void onBtnClick (int id) {
308- switch (id) {
309- case 0 : {
359+ switch ((controlEvt_e) id) {
360+ case EVT_BTNLEFT : {
310361 controlsEvent (false );
311362 break ;
312363 }
313- case 1 :
314- case 3 : {
364+ case EVT_BTNCENTER:
365+ case EVT_ENCBTNB:
366+ case EVT_ENC2BTNB: {
315367 if (display.mode == NUMBERS) {
316368 display.numOfNextStation = 0 ;
317369 display.swichMode (PLAYER);
@@ -325,26 +377,45 @@ void onBtnClick(int id) {
325377 }
326378 break ;
327379 }
328- case 2 : {
380+ case EVT_BTNRIGHT : {
329381 controlsEvent (true );
330382 break ;
331383 }
384+ case EVT_BTNUP:
385+ case EVT_BTNDOWN: {
386+ if (DSP_MODEL==DSP_DUMMY){
387+ if (id==EVT_BTNUP){
388+ player.next ();
389+ }else {
390+ player.prev ();
391+ }
392+ }else {
393+ if (display.mode == PLAYER) {
394+ display.swichMode (STATIONS);
395+ }
396+ if (display.mode == STATIONS) {
397+ controlsEvent (id==EVT_BTNDOWN);
398+ }
399+ }
400+ break ;
401+ }
332402 }
333403}
334404
335405void onBtnDoubleClick (int id) {
336- switch (id) {
337- case 0 : {
406+ switch ((controlEvt_e) id) {
407+ case EVT_BTNLEFT : {
338408 if (display.mode != PLAYER) return ;
339409 player.prev ();
340410 break ;
341411 }
342- case 1 :
343- case 3 : {
412+ case EVT_BTNCENTER:
413+ case EVT_ENCBTNB:
414+ case EVT_ENC2BTNB: {
344415 display.swichMode (display.mode == PLAYER ? STATIONS : PLAYER);
345416 break ;
346417 }
347- case 2 : {
418+ case EVT_BTNRIGHT : {
348419 if (display.mode != PLAYER) return ;
349420 player.next ();
350421 break ;
0 commit comments