diff --git a/src/main.cpp b/src/main.cpp index 104a41d..eb97cd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -291,14 +291,15 @@ volatile SemaphoreHandle_t timerSemaphore; // Button-helper typedef struct { - bool lastState; - bool currentState; - bool isPressed; - bool isReleased; + bool lastState : 1; + bool currentState : 1; + bool isPressed : 1; + bool isReleased : 1; unsigned long lastPressedTimestamp; unsigned long lastReleasedTimestamp; } t_button; -t_button buttons[4]; + +t_button buttons[6]; Preferences prefsRfid; Preferences prefsSettings; @@ -491,7 +492,11 @@ void buttonHandler() { buttons[0].currentState = digitalRead(NEXT_BUTTON); buttons[1].currentState = digitalRead(PREVIOUS_BUTTON); buttons[2].currentState = digitalRead(PAUSEPLAY_BUTTON); - buttons[3].currentState = digitalRead(DREHENCODER_BUTTON); + #ifdef USEROTARY_ENABLE + buttons[3].currentState = digitalRead(DREHENCODER_BUTTON); + #endif + if(BUTTON_4 > 0 && BUTTON_4 < 50) buttons[4].currentState = digitalRead(BUTTON_4); + if(BUTTON_5 > 0 && BUTTON_5 < 50) buttons[5].currentState = digitalRead(BUTTON_5); // Iterate over all buttons in struct-array for (uint8_t i=0; i < sizeof(buttons) / sizeof(buttons[0]); i++) { @@ -572,6 +577,16 @@ void doButtonActions(void) { doCmdAction(BUTTON_3_LONG); buttons[i].isPressed = false; break; + + case 4: + doCmdAction(BUTTON_4_LONG); + buttons[i].isPressed = false; + break; + + case 5: + doCmdAction(BUTTON_5_LONG); + buttons[i].isPressed = false; + break; } } else { switch (i) // Short-press-actions @@ -594,6 +609,17 @@ void doButtonActions(void) { case 3: doCmdAction(BUTTON_3_SHORT); buttons[i].isPressed = false; + break; + + case 4: + doCmdAction(BUTTON_4_SHORT); + buttons[i].isPressed = false; + break; + + case 5: + doCmdAction(BUTTON_5_SHORT); + buttons[i].isPressed = false; + break; } } } @@ -2504,7 +2530,7 @@ void doRfidCardModifications(const uint32_t mod) { } #endif - doAction(mod); + doCmdAction(mod); } void doCmdAction(const uint32_t mod) { @@ -2900,10 +2926,10 @@ void doCmdAction(const uint32_t mod) { case CMD_NEXTTRACK: trackControlToQueueSender(NEXTTRACK); break; - case CMD_FIRSTRACK: + case CMD_FIRSTTRACK: trackControlToQueueSender(FIRSTTRACK); break; - case CMD_LASTRACK: + case CMD_LASTTRACK: trackControlToQueueSender(LASTTRACK); break; case CMD_VOLUMEINIT: diff --git a/src/settings-custom.h b/src/settings-custom.h index 36d9929..56096e8 100644 --- a/src/settings-custom.h +++ b/src/settings-custom.h @@ -52,6 +52,8 @@ #define PAUSEPLAY_BUTTON 5 // GPIO to detect pause/play #define NEXT_BUTTON 4 // GPIO to detect next #define PREVIOUS_BUTTON 2 // GPIO to detect previous (Important: as of 19.11.2020 changed from 33 to 2; make sure to change in SD-MMC-mode) +#define BUTTON_4 99 // Button 4 +#define BUTTON_5 99 // Button 5 // (optional) Power-control #define POWER 17 // GPIO used to drive transistor-circuit, that switches off peripheral devices while ESP32-deepsleep diff --git a/src/settings-espa1s.h b/src/settings-espa1s.h index 7af0e5f..7c776f3 100644 --- a/src/settings-espa1s.h +++ b/src/settings-espa1s.h @@ -46,6 +46,8 @@ #define PAUSEPLAY_BUTTON 36 // GPIO to detect pause/play #define NEXT_BUTTON 199 // GPIO to detect next #define PREVIOUS_BUTTON 198 // GPIO to detect previous (Important: as of 19.11.2020 changed from 33 to 2) +#define BUTTON_4 99 // Button 4 +#define BUTTON_5 99 // Button 5 // Power-control #define POWER 19 // GPIO used to drive transistor-circuit, that switches off peripheral devices while ESP32-deepsleep diff --git a/src/settings-lolin32.h b/src/settings-lolin32.h index 43c6853..ae7ba1b 100644 --- a/src/settings-lolin32.h +++ b/src/settings-lolin32.h @@ -58,6 +58,8 @@ #define PAUSEPLAY_BUTTON 5 // GPIO to detect pause/play #define NEXT_BUTTON 4 // GPIO to detect next #define PREVIOUS_BUTTON 2 // GPIO to detect previous (Important: as of 19.11.2020 changed from 33 to 2; make sure to change in SD-MMC-mode) +#define BUTTON_4 99 // Button 4 +#define BUTTON_5 99 // Button 5 // (optional) Power-control #define POWER 17 // GPIO used to drive transistor-circuit, that switches off peripheral devices while ESP32-deepsleep diff --git a/src/settings-lolin_d32.h b/src/settings-lolin_d32.h index d9b7fea..7d21828 100644 --- a/src/settings-lolin_d32.h +++ b/src/settings-lolin_d32.h @@ -59,6 +59,8 @@ #define PAUSEPLAY_BUTTON 5 // GPIO to detect pause/play #define NEXT_BUTTON 4 // GPIO to detect next #define PREVIOUS_BUTTON 2 // GPIO to detect previous (Important: as of 19.11.2020 changed from 33 to 2) +#define BUTTON_4 99 // Button 4 +#define BUTTON_5 99 // Button 5 // (optional) Power-control #define POWER 17 // GPIO used to drive transistor-circuit, that switches off peripheral devices while ESP32-deepsleep diff --git a/src/settings-lolin_d32_pro.h b/src/settings-lolin_d32_pro.h index 2467b15..56fe13e 100644 --- a/src/settings-lolin_d32_pro.h +++ b/src/settings-lolin_d32_pro.h @@ -54,6 +54,8 @@ #define PAUSEPLAY_BUTTON 32 // GPIO to detect pause/play #define NEXT_BUTTON 0 // GPIO to detect next #define PREVIOUS_BUTTON 2 // GPIO to detect previous (Important: as of 19.11.2020 changed from 33 to 2) +#define BUTTON_4 99 // Button 4 +#define BUTTON_5 99 // Button 5 // (optional) Power-control #define POWER 5 // GPIO used to drive transistor-circuit, that switches off peripheral devices while ESP32-deepsleep diff --git a/src/settings.h b/src/settings.h index 8db58fb..975e5dd 100644 --- a/src/settings.h +++ b/src/settings.h @@ -151,25 +151,30 @@ float voltageIndicatorHigh = 4.2; // Upper range for Neopixel- // Button Layout -#define BUTTON_MULTI_01 = TOGGLE_WIFI_STATUS -#define BUTTON_MULTI_02 = ENABLE_FTP_SERVER -#define BUTTON_MULTI_03 = CMD_NOTHING -#define BUTTON_MULTI_12 = CMD_MEASUREBATTERY -#define BUTTON_MULTI_13 = CMD_NOTHING -#define BUTTON_MULTI_23 = CMD_NOTHING - -#define BUTTON_0_SHORT = CMD_NEXTTRACK -#define BUTTON_1_SHORT = CMD_PREVTRACK -#define BUTTON_2_SHORT = CMD_PLAYPAUSE -#define BUTTON_3_SHORT = CMD_MEASUREBATTERY -#define BUTTON_3_LONG = CMD_SLEEPMODE +#define BUTTON_MULTI_01 TOGGLE_WIFI_STATUS +#define BUTTON_MULTI_02 ENABLE_FTP_SERVER +#define BUTTON_MULTI_03 CMD_NOTHING +#define BUTTON_MULTI_12 CMD_MEASUREBATTERY +#define BUTTON_MULTI_13 CMD_NOTHING +#define BUTTON_MULTI_23 CMD_NOTHING + +#define BUTTON_0_SHORT CMD_NEXTTRACK +#define BUTTON_1_SHORT CMD_PREVTRACK +#define BUTTON_2_SHORT CMD_PLAYPAUSE +#define BUTTON_3_SHORT CMD_MEASUREBATTERY +#define BUTTON_3_LONG CMD_SLEEPMODE + +#define BUTTON_4_SHORT CMD_VOLUMEDOWN +#define BUTTON_4_LONG CMD_VOLUMEDOWN +#define BUTTON_5_SHORT CMD_VOLUMEUP +#define BUTTON_5_LONG CMD_VOLUMEUP #ifdef USEROTARY_ENABLE - #define BUTTON_0_LONG = CMD_LASTTRACK - #define BUTTON_1_LONG = CMD_FIRSTTRACK - #define BUTTON_2_LONG = CMD_PLAYPAUSE + #define BUTTON_0_LONG CMD_LASTTRACK + #define BUTTON_1_LONG CMD_FIRSTTRACK + #define BUTTON_2_LONG CMD_PLAYPAUSE #else - #define BUTTON_0_LONG = CMD_VOLUMEDOWN - #define BUTTON_1_LONG = CMD_VOLUMEUP - #define BUTTON_2_LONG = CMD_SLEEPMODE -#endif \ No newline at end of file + #define BUTTON_0_LONG CMD_VOLUMEDOWN + #define BUTTON_1_LONG CMD_VOLUMEUP + #define BUTTON_2_LONG CMD_SLEEPMODE +#endif diff --git a/src/values.h b/src/values.h index a26a3f6..fb54324 100644 --- a/src/values.h +++ b/src/values.h @@ -47,9 +47,9 @@ #define CMD_PLAYPAUSE 170 // Admin-Cmd Play/Pause #define CMD_PREVTRACK 171 // Admin-Cmd Prev Track -#define CMD_NEXTTACK 172 // Admin-Cmd Next Track +#define CMD_NEXTTRACK 172 // Admin-Cmd Next Track #define CMD_FIRSTTRACK 173 // Admin-Cmd Prev Track -#define CMD_LASTTACK 174 // Admin-Cmd Next Track +#define CMD_LASTTRACK 174 // Admin-Cmd Next Track #define CMD_VOLUMEINIT 175 // Set Volume to Initial #define CMD_VOLUMEUP 176 // Set Volume up #define CMD_VOLUMEDOWN 177 // Set Volume down