This commit is contained in:
e2002
2022-03-20 18:43:32 +03:00
parent c9ad6d053c
commit ee2350e28f
17 changed files with 244 additions and 42 deletions

View File

@@ -6,19 +6,25 @@
#include "display.h"
long encOldPosition = 0;
long enc2OldPosition = 0;
int lpId = -1;
#define ISPUSHBUTTONS BTN_LEFT!=255 || BTN_LEFT!=255 || BTN_RIGHT!=255 || ENC_BTNB!=255
#define ISPUSHBUTTONS BTN_LEFT!=255 || BTN_CENTER!=255 || BTN_RIGHT!=255 || ENC_BTNB!=255 || BTN_UP!=255 || BTN_DOWN!=255 || ENC2_BTNB!=255
#if ISPUSHBUTTONS
#include "OneButton.h"
OneButton button[] {{BTN_LEFT, true, BTN_INTERNALPULLUP}, {BTN_CENTER, true, BTN_INTERNALPULLUP}, {BTN_RIGHT, true, BTN_INTERNALPULLUP}, {ENC_BTNB, true, ENC_INTERNALPULLUP}};
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}};
constexpr uint8_t nrOfButtons = sizeof(button) / sizeof(button[0]);
#endif
#if ENC_BTNL!=255 && ENC_BTNR!=255
#if (ENC_BTNL!=255 && ENC_BTNR!=255) || (ENC2_BTNL!=255 && ENC2_BTNR!=255)
#include <ESP32Encoder.h>
#if (ENC_BTNL!=255 && ENC_BTNR!=255)
ESP32Encoder encoder;
#endif
#if (ENC2_BTNL!=255 && ENC2_BTNR!=255)
ESP32Encoder encoder2;
#endif
#endif
#if IR_PIN!=255
#include <assert.h>
@@ -41,17 +47,25 @@ decode_results irResults;
void initControls() {
#if ENC_BTNL!=255
ESP32Encoder::useInternalWeakPullResistors = ENC_INTERNALPULLUP ? UP : DOWN;
encoder.useInternalWeakPullResistors = ENC_INTERNALPULLUP ? UP : DOWN;
if (ENC_HALFQUARD) {
encoder.attachHalfQuad(ENC_BTNL, ENC_BTNR);
} else {
encoder.attachFullQuad(ENC_BTNL, ENC_BTNR);
}
#endif
#if ENC2_BTNL!=255
encoder2.useInternalWeakPullResistors = ENC2_INTERNALPULLUP ? UP : DOWN;
if (ENC2_HALFQUARD) {
encoder2.attachHalfQuad(ENC2_BTNL, ENC2_BTNR);
} else {
encoder2.attachFullQuad(ENC2_BTNL, ENC2_BTNR);
}
#endif
#if ISPUSHBUTTONS
for (int i = 0; i < nrOfButtons; i++)
{
if ((i == 0 && BTN_LEFT == 255) || (i == 1 && BTN_CENTER == 255) || (i == 2 && BTN_RIGHT == 255) || (i == 3 && ENC_BTNB == 255)) continue;
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;
button[i].attachClick([](void* p) {
onBtnClick((int)p);
}, (void*)i);
@@ -84,14 +98,20 @@ void loopControls() {
#if ENC_BTNL!=255
encoderLoop();
#endif
#if ENC2_BTNL!=255
encoder2Loop();
#endif
#if ISPUSHBUTTONS
for (unsigned i = 0; i < nrOfButtons; i++)
{
if ((i == 0 && BTN_LEFT == 255) || (i == 1 && BTN_CENTER == 255) || (i == 2 && BTN_RIGHT == 255) || (i == 3 && ENC_BTNB == 255)) continue;
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;
button[i].tick();
if (lpId >= 0) {
if(DSP_MODEL==DSP_DUMMY && (lpId==4 || lpId==5)) continue;
onBtnDuringLongPress(lpId);
yield();
}
yield();
}
#endif
#if IR_PIN!=255
@@ -111,6 +131,22 @@ void encoderLoop() {
}
#endif
#if ENC2_BTNL!=255
void encoder2Loop() {
long encNewPosition = encoder2.getCount() / 2;
if (encNewPosition != 0 && encNewPosition != enc2OldPosition) {
enc2OldPosition = encNewPosition;
encoder2.setCount(0);
uint8_t bp = 2;
if(ENC2_BTNB!=255){
bp = digitalRead(ENC2_BTNB);
}
if(bp==HIGH && display.mode!=STATIONS) display.swichMode(STATIONS);
controlsEvent(encNewPosition > 0);
}
}
#endif
#if IR_PIN!=255
void irBlink() {
if (player.mode == STOPPED) {
@@ -183,6 +219,7 @@ void irLoop() {
}
case IR_CODE_HASH: {
if (display.mode == NUMBERS) {
display.returnTile();
display.swichMode(PLAYER);
display.numOfNextStation = 0;
break;
@@ -236,14 +273,16 @@ void irLoop() {
#endif // if IR_PIN!=255
void onBtnLongPressStart(int id) {
switch (id) {
case 0:
case 2: {
switch ((controlEvt_e)id) {
case EVT_BTNLEFT:
case EVT_BTNRIGHT:
case EVT_BTNUP:
case EVT_BTNDOWN:{
lpId = id;
break;
}
case 1:
case 3: {
case EVT_BTNCENTER:
case EVT_ENCBTNB: {
display.swichMode(display.mode == PLAYER ? STATIONS : PLAYER);
break;
}
@@ -251,9 +290,11 @@ void onBtnLongPressStart(int id) {
}
void onBtnLongPressStop(int id) {
switch (id) {
case 0:
case 2: {
switch ((controlEvt_e)id) {
case EVT_BTNLEFT:
case EVT_BTNRIGHT:
case EVT_BTNUP:
case EVT_BTNDOWN:{
lpId = -1;
break;
}
@@ -272,15 +313,25 @@ boolean checklpdelay(int m, unsigned long &tstamp) {
void onBtnDuringLongPress(int id) {
if (checklpdelay(BTN_LONGPRESS_LOOP_DELAY, lpdelay)) {
switch (id) {
case 0: {
switch ((controlEvt_e)id) {
case EVT_BTNLEFT: {
controlsEvent(false);
break;
}
case 2: {
case EVT_BTNRIGHT: {
controlsEvent(true);
break;
}
case EVT_BTNUP:
case EVT_BTNDOWN: {
if (display.mode == PLAYER) {
display.swichMode(STATIONS);
}
if (display.mode == STATIONS) {
controlsEvent(id==EVT_BTNDOWN);
}
break;
}
}
}
}
@@ -305,13 +356,14 @@ void controlsEvent(bool toRight) {
}
void onBtnClick(int id) {
switch (id) {
case 0: {
switch ((controlEvt_e)id) {
case EVT_BTNLEFT: {
controlsEvent(false);
break;
}
case 1:
case 3: {
case EVT_BTNCENTER:
case EVT_ENCBTNB:
case EVT_ENC2BTNB: {
if (display.mode == NUMBERS) {
display.numOfNextStation = 0;
display.swichMode(PLAYER);
@@ -325,26 +377,45 @@ void onBtnClick(int id) {
}
break;
}
case 2: {
case EVT_BTNRIGHT: {
controlsEvent(true);
break;
}
case EVT_BTNUP:
case EVT_BTNDOWN: {
if(DSP_MODEL==DSP_DUMMY){
if(id==EVT_BTNUP){
player.next();
}else{
player.prev();
}
}else{
if (display.mode == PLAYER) {
display.swichMode(STATIONS);
}
if (display.mode == STATIONS) {
controlsEvent(id==EVT_BTNDOWN);
}
}
break;
}
}
}
void onBtnDoubleClick(int id) {
switch (id) {
case 0: {
switch ((controlEvt_e)id) {
case EVT_BTNLEFT: {
if (display.mode != PLAYER) return;
player.prev();
break;
}
case 1:
case 3: {
case EVT_BTNCENTER:
case EVT_ENCBTNB:
case EVT_ENC2BTNB: {
display.swichMode(display.mode == PLAYER ? STATIONS : PLAYER);
break;
}
case 2: {
case EVT_BTNRIGHT: {
if (display.mode != PLAYER) return;
player.next();
break;

View File

@@ -1,11 +1,14 @@
#ifndef controls_h
#define controls_h
enum controlEvt_e { EVT_BTNLEFT, EVT_BTNCENTER, EVT_BTNRIGHT, EVT_ENCBTNB, EVT_BTNUP, EVT_BTNDOWN, EVT_ENC2BTNB };
boolean checklpdelay(int m, unsigned long &tstamp);
void initControls();
void loopControls();
void encoderLoop();
void encoder2Loop();
void irLoop();
void irNum(byte num);
void irBlink();

View File

@@ -260,7 +260,9 @@ void Display::swichMode(displayMode_e newmode) {
volume();
#endif
} else {
meta.lock();
if (newmode != NUMBERS) {
meta.lock();
}
title1.lock();
if (TITLE_SIZE2 != 0) title2.lock();
#ifdef CLOCK_SPACE
@@ -271,7 +273,8 @@ void Display::swichMode(displayMode_e newmode) {
dsp.frameTitle("VOLUME");
}
if (newmode == NUMBERS) {
dsp.frameTitle("STATION");
//dsp.frameTitle("STATION");
meta.reset();
}
if (newmode == STATIONS) {
currentPlItem = config.store.lastStation;
@@ -305,6 +308,11 @@ void Display::drawPlaylist() {
}
void Display::drawNextStationNum(uint16_t num) {
char plMenu[1][40];
char currentItemText[40] = {0};
config.fillPlMenu(plMenu, num, 1);
strlcpy(currentItemText, plMenu[0], 39);
meta.setText(dsp.utf8Rus(currentItemText, true));
dsp.drawNextStationNum(num);
}
@@ -319,6 +327,7 @@ void Display::loop() {
break;
}
case NUMBERS: {
meta.loop();
break;
}
case STATIONS: {
@@ -354,6 +363,12 @@ void Display::station() {
netserver.requestOnChange(STATION, 0);
}
void Display::returnTile(){
meta.setText(dsp.utf8Rus(config.station.name, true));
meta.reset();
dsp.loop();
}
void Display::title(const char *str) {
const char *title = str;
char ttl[BUFLEN / 2] = { 0 };

View File

@@ -55,6 +55,7 @@ class Display {
void bootLogo();
void station();
void title(const char *str);
void returnTile();
void time(bool redraw = false);
void volume();
void ip();

View File

@@ -1,7 +1,7 @@
#ifndef options_h
#define options_h
#define VERSION "0.5.020"
#define VERSION "0.5.035"
/*******************************************************
DO NOT EDIT THIS FILE.
@@ -96,6 +96,22 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
#define ENC_HALFQUARD true
#endif
#ifndef ENC2_BTNL
#define ENC2_BTNL 255
#endif
#ifndef ENC2_BTNB
#define ENC2_BTNB 255
#endif
#ifndef ENC2_BTNR
#define ENC2_BTNR 255
#endif
#ifndef ENC2_INTERNALPULLUP
#define ENC2_INTERNALPULLUP true
#endif
#ifndef ENC2_HALFQUARD
#define ENC2_HALFQUARD true
#endif
/* BUTTONS */
#ifndef BTN_LEFT
#define BTN_LEFT 255
@@ -106,6 +122,12 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
#ifndef BTN_RIGHT
#define BTN_RIGHT 255
#endif
#ifndef BTN_UP
#define BTN_UP 255
#endif
#ifndef BTN_DOWN
#define BTN_DOWN 255
#endif
#ifndef BTN_INTERNALPULLUP
#define BTN_INTERNALPULLUP true
#endif

View File

@@ -64,7 +64,7 @@ void LiquidCrystal_I2C::init_priv()
if((_sda_pin==255 && _scl_pin==255) || (_sda_pin==21 && _scl_pin==22)){
Wire.begin();
}else{
Wire.begin(_sda_pin, _scl_pin, (uint32_t)100000);
Wire.begin((int)_sda_pin, (int)_scl_pin, (uint32_t)100000);
}
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
begin(_cols, _rows);

View File

@@ -64,7 +64,7 @@ void DisplayLC1602::getScrolBbounds(const char* text, const char* separator, byt
}
void DisplayLC1602::clearScroll(uint16_t texttop, uint16_t textheight, uint16_t bg) {
for(uint16_t x=0; x<swidth-controlspaces[texttop]; x++){
for(uint16_t x=0; x<swidth-(fillSpaces?controlspaces[texttop]:0); x++){
setCursor(x, texttop);
print(" ");
}
@@ -111,7 +111,7 @@ void DisplayLC1602::drawVolumeBar(bool withNumber) {
void DisplayLC1602::drawNextStationNum(uint16_t num) {
char numstr[7];
sprintf(numstr, "%d", num);
centerText(" ", 1, 0, 0);
clearScroll(1, 0, 0);
centerText(numstr, 1, TFT_LOGO, TFT_BG);
}

View File

@@ -167,13 +167,13 @@ void DisplaySSD1306::drawPlaylist(uint16_t currentItem, char* currentItemText) {
for (byte i = 0; i < PLMITEMS; i++) {
plMenu[i][0] = '\0';
}
config.fillPlMenu(plMenu, currentItem - ((DSP_MODEL==DSP_SSD1306)?3:2), PLMITEMS);
setTextSize(1);
config.fillPlMenu(plMenu, currentItem - 2, PLMITEMS);
setTextSize((DSP_MODEL==DSP_SSD1306)?2:1);
int yStart = (sheight / 2 - PLMITEMHEIGHT / 2) - PLMITEMHEIGHT * (PLMITEMS - 1) / 2 + 3;
fillRect(0, (sheight / 2 - PLMITEMHEIGHT / 2) + 1, swidth, PLMITEMHEIGHT, TFT_LOGO);
setTextColor(TFT_FG, TFT_BG);
for (byte i = 0; i < PLMITEMS; i++) {
if (i == ((DSP_MODEL==DSP_SSD1306)?3:2)) {
if (i == 2) {
strlcpy(currentItemText, plMenu[i], PLMITEMLENGHT - 1);
} else {
setCursor(TFT_FRAMEWDT, yStart + i * PLMITEMHEIGHT);

View File

@@ -10,17 +10,18 @@
#define PLMITEMLENGHT 40
#if DSP_MODEL==DSP_SSD1306
#define PLMITEMS 7
#define PLMITEMHEIGHT 9
#define PLMITEMS 5
#define PLMITEMHEIGHT 18
#define TITLE_TOP2 TFT_FRAMEWDT + 3 * TFT_LINEHGHT
#define PLCURRENT_SIZE 1
#define PLCURRENT_SIZE 2
#define BOOTSTR_TOP1 64-TFT_LINEHGHT*2-5
#define BOOTSTR_TOP2 64-TFT_LINEHGHT
#define VOL_TOP 24
#else
#define PLMITEMS 5
#define PLMITEMHEIGHT 10
#define TITLE_TOP2 TFT_FRAMEWDT + 2 * TFT_LINEHGHT
#define PLCURRENT_SIZE 1
@@ -33,6 +34,7 @@
#define CLOCK_SPACE 38
#define VOL_SPACE 0
#define VOL_TOP 16
#endif
class DisplaySSD1306: public Adafruit_SSD1306 {
public: