From f1d33ca12157eaab485a8af8d947e411b18e46ae Mon Sep 17 00:00:00 2001 From: Maciej Czerniak Date: Wed, 7 Feb 2018 22:29:08 +0100 Subject: [PATCH 1/2] support board with 2 relays and stm8s103 --- code/espurna/config/general.h | 1 + code/espurna/config/hardware.h | 14 ++++++++++++++ code/espurna/relay.ino | 9 +++++++++ code/platformio.ini | 25 +++++++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 81c4d749..9e454ecc 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -275,6 +275,7 @@ PROGMEM const char* const custom_reset_string[] = { #define RELAY_PROVIDER_DUAL 1 #define RELAY_PROVIDER_LIGHT 2 #define RELAY_PROVIDER_RFBRIDGE 3 +#define RELAY_PROVIDER_STM 4 // Default boot mode: 0 means OFF, 1 ON and 2 whatever was before #define RELAY_BOOT_MODE RELAY_BOOT_OFF diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 7b950002..4f69ce52 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -1423,6 +1423,20 @@ // ----------------------------------------------------------------------------- +#elif defined(STM_RELAY) + + // Info + #define MANUFACTURER "STM_RELAY" + #define DEVICE "2CH" + + // Relays + #define DUMMY_RELAY_COUNT 2 + #define RELAY_PROVIDER RELAY_PROVIDER_STM + + // Remove UART noise on serial line + #define TERMINAL_SUPPORT 0 + #define DEBUG_SERIAL_SUPPORT 0 + #endif // ----------------------------------------------------------------------------- diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 5fa9af7e..abaf83cf 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -77,6 +77,15 @@ void _relayProviderStatus(unsigned char id, bool status) { #endif + #if RELAY_PROVIDER == RELAY_PROVIDER_STM + Serial.flush(); + Serial.write(0xA0); + Serial.write(id + 1); + Serial.write(status); + Serial.write(0xA1 + status + id); + Serial.flush(); + #endif + #if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT // If the number of relays matches the number of light channels diff --git a/code/platformio.ini b/code/platformio.ini index f63dd446..0d4acdd1 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -1388,6 +1388,31 @@ upload_speed = 460800 monitor_baud = 115200 extra_scripts = ${common.extra_scripts} +[env:stm-relay-ota] +platform = ${common.platform} +framework = arduino +board = esp01_1m +board_flash_mode = dout +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m} -DSTM_RELAY +monitor_baud = 115200 +extra_scripts = ${common.extra_scripts} + +[env:stm-relay-ota] +platform = ${common.platform} +framework = arduino +board = esp01_1m +board_flash_mode = dout +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m} -DSTM_RELAY +upload_speed = 115200 +upload_port = "192.168.4.1" +upload_flags = --auth=fibonacci --port 8266 +monitor_baud = 115200 +extra_scripts = ${common.extra_scripts} + # ------------------------------------------------------------------------------ # GENERIC OTA ENVIRONMENTS # ------------------------------------------------------------------------------ From 8c629ba7ab1e0a915f230a40d730769270379b7b Mon Sep 17 00:00:00 2001 From: Maciej Czerniak Date: Wed, 7 Feb 2018 23:32:01 +0100 Subject: [PATCH 2/2] hack for correctly restoring relay state on boot - because of broken stm firmware --- code/espurna/relay.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index abaf83cf..02012df2 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -394,7 +394,11 @@ void _relayBoot() { } _relays[i].current_status = !status; _relays[i].target_status = status; - _relays[i].change_time = millis(); + #ifdef RELAY_PROVIDER_STM + _relays[i].change_time = millis() + 3000 + 1000 * i; + #else + _relays[i].change_time = millis(); + #endif bit <<= 1; }