diff --git a/code/espurna/alexa.cpp b/code/espurna/alexa.cpp index 3215238c..818334fd 100644 --- a/code/espurna/alexa.cpp +++ b/code/espurna/alexa.cpp @@ -6,12 +6,13 @@ Copyright (C) 2016-2019 by Xose Pérez */ -#include "alexa.h" +#include "espurna.h" #if ALEXA_SUPPORT #include +#include "alexa.h" #include "api.h" #include "light.h" #include "mqtt.h" diff --git a/code/espurna/alexa.h b/code/espurna/alexa.h index 5503b89b..4ed6ab19 100644 --- a/code/espurna/alexa.h +++ b/code/espurna/alexa.h @@ -8,7 +8,5 @@ Copyright (C) 2016-2019 by Xose Pérez #pragma once -#include "espurna.h" - bool alexaEnabled(); void alexaSetup(); diff --git a/code/espurna/curtain_kingart.cpp b/code/espurna/curtain_kingart.cpp index 5d9f6d23..a2e8c8b9 100644 --- a/code/espurna/curtain_kingart.cpp +++ b/code/espurna/curtain_kingart.cpp @@ -10,10 +10,11 @@ Copyright (C) 2020 - Eric Chauvet */ -#include "curtain_kingart.h" +#include "espurna.h" #if KINGART_CURTAIN_SUPPORT +#include "curtain_kingart.h" #include "mqtt.h" #include "ntp.h" #include "ntp_timelib.h" diff --git a/code/espurna/curtain_kingart.h b/code/espurna/curtain_kingart.h index caa42613..37028a01 100644 --- a/code/espurna/curtain_kingart.h +++ b/code/espurna/curtain_kingart.h @@ -7,8 +7,6 @@ Copyright (C) 2019 by Albert Weterings */ -#include "espurna.h" - void kingartCurtainSetup(); void curtainSetPosition(unsigned char id, long value); unsigned char curtainCount(); diff --git a/code/espurna/domoticz.cpp b/code/espurna/domoticz.cpp index 125bd8b1..7087345d 100644 --- a/code/espurna/domoticz.cpp +++ b/code/espurna/domoticz.cpp @@ -223,7 +223,7 @@ void status(const JsonObject& root, unsigned char nvalue) { } // domoticz uses 100 as maximum value while we're using a custom scale - lightBrightness((root["Level"].as() / 100l) * Light::BrightnessMax); + lightBrightnessPercent(root["Level"].as()); lightState(nvalue > 0); lightUpdate(); } diff --git a/code/espurna/encoder.cpp b/code/espurna/encoder.cpp index b772aae9..ad823263 100644 --- a/code/espurna/encoder.cpp +++ b/code/espurna/encoder.cpp @@ -6,11 +6,13 @@ Copyright (C) 2018-2019 by Xose Pérez */ -#include "encoder.h" +#include "espurna.h" #if ENCODER_SUPPORT && (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) +#include "encoder.h" #include "light.h" + #include "libs/Encoder.h" #include diff --git a/code/espurna/encoder.h b/code/espurna/encoder.h index 0f62dc68..9e7580d2 100644 --- a/code/espurna/encoder.h +++ b/code/espurna/encoder.h @@ -6,6 +6,4 @@ Copyright (C) 2018-2019 by Xose Pérez */ -#include "espurna.h" - void encoderSetup(); diff --git a/code/espurna/homeassistant.cpp b/code/espurna/homeassistant.cpp index 2c4cf853..2e50ba16 100644 --- a/code/espurna/homeassistant.cpp +++ b/code/espurna/homeassistant.cpp @@ -14,6 +14,7 @@ Copyright (C) 2019-2021 by Maxim Prokhorov #pragma once -#include "espurna.h" - void haSetup(); diff --git a/code/espurna/influxdb.cpp b/code/espurna/influxdb.cpp index 500ff64d..356d020a 100644 --- a/code/espurna/influxdb.cpp +++ b/code/espurna/influxdb.cpp @@ -6,16 +6,17 @@ Copyright (C) 2017-2019 by Xose Pérez */ -#include "influxdb.h" +#include "espurna.h" #if INFLUXDB_SUPPORT #include #include +#include "influxdb.h" #include "mqtt.h" -#include "rpc.h" #include "relay.h" +#include "rpc.h" #include "sensor.h" #include "terminal.h" #include "ws.h" diff --git a/code/espurna/influxdb.h b/code/espurna/influxdb.h index 568c9c5c..3ee3db6b 100644 --- a/code/espurna/influxdb.h +++ b/code/espurna/influxdb.h @@ -6,8 +6,6 @@ Copyright (C) 2017-2019 by Xose Pérez */ -#include "espurna.h" - bool idbSend(const char * topic, unsigned char id, const char * payload); bool idbSend(const char * topic, const char * payload); bool idbEnabled(); diff --git a/code/espurna/light.cpp b/code/espurna/light.cpp index 93a25055..a7506cfd 100644 --- a/code/espurna/light.cpp +++ b/code/espurna/light.cpp @@ -2852,10 +2852,18 @@ void lightChannelStep(size_t id, long steps, long multiplier) { lightChannel(id, lightChannel(id) + (steps * multiplier)); } +void lightChannelStep(size_t id, long steps) { + lightChannelStep(id, steps, Light::ValueStep); +} + long lightBrightness() { return _light_brightness; } +void lightBrightnessPercent(long percent) { + lightBrightness((percent / 100l) * Light::BrightnessMax); +} + void lightBrightness(long brightness) { _light_brightness = std::clamp(brightness, Light::BrightnessMin, Light::BrightnessMax); } @@ -2864,6 +2872,10 @@ void lightBrightnessStep(long steps, long multiplier) { lightBrightness(static_cast(_light_brightness) + (steps * multiplier)); } +void lightBrightnessStep(long steps) { + lightBrightnessStep(steps, Light::ValueStep); +} + unsigned long lightTransitionTime() { return _light_use_transitions ? _light_transition_time : 0; } diff --git a/code/espurna/light.h b/code/espurna/light.h index e1bb990b..e75242d4 100644 --- a/code/espurna/light.h +++ b/code/espurna/light.h @@ -22,20 +22,22 @@ // TODO: lowercase namespace Light { -constexpr size_t ChannelsMax = 5; +constexpr size_t ChannelsMax { 5 }; -constexpr long ValueMin = LIGHT_MIN_VALUE; -constexpr long ValueMax = LIGHT_MAX_VALUE; +constexpr long ValueStep { LIGHT_STEP }; -constexpr long BrightnessMin = LIGHT_MIN_BRIGHTNESS; -constexpr long BrightnessMax = LIGHT_MAX_BRIGHTNESS; +constexpr long ValueMin { LIGHT_MIN_VALUE }; +constexpr long ValueMax { LIGHT_MAX_VALUE }; -constexpr long MiredsCold = LIGHT_COLDWHITE_MIRED; -constexpr long MiredsWarm = LIGHT_WARMWHITE_MIRED; +constexpr long BrightnessMin { LIGHT_MIN_BRIGHTNESS }; +constexpr long BrightnessMax { LIGHT_MAX_BRIGHTNESS }; -constexpr long PwmMin = LIGHT_MIN_PWM; -constexpr long PwmMax = LIGHT_MAX_PWM; -constexpr long PwmLimit = LIGHT_LIMIT_PWM; +constexpr long MiredsCold { LIGHT_COLDWHITE_MIRED }; +constexpr long MiredsWarm { LIGHT_WARMWHITE_MIRED }; + +constexpr long PwmMin { LIGHT_MIN_PWM }; +constexpr long PwmMax { LIGHT_MAX_PWM }; +constexpr long PwmLimit { LIGHT_LIMIT_PWM }; enum class Report { None = 0, @@ -235,14 +237,19 @@ bool lightState(size_t id); void lightState(bool state); bool lightState(); +// TODO: overload with struct Percent { ... }, struct Brightness { ... }, etc. +void lightBrightnessPercent(long percent); void lightBrightness(long brightness); long lightBrightness(); long lightChannel(size_t id); void lightChannel(size_t id, long value); -void lightBrightnessStep(long steps, long multiplier = LIGHT_STEP); -void lightChannelStep(size_t id, long steps, long multiplier = LIGHT_STEP); +void lightBrightnessStep(long steps); +void lightBrightnessStep(long steps, long multiplier); + +void lightChannelStep(size_t id, long steps); +void lightChannelStep(size_t id, long steps, long multiplier); void lightUpdate(bool save, LightTransition transition, Light::Report report); void lightUpdate(bool save, LightTransition transition, int report); diff --git a/code/espurna/mcp23s08.cpp b/code/espurna/mcp23s08.cpp index edd2ab6e..ab8600ce 100644 --- a/code/espurna/mcp23s08.cpp +++ b/code/espurna/mcp23s08.cpp @@ -11,10 +11,11 @@ Copyright (C) 2016 Plamen Kovandjiev & Dimitar A */ -#include "mcp23s08.h" +#include "espurna.h" #if MCP23S08_SUPPORT +#include "mcp23s08.h" #include "mcp23s08_pin.h" #include diff --git a/code/espurna/mcp23s08.h b/code/espurna/mcp23s08.h index 723c97a4..480f41cd 100644 --- a/code/espurna/mcp23s08.h +++ b/code/espurna/mcp23s08.h @@ -13,7 +13,9 @@ Copyright (C) 2016 Plamen Kovandjiev & Dimitar A #pragma once -#include "espurna.h" +#include + +#include "gpio.h" constexpr size_t McpGpioPins = 8; diff --git a/code/espurna/mqtt.cpp b/code/espurna/mqtt.cpp index d84da63e..b8f8f3aa 100644 --- a/code/espurna/mqtt.cpp +++ b/code/espurna/mqtt.cpp @@ -7,7 +7,7 @@ Updated secure client support by Niek van der Maas < mail at niekvandermaas dot */ -#include "mqtt.h" +#include "espurna.h" #if MQTT_SUPPORT diff --git a/code/espurna/mqtt.h b/code/espurna/mqtt.h index f0f3e431..f8082c1f 100644 --- a/code/espurna/mqtt.h +++ b/code/espurna/mqtt.h @@ -9,7 +9,7 @@ Updated secure client support by Niek van der Maas < mail at niekvandermaas dot #pragma once -#include "espurna.h" +#include "system.h" #include diff --git a/code/espurna/ntp.cpp b/code/espurna/ntp.cpp index b5c578ba..06c89e6d 100644 --- a/code/espurna/ntp.cpp +++ b/code/espurna/ntp.cpp @@ -11,7 +11,7 @@ Copyright (C) 2019 by Maxim Prokhorov */ -#include "ntp.h" +#include "espurna.h" #if NTP_SUPPORT @@ -19,6 +19,7 @@ Copyright (C) 2019 by Maxim Prokhorov #include #include +#include #include #include @@ -31,6 +32,7 @@ static_assert( #include "config/buildtime.h" +#include "ntp.h" #include "ntp_timelib.h" #include "ws.h" diff --git a/code/espurna/ntp.h b/code/espurna/ntp.h index d4756cfa..1db27492 100644 --- a/code/espurna/ntp.h +++ b/code/espurna/ntp.h @@ -9,7 +9,7 @@ Copyright (C) 2019-2021 by Maxim Prokhorov enum class NtpTick { EveryMinute, diff --git a/code/espurna/relay.cpp b/code/espurna/relay.cpp index d116fb88..4f0f2d62 100644 --- a/code/espurna/relay.cpp +++ b/code/espurna/relay.cpp @@ -6,7 +6,7 @@ Copyright (C) 2016-2019 by Xose Pérez */ -#include "relay.h" +#include "espurna.h" #if RELAY_SUPPORT @@ -20,11 +20,12 @@ Copyright (C) 2016-2019 by Xose Pérez #include "api.h" #include "mqtt.h" +#include "relay.h" #include "rpc.h" #include "rtcmem.h" #include "settings.h" -#include "terminal.h" #include "storage_eeprom.h" +#include "terminal.h" #include "utils.h" #include "ws.h" diff --git a/code/espurna/relay.h b/code/espurna/relay.h index ee7cce8a..a73ac468 100644 --- a/code/espurna/relay.h +++ b/code/espurna/relay.h @@ -8,7 +8,11 @@ Copyright (C) 2016-2019 by Xose Pérez #pragma once -#include "espurna.h" +#include + +#include +#include + #include "rpc.h" constexpr size_t RelaysMax { 32ul }; diff --git a/code/espurna/rfbridge.cpp b/code/espurna/rfbridge.cpp index 87bc8444..7f986de1 100644 --- a/code/espurna/rfbridge.cpp +++ b/code/espurna/rfbridge.cpp @@ -6,12 +6,13 @@ Copyright (C) 2016-2019 by Xose Pérez */ -#include "rfbridge.h" +#include "espurna.h" #if RFB_SUPPORT #include "api.h" #include "relay.h" +#include "rfbridge.h" #include "terminal.h" #include "mqtt.h" #include "ws.h" diff --git a/code/espurna/rfbridge.h b/code/espurna/rfbridge.h index ebd8d122..a05c745b 100644 --- a/code/espurna/rfbridge.h +++ b/code/espurna/rfbridge.h @@ -8,9 +8,8 @@ Copyright (C) 2016-2019 by Xose Pérez #pragma once -#include "espurna.h" - -#if RFB_SUPPORT +#include +#include using RfbCodeHandler = void(*)(unsigned char protocol, const char* code); void rfbOnCode(RfbCodeHandler); @@ -26,5 +25,3 @@ void rfbStore(size_t id, bool status, const char* code); void rfbForget(size_t id, bool status); void rfbSetup(); - -#endif // RFB_SUPPORT == 1 diff --git a/code/espurna/rfm69.cpp b/code/espurna/rfm69.cpp index 8430266e..732ab59f 100644 --- a/code/espurna/rfm69.cpp +++ b/code/espurna/rfm69.cpp @@ -6,7 +6,7 @@ Copyright (C) 2016-2017 by Xose Pérez */ -#include "rfm69.h" +#include "espurna.h" #if RFM69_SUPPORT @@ -16,6 +16,7 @@ Copyright (C) 2016-2017 by Xose Pérez #include #include +#include "rfm69.h" #include "mqtt.h" #include "ws.h" diff --git a/code/espurna/rfm69.h b/code/espurna/rfm69.h index f7fde296..7de3e032 100644 --- a/code/espurna/rfm69.h +++ b/code/espurna/rfm69.h @@ -8,6 +8,4 @@ Copyright (C) 2016-2017 by Xose Pérez #pragma once -#include "espurna.h" - void rfm69Setup(); diff --git a/code/espurna/rpc.h b/code/espurna/rpc.h index 4316e899..457a1164 100644 --- a/code/espurna/rpc.h +++ b/code/espurna/rpc.h @@ -6,7 +6,7 @@ Part of MQTT and API modules #pragma once -#include "espurna.h" +#include // -------------------------------------------------------------------------- diff --git a/code/espurna/rtcmem.cpp b/code/espurna/rtcmem.cpp index bcc09ebb..a6106fb6 100644 --- a/code/espurna/rtcmem.cpp +++ b/code/espurna/rtcmem.cpp @@ -6,6 +6,7 @@ Copyright (C) 2019 by Maxim Prokhorov */ +#include "espurna.h" #include "rtcmem.h" volatile RtcmemData* Rtcmem = reinterpret_cast(RTCMEM_ADDR); diff --git a/code/espurna/rtcmem.h b/code/espurna/rtcmem.h index 10d727ed..d89115e3 100644 --- a/code/espurna/rtcmem.h +++ b/code/espurna/rtcmem.h @@ -11,8 +11,6 @@ Copyright (C) 2019 by Maxim Prokhorov #include #include -#include "espurna.h" - // Base address of USER RTC memory // https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers #define RTCMEM_ADDR_BASE (0x60001200) diff --git a/code/espurna/scheduler.cpp b/code/espurna/scheduler.cpp index f4a3358c..751d7ec3 100644 --- a/code/espurna/scheduler.cpp +++ b/code/espurna/scheduler.cpp @@ -7,7 +7,7 @@ Adapted by Xose Pérez */ -#include "scheduler.h" +#include "espurna.h" #if SCHEDULER_SUPPORT @@ -16,9 +16,10 @@ Adapted by Xose Pérez #include "mqtt.h" #include "ntp.h" #include "ntp_timelib.h" -#include "relay.h" -#include "ws.h" #include "curtain_kingart.h" +#include "relay.h" +#include "scheduler.h" +#include "ws.h" // ----------------------------------------------------------------------------- diff --git a/code/espurna/scheduler.h b/code/espurna/scheduler.h index 78d6a52b..f2460e15 100644 --- a/code/espurna/scheduler.h +++ b/code/espurna/scheduler.h @@ -9,6 +9,4 @@ Adapted by Xose Pérez #pragma once -#include "espurna.h" - void schSetup(); diff --git a/code/espurna/system.h b/code/espurna/system.h index 926c6ab7..8793d284 100644 --- a/code/espurna/system.h +++ b/code/espurna/system.h @@ -116,21 +116,6 @@ Mode currentMode(); } // namespace heartbeat -namespace settings { -namespace internal { - -template <> -heartbeat::Mode convert(const String& value); - -template <> -heartbeat::Milliseconds convert(const String& value); - -template <> -heartbeat::Seconds convert(const String& value); - -} // namespace internal -} // namespace settings - unsigned long systemFreeStack(); HeapStats systemHeapStats(); diff --git a/code/espurna/telnet.cpp b/code/espurna/telnet.cpp index 7f65450f..8a5e9d63 100644 --- a/code/espurna/telnet.cpp +++ b/code/espurna/telnet.cpp @@ -15,7 +15,7 @@ Updated to use WiFiServer and support reverse connections by Niek van der Maas < */ -#include "telnet.h" +#include "espurna.h" #if TELNET_SUPPORT @@ -24,6 +24,7 @@ Updated to use WiFiServer and support reverse connections by Niek van der Maas < #include "board.h" #include "crash.h" +#include "telnet.h" #include "terminal.h" #include "ws.h" diff --git a/code/espurna/telnet.h b/code/espurna/telnet.h index e202e893..0800af86 100644 --- a/code/espurna/telnet.h +++ b/code/espurna/telnet.h @@ -8,13 +8,7 @@ Copyright (C) 2017-2019 by Xose Pérez #pragma once -#include "espurna.h" - #include -#include - -#include -#include constexpr unsigned char TELNET_IAC = 0xFF; constexpr unsigned char TELNET_XEOF = 0xEC; diff --git a/code/espurna/terminal.cpp b/code/espurna/terminal.cpp index 39c14fc6..1fafcc39 100644 --- a/code/espurna/terminal.cpp +++ b/code/espurna/terminal.cpp @@ -13,11 +13,12 @@ Copyright (C) 2020 by Maxim Prokhorov #include "api.h" #include "crash.h" +#include "mqtt.h" #include "settings.h" #include "system.h" #include "telnet.h" +#include "terminal.h" #include "utils.h" -#include "mqtt.h" #include "wifi.h" #include "ws.h" diff --git a/code/espurna/thermostat.cpp b/code/espurna/thermostat.cpp index 01a9b08e..270b48bf 100644 --- a/code/espurna/thermostat.cpp +++ b/code/espurna/thermostat.cpp @@ -6,15 +6,16 @@ Copyright (C) 2017 by Dmitry Blinov */ -#include "thermostat.h" +#include "espurna.h" #if THERMOSTAT_SUPPORT +#include "mqtt.h" #include "ntp.h" #include "ntp_timelib.h" #include "relay.h" #include "sensor.h" -#include "mqtt.h" +#include "thermostat.h" #include "ws.h" #include diff --git a/code/espurna/thermostat.h b/code/espurna/thermostat.h index de5eeaca..4d1812d0 100644 --- a/code/espurna/thermostat.h +++ b/code/espurna/thermostat.h @@ -8,7 +8,8 @@ Copyright (C) 2017 by Dmitry Blinov #pragma once -#include "espurna.h" +#include +#include #define ASK_TEMP_RANGE_INTERVAL_INITIAL 15000 // ask initially once per every 15 seconds #define ASK_TEMP_RANGE_INTERVAL_REGULAR 60000 // ask every minute to be sure diff --git a/code/espurna/thingspeak.cpp b/code/espurna/thingspeak.cpp index 69e42647..327db2cc 100644 --- a/code/espurna/thingspeak.cpp +++ b/code/espurna/thingspeak.cpp @@ -6,18 +6,19 @@ Copyright (C) 2019 by Xose Pérez */ -#include "thingspeak.h" +#include "espurna.h" #if THINGSPEAK_SUPPORT -#include - #include "mqtt.h" #include "relay.h" #include "rpc.h" #include "sensor.h" +#include "thingspeak.h" #include "ws.h" +#include + #if THINGSPEAK_USE_ASYNC #include #else diff --git a/code/espurna/thingspeak.h b/code/espurna/thingspeak.h index 3517548c..d4aae0c5 100644 --- a/code/espurna/thingspeak.h +++ b/code/espurna/thingspeak.h @@ -8,7 +8,7 @@ Copyright (C) 2019 by Xose Pérez #pragma once -#include "espurna.h" +#include constexpr size_t tspkDataBufferSize { 256ul }; diff --git a/code/espurna/tuya.cpp b/code/espurna/tuya.cpp index d6fe6312..e17e08a6 100644 --- a/code/espurna/tuya.cpp +++ b/code/espurna/tuya.cpp @@ -8,13 +8,14 @@ Copyright (C) 2019-2021 by Maxim Prokhorov */ -#include "uartmqtt.h" +#include "espurna.h" #if UART_MQTT_SUPPORT #include "mqtt.h" +#include "uartmqtt.h" char _uartmqttBuffer[UART_MQTT_BUFFER_SIZE]; bool _uartmqttNewData = false; diff --git a/code/espurna/uartmqtt.h b/code/espurna/uartmqtt.h index b668a52a..b3c2af1d 100644 --- a/code/espurna/uartmqtt.h +++ b/code/espurna/uartmqtt.h @@ -9,6 +9,4 @@ Adapted by Xose Pérez #pragma once -#include "espurna.h" - void uartmqttSetup(); diff --git a/code/espurna/web.cpp b/code/espurna/web.cpp index 8c0e21a8..debce848 100644 --- a/code/espurna/web.cpp +++ b/code/espurna/web.cpp @@ -6,7 +6,7 @@ Copyright (C) 2016-2019 by Xose Pérez */ -#include "web.h" +#include "espurna.h" #if WEB_SUPPORT @@ -14,10 +14,11 @@ Copyright (C) 2016-2019 by Xose Pérez #include #include -#include "system.h" -#include "settings.h" -#include "utils.h" #include "ntp.h" +#include "settings.h" +#include "system.h" +#include "utils.h" +#include "web.h" #include #include diff --git a/code/espurna/ws.cpp b/code/espurna/ws.cpp index d963640a..c37357ec 100644 --- a/code/espurna/ws.cpp +++ b/code/espurna/ws.cpp @@ -6,15 +6,17 @@ Copyright (C) 2016-2019 by Xose Pérez */ -#include "ws.h" +#include "espurna.h" #if WEB_SUPPORT +#include #include #include "system.h" #include "ntp.h" #include "utils.h" +#include "ws.h" #include "web.h" #include "wifi.h" #include "ws_internal.h" diff --git a/code/espurna/ws.h b/code/espurna/ws.h index a6de69f8..d4017769 100644 --- a/code/espurna/ws.h +++ b/code/espurna/ws.h @@ -9,11 +9,8 @@ Copyright (C) 2019 by Maxim Prokhorov #pragma once -#include "espurna.h" - #include -#include #include #include diff --git a/code/espurna/ws_internal.h b/code/espurna/ws_internal.h index 502f9170..eca327f9 100644 --- a/code/espurna/ws_internal.h +++ b/code/espurna/ws_internal.h @@ -9,9 +9,6 @@ Copyright (C) 2019 by Maxim Prokhorov #pragma once -#include "espurna.h" -#include "ws.h" - #include #include