mirror of
https://github.com/wled/WLED.git
synced 2025-07-22 02:06:32 +00:00
Added.
- PIS sensor switch option for button Bugfix. - proper switch high/low handling
This commit is contained in:
parent
777a95d23c
commit
0cdab52418
@ -39,6 +39,7 @@ bool isButtonPressed(uint8_t i)
|
|||||||
break;
|
break;
|
||||||
case BTN_TYPE_PUSH_ACT_HIGH:
|
case BTN_TYPE_PUSH_ACT_HIGH:
|
||||||
case BTN_TYPE_SWITCH_ACT_HIGH:
|
case BTN_TYPE_SWITCH_ACT_HIGH:
|
||||||
|
case BTN_TYPE_PIR_SENSOR:
|
||||||
if (digitalRead(btnPin[i]) == HIGH) return true;
|
if (digitalRead(btnPin[i]) == HIGH) return true;
|
||||||
break;
|
break;
|
||||||
case BTN_TYPE_TOUCH:
|
case BTN_TYPE_TOUCH:
|
||||||
@ -52,6 +53,7 @@ bool isButtonPressed(uint8_t i)
|
|||||||
|
|
||||||
void handleSwitch(uint8_t b)
|
void handleSwitch(uint8_t b)
|
||||||
{
|
{
|
||||||
|
// isButtonPressed() handles inverted/noninverted logic
|
||||||
if (buttonPressedBefore[b] != isButtonPressed(b)) {
|
if (buttonPressedBefore[b] != isButtonPressed(b)) {
|
||||||
buttonPressedTime[b] = millis();
|
buttonPressedTime[b] = millis();
|
||||||
buttonPressedBefore[b] = !buttonPressedBefore[b];
|
buttonPressedBefore[b] = !buttonPressedBefore[b];
|
||||||
@ -60,12 +62,12 @@ void handleSwitch(uint8_t b)
|
|||||||
if (buttonLongPressed[b] == buttonPressedBefore[b]) return;
|
if (buttonLongPressed[b] == buttonPressedBefore[b]) return;
|
||||||
|
|
||||||
if (millis() - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce)
|
if (millis() - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce)
|
||||||
if (buttonPressedBefore[b] ^ (buttonType[b]==BTN_TYPE_SWITCH_ACT_HIGH)) { //LOW, falling edge, switch closed
|
if (!buttonPressedBefore[b]) { // on -> off
|
||||||
if (macroButton[b]) applyPreset(macroButton[b]);
|
if (macroButton[b]) applyPreset(macroButton[b]);
|
||||||
else { //turn on
|
else { //turn on
|
||||||
if (!bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);}
|
if (!bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);}
|
||||||
}
|
}
|
||||||
} else { //HIGH, rising edge, switch opened
|
} else { // off -> on
|
||||||
if (macroLongPress[b]) applyPreset(macroLongPress[b]);
|
if (macroLongPress[b]) applyPreset(macroLongPress[b]);
|
||||||
else { //turn off
|
else { //turn off
|
||||||
if (bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);}
|
if (bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);}
|
||||||
@ -75,8 +77,9 @@ void handleSwitch(uint8_t b)
|
|||||||
// publish MQTT message
|
// publish MQTT message
|
||||||
if (WLED_MQTT_CONNECTED) {
|
if (WLED_MQTT_CONNECTED) {
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
if (buttonType[b] == BTN_TYPE_PIR_SENSOR) sprintf_P(subuf, PSTR("%s/motion/%d"), mqttDeviceTopic, (int)b);
|
||||||
mqtt->publish(subuf, 0, false, (buttonPressedBefore[b] ^ (buttonType[b]==BTN_TYPE_SWITCH_ACT_HIGH)) ? "on" : "off");
|
else sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
||||||
|
mqtt->publish(subuf, 0, false, !buttonPressedBefore[b] ? "off" : "on");
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state
|
buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state
|
||||||
@ -178,7 +181,8 @@ void handleButton()
|
|||||||
handleAnalog(b); continue;
|
handleAnalog(b); continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonType[b] == BTN_TYPE_SWITCH || buttonType[b] == BTN_TYPE_SWITCH_ACT_HIGH) { //button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NOT gpio0)
|
//button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NOT gpio0)
|
||||||
|
if (buttonType[b] == BTN_TYPE_SWITCH || buttonType[b] == BTN_TYPE_SWITCH_ACT_HIGH || buttonType[b] == BTN_TYPE_PIR_SENSOR) {
|
||||||
handleSwitch(b); continue;
|
handleSwitch(b); continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +162,7 @@
|
|||||||
#define BTN_TYPE_TOUCH 6
|
#define BTN_TYPE_TOUCH 6
|
||||||
#define BTN_TYPE_ANALOG 7
|
#define BTN_TYPE_ANALOG 7
|
||||||
#define BTN_TYPE_ANALOG_INVERTED 8
|
#define BTN_TYPE_ANALOG_INVERTED 8
|
||||||
|
#define BTN_TYPE_PIR_SENSOR 9
|
||||||
|
|
||||||
//Ethernet board types
|
//Ethernet board types
|
||||||
#define WLED_NUM_ETH_TYPES 5
|
#define WLED_NUM_ETH_TYPES 5
|
||||||
|
@ -304,11 +304,12 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
|
|||||||
c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`;
|
c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`;
|
||||||
c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`;
|
c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`;
|
||||||
c += `<option value="3" ${t==3?"selected":""}>Push inverted</option>`;
|
c += `<option value="3" ${t==3?"selected":""}>Push inverted</option>`;
|
||||||
c += `<option value="4" ${t==4?"selected":""}>Switch</option>`;
|
c += `<option value="4" ${t==4?"selected":""}>Switch (low)</option>`;
|
||||||
c += `<option value="5" ${t==5?"selected":""}>Switch inverted</option>`;
|
c += `<option value="5" ${t==5?"selected":""}>Switch (high)</option>`;
|
||||||
c += `<option value="6" ${t==6?"selected":""}>Touch</option>`;
|
c += `<option value="6" ${t==6?"selected":""}>Touch</option>`;
|
||||||
c += `<option value="7" ${t==7?"selected":""}>Analog</option>`;
|
c += `<option value="7" ${t==7?"selected":""}>Analog</option>`;
|
||||||
c += `<option value="8" ${t==8?"selected":""}>Analog inverted</option>`;
|
c += `<option value="8" ${t==8?"selected":""}>Analog inverted</option>`;
|
||||||
|
c += `<option value="9" ${t==9?"selected":""}>PIR sensor</option>`;
|
||||||
c += `</select>`;
|
c += `</select>`;
|
||||||
c += `<span style="cursor: pointer;" onclick="off('${bt}')"> ×</span><br>`;
|
c += `<span style="cursor: pointer;" onclick="off('${bt}')"> ×</span><br>`;
|
||||||
gId("btns").innerHTML = c;
|
gId("btns").innerHTML = c;
|
||||||
|
File diff suppressed because one or more lines are too long
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2106023
|
#define VERSION 2106024
|
||||||
|
|
||||||
//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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user