From b352284ea9f3c676b5a35805d8d8716c1583c93c Mon Sep 17 00:00:00 2001 From: Adrien Foulon Date: Tue, 18 Feb 2020 14:13:38 +0100 Subject: [PATCH] Add options for button + fix build error --- code/espurna/board.h | 2 - code/espurna/board.ino | 318 ----------------------------------- code/espurna/button.h | 6 +- code/espurna/button.ino | 113 +++++++++++-- code/espurna/button_config.h | 25 +-- code/espurna/relay.ino | 4 +- code/espurna/thinkspeak.ino | 2 +- code/espurna/ws.ino | 2 +- code/ui/src/App.vue | 2 +- 9 files changed, 107 insertions(+), 367 deletions(-) diff --git a/code/espurna/board.h b/code/espurna/board.h index a9fe2b9c26..7b24877444 100644 --- a/code/espurna/board.h +++ b/code/espurna/board.h @@ -14,5 +14,3 @@ String getEspurnaSensors(); String getEspurnaWebUI(); -int getBoardId(); - diff --git a/code/espurna/board.ino b/code/espurna/board.ino index a0ba05cf24..5323954d69 100644 --- a/code/espurna/board.ino +++ b/code/espurna/board.ino @@ -326,321 +326,3 @@ bool haveRelaysOrSensors() { return result; } -int getBoardId() { - #if defined(ESPURNA_CORE) - return 0; - #elif defined(ESPURNA_BASE) - return 1; - #elif defined(NODEMCU_LOLIN) - return 2; - #elif defined(NODEMCU_BASIC) - return 3; - #elif defined(WEMOS_D1_MINI) - return 4; - #elif defined(WEMOS_D1_MINI_RELAYSHIELD) - return 5; - #elif defined(WEMOS_D1_TARPUNA_SHIELD) - return 6; - #elif defined(TINKERMAN_ESPURNA_H06) - return 7; - #elif defined(TINKERMAN_ESPURNA_H08) - return 8; - #elif defined(TINKERMAN_ESPURNA_SWITCH) - return 9; - #elif defined(TINKERMAN_RFM69GW) - return 10; - #elif defined(ITEAD_SONOFF_BASIC) - return 11; - #elif defined(ITEAD_SONOFF_RF) - return 12; - #elif defined(ITEAD_SONOFF_MINI) - return 13; - #elif defined(ITEAD_SONOFF_TH) - return 14; - #elif defined(ITEAD_SONOFF_SV) - return 15; - #elif defined(ITEAD_SLAMPHER) - return 16; - #elif defined(ITEAD_S20) - return 17; - #elif defined(ITEAD_SONOFF_TOUCH) - return 18; - #elif defined(ITEAD_SONOFF_POW) - return 19; - #elif defined(ITEAD_SONOFF_POW_R2) - return 20; - #elif defined(ITEAD_SONOFF_DUAL) - return 21; - #elif defined(ITEAD_SONOFF_DUAL_R2) - return 22; - #elif defined(ITEAD_SONOFF_4CH) - return 23; - #elif defined(ITEAD_SONOFF_4CH_PRO) - return 24; - #elif defined(ITEAD_1CH_INCHING) - return 25; - #elif defined(ITEAD_MOTOR) - return 26; - #elif defined(ITEAD_BNSZ01) - return 27; - #elif defined(ITEAD_SONOFF_RFBRIDGE) - return 28; - #elif defined(ITEAD_SONOFF_B1) - return 29; - #elif defined(ITEAD_SONOFF_LED) - return 30; - #elif defined(ITEAD_SONOFF_T1_1CH) - return 31; - #elif defined(ITEAD_SONOFF_T1_2CH) - return 32; - #elif defined(ITEAD_SONOFF_T1_3CH) - return 33; - #elif defined(ITEAD_SONOFF_S31) - return 34; - #elif defined(ITEAD_SONOFF_S31_LITE) - return 35; - #elif defined(ITEAD_SONOFF_IFAN02) - return 36; - #elif defined(ORVIBO_B25) - return 37; - #elif defined(YJZK_SWITCH_1CH) - return 38; - #elif defined(YJZK_SWITCH_2CH) - return 39; - #elif defined(YJZK_SWITCH_3CH) - return 40; - #elif defined(ELECTRODRAGON_WIFI_IOT) - return 41; - #elif defined(WORKCHOICE_ECOPLUG) - return 42; - #elif defined(AITHINKER_AI_LIGHT) - return 43; - #elif defined(LYASI_LIGHT) - return 44; - #elif defined(MAGICHOME_LED_CONTROLLER) - return 45; - #elif defined(MAGICHOME_LED_CONTROLLER_20) - return 46; - #elif defined(MAGICHOME_ZJ_WFMN_A_11) - return 47; - #elif defined(MAGICHOME_ZJ_WFMN_B_11) - return 48; - #elif defined(MAGICHOME_ZJ_WFMN_C_11) - return 49; - #elif defined(MAGICHOME_ZJ_ESPM_5CH_B_13) - return 50; - #elif defined(MAGICHOME_ZJ_LB_RGBWW_L) - return 51; - #elif defined(HUACANXING_H801) - return 52; - #elif defined(HUACANXING_H802) - return 53; - #elif defined(JANGOE_WIFI_RELAY_NC) - return 54; - #elif defined(JANGOE_WIFI_RELAY_NO) - return 55; - #elif defined(JORGEGARCIA_WIFI_RELAYS) - return 56; - #elif defined(OPENENERGYMONITOR_MQTT_RELAY) - return 57; - #elif defined(WION_50055) - return 58; - #elif defined(EXS_WIFI_RELAY_V31) - return 59; - #elif defined(EXS_WIFI_RELAY_V50) - return 60; - #elif defined(GENERIC_V9261F) - return 61; - #elif defined(GENERIC_ECH1560) - return 62; - #elif defined(MANCAVEMADE_ESPLIVE) - return 63; - #elif defined(INTERMITTECH_QUINLED) - return 64; - #elif defined(ARILUX_AL_LC01) - return 65; - #elif defined(ARILUX_AL_LC02) - return 66; - #elif defined(ARILUX_AL_LC02_V14) - return 67; - #elif defined(ARILUX_AL_LC06) - return 68; - #elif defined(ARILUX_AL_LC11) - return 69; - #elif defined(ARILUX_E27) - return 70; - #elif defined(XENON_SM_PW702U) - return 71; - #elif defined(ISELECTOR_SM_PW702) - return 72; - #elif defined(AUTHOMETION_LYT8266) - return 73; - #elif defined(GIZWITS_WITTY_CLOUD) - return 74; - #elif defined(KMC_70011) - return 75; - #elif defined(EUROMATE_WIFI_STECKER_SCHUKO) - return 76; - #elif defined(EUROMATE_WIFI_STECKER_SCHUKO_V2) - return 77; - #elif defined(GENERIC_8CH) - return 78; - #elif defined(STM_RELAY) - return 79; - #elif defined(TONBUX_POWERSTRIP02) - return 80; - #elif defined(LINGAN_SWA1) - return 81; - #elif defined(HEYGO_HY02) - return 82; - #elif defined(MAXCIO_WUS002S) - return 83; - #elif defined(MAXCIO_WDE004) - return 84; - #elif defined(OUKITEL_P1) - return 85; - #elif defined(YIDIAN_XSSSA05) - return 86; - #elif defined(TONBUX_XSSSA01) - return 87; - #elif defined(TONBUX_XSSSA06) - return 88; - #elif defined(GREEN_ESP8266RELAY) - return 89; - #elif defined(IKE_ESPIKE) - return 90; - #elif defined(ARNIEX_SWIFITCH) - return 91; - #elif defined(GENERIC_ESP01S_RELAY_V40) - return 92; - #elif defined(GENERIC_ESP01S_RGBLED_V10) - return 93; - #elif defined(GENERIC_ESP01S_DHT11_V10) - return 94; - #elif defined(GENERIC_ESP01S_DS18B20_V10) - return 95; - #elif defined(PILOTAK_ESP_DIN_V1) - return 96; - #elif defined(HELTEC_TOUCHRELAY) - return 97; - #elif defined(ZHILDE_EU44_W) - return 98; - #elif defined(ALLNET_4DUINO_IOT_WLAN_RELAIS) - return 99; - #elif defined(LUANI_HVIO) - return 100; - #elif defined(TONBUX_MOSQUITO_KILLER) - return 101; - #elif defined(NEO_COOLCAM_NAS_WR01W) - return 102; - #elif defined(DELTACO_SH_P01) - return 103; - #elif defined(DELTACO_SH_P03USB) - return 104; - #elif defined(FORNORM_ZLD_34EU) - return 105; - #elif defined(BH_ONOFRE) - return 106; - #elif defined(BLITZWOLF_BWSHPX) - return 107; - #elif defined(BLITZWOLF_BWSHPX_V23) - return 108; - #elif defined(BLITZWOLF_BWSHP5) - return 109; - #elif defined(TECKIN_SP21) - return 110; - #elif defined(TECKIN_SP22_V14) - return 111; - #elif defined(GOSUND_WS1) - return 112; - #elif defined(HOMECUBE_16A) - return 113; - #elif defined(VANZAVANZU_SMART_WIFI_PLUG_MINI) - return 114; - #elif defined(GENERIC_AG_L4) - return 115; - #elif defined(ALLTERCO_SHELLY1) - return 116; - #elif defined(ALLTERCO_SHELLY2) - return 117; - #elif defined(ALLTERCO_SHELLY1PM) - return 118; - #elif defined(ALLTERCO_SHELLY25) - return 119; - #elif defined(LOHAS_E27_9W) - return 120; - #elif defined(LOHAS_E26_A19) - return 121; - #elif defined(TECKIN_SB53) - return 122; - #elif defined(XIAOMI_SMART_DESK_LAMP) - return 123; - #elif defined(PHYX_ESP12_RGB) - return 124; - #elif defined(IWOOLE_LED_TABLE_LAMP) - return 125; - #elif defined(GENERIC_GU10) - return 126; - #elif defined(GENERIC_E14) - return 127; - #elif defined(DELTACO_SH_LEXXW) - return 128; - #elif defined(DELTACO_SH_LEXXRGB) - return 129; - #elif defined(NEXETE_A19) - return 130; - #elif defined(LOMBEX_LUX_NOVA2_TUNABLE_WHITE) - return 131; - #elif defined(LOMBEX_LUX_NOVA2_WHITE_COLOR) - return 132; - #elif defined(BESTEK_MRJ1011) - return 133; - #elif defined(GBLIFE_RGBW_SOCKET) - return 134; - #elif defined(SMARTLIFE_MINI_SMART_SOCKET) - return 135; - #elif defined(HAMA_WIFI_STECKDOSE_00176533) - return 136; - #elif defined(DIGOO_NX_SP202) - return 137; - #elif defined(FOXEL_LIGHTFOX_DUAL) - return 138; - #elif defined(TECKIN_SP20) - return 139; - #elif defined(LITESUN_LA_WF3) - return 140; - #elif defined(PSH_WIFI_PLUG) - return 141; - #elif defined(PSH_RGBW_CONTROLLER) - return 142; - #elif defined(PSH_WIFI_SENSOR) - return 143; - #elif defined(JINVOO_VALVE_SM_AW713) - return 144; - #elif defined(TUYA_GENERIC_DIMMER) - return 145; - #elif defined(ETEKCITY_ESW01_USA) - return 146; - #elif defined(FS_UAP1) - return 147; - #elif defined(TFLAG_NX_SMX00) - return 148; - #elif defined(MUVIT_IO_MIOBULB001) - return 149; - #elif defined(HYKKER_SMART_HOME_POWER_PLUG) - return 150; - #elif defined(KOGAN_SMARTER_HOME_PLUG_W_POW) - return 151; - #elif defined(LSC_SMART_LED_LIGHT_STRIP) - return 152; - #elif defined(EHOMEDIY_WT02) - return 153; - #elif defined(EHOMEDIY_WT03) - return 154; - #elif defined(LINKSPRITE_LINKNODE_R4) - return 155; - #else - return -1; // CUSTOM - #endif -} - diff --git a/code/espurna/button.h b/code/espurna/button.h index c1bb885076..235e02a712 100644 --- a/code/espurna/button.h +++ b/code/espurna/button.h @@ -12,15 +12,11 @@ Copyright (C) 2016-2019 by Xose Pérez struct button_t { - // TODO: dblclick and debounce delays - right now a global setting, independent of ID - static unsigned long DebounceDelay; - static unsigned long DblclickDelay; - // Use built-in indexed definitions to configure DebounceEvent button_t(unsigned char index); // Provide custom DebounceEvent parameters instead - button_t(unsigned char pin, unsigned char mode, unsigned long actions, unsigned char relayID); + button_t(unsigned char pin, unsigned char mode, unsigned long actions, unsigned char relayID, unsigned long int debounceDelay, unsigned long int dblClickDelay); bool state(); diff --git a/code/espurna/button.ino b/code/espurna/button.ino index 5972751c3f..f7cba52a13 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -19,20 +19,64 @@ Copyright (C) 2016-2019 by Xose Pérez #include "button.h" #include "button_config.h" -// ----------------------------------------------------------------------------- -// TODO: dblclick and debounce delays - right now a global setting, independent of ID -unsigned long button_t::DebounceDelay = BUTTON_DEBOUNCE_DELAY; -unsigned long button_t::DblclickDelay = BUTTON_DBLCLICK_DELAY; -button_t::button_t(unsigned char pin, unsigned char mode, unsigned long actions, unsigned char relayID) : - event(new DebounceEvent(pin, mode, DebounceDelay, DblclickDelay)), +unsigned char _buttonPin(unsigned char index) { + return getSetting({"btnGPIO", index}, _buttonPinDefault(index)); +} + +unsigned char _buttonMode(unsigned char index) { + return getSetting({"btnMode", index}, _buttonModeDefault(index)); +} + +unsigned long int _buttonLongClickDelay(unsigned char index) { + return getSetting({"btnLngDl", index}, BUTTON_LNGCLICK_DELAY); +} + +unsigned long int _buttonLongLongClickDelay(unsigned char index) { + return getSetting({"btnLngLngDl", index}, BUTTON_LNGLNGCLICK_DELAY); +} + +unsigned long int _buttonDoubleClickDelay(unsigned char index) { + return getSetting({"btnDblDl", index}, BUTTON_DBLCLICK_DELAY); +} + +unsigned long int _buttonDebounceDelay(unsigned char index) { + return getSetting({"btnDbnce", index}, BUTTON_DEBOUNCE_DELAY); +} + +const uint8_t _buttonMapReleased(unsigned char index, uint8_t count, uint8_t length) { + return ( + (1 == count) ? ( + (length > _buttonLongLongClickDelay(index)) ? BUTTON_EVENT_LNGLNGCLICK : + (length > _buttonLongClickDelay(index)) ? BUTTON_EVENT_LNGCLICK : BUTTON_EVENT_CLICK + ) : + (2 == count) ? BUTTON_EVENT_DBLCLICK : + (3 == count) ? BUTTON_EVENT_TRIPLECLICK : + BUTTON_EVENT_NONE + ); +} + +const uint8_t _buttonMapEvent(unsigned char index, uint8_t event, uint8_t count, uint16_t length) { + return ( + (event == EVENT_PRESSED) ? BUTTON_EVENT_PRESSED : + (event == EVENT_CHANGED) ? BUTTON_EVENT_CLICK : + (event == EVENT_RELEASED) ? _buttonMapReleased(index, count, length) : + BUTTON_EVENT_NONE + ); +} + + +// ----------------------------------------------------------------------------- + +button_t::button_t(unsigned char pin, unsigned char mode, unsigned long actions, unsigned char relayID, unsigned long int debounceDelay, unsigned long int dblClickDelay) : + event(new DebounceEvent(pin, mode, debounceDelay, dblClickDelay)), actions(actions), relayID(relayID) {} button_t::button_t(unsigned char index) : - button_t(_buttonPin(index), _buttonMode(index), _buttonConstructActions(index), _buttonRelay(index)) + button_t(_buttonPin(index), _buttonMode(index), _buttonConstructActions(index), _buttonRelay(index), _buttonDebounceDelay(index), _buttonDoubleClickDelay(index)) {} bool button_t::state() { @@ -53,6 +97,11 @@ void buttonMQTT(unsigned char id, uint8_t event) { mqttSend(MQTT_TOPIC_BUTTON, id, payload, false, false); // 1st bool = force, 2nd = retain } + +unsigned char _buttonSendAllEvents(unsigned char index) { + return getSetting({"btnSndAllEvts", index}, BUTTON_MQTT_SEND_ALL_EVENTS); +} + #endif #if WEB_SUPPORT @@ -64,6 +113,45 @@ void _buttonWebSocketOnVisible(JsonObject& root) { } } +void _buttonWebSocketOnConnected(JsonObject& root) { + if (buttonCount() < 1) return; + + JsonObject& module = root.createNestedObject("btn"); + + JsonArray& schema = module.createNestedArray("_schema"); + schema.add("GPIO"); + schema.add("mode"); + schema.add("relay"); + + schema.add("dbnce"); + schema.add("dblDl"); + schema.add("lngDl"); + schema.add("lngLngDl"); + + #if MQTT_SUPPORT + schema.add("sndAllEvts"); + #endif + + + JsonArray& buttons = module.createNestedArray("list"); + + for (unsigned char i=0; iloop()) { buttonEvent(id, _buttonMapEvent( + id, event, button.event->getEventCount(), button.event->getEventLength() diff --git a/code/espurna/button_config.h b/code/espurna/button_config.h index 9228a923a2..0fa0015d4b 100644 --- a/code/espurna/button_config.h +++ b/code/espurna/button_config.h @@ -6,7 +6,7 @@ BUTTON MODULE #pragma once -constexpr const unsigned char _buttonPin(unsigned char index) { +constexpr const unsigned char _buttonPinDefault(unsigned char index) { return ( (index == 0) ? BUTTON1_PIN : (index == 1) ? BUTTON2_PIN : @@ -19,7 +19,7 @@ constexpr const unsigned char _buttonPin(unsigned char index) { ); } -constexpr const unsigned char _buttonMode(unsigned char index) { +constexpr const unsigned char _buttonModeDefault(unsigned char index) { return ( (index == 0) ? BUTTON1_MODE : (index == 1) ? BUTTON2_MODE : @@ -134,27 +134,6 @@ constexpr const unsigned char _buttonDecodeEventAction(unsigned long actions, un ); } -constexpr const uint8_t _buttonMapReleased(uint8_t count, uint8_t length) { - return ( - (1 == count) ? ( - (length > BUTTON_LNGLNGCLICK_DELAY) ? BUTTON_EVENT_LNGLNGCLICK : - (length > BUTTON_LNGCLICK_DELAY) ? BUTTON_EVENT_LNGCLICK : BUTTON_EVENT_CLICK - ) : - (2 == count) ? BUTTON_EVENT_DBLCLICK : - (3 == count) ? BUTTON_EVENT_TRIPLECLICK : - BUTTON_EVENT_NONE - ); -} - -constexpr const uint8_t _buttonMapEvent(uint8_t event, uint8_t count, uint16_t length) { - return ( - (event == EVENT_PRESSED) ? BUTTON_EVENT_PRESSED : - (event == EVENT_CHANGED) ? BUTTON_EVENT_CLICK : - (event == EVENT_RELEASED) ? _buttonMapReleased(count, length) : - BUTTON_EVENT_NONE - ); -} - constexpr uint32_t _buttonConstructActions(unsigned long pressed, unsigned long click, unsigned long dblclick, unsigned long lngclick, unsigned long lnglngclick, unsigned long tripleclick) { return ( (tripleclick << 20) | diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 7b8ef71723..30d57cf5ec 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -923,7 +923,7 @@ void _relayWebSocketSendRelays(JsonObject& root) { #if SCHEDULER_SUPPORT - schema.add('lastSch'); + schema.add("lastSch"); #endif #if MQTT_SUPPORT @@ -942,7 +942,7 @@ void _relayWebSocketSendRelays(JsonObject& root) { relay.add(_relayFriendlyName(i)); //gpio relay.add(_relays[i].type); //type //relay.add(_relays[i].reset_pin); //reset - relay.add(getSetting({"relayName", i}); //name + relay.add(getSetting({"relayName", i})); //name relay.add(getSetting({"relayBoot", i}, RELAY_BOOT_MODE)); //boot relay.add(_relays[i].pulse); //pulse relay.add(_relays[i].pulse_ms / 1000.0); //time diff --git a/code/espurna/thinkspeak.ino b/code/espurna/thinkspeak.ino index 44577a6529..46ccea589d 100644 --- a/code/espurna/thinkspeak.ino +++ b/code/espurna/thinkspeak.ino @@ -106,7 +106,7 @@ void _tspkWebSocketOnConnected(JsonObject& root) { tspk["enabled"] = getSetting("tspkEnabled", 1 == THINGSPEAK_ENABLED); tspk["key"] = getSetting("tspkKey", THINGSPEAK_APIKEY); tspk["clear"] = getSetting("tspkClear", 1 == THINGSPEAK_CLEAR_CACHE); - tspk["address"] = getSetting("tspkAddress", THINGSPEAK_ADDRESS) + tspk["address"] = getSetting("tspkAddress", THINGSPEAK_ADDRESS); JsonArray& relays = tspk.createNestedArray("relays"); for (byte i=0; i jsonBuffer; JsonObject& root = jsonBuffer.createObject(); if (changePassword) { - StaticJsonBuffer jsonBuffer; root["webMode"] = WEB_MODE_PASSWORD; wsSend(client_id, root); return; diff --git a/code/ui/src/App.vue b/code/ui/src/App.vue index 3bd7d31fca..b64b64ee3a 100644 --- a/code/ui/src/App.vue +++ b/code/ui/src/App.vue @@ -22,7 +22,7 @@