Skip to content

Commit

Permalink
MoonModules#3 - add power button definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
croachc committed Aug 23, 2024
1 parent b39dc34 commit b41f271
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
21 changes: 11 additions & 10 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1302,32 +1302,33 @@ 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
-D LEDPIN=25
-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]
Expand Down
23 changes: 21 additions & 2 deletions usermods/PowerButton/usermode_powerbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define USERMOD_POWER_BUTTON_INTERVAL 50
#endif

#define LONG_PRESS_TIME (2500)

// power_btn_pin 39
// btn_pin 14

Expand All @@ -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;

/*
Expand Down Expand Up @@ -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;
}
}

/*
Expand Down
1 change: 1 addition & 0 deletions wled00/pin_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wled00/usermods_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b41f271

Please sign in to comment.