Skip to content

Commit ee2350e

Browse files
committed
v0.5.035
1 parent c9ad6d0 commit ee2350e

File tree

17 files changed

+244
-42
lines changed

17 files changed

+244
-42
lines changed

Controls.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
## Controls
2+
3+
<img src="images/controls.jpg" width="830" height="440"><br />
4+
5+
---
6+
- [Buttons](#buttons)
7+
- [Encoders](#encoders)
8+
- [IR receiver](#ir-receiver)
9+
- [Joystick](#joystic)
10+
- [Back to Readme](Readme.md)
11+
12+
---
13+
### Buttons
14+
Up to 5 buttons can be connected to the device. Three buttons are enough to control it.
15+
16+
Button actions:
17+
- BTN_LEFT\
18+
click: volume down\
19+
dblclick: previous station\
20+
longpress: quick volume down
21+
- BTN_CENTER\
22+
click: start/stop playing\
23+
dblclick: toggle between PLAYER/PLAYLIST mode\
24+
longpress: toggle between PLAYER/PLAYLIST mode
25+
- BTN_RIGHT\
26+
click: volume up\
27+
dblclick: next station\
28+
longpress: quick volume up
29+
- BTN_UP\
30+
click: without display - next station, with display - move up\
31+
dblclick: doing nothing\
32+
longpress: with display - quick move up
33+
- BTN_DOWN\
34+
click: without display - prev station, with display - move down\
35+
dblclick: doing nothing\
36+
longpress: with display - quick move down
37+
38+
---
39+
### Encoders
40+
You can connect one or two encoders to replace/complete the buttons. One encoder (without buttons) is enough to control the device.
41+
42+
- ENCODER1\
43+
rotate left: (ENC_BTNL) in PLAYER mode - volume down, in PLAYLIST mode - move up\
44+
rotate right: (ENC_BTNR) in PLAYER mode - volume up, in PLAYLIST mode - move down\
45+
click, dblclick, longpress: (ENC_BTNB) same as BTN_CENTER
46+
- ENCODER2\
47+
rotate left: (ENC2_BTNL) if not pressed - switch to PLAYLIST mode and move up, if pressed - volume down\
48+
rotate right: (ENC2_BTNR) if not pressed - switch to PLAYLIST mode and move down, if pressed - volume up\
49+
click, dblclick: (ENC2_BTNB) same as BTN_CENTER
50+
51+
---
52+
### IR receiver
53+
- IR_CODE_PLAY: start/stop playing
54+
- IR_CODE_PREV: previous station
55+
- IR_CODE_NEXT: next station
56+
- IR_CODE_VOLUP: volume up, longpress - quick volume up
57+
- IR_CODE_VOLDN: volume down, longpress - quick volume down
58+
- IR_CODE_HASH: toggle between PLAYER/PLAYLIST mode
59+
- IR_CODE_NUM0-NUM9:\
60+
Start entering the station number. To finish input and start playback, press the play button. To cancel, press hash.
61+
62+
---
63+
### Joystick
64+
You can use a joystick [like this](https://aliexpress.com/item/4000681560472.html) instead of connecting five buttons
65+
66+
<img src="images/joystick.jpg" width="300" height="300"><br />
67+
68+
---

Images.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
\
2626
![ёRadio](images/img11.jpg)\
2727
\
28-
![ёRadio](images/img12.jpg)
28+
![ёRadio](images/img12.jpg)\
29+
\
30+
![ёRadio](images/img13.jpg)\
31+
\
32+
![ёRadio](images/img14.jpg)

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Hardware setup](#hardware-setup)
1010
- [Quick start](#quick-start)
1111
- [Update](#update)
12+
- [Controls](Controls.md)
1213
- [MQTT](#mqtt)
1314
- [Home Assistant](#home-assistant)
1415
- [More features](#more-features)
@@ -230,7 +231,7 @@ download _http://\<yoradioip\>/data/playlist.csv_ and _http://\<yoradioip\>/data
230231
**Commands**: \
231232
**prev** - prev station \
232233
**next** - next station \
233-
**toggle** - start/stop playing \
234+
**toggle** - start/stop playing \
234235
**stop** - stop playing \
235236
**start, play** - start playing \
236237
**boot, reboot** - reboot \
@@ -243,6 +244,13 @@ download _http://\<yoradioip\>/data/playlist.csv_ and _http://\<yoradioip\>/data
243244

244245
---
245246
## Version history
247+
#### v0.5.033
248+
- added two buttons BTN_UP, BTN_DOWN
249+
- added the pins for the second encoder ENC2_BTNL, ENC2_BTNB, ENC2_BTNR
250+
- fixed display of playlist with SSD1306 configuration
251+
- improvements in the displays work
252+
- bugs fixes, some improvements
253+
246254
#### v0.5.020
247255
- added support for SSD1306 128x32 I2C displays
248256

exsamples/myoptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
4949
//#define ENC_HALFQUARD true /* Experiment with it */
5050
/******************************************/
5151

52+
/* ENCODER2 */
53+
//#define ENC2_BTNL 255 /* Left rotation */
54+
//#define ENC2_BTNB 255 /* Encoder button */
55+
//#define ENC2_BTNR 255 /* Right rotation */
56+
//#define ENC2_INTERNALPULLUP true /* Enable the weak pull up resistors */
57+
//#define ENC2_HALFQUARD true /* Experiment with it */
58+
/******************************************/
59+
5260
/* BUTTONS */
5361
//#define BTN_LEFT 255 /* VolDown, Prev */
5462
//#define BTN_CENTER 255 /* Play, Stop, Show playlist */

images/controls.jpg

77.4 KB
Loading

images/img13.jpg

10.9 KB
Loading

images/img14.jpg

290 KB
Loading

images/joystick.jpg

15.4 KB
Loading

yoRadio/controls.cpp

Lines changed: 98 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66
#include "display.h"
77

88
long encOldPosition = 0;
9+
long enc2OldPosition = 0;
910
int 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}};
1516
constexpr 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)
2022
ESP32Encoder 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

4248
void 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
115151
void 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

238275
void 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

253292
void 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

273314
void 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

307358
void 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

335405
void 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;

yoRadio/controls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#ifndef controls_h
22
#define controls_h
33

4+
enum controlEvt_e { EVT_BTNLEFT, EVT_BTNCENTER, EVT_BTNRIGHT, EVT_ENCBTNB, EVT_BTNUP, EVT_BTNDOWN, EVT_ENC2BTNB };
5+
46
boolean checklpdelay(int m, unsigned long &tstamp);
57

68
void initControls();
79
void loopControls();
810
void encoderLoop();
11+
void encoder2Loop();
912
void irLoop();
1013
void irNum(byte num);
1114
void irBlink();

0 commit comments

Comments
 (0)