mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-28 09:39:11 +03:00
Merge branch 'dev'
This commit is contained in:
@@ -23,10 +23,10 @@
|
||||
// Constructor
|
||||
PButton::PButton() {
|
||||
// Initialization of default properties
|
||||
Debounce_ = 40; // Debounce period to prevent flickering when pressing or releasing the button (in ms)
|
||||
DblClickDelay_ = 250; // Max period between clicks for a double click event (in ms)
|
||||
LongPressDelay_ = 750; // Hold period for a long press event (in ms)
|
||||
VLongPressDelay_ = 3000; // Hold period for a very long press event (in ms)
|
||||
Debounce_ = 40; // Debounce period to prevent flickering when pressing or releasing the button (in ms)
|
||||
DblClickDelay_ = 250; // Max period between clicks for a double click event (in ms)
|
||||
LongPressDelay_ = 9500; // Hold period for a long press event (in ms)
|
||||
VLongPressDelay_ = 20000; // Hold period for a very long press event (in ms)
|
||||
|
||||
cb_onClick = nullptr;
|
||||
cb_onDblClick = nullptr;
|
||||
@@ -54,7 +54,15 @@ bool PButton::init(uint8_t pin, bool pullMode) {
|
||||
pullMode_ = pullMode; // 1=HIGH (pullup) 0=LOW (pulldown)
|
||||
|
||||
#if defined(ESP32)
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
if (pin_ == 34 || pin_ == 35 || pin_ == 36 || pin_ == 39) {
|
||||
pinMode(pin_, INPUT);
|
||||
} else {
|
||||
pinMode(pin_, pullMode ? INPUT_PULLUP : INPUT_PULLDOWN);
|
||||
}
|
||||
#else
|
||||
pinMode(pin_, pullMode ? INPUT_PULLUP : INPUT_PULLDOWN);
|
||||
#endif
|
||||
#else // esp8266 and standalone
|
||||
pinMode(pin_, pullMode ? INPUT_PULLUP : INPUT);
|
||||
#endif
|
||||
@@ -93,7 +101,15 @@ bool PButton::check(void) {
|
||||
|
||||
// make sure the pin is still input
|
||||
#if defined(ESP32)
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
if (pin_ == 34 || pin_ == 35 || pin_ == 36 || pin_ == 39) {
|
||||
pinMode(pin_, INPUT);
|
||||
} else {
|
||||
pinMode(pin_, pullMode_ ? INPUT_PULLUP : INPUT_PULLDOWN);
|
||||
}
|
||||
#else
|
||||
pinMode(pin_, pullMode_ ? INPUT_PULLUP : INPUT_PULLDOWN);
|
||||
#endif
|
||||
#else // esp8266 and standalone
|
||||
pinMode(pin_, pullMode_ ? INPUT_PULLUP : INPUT);
|
||||
#endif
|
||||
|
||||
@@ -36,6 +36,9 @@ class PButton {
|
||||
void onVLongPress(uint16_t, buttonEventHandler handler);
|
||||
bool init(uint8_t pin, bool pullMode);
|
||||
bool check(void);
|
||||
bool button_busy() {
|
||||
return buttonBusy_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t Debounce_; // Debounce period to prevent flickering when pressing or releasing the button (in ms)
|
||||
@@ -47,21 +50,21 @@ class PButton {
|
||||
bool pullMode_;
|
||||
bool enabled_;
|
||||
|
||||
bool state_; // Value read from button
|
||||
bool lastState_; // Last value of button state
|
||||
bool dblClickWaiting_; // whether we're waiting for a double click (down)
|
||||
bool dblClickOnNextUp_; // whether to register a double click on next release, or whether to wait and click
|
||||
bool singleClickOK_; // whether it's OK to do a single click
|
||||
bool state_; // Value read from button
|
||||
bool lastState_; // Last value of button state
|
||||
bool dblClickWaiting_; // whether we're waiting for a double click (down)
|
||||
bool dblClickOnNextUp_; // whether to register a double click on next release, or whether to wait and click
|
||||
bool singleClickOK_; // whether it's OK to do a single click
|
||||
|
||||
uint32_t downTime_; // time the button was pressed down
|
||||
uint32_t upTime_; // time the button was released
|
||||
uint32_t downTime_; // time the button was pressed down
|
||||
uint32_t upTime_; // time the button was released
|
||||
|
||||
bool ignoreUP_; // whether to ignore the button release because the click+hold was triggered
|
||||
bool waitForUP_; // when held, whether to wait for the up event
|
||||
bool longPressHappened_; // whether or not the hold event happened already
|
||||
bool vLongPressHappened_; // whether or not the long hold event happened already
|
||||
|
||||
bool buttonBusy_; // false if idle
|
||||
bool buttonBusy_; // false if idle
|
||||
|
||||
buttonEventHandler cb_onClick, cb_onDblClick, cb_onLongPress, cb_onVLongPress;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user