diff --git a/platformio.ini b/platformio.ini index c71c05db3f..1a480bb908 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1302,20 +1302,21 @@ board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ; RAM: [=== ] 26.3% (used 86188 bytes from 327680 bytes) ; Flash: [========= ] 85.2% (used 1619513 bytes from 1900544 bytes) -[env:Croach_WLED_Box_4MB] +[env:WLED_Box_4MB] extends = esp32_4MB_M_base build_flags = ${esp32_4MB_M_base.build_flags} - -D WLED_RELEASE_NAME=Croach_WLED_BOX_4MB - ;-D WLED_DISABLE_ALEXA - ;-D WLED_DISABLE_HUESYNC ;; Over the limits ? - ;-D WLED_DISABLE_LOXONE ;; Over the limits - ;-D WLED_DISABLE_MQTT - ;-D WLED_DISABLE_INFRARED + -D WLED_RELEASE_NAME=WLED_BOX + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC ;; Over the limits ? + -D WLED_DISABLE_LOXONE ;; Over the limits + -D WLED_DISABLE_MQTT + -D WLED_DISABLE_INFRARED -D WLEDMM_SAVE_FLASH ;; a humble attempt to save a few extra bytes -D USERMOD_PWM_FAN -D USERMOD_BATTERY ;; enable Battery usermod -D USERMOD_BATTERY_USE_LIPO ;; use new "discharging curve" for LiPo cells -D USERMOD_WEATHER ; WLEDMM usermod + -D USERMOD_POWER_BUTTON -D PWM_PIN=5 -D HW_PIN_SDA=21 -D HW_PIN_SCL=22 @@ -1323,11 +1324,11 @@ build_flags = ${esp32_4MB_M_base.build_flags} -D TEMPERATURE_PIN=32 -D ENCODER_DT_PIN=17 -D ENCODER_CLK_PIN=16 -D ENCODER_SW_PIN=4 -D SR_DMTYPE=1 -D I2S_SDPIN=19 -D I2S_CKPIN=23 -D I2S_WSPIN=18 -D MCLK_PIN=-1 +lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation build_unflags = ${esp32_4MB_M_base.build_unflags} board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv -RAM: [=== ] 26.6% (used 87124 bytes from 327680 bytes) -Flash: [======== ] 81.5% (used 1548385 bytes from 1900544 bytes) - +; RAM: [=== ] 26.3% (used 86324 bytes from 327680 bytes) +; Flash: [======== ] 78.2% (used 1485909 bytes from 1900544 bytes) ;; standard framework build for 16MB flash, optimized for speed [env:esp32_16MB_S] diff --git a/usermods/PowerButton/usermode_powerbutton.h b/usermods/PowerButton/usermode_powerbutton.h index 0002e8be9b..0d0e6ce997 100644 --- a/usermods/PowerButton/usermode_powerbutton.h +++ b/usermods/PowerButton/usermode_powerbutton.h @@ -10,6 +10,8 @@ #define USERMOD_POWER_BUTTON_INTERVAL 50 #endif +#define LONG_PRESS_TIME (2500) + // power_btn_pin 39 // btn_pin 14 @@ -21,16 +23,23 @@ */ class UsermodPowerButton : public Usermod { private: + enum ButtonStatus { + Pressed, + Released, + }; // power button pin can be defined in my_config.h int8_t powerBtnPin = USERMOD_POWER_BUTTON_PIN; // how often to read the button status unsigned long readingInterval = USERMOD_POWER_BUTTON_INTERVAL; unsigned long nextReadTime = 0; unsigned long lastReadTime = 0; + unsigned long pressedTime = 0; bool initDone = false; bool initializing = true; + ButtonStatus btnStatus = Released; + byte oriBright = 0; /* @@ -129,8 +138,18 @@ class UsermodPowerButton : public Usermod { initializing = false; - // Croach: handle to power button status - // press -> relase, trigger sleep + if (LOW == digitalRead(powerBtnPin)) { // pressed + if (Released == btnStatus) { + pressedTime = millis(); + } + btnStatus = Pressed; + } else { + if ((Pressed == btnStatus) && + (LONG_PRESS_TIME < (millis() - pressedTime))) { + sleep(); + } + btnStatus = Released; + } } /* diff --git a/wled00/pin_manager.cpp b/wled00/pin_manager.cpp index d1e7a18b45..ce67765d33 100644 --- a/wled00/pin_manager.cpp +++ b/wled00/pin_manager.cpp @@ -68,6 +68,7 @@ String PinManagerClass::getOwnerText(PinOwner tag) { case PinOwner::UM_PWM_OUTPUTS : return(F("PWM Output (UM)")); break; // "usermod_pwm_outputs.h" case PinOwner::UM_Battery : return(F("Battery (UM)")); break; // "usermod_battery.h" case PinOwner::UM_LDR_DUSK_DAWN : return(F("LDR dusk/dawn (UM)")); break; // "usermod_LDR_Dusk_Dawn_v2.h" + case PinOwner::UM_PowerButton : return(F("Power Button (UM)")); break; // "usermod_powerbutton.h" case PinOwner::UM_Example : return(F("example (UM)")); break; // unspecified usermod case PinOwner::UM_Unspecified : return(F("usermod (UM)")); break; // unspecified usermod diff --git a/wled00/usermods_list.cpp b/wled00/usermods_list.cpp index a6e7ba7a85..a0fc03eddf 100644 --- a/wled00/usermods_list.cpp +++ b/wled00/usermods_list.cpp @@ -185,6 +185,10 @@ #include "../usermods/LDR_Dusk_Dawn_v2/usermod_LDR_Dusk_Dawn_v2.h" #endif +#ifdef USERMOD_POWER_BUTTON +#include "../usermods/PowerButton/usermode_powerbutton.h" +#endif + //WLEDMM ARTIFX #ifdef USERMOD_ARTIFX #include "../usermods/artifx/usermod_v2_artifx.h"