This commit is contained in:
e2002
2022-12-13 16:31:32 +03:00
parent 6c9b2651e3
commit b75b9c6d11
5 changed files with 41 additions and 25 deletions

View File

@@ -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);

View File

@@ -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 <class T> int eepromWrite(int ee, const T& value);
template <class T> int eepromRead(int ee, T& value);

View File

@@ -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: {

View File

@@ -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 };

View File

@@ -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