From b75b9c6d1153a722e0fd521a3b65a9fac40cb1e2 Mon Sep 17 00:00:00 2001 From: e2002 Date: Tue, 13 Dec 2022 16:31:32 +0300 Subject: [PATCH] btn_mode --- yoRadio/src/core/config.cpp | 29 +++++++++++------------------ yoRadio/src/core/config.h | 4 ++++ yoRadio/src/core/controls.cpp | 28 ++++++++++++++++++++++------ yoRadio/src/core/controls.h | 2 +- yoRadio/src/core/options.h | 3 +++ 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/yoRadio/src/core/config.cpp b/yoRadio/src/core/config.cpp index 1589989..5a07319 100644 --- a/yoRadio/src/core/config.cpp +++ b/yoRadio/src/core/config.cpp @@ -32,7 +32,7 @@ void Config::init() { loadTheme(); ssidsCount = 0; - if(SDC_CS!=255 && store.play_mode==/*PM_SDCARD*/PM_WEB){ + if(SDC_CS!=255 && store.play_mode==PM_WEB){ pinMode(SDC_CS, OUTPUT); digitalWrite(SDC_CS, HIGH); SDSPI.begin(SDC_SPI); SDSPI.setFrequency(1000000); @@ -311,16 +311,10 @@ void Config::listSD(File &plSDfile, File &plSDindex, const char * dirname, uint8 while(file){ if(file.isDirectory()){ -// Serial.print(" DIR : "); -// Serial.println(file.name()); if(levels){ listSD(plSDfile, plSDindex, file.path(), levels -1); } } else { -// Serial.print(" FILE: "); -// Serial.print(file.name()); -// Serial.print(" SIZE: "); -// Serial.println(file.size()); if(endsWith(file.name(), ".mp3") || endsWith(file.name(), ".m4a") || endsWith(file.name(), ".aac") || endsWith(file.name(), ".wav") || endsWith(file.name(), ".flac")){ pos = plSDfile.position(); plSDfile.print(file.name()); plSDfile.print("\t"); plSDfile.print(file.path()); plSDfile.print("\t"); plSDfile.println(0); @@ -338,18 +332,8 @@ void Config::indexSDPlaylist() { if (!playlist) { return; } - - -// char sName[BUFLEN], sUrl[BUFLEN]; -// int sOvol; File index = SPIFFS.open(INDEX_SD_PATH, "w"); listSD(playlist, index, "/", 2); -/* while (playlist.available()) { - uint32_t pos = playlist.position(); - if (parseCSV(playlist.readStringUntil('\n').c_str(), sName, sUrl, sOvol)) { - index.write((byte *) &pos, 4); - } - }*/ index.close(); playlist.close(); } @@ -357,7 +341,6 @@ void Config::indexSDPlaylist() { void Config::initSDPlaylist() { store.countStation = 0; indexSDPlaylist(); - if (SPIFFS.exists(INDEX_SD_PATH)) { File index = SD.open(INDEX_SD_PATH, "r"); store.countStation = index.size() / 4; @@ -633,6 +616,16 @@ void Config::doSleep(){ esp_deep_sleep_start(); } +void Config::doSleepW(){ + if(BRIGHTNESS_PIN!=255) analogWrite(BRIGHTNESS_PIN, 0); + display.deepsleep(); +#ifdef USE_NEXTION + nextion.sleep(); +#endif + if(WAKE_PIN!=255) esp_sleep_enable_ext0_wakeup((gpio_num_t)WAKE_PIN, LOW); + esp_deep_sleep_start(); +} + void Config::sleepForAfter(uint16_t sf, uint16_t sa){ sleepfor = sf; if(sa > 0) _sleepTimer.attach(sa * 60, doSleep); diff --git a/yoRadio/src/core/config.h b/yoRadio/src/core/config.h index 29dd843..07f52c2 100644 --- a/yoRadio/src/core/config.h +++ b/yoRadio/src/core/config.h @@ -29,6 +29,9 @@ #endif #define BOOTLOG( ... ) { char buf[120]; sprintf( buf, __VA_ARGS__ ) ; Serial.print("##[BOOT]#\t"); Serial.println(buf); } #define EVERY_MS(x) static uint32_t tmr; bool flag = millis() - tmr >= (x); if (flag) tmr += (x); if (flag) + +#define MAX_PLAY_MODE 1 + void u8fix(char *src); struct theme_t { @@ -185,6 +188,7 @@ class Config { void setDspOn(bool dspon); void sleepForAfter(uint16_t sleepfor, uint16_t sleepafter=0); void bootInfo(); + void doSleepW(); private: template int eepromWrite(int ee, const T& value); template int eepromRead(int ee, T& value); diff --git a/yoRadio/src/core/controls.cpp b/yoRadio/src/core/controls.cpp index 99a3778..e8e80eb 100644 --- a/yoRadio/src/core/controls.cpp +++ b/yoRadio/src/core/controls.cpp @@ -10,10 +10,10 @@ long encOldPosition = 0; long enc2OldPosition = 0; int lpId = -1; -#define ISPUSHBUTTONS BTN_LEFT!=255 || BTN_CENTER!=255 || BTN_RIGHT!=255 || ENC_BTNB!=255 || BTN_UP!=255 || BTN_DOWN!=255 || ENC2_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 || BTN_MODE!=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}, {BTN_UP, true, BTN_INTERNALPULLUP}, {BTN_DOWN, true, BTN_INTERNALPULLUP}, {ENC2_BTNB, true, ENC2_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}, {BTN_MODE, true, BTN_INTERNALPULLUP}}; constexpr uint8_t nrOfButtons = sizeof(button) / sizeof(button[0]); #endif @@ -95,7 +95,7 @@ void initControls() { #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) || (i == 4 && BTN_UP == 255) || (i == 5 && BTN_DOWN == 255) || (i == 6 && ENC2_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) || (i == 7 && BTN_MODE == 255)) continue; button[i].attachClick([](void* p) { onBtnClick((int)p); }, (void*)i); @@ -324,7 +324,8 @@ void irLoop() { break; } case IR_AST: { - ESP.restart(); + //ESP.restart(); + onBtnClick(EVT_BTNMODE); break; } } /* switch (target) */ @@ -361,8 +362,12 @@ void onBtnLongPressStart(int id) { display.putRequest(NEWMODE, display.mode() == PLAYER ? VOL : PLAYER); break; } - default: + case EVT_BTNMODE: { + //onBtnClick(EVT_BTNMODE); + config.doSleepW(); break; + } + default: break; } } @@ -489,6 +494,16 @@ void onBtnClick(int id) { } break; } + case EVT_BTNMODE: { + config.store.play_mode++; + if(config.store.play_mode > MAX_PLAY_MODE){ + config.store.play_mode=0; + config.save(); + ESP.restart(); + } + break; + } + default: break; } } @@ -502,7 +517,8 @@ void onBtnDoubleClick(int id) { case EVT_BTNCENTER: case EVT_ENCBTNB: case EVT_ENC2BTNB: { - display.putRequest(NEWMODE, display.mode() == PLAYER ? VOL : PLAYER); + //display.putRequest(NEWMODE, display.mode() == PLAYER ? VOL : PLAYER); + onBtnClick(EVT_BTNMODE); break; } case EVT_BTNRIGHT: { diff --git a/yoRadio/src/core/controls.h b/yoRadio/src/core/controls.h index de3c228..b4b5022 100644 --- a/yoRadio/src/core/controls.h +++ b/yoRadio/src/core/controls.h @@ -6,7 +6,7 @@ #include "../yoEncoder/yoEncoder.h" #endif -enum controlEvt_e { EVT_BTNLEFT, EVT_BTNCENTER, EVT_BTNRIGHT, EVT_ENCBTNB, EVT_BTNUP, EVT_BTNDOWN, EVT_ENC2BTNB }; +enum controlEvt_e { EVT_BTNLEFT, EVT_BTNCENTER, EVT_BTNRIGHT, EVT_ENCBTNB, EVT_BTNUP, EVT_BTNDOWN, EVT_ENC2BTNB, EVT_BTNMODE }; //enum tsDirection_e { TSD_STAY, TSD_LEFT, TSD_RIGHT, TSD_UP, TSD_DOWN, TDS_REQUEST }; diff --git a/yoRadio/src/core/options.h b/yoRadio/src/core/options.h index b9a4f65..15f9ba5 100644 --- a/yoRadio/src/core/options.h +++ b/yoRadio/src/core/options.h @@ -171,6 +171,9 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti #ifndef BTN_DOWN #define BTN_DOWN 255 #endif +#ifndef BTN_MODE + #define BTN_MODE 255 +#endif #ifndef BTN_INTERNALPULLUP #define BTN_INTERNALPULLUP true #endif