Add switch support
This commit is contained in:
parent
5786f1d057
commit
48d5584491
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
### Builds after release 0.12.0
|
### Builds after release 0.12.0
|
||||||
|
|
||||||
|
#### Build 2104120
|
||||||
|
|
||||||
|
- Added switch support (button macro is switch closing action, long press macro switch opening)
|
||||||
|
- Replaced Circus effect with new Running Dual effect (Circus is Tricolor Chase with Red/White/Black)
|
||||||
|
- Fixed ledmap with multiple segments (PR #1864)
|
||||||
|
|
||||||
#### Build 2104030
|
#### Build 2104030
|
||||||
|
|
||||||
- Fixed ESP32 crash on Drip effect with reversed segment (#1854)
|
- Fixed ESP32 crash on Drip effect with reversed segment (#1854)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
* Physical IO
|
* Physical IO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define WLED_DEBOUNCE_THRESHOLD 50 //only consider button input of at least 50ms as valid (debouncing)
|
||||||
|
|
||||||
void shortPressAction()
|
void shortPressAction()
|
||||||
{
|
{
|
||||||
if (!macroButton)
|
if (!macroButton)
|
||||||
@ -25,10 +27,42 @@ bool isButtonPressed()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void handleSwitch()
|
||||||
|
{
|
||||||
|
if (buttonPressedBefore != isButtonPressed()) {
|
||||||
|
buttonPressedTime = millis();
|
||||||
|
buttonPressedBefore = !buttonPressedBefore;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttonLongPressed == buttonPressedBefore) return;
|
||||||
|
|
||||||
|
if (millis() - buttonPressedTime > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce)
|
||||||
|
if (buttonPressedBefore) { //LOW, falling edge, switch closed
|
||||||
|
if (macroButton) applyPreset(macroButton);
|
||||||
|
else { //turn on
|
||||||
|
if (!bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);}
|
||||||
|
}
|
||||||
|
} else { //HIGH, rising edge, switch opened
|
||||||
|
if (macroLongPress) applyPreset(macroLongPress);
|
||||||
|
else { //turn off
|
||||||
|
if (bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buttonLongPressed = buttonPressedBefore; //save the last "long term" switch state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void handleButton()
|
void handleButton()
|
||||||
{
|
{
|
||||||
if (btnPin<0 || !buttonEnabled) return;
|
if (btnPin<0 || buttonType < BTN_TYPE_PUSH) return;
|
||||||
|
|
||||||
|
|
||||||
|
if (buttonType == BTN_TYPE_SWITCH) { //button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NO gpio0)
|
||||||
|
handleSwitch(); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//momentary button logic
|
||||||
if (isButtonPressed()) //pressed
|
if (isButtonPressed()) //pressed
|
||||||
{
|
{
|
||||||
if (!buttonPressedBefore) buttonPressedTime = millis();
|
if (!buttonPressedBefore) buttonPressedTime = millis();
|
||||||
@ -48,7 +82,7 @@ void handleButton()
|
|||||||
else if (!isButtonPressed() && buttonPressedBefore) //released
|
else if (!isButtonPressed() && buttonPressedBefore) //released
|
||||||
{
|
{
|
||||||
long dur = millis() - buttonPressedTime;
|
long dur = millis() - buttonPressedTime;
|
||||||
if (dur < 50) {buttonPressedBefore = false; return;} //too short "press", debounce
|
if (dur < WLED_DEBOUNCE_THRESHOLD) {buttonPressedBefore = false; return;} //too short "press", debounce
|
||||||
bool doublePress = buttonWaitTime;
|
bool doublePress = buttonWaitTime;
|
||||||
buttonWaitTime = 0;
|
buttonWaitTime = 0;
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ void deserializeConfig() {
|
|||||||
if (hw_led["rev"]) busses.getBus(0)->reversed = true; //set 0.11 global reversed setting for first bus
|
if (hw_led["rev"]) busses.getBus(0)->reversed = true; //set 0.11 global reversed setting for first bus
|
||||||
|
|
||||||
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
|
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
|
||||||
CJSON(buttonEnabled, hw_btn_ins_0["type"]);
|
CJSON(buttonType, hw_btn_ins_0["type"]);
|
||||||
int hw_btn_pin = hw_btn_ins_0[F("pin")][0];
|
int hw_btn_pin = hw_btn_ins_0[F("pin")][0];
|
||||||
if (pinManager.allocatePin(hw_btn_pin,false)) {
|
if (pinManager.allocatePin(hw_btn_pin,false)) {
|
||||||
btnPin = hw_btn_pin;
|
btnPin = hw_btn_pin;
|
||||||
@ -477,7 +477,7 @@ void serializeConfig() {
|
|||||||
|
|
||||||
// button BTNPIN
|
// button BTNPIN
|
||||||
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
|
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
|
||||||
hw_btn_ins_0["type"] = (buttonEnabled) ? BTN_TYPE_PUSH : BTN_TYPE_NONE;
|
hw_btn_ins_0["type"] = buttonType;
|
||||||
|
|
||||||
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
|
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
|
||||||
hw_btn_ins_0_pin.add(btnPin);
|
hw_btn_ins_0_pin.add(btnPin);
|
||||||
|
@ -135,7 +135,7 @@
|
|||||||
#define BTN_TYPE_RESERVED 1
|
#define BTN_TYPE_RESERVED 1
|
||||||
#define BTN_TYPE_PUSH 2
|
#define BTN_TYPE_PUSH 2
|
||||||
#define BTN_TYPE_PUSH_ACT_HIGH 3 //not implemented
|
#define BTN_TYPE_PUSH_ACT_HIGH 3 //not implemented
|
||||||
#define BTN_TYPE_SWITCH 4 //not implemented
|
#define BTN_TYPE_SWITCH 4
|
||||||
#define BTN_TYPE_SWITCH_ACT_HIGH 5 //not implemented
|
#define BTN_TYPE_SWITCH_ACT_HIGH 5 //not implemented
|
||||||
|
|
||||||
//Ethernet board types
|
//Ethernet board types
|
||||||
|
@ -16,7 +16,12 @@ function GetV(){var d=document;}
|
|||||||
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
|
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
|
||||||
<h2>Sync setup</h2>
|
<h2>Sync setup</h2>
|
||||||
<h3>Button setup</h3>
|
<h3>Button setup</h3>
|
||||||
On/Off button enabled: <input type="checkbox" name="BT"><br>
|
Button type:
|
||||||
|
<select name=BT>
|
||||||
|
<option value=0>Disabled</option>
|
||||||
|
<option value=2>Pushbutton</option>
|
||||||
|
<option value=4>Switch</option>
|
||||||
|
</select><br>
|
||||||
Infrared remote:
|
Infrared remote:
|
||||||
<select name=IR>
|
<select name=IR>
|
||||||
<option value=0>Disabled</option>
|
<option value=0>Disabled</option>
|
||||||
|
@ -222,12 +222,13 @@ var d=document;function H(){window.open("https://github.com/Aircoookie/WLED/wiki
|
|||||||
id="form_s" name="Sf" method="post"><div class="helpB"><button type="button"
|
id="form_s" name="Sf" method="post"><div class="helpB"><button type="button"
|
||||||
onclick="H()">?</button></div><button type="button" onclick="B()">Back</button>
|
onclick="H()">?</button></div><button type="button" onclick="B()">Back</button>
|
||||||
<button type="submit">Save</button><hr><h2>Sync setup</h2><h3>Button setup</h3>
|
<button type="submit">Save</button><hr><h2>Sync setup</h2><h3>Button setup</h3>
|
||||||
On/Off button enabled: <input type="checkbox" name="BT"><br>Infrared remote:
|
Button: <select name="BT"><option value="0">Disabled</option><option value="2">
|
||||||
<select name="IR"><option value="0">Disabled</option><option value="1">
|
Pushbutton</option><option value="4">Switch</option></select><br>
|
||||||
24-key RGB</option><option value="2">24-key with CT</option><option value="3">
|
Infrared remote: <select name="IR"><option value="0">Disabled</option><option
|
||||||
40-key blue</option><option value="4">44-key RGB</option><option value="5">
|
value="1">24-key RGB</option><option value="2">24-key with CT</option><option
|
||||||
21-key RGB</option><option value="6">6-key black</option><option value="7">
|
value="3">40-key blue</option><option value="4">44-key RGB</option><option
|
||||||
9-key red</option></select><br><a
|
value="5">21-key RGB</option><option value="6">6-key black</option><option
|
||||||
|
value="7">9-key red</option></select><br><a
|
||||||
href="https://github.com/Aircoookie/WLED/wiki/Infrared-Control" target="_blank">
|
href="https://github.com/Aircoookie/WLED/wiki/Infrared-Control" target="_blank">
|
||||||
IR info</a><h3>WLED Broadcast</h3>UDP Port: <input name="UP" type="number"
|
IR info</a><h3>WLED Broadcast</h3>UDP Port: <input name="UP" type="number"
|
||||||
min="1" max="65535" class="d5" required><br>2nd Port: <input name="U2"
|
min="1" max="65535" class="d5" required><br>2nd Port: <input name="U2"
|
||||||
|
@ -196,7 +196,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
//SYNC
|
//SYNC
|
||||||
if (subPage == 4)
|
if (subPage == 4)
|
||||||
{
|
{
|
||||||
buttonEnabled = request->hasArg(F("BT"));
|
buttonType = request->arg(F("BT")).toInt();
|
||||||
irEnabled = request->arg(F("IR")).toInt();
|
irEnabled = request->arg(F("IR")).toInt();
|
||||||
int t = request->arg(F("UP")).toInt();
|
int t = request->arg(F("UP")).toInt();
|
||||||
if (t > 0) udpPort = t;
|
if (t > 0) udpPort = t;
|
||||||
|
@ -422,8 +422,8 @@ void WLED::beginStrip()
|
|||||||
digitalWrite(rlyPin, (rlyMde ? bri : !bri));
|
digitalWrite(rlyPin, (rlyMde ? bri : !bri));
|
||||||
|
|
||||||
// disable button if it is "pressed" unintentionally
|
// disable button if it is "pressed" unintentionally
|
||||||
if (btnPin>=0 && isButtonPressed())
|
if (btnPin>=0 && buttonType == BTN_TYPE_PUSH && isButtonPressed())
|
||||||
buttonEnabled = false;
|
buttonType = BTN_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WLED::initAP(bool resetAP)
|
void WLED::initAP(bool resetAP)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2104030
|
#define VERSION 2104120
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
@ -254,7 +254,7 @@ WLED_GLOBAL NodesMap Nodes;
|
|||||||
WLED_GLOBAL bool nodeListEnabled _INIT(true);
|
WLED_GLOBAL bool nodeListEnabled _INIT(true);
|
||||||
WLED_GLOBAL bool nodeBroadcastEnabled _INIT(true);
|
WLED_GLOBAL bool nodeBroadcastEnabled _INIT(true);
|
||||||
|
|
||||||
WLED_GLOBAL bool buttonEnabled _INIT(true);
|
WLED_GLOBAL byte buttonType _INIT(BTN_TYPE_PUSH);
|
||||||
WLED_GLOBAL byte irEnabled _INIT(0); // Infrared receiver
|
WLED_GLOBAL byte irEnabled _INIT(0); // Infrared receiver
|
||||||
|
|
||||||
WLED_GLOBAL uint16_t udpPort _INIT(21324); // WLED notifier default port
|
WLED_GLOBAL uint16_t udpPort _INIT(21324); // WLED notifier default port
|
||||||
|
@ -93,7 +93,7 @@ void loadSettingsFromEEPROM()
|
|||||||
|
|
||||||
notifyButton = EEPROM.read(230);
|
notifyButton = EEPROM.read(230);
|
||||||
notifyTwice = EEPROM.read(231);
|
notifyTwice = EEPROM.read(231);
|
||||||
buttonEnabled = EEPROM.read(232);
|
buttonType = EEPROM.read(232) ? BTN_TYPE_PUSH : BTN_TYPE_NONE;
|
||||||
|
|
||||||
staticIP[0] = EEPROM.read(234);
|
staticIP[0] = EEPROM.read(234);
|
||||||
staticIP[1] = EEPROM.read(235);
|
staticIP[1] = EEPROM.read(235);
|
||||||
|
@ -349,7 +349,7 @@ void getSettingsJS(byte subPage, char* dest)
|
|||||||
|
|
||||||
if (subPage == 4)
|
if (subPage == 4)
|
||||||
{
|
{
|
||||||
sappend('c',SET_F("BT"),buttonEnabled);
|
sappend('v',SET_F("BT"),buttonType);
|
||||||
sappend('v',SET_F("IR"),irEnabled);
|
sappend('v',SET_F("IR"),irEnabled);
|
||||||
sappend('v',SET_F("UP"),udpPort);
|
sappend('v',SET_F("UP"),udpPort);
|
||||||
sappend('v',SET_F("U2"),udpPort2);
|
sappend('v',SET_F("U2"),udpPort2);
|
||||||
|
Loading…
Reference in New Issue
Block a user