From ee7356b91a6c70f1e3dd06ab3358d2bf37ce728e Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Fri, 13 Mar 2020 09:02:26 +0300 Subject: [PATCH] relay: clean-up for ota .bin --- code/espurna/button.ino | 3 +++ code/espurna/config/dependencies.h | 16 ++++++++++++++++ code/espurna/config/general.h | 4 ++++ code/espurna/config/hardware.h | 14 ++++++++------ code/espurna/domoticz.ino | 9 +++++++-- code/espurna/espurna.ino | 4 +++- code/espurna/ir.ino | 3 +++ code/espurna/led.ino | 4 ++++ code/espurna/relay.ino | 4 ++++ code/espurna/rpc.ino | 4 ---- code/espurna/rpnrules.ino | 26 +++++++++++++++----------- code/espurna/sensor.ino | 4 ++-- code/test/build/core.h | 2 +- 13 files changed, 70 insertions(+), 27 deletions(-) diff --git a/code/espurna/button.ino b/code/espurna/button.ino index 4bb269fe..d9353a52 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -411,6 +411,8 @@ void buttonEvent(unsigned char id, button_event_t event) { #endif switch (action) { + + #if RELAY_SUPPORT case BUTTON_ACTION_TOGGLE: relayToggle(button.relayID); break; @@ -422,6 +424,7 @@ void buttonEvent(unsigned char id, button_event_t event) { case BUTTON_ACTION_OFF: relayStatus(button.relayID, false); break; + #endif // RELAY_SUPPORT == 1 case BUTTON_ACTION_AP: if (wifiState() & WIFI_STATE_AP) { diff --git a/code/espurna/config/dependencies.h b/code/espurna/config/dependencies.h index 77d9a7dd..bb25db23 100644 --- a/code/espurna/config/dependencies.h +++ b/code/espurna/config/dependencies.h @@ -38,6 +38,8 @@ #if ALEXA_SUPPORT #undef BROKER_SUPPORT #define BROKER_SUPPORT 1 // If Alexa enabled enable BROKER +#undef RELAY_SUPPORT +#define RELAY_SUPPORT 1 // and switches #endif #if RPN_RULES_SUPPORT @@ -47,6 +49,11 @@ #define MQTT_SUPPORT 1 #endif +#if RF_SUPPORT +#undef RELAY_SUPPORT +#define RELAY_SUPPORT 1 +#endif + #if LED_SUPPORT #undef BROKER_SUPPORT #define BROKER_SUPPORT 1 // If LED is enabled enable BROKER to supply status changes @@ -74,11 +81,18 @@ #define BROKER_SUPPORT 1 // If Thingspeak enabled enable BROKER #endif +#if THERMOSTAT_SUPPORT +#undef RELAY_SUPPORT +#define RELAY_SUPPORT 1 // Thermostat depends on switches +#endif + #if SCHEDULER_SUPPORT #undef NTP_SUPPORT #define NTP_SUPPORT 1 // Scheduler needs NTP to work #undef BROKER_SUPPORT #define BROKER_SUPPORT 1 // Scheduler needs Broker to trigger every minute +#undef RELAY_SUPPORT +#define RELAY_SUPPORT 1 // Scheduler needs relays #endif #if LWIP_VERSION_MAJOR != 1 @@ -101,6 +115,8 @@ #if TUYA_SUPPORT #undef BROKER_SUPPORT #define BROKER_SUPPORT 1 // Broker is required to process relay & lights events +#undef RELAY_SUPPORT +#define RELAY_SUPPORT 1 // Most of the time we require it #endif //------------------------------------------------------------------------------ diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index f4f13972..1909b575 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -426,6 +426,10 @@ // RELAY //------------------------------------------------------------------------------ +#ifndef RELAY_SUPPORT +#define RELAY_SUPPORT 1 +#endif + // Default boot mode: 0 means OFF, 1 ON and 2 whatever was before #ifndef RELAY_BOOT_MODE #define RELAY_BOOT_MODE RELAY_BOOT_OFF diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 58d1bd67..35ecb2f1 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -56,10 +56,10 @@ #define ALEXA_SUPPORT 0 #define API_SUPPORT 0 #define BROKER_SUPPORT 0 - #define DOMOTICZ_SUPPORT 0 #define DEBUG_SERIAL_SUPPORT 0 #define DEBUG_TELNET_SUPPORT 0 #define DEBUG_WEB_SUPPORT 0 + #define DOMOTICZ_SUPPORT 0 #define HOMEASSISTANT_SUPPORT 0 #define I2C_SUPPORT 0 #define MQTT_SUPPORT 0 @@ -71,11 +71,13 @@ #define WEB_SUPPORT 0 // Extra light-weight image - //#define BUTTON_SUPPORT 0 - //#define LED_SUPPORT 0 - //#define MDNS_SERVER_SUPPORT 0 - //#define TELNET_SUPPORT 0 - //#define TERMINAL_SUPPORT 0 + //#define BUTTON_SUPPORT 0 // don't need / have buttons + //#define LED_SUPPORT 0 // don't need wifi indicator + //#define RELAY_SUPPORT 0 // don't need to preserve pin state between resets + //#define OTA_ARDUINOOTA_SUPPORT 0 // when only using `ota` command + //#define MDNS_SERVER_SUPPORT 0 // + //#define TELNET_SUPPORT 0 // when only using espota.py + //#define TERMINAL_SUPPORT 0 // #elif defined(ESPURNA_BASE) diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 34c8e5c7..4e4b4912 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -128,7 +128,9 @@ void _domoticzMqtt(unsigned int type, const char * topic, char * payload) { mqttSubscribeRaw(dczTopicOut.c_str()); // Send relays state on connection - domoticzSendRelays(); + #if RELAY_SUPPORT + domoticzSendRelays(); + #endif } @@ -231,7 +233,10 @@ void _domoticzConfigure() { const bool enabled = getSetting("dczEnabled", 1 == DOMOTICZ_ENABLED); if (enabled != _dcz_enabled) _domoticzMqttSubscribe(enabled); - _domoticzRelayConfigure(relayCount()); + #if RELAY_SUPPORT + _domoticzRelayConfigure(relayCount()); + #endif + _dcz_enabled = enabled; } diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index f103b98b..478ddbd9 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -193,7 +193,9 @@ void setup() { #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE lightSetup(); #endif - relaySetup(); + #if RELAY_SUPPORT + relaySetup(); + #endif #if BUTTON_SUPPORT buttonSetup(); #endif diff --git a/code/espurna/ir.ino b/code/espurna/ir.ino index 45afc43d..a0f4a61e 100644 --- a/code/espurna/ir.ino +++ b/code/espurna/ir.ino @@ -284,6 +284,8 @@ void _irProcess(unsigned char type, unsigned long code) { unsigned long button_value = pgm_read_dword(&IR_BUTTON[i][2]); switch (button_action) { + + #if RELAY_SUPPORT case IR_BUTTON_ACTION_STATE: relayStatus(0, button_value); break; @@ -291,6 +293,7 @@ void _irProcess(unsigned char type, unsigned long code) { case IR_BUTTON_ACTION_TOGGLE: relayToggle(button_value); break; + #endif // RELAY_SUPPORT == 1 #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE diff --git a/code/espurna/led.ino b/code/espurna/led.ino index 9197128a..9d936332 100644 --- a/code/espurna/led.ino +++ b/code/espurna/led.ino @@ -394,6 +394,8 @@ void ledLoop() { } break; + #if RELAY_SUPPORT + case LED_MODE_FINDME_WIFI: if ((wifi_state & WIFI_STATE_WPS) || (wifi_state & WIFI_STATE_SMARTCONFIG)) { _ledBlink(led, LedMode::NetworkAutoconfig); @@ -471,6 +473,8 @@ void ledLoop() { break; } + #endif // RELAY_SUPPORT == 1 + case LED_MODE_ON: if (!_led_update) break; _ledStatus(led, true); diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 44f63db7..92155bc7 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -6,6 +6,8 @@ Copyright (C) 2016-2019 by Xose PĂ©rez */ +#if RELAY_SUPPORT + #include #include #include @@ -1437,3 +1439,5 @@ void relaySetup() { DEBUG_MSG_P(PSTR("[RELAY] Number of relays: %d\n"), _relays.size()); } + +#endif // RELAY_SUPPORT == 1 diff --git a/code/espurna/rpc.ino b/code/espurna/rpc.ino index 294187d0..58bed101 100644 --- a/code/espurna/rpc.ino +++ b/code/espurna/rpc.ino @@ -6,8 +6,6 @@ Copyright (C) 2020 by Maxim Prokhorov */ -#if MQTT_SUPPORT || API_SUPPORT - #include #include @@ -66,5 +64,3 @@ PayloadStatus rpcParsePayload(const char* payload, const rpc_payload_check_t ext return PayloadStatus::Unknown; } - -#endif // MQTT_SUPPORT || API_SUPPORT diff --git a/code/espurna/rpnrules.ino b/code/espurna/rpnrules.ino index a3340e4f..f9ca9486 100644 --- a/code/espurna/rpnrules.ino +++ b/code/espurna/rpnrules.ino @@ -215,17 +215,21 @@ void _rpnInit() { }); // Accept relay number and numeric API status value (0, 1 and 2) - rpn_operator_set(_rpn_ctxt, "relay", 2, [](rpn_context & ctxt) { - float status, id; - rpn_stack_pop(ctxt, id); - rpn_stack_pop(ctxt, status); - if (int(status) == 2) { - relayToggle(int(id)); - } else { - relayStatus(int(id), int(status) == 1); - } - return true; - }); + #if RELAY_SUPPORT + + rpn_operator_set(_rpn_ctxt, "relay", 2, [](rpn_context & ctxt) { + float status, id; + rpn_stack_pop(ctxt, id); + rpn_stack_pop(ctxt, status); + if (int(status) == 2) { + relayToggle(int(id)); + } else { + relayStatus(int(id), int(status) == 1); + } + return true; + }); + + #endif // RELAY_SUPPORT == 1 // Channel operators #if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT diff --git a/code/espurna/sensor.ino b/code/espurna/sensor.ino index ed51b6c3..96c975c8 100644 --- a/code/espurna/sensor.ino +++ b/code/espurna/sensor.ino @@ -2028,7 +2028,7 @@ void sensorLoop() { _sensorPre(); // Get the first relay state - #if SENSOR_POWER_CHECK_STATUS + #if RELAY_SUPPORT && SENSOR_POWER_CHECK_STATUS bool relay_off = (relayCount() == 1) && (relayStatus(0) == 0); #endif @@ -2046,7 +2046,7 @@ void sensorLoop() { value_raw = magnitude.sensor->value(magnitude.local); // Completely remove spurious values if relay is OFF - #if SENSOR_POWER_CHECK_STATUS + #if RELAY_SUPPORT && SENSOR_POWER_CHECK_STATUS if (relay_off) { if (magnitude.type == MAGNITUDE_POWER_ACTIVE || magnitude.type == MAGNITUDE_POWER_REACTIVE || diff --git a/code/test/build/core.h b/code/test/build/core.h index 37b631b1..f1e0c983 100644 --- a/code/test/build/core.h +++ b/code/test/build/core.h @@ -1,10 +1,10 @@ #define ALEXA_SUPPORT 0 #define API_SUPPORT 0 #define BROKER_SUPPORT 0 -#define DOMOTICZ_SUPPORT 0 #define DEBUG_SERIAL_SUPPORT 0 #define DEBUG_TELNET_SUPPORT 0 #define DEBUG_WEB_SUPPORT 0 +#define DOMOTICZ_SUPPORT 0 #define HOMEASSISTANT_SUPPORT 0 #define I2C_SUPPORT 0 #define MQTT_SUPPORT 0