From 64d6ef86ceebcfdab82f2bec9946fc66a548c656 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sat, 24 Nov 2018 03:29:32 +0100 Subject: [PATCH 01/22] PS_16_DZ: initial support --- sonoff/language/tuya.patch | 13 ++ sonoff/my_user_config.h | 1 + sonoff/sonoff.h | 2 +- sonoff/sonoff_post.h | 1 + sonoff/sonoff_template.h | 22 +++- sonoff/xdrv_04_light.ino | 5 + sonoff/xdrv_19_ps16dz_dimmer.ino | 211 +++++++++++++++++++++++++++++++ 7 files changed, 252 insertions(+), 3 deletions(-) create mode 100644 sonoff/language/tuya.patch create mode 100644 sonoff/xdrv_19_ps16dz_dimmer.ino diff --git a/sonoff/language/tuya.patch b/sonoff/language/tuya.patch new file mode 100644 index 000000000..685f4458c --- /dev/null +++ b/sonoff/language/tuya.patch @@ -0,0 +1,13 @@ +diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h +index 4e3aa00..925080d 100644 +--- a/sonoff/language/en-GB.h ++++ b/sonoff/language/en-GB.h +@@ -527,6 +527,8 @@ + #define D_SENSOR_TX20_TX "TX20" + #define D_SENSOR_RFSEND "RFSend" + #define D_SENSOR_RFRECV "RFrecv" ++#define D_SENSOR_TUYA_TX "Tuya Tx" ++#define D_SENSOR_TUYA_RX "Tuya Rx" + + // Units + #define D_UNIT_AMPERE "A" diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 91b764688..dc23003cd 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -360,6 +360,7 @@ #define USE_TUYA_DIMMER // Add support for Tuya Serial Dimmer #define TUYA_DIMMER_ID 0 // Default dimmer Id #define USE_ARMTRONIX_DIMMERS // Add support for Armtronix Dimmers (+1k4 code) +#define USE_PS_16_DZ // ADD support for PS-16-DZ Dimmer // Power monitoring sensors ----------------------- #define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code) diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index e53a7c83d..07b87661c 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -231,7 +231,7 @@ enum Ws2812Color { WS_RED, WS_GREEN, WS_BLUE }; enum LightSubtypes { LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_RGBWC }; // Do not insert new fields enum LightTypes { LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6, LT_PWM7, - LT_NU8, LT_SERIAL1, LT_SERIAL2, LT_WS2812, LT_RGBW, LT_RGBWC, LT_NU14, LT_NU15 }; // Do not insert new fields + LT_NU8, LT_SERIAL1, LT_SERIAL2, LT_WS2812, LT_RGBW, LT_RGBWC, LT_SERIAL3, LT_NU15 }; // Do not insert new fields enum LightSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX}; diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index 1e52a8641..b6fc2c77f 100644 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -111,6 +111,7 @@ void KNX_CB_Action(message_t const &msg, void *arg); #ifndef TUYA_DIMMER_ID #define TUYA_DIMMER_ID 0 // Default dimmer Id #endif +#define USE_PS_16_DZ // Add support for PS-16-DZ Dimmer #define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code) #define USE_PZEM_AC // Add support for PZEM014,016 Energy monitor (+1k1 code) #define USE_PZEM_DC // Add support for PZEM003,017 Energy monitor (+1k1 code) diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 3135dd339..98e329bdf 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -256,6 +256,7 @@ enum SupportedModules { GOSUND, ARMTRONIX_DIMMERS, SK03_TUYA, + PS_16_DZ, MAXMODULE }; /********************************************************************************************/ @@ -494,7 +495,8 @@ const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { AILIGHT, // Light Bulbs PHILIPS, WITTY, // Development Devices - WEMOS + WEMOS, + PS_16_DZ }; // Default module settings @@ -1270,7 +1272,23 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_LED1_INV, // GPIO14 Blue Led (0 = On, 1 = Off) GPIO_REL1, // GPIO15 Relay (0 = Off, 1 = On) 0, 0 - } + }, + { "PS-16-DZ", // PS-16-DZ Dimmer (ESP8266 w/ separate Nuvoton MCU dimmer) + // https://www.aliexpress.com/item/SM-Smart-WIFI-Wall-Dimmer-Light-Switch-US-Ewelink-APP-Remote-Control-Wi-Fi-Wirele-Work/32871151902.html + GPIO_USER, + GPIO_TXD, // GPIO01 MCU serial control + GPIO_USER, + GPIO_RXD, // GPIO03 MCU serial control + GPIO_USER, + GPIO_USER, + 0, 0, 0, 0, 0, 0, // Flash connection + GPIO_USER, + GPIO_USER, + GPIO_USER, + GPIO_USER, + GPIO_USER, + 0 + } }; /* diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 92e19fb57..10caf2472 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -841,6 +841,11 @@ void LightAnimate(void) LightSerial2Duty(cur_col[0],cur_col[1]); } #endif // USE_ARMTRONIX_DIMMERS +#ifdef USE_PS16DZ_DIMMERS + if (light_type == LT_SERIAL3) { + PS16DZSerialDuty(cur_col[0]); + } +#endif // USE_PS16DZ_DIMMERS } } diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino new file mode 100644 index 000000000..82f81eefa --- /dev/null +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -0,0 +1,211 @@ +/* + xdrv_16_ps16dzdimmer.ino - PS16DZ dimmer support for Sonoff-Tasmota + + Copyright (C) 2018 Joel Stein and Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_PS_16_DZ + +#define XDRV_19 19 + +#define PS16DZ_BUFFER_SIZE 256 + +#include + +TasmotaSerial *PS16DZSerial = nullptr; + +boolean ps16dz_ignore_dim = false; // Flag to skip serial send to prevent looping when processing inbound states from the faceplate interaction +int8_t ps16dz_wifi_state = -2; // Keep MCU wifi-status in sync with WifiState() + +boolean ps16dz_power = false; +uint8_t ps16dz_bright = 0; +uint64_t ps16dz_seq = 0; + +char ps16dz_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer +int ps16dz_byte_counter = 0; // Index in serial receive buffer + +/*********************************************************************************************\ + * Internal Functions +\*********************************************************************************************/ + + +boolean PS16DZSetPower(void) +{ + boolean status = false; + + uint8_t rpower = XdrvMailbox.index; + int16_t source = XdrvMailbox.payload; + + if (source != SRC_SWITCH && PS16DZSerial) { // ignore to prevent loop from pushing state from faceplate interaction + + snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+UPDATE=\"sequence\":\"%lld\",\"switch\":\"%s\""), ps16dz_seq++, rpower?"on":"off"); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_buffer ); + AddLog(LOG_LEVEL_DEBUG); + + PS16DZSerial->print(ps16dz_buffer); + PS16DZSerial->write(0x1B); + + status = true; + } + return status; +} + +void PS16DZSerialDuty(uint8_t duty) +{ + if (duty > 0 && !ps16dz_ignore_dim && PS16DZSerial) { + if (duty < 25) { + duty = 25; // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself + } + + snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+UPDATE=\"sequence\":\"%lld\",\"bright\":\"%d\""), ps16dz_seq++, duty/(255./100.)); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_buffer ); + AddLog(LOG_LEVEL_DEBUG); + + PS16DZSerial->print(ps16dz_buffer); + PS16DZSerial->write(0x1B); + + } else { + ps16dz_ignore_dim = false; // reset flag + + snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send Dim Level skipped due to 0 or already set. Value=%d"), duty); + AddLog(LOG_LEVEL_DEBUG); + + } +} + +void PS16DZResetWifi(void) +{ + if (!Settings.flag.button_restrict) { + char scmnd[20]; + snprintf_P(scmnd, sizeof(scmnd), D_CMND_WIFICONFIG " %d", 2); + ExecuteCommand(scmnd, SRC_BUTTON); + } +} + +/*********************************************************************************************\ + * API Functions +\*********************************************************************************************/ + +boolean PS16DZModuleSelected(void) +{ + light_type = LT_SERIAL3; + return true; +} + +void PS16DZInit(void) +{ + PS16DZSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2); + if (PS16DZSerial->begin(19200)) { + if (PS16DZSerial->hardwareSerial()) { ClaimSerial(); } + } +} + +void PS16DZSerialInput(void) +{ + char scmnd[20]; + String ps16dz_command; + while (PS16DZSerial->available()) { + yield(); + ps16dz_command = PS16DZSerial->readStringUntil(0x1B); + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: command received: %s"), ps16dz_command.c_str()); + AddLog(LOG_LEVEL_DEBUG); + if(ps16dz_command.substring(3,6) == "UPDATE" || ps16dz_command.substring(3,6) == "RESULT"){ + char *end_str; + char *string = strdup(ps16dz_command.substring(10).c_str()); + char* token = strtok_r(string, ",", &end_str); + while (token != NULL) { + char* end_token; + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: token = %s"), token); + AddLog(LOG_LEVEL_DEBUG); + char* token2 = strtok_r(token, ":", &end_token); + char* token3 = strtok_r(NULL, ":", &end_token); + if(!strncmp(token2, "\"switch\"", 8)){ + ps16dz_power = !strncmp(token3, "\"on\"", 4)?true:false; + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: power received: %s"), token3); + AddLog(LOG_LEVEL_DEBUG); + if((power || Settings.light_dimmer > 0) && (power !=ps16dz_power)) { + ExecuteCommandPower(1, ps16dz_power, SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction + } + } + else if(!strncmp(token2, "\"bright\"", 8)){ + ps16dz_bright = atoi(token3); + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: brightness received: %d"), ps16dz_bright); + AddLog(LOG_LEVEL_DEBUG); + if(power && ps16dz_bright > 0) { + + snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), ps16dz_bright ); + + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: Send CMND_DIMMER_STR=%s"), scmnd ); + AddLog(LOG_LEVEL_DEBUG); + + ps16dz_ignore_dim = true; + ExecuteCommand(scmnd, SRC_SWITCH); + } + + } + else if(!strncmp(token2, "\"sequence\"", 10)){ + ps16dz_seq = strtoull(token3, NULL, 10); + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %lld"), ps16dz_seq); + AddLog(LOG_LEVEL_DEBUG); + } + + token = strtok_r(NULL, ",", &end_str); + } + } + else if(ps16dz_command.substring(3,7) == "SETTING"){ + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: Reset")); + AddLog(LOG_LEVEL_DEBUG); + PS16DZResetWifi(); + } + snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+SEND=ok")); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_buffer ); + AddLog(LOG_LEVEL_DEBUG); + + PS16DZSerial->print(ps16dz_buffer); + PS16DZSerial->write(0x1B); + } +} + + + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +boolean Xdrv19(byte function) +{ + boolean result = false; + + if (PS_16_DZ == Settings.module) { + switch (function) { + case FUNC_MODULE_INIT: + result = PS16DZModuleSelected(); + break; + case FUNC_INIT: + PS16DZInit(); + break; + case FUNC_LOOP: + if (PS16DZSerial) { PS16DZSerialInput(); } + break; + case FUNC_SET_DEVICE_POWER: + result = PS16DZSetPower(); + break; + } + } + return result; +} + +#endif // USE_PS_16_DZ From dfc154ab167708860734a3613b46be8a86387382 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sat, 24 Nov 2018 03:38:55 +0100 Subject: [PATCH 02/22] PS_16_DZ: remove unwanted file --- sonoff/language/tuya.patch | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 sonoff/language/tuya.patch diff --git a/sonoff/language/tuya.patch b/sonoff/language/tuya.patch deleted file mode 100644 index 685f4458c..000000000 --- a/sonoff/language/tuya.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h -index 4e3aa00..925080d 100644 ---- a/sonoff/language/en-GB.h -+++ b/sonoff/language/en-GB.h -@@ -527,6 +527,8 @@ - #define D_SENSOR_TX20_TX "TX20" - #define D_SENSOR_RFSEND "RFSend" - #define D_SENSOR_RFRECV "RFrecv" -+#define D_SENSOR_TUYA_TX "Tuya Tx" -+#define D_SENSOR_TUYA_RX "Tuya Rx" - - // Units - #define D_UNIT_AMPERE "A" From 55b287d6da7a624f021be6d485d91b368ef6ff88 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sat, 24 Nov 2018 04:09:57 +0100 Subject: [PATCH 03/22] PS_16_DZ: fix define in xdrv04 --- sonoff/xdrv_04_light.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 10caf2472..d306bc974 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -841,11 +841,11 @@ void LightAnimate(void) LightSerial2Duty(cur_col[0],cur_col[1]); } #endif // USE_ARMTRONIX_DIMMERS -#ifdef USE_PS16DZ_DIMMERS +#ifdef USE_PS_16_DZ if (light_type == LT_SERIAL3) { PS16DZSerialDuty(cur_col[0]); } -#endif // USE_PS16DZ_DIMMERS +#endif // USE_PS_16_DZ } } From 34da2859ba8afdc10c4ef8ff3f72e0c2b5a5e72f Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sat, 24 Nov 2018 05:08:14 +0100 Subject: [PATCH 04/22] PS_16_DZ: fixes --- sonoff/sonoff.h | 2 +- sonoff/xdrv_04_light.ino | 2 +- sonoff/xdrv_19_ps16dz_dimmer.ino | 39 ++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 07b87661c..e53a7c83d 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -231,7 +231,7 @@ enum Ws2812Color { WS_RED, WS_GREEN, WS_BLUE }; enum LightSubtypes { LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_RGBWC }; // Do not insert new fields enum LightTypes { LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6, LT_PWM7, - LT_NU8, LT_SERIAL1, LT_SERIAL2, LT_WS2812, LT_RGBW, LT_RGBWC, LT_SERIAL3, LT_NU15 }; // Do not insert new fields + LT_NU8, LT_SERIAL1, LT_SERIAL2, LT_WS2812, LT_RGBW, LT_RGBWC, LT_NU14, LT_NU15 }; // Do not insert new fields enum LightSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX}; diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index d306bc974..455adc4d0 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -842,7 +842,7 @@ void LightAnimate(void) } #endif // USE_ARMTRONIX_DIMMERS #ifdef USE_PS_16_DZ - if (light_type == LT_SERIAL3) { + if (light_type == LT_SERIAL1) { PS16DZSerialDuty(cur_col[0]); } #endif // USE_PS_16_DZ diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index 82f81eefa..fb43e31d2 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -1,5 +1,5 @@ /* - xdrv_16_ps16dzdimmer.ino - PS16DZ dimmer support for Sonoff-Tasmota + xdrv_16_ps16dz_dimmer.ino - PS16DZ dimmer support for Sonoff-Tasmota Copyright (C) 2018 Joel Stein and Theo Arends @@ -42,6 +42,31 @@ int ps16dz_byte_counter = 0; // Index in serial receive buffer \*********************************************************************************************/ +size_t print_uint64_t(uint64_t number) +{ + size_t n = 0; + unsigned char buf[21]; + uint8_t i = 0; + + if (number == 0) + { + n += snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "%s%c"), ps16dz_buffer, (char)'0'); + return n; + } + + while (number > 0) + { + uint64_t q = number/10; + buf[i++] = number - q*10; + number = q; + } + + for (; i > 0; i--) + n += snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "%s%c"), ps16dz_buffer, (char) ('0' + buf[i - 1])); + + return n; +} + boolean PS16DZSetPower(void) { boolean status = false; @@ -51,7 +76,9 @@ boolean PS16DZSetPower(void) if (source != SRC_SWITCH && PS16DZSerial) { // ignore to prevent loop from pushing state from faceplate interaction - snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+UPDATE=\"sequence\":\"%lld\",\"switch\":\"%s\""), ps16dz_seq++, rpower?"on":"off"); + snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); + print_uint64_t(ps16dz_seq++); + snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_buffer, rpower?"on":"off"); snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_buffer ); AddLog(LOG_LEVEL_DEBUG); @@ -70,7 +97,9 @@ void PS16DZSerialDuty(uint8_t duty) duty = 25; // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself } - snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+UPDATE=\"sequence\":\"%lld\",\"bright\":\"%d\""), ps16dz_seq++, duty/(255./100.)); + snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); + print_uint64_t(ps16dz_seq++); + snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "%s\",\"bright\":\"%d\""), ps16dz_buffer, round(duty * (100. / 255.))); snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_buffer ); AddLog(LOG_LEVEL_DEBUG); @@ -101,7 +130,7 @@ void PS16DZResetWifi(void) boolean PS16DZModuleSelected(void) { - light_type = LT_SERIAL3; + light_type = LT_SERIAL1; return true; } @@ -158,7 +187,7 @@ void PS16DZSerialInput(void) } else if(!strncmp(token2, "\"sequence\"", 10)){ ps16dz_seq = strtoull(token3, NULL, 10); - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %lld"), ps16dz_seq); + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %0ld"), ps16dz_seq/1000000L, ps16dz_seq%1000000L); AddLog(LOG_LEVEL_DEBUG); } From 9574fc7c65dc755494b2d10297c16de114381476 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sat, 24 Nov 2018 16:24:44 +0100 Subject: [PATCH 05/22] PS_16_DZ: fixes --- sonoff/xdrv_19_ps16dz_dimmer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index fb43e31d2..ce8ce7267 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -1,5 +1,5 @@ /* - xdrv_16_ps16dz_dimmer.ino - PS16DZ dimmer support for Sonoff-Tasmota + xdrv_19_ps16dz_dimmer.ino - PS_16_DZ dimmer support for Sonoff-Tasmota Copyright (C) 2018 Joel Stein and Theo Arends From 5ce19fc3f77370cc49d36d0d444a25f3e31adea7 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sun, 25 Nov 2018 22:43:28 +0100 Subject: [PATCH 06/22] PS_16_DZ: don't use String class --- sonoff/xdrv_19_ps16dz_dimmer.ino | 143 ++++++++++++++++--------------- 1 file changed, 75 insertions(+), 68 deletions(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index ce8ce7267..d1cb69221 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -28,14 +28,14 @@ TasmotaSerial *PS16DZSerial = nullptr; boolean ps16dz_ignore_dim = false; // Flag to skip serial send to prevent looping when processing inbound states from the faceplate interaction -int8_t ps16dz_wifi_state = -2; // Keep MCU wifi-status in sync with WifiState() boolean ps16dz_power = false; uint8_t ps16dz_bright = 0; uint64_t ps16dz_seq = 0; -char ps16dz_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer -int ps16dz_byte_counter = 0; // Index in serial receive buffer +char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer +char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer +int ps16dz_byte_counter = 0; /*********************************************************************************************\ * Internal Functions @@ -50,7 +50,7 @@ size_t print_uint64_t(uint64_t number) if (number == 0) { - n += snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "%s%c"), ps16dz_buffer, (char)'0'); + n += snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s%c"), ps16dz_tx_buffer, (char)'0'); return n; } @@ -62,7 +62,7 @@ size_t print_uint64_t(uint64_t number) } for (; i > 0; i--) - n += snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "%s%c"), ps16dz_buffer, (char) ('0' + buf[i - 1])); + n += snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s%c"), ps16dz_tx_buffer, (char) ('0' + buf[i - 1])); return n; } @@ -76,13 +76,13 @@ boolean PS16DZSetPower(void) if (source != SRC_SWITCH && PS16DZSerial) { // ignore to prevent loop from pushing state from faceplate interaction - snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); + snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); print_uint64_t(ps16dz_seq++); - snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_buffer, rpower?"on":"off"); - snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_buffer ); + snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off"); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); - PS16DZSerial->print(ps16dz_buffer); + PS16DZSerial->print(ps16dz_tx_buffer); PS16DZSerial->write(0x1B); status = true; @@ -97,13 +97,13 @@ void PS16DZSerialDuty(uint8_t duty) duty = 25; // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself } - snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); + snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); print_uint64_t(ps16dz_seq++); - snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "%s\",\"bright\":\"%d\""), ps16dz_buffer, round(duty * (100. / 255.))); - snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_buffer ); + snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":\"%d\""), ps16dz_tx_buffer, round(duty * (100. / 255.))); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); - PS16DZSerial->print(ps16dz_buffer); + PS16DZSerial->print(ps16dz_tx_buffer); PS16DZSerial->write(0x1B); } else { @@ -145,66 +145,73 @@ void PS16DZInit(void) void PS16DZSerialInput(void) { char scmnd[20]; - String ps16dz_command; while (PS16DZSerial->available()) { yield(); - ps16dz_command = PS16DZSerial->readStringUntil(0x1B); - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: command received: %s"), ps16dz_command.c_str()); - AddLog(LOG_LEVEL_DEBUG); - if(ps16dz_command.substring(3,6) == "UPDATE" || ps16dz_command.substring(3,6) == "RESULT"){ - char *end_str; - char *string = strdup(ps16dz_command.substring(10).c_str()); - char* token = strtok_r(string, ",", &end_str); - while (token != NULL) { - char* end_token; - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: token = %s"), token); - AddLog(LOG_LEVEL_DEBUG); - char* token2 = strtok_r(token, ":", &end_token); - char* token3 = strtok_r(NULL, ":", &end_token); - if(!strncmp(token2, "\"switch\"", 8)){ - ps16dz_power = !strncmp(token3, "\"on\"", 4)?true:false; - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: power received: %s"), token3); - AddLog(LOG_LEVEL_DEBUG); - if((power || Settings.light_dimmer > 0) && (power !=ps16dz_power)) { - ExecuteCommandPower(1, ps16dz_power, SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction - } - } - else if(!strncmp(token2, "\"bright\"", 8)){ - ps16dz_bright = atoi(token3); - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: brightness received: %d"), ps16dz_bright); - AddLog(LOG_LEVEL_DEBUG); - if(power && ps16dz_bright > 0) { - - snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), ps16dz_bright ); - - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: Send CMND_DIMMER_STR=%s"), scmnd ); - AddLog(LOG_LEVEL_DEBUG); - - ps16dz_ignore_dim = true; - ExecuteCommand(scmnd, SRC_SWITCH); - } - - } - else if(!strncmp(token2, "\"sequence\"", 10)){ - ps16dz_seq = strtoull(token3, NULL, 10); - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %0ld"), ps16dz_seq/1000000L, ps16dz_seq%1000000L); - AddLog(LOG_LEVEL_DEBUG); - } - - token = strtok_r(NULL, ",", &end_str); - } + //ps16dz_command = PS16DZSerial->readStringUntil(0x1B); + byte serial_in_byte = PS16DZSerial->read(); + if (serial_in_byte != 0x1B){ + ps16dz_rx_buffer[ps16dz_byte_counter++] = serial_in_byte; } - else if(ps16dz_command.substring(3,7) == "SETTING"){ - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: Reset")); + else { + ps16dz_rx_buffer[ps16dz_byte_counter++] = 0x00; + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: command received: %s"), ps16dz_rx_buffer); AddLog(LOG_LEVEL_DEBUG); - PS16DZResetWifi(); + if(!strncmp(ps16dz_rx_buffer+3, "UPDATE", 6) || !strncmp(ps16dz_rx_buffer+3, "RESULT", 6)) { + char *end_str; + char *string = ps16dz_rx_buffer+10; + char* token = strtok_r(string, ",", &end_str); + while (token != NULL) { + char* end_token; + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: token = %s"), token); + AddLog(LOG_LEVEL_DEBUG); + char* token2 = strtok_r(token, ":", &end_token); + char* token3 = strtok_r(NULL, ":", &end_token); + if(!strncmp(token2, "\"switch\"", 8)){ + ps16dz_power = !strncmp(token3, "\"on\"", 4)?true:false; + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: power received: %s"), token3); + AddLog(LOG_LEVEL_DEBUG); + if((power || Settings.light_dimmer > 0) && (power !=ps16dz_power)) { + ExecuteCommandPower(1, ps16dz_power, SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction + } + } + else if(!strncmp(token2, "\"bright\"", 8)){ + ps16dz_bright = atoi(token3); + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: brightness received: %d"), ps16dz_bright); + AddLog(LOG_LEVEL_DEBUG); + if(power && ps16dz_bright > 0) { + + snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), ps16dz_bright ); + + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: Send CMND_DIMMER_STR=%s"), scmnd ); + AddLog(LOG_LEVEL_DEBUG); + + ps16dz_ignore_dim = true; + ExecuteCommand(scmnd, SRC_SWITCH); + } + } + else if(!strncmp(token2, "\"sequence\"", 10)){ + ps16dz_seq = strtoull(token3, NULL, 10); + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %0ld"), ps16dz_seq/1000000L, ps16dz_seq%1000000L); + AddLog(LOG_LEVEL_DEBUG); + } + token = strtok_r(NULL, ",", &end_str); + } + } + else if(!strncmp(ps16dz_rx_buffer+3, "SETTING", 7)) { + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: Reset")); + AddLog(LOG_LEVEL_DEBUG); + PS16DZResetWifi(); + } + memset(ps16dz_rx_buffer, 0, sizeof(ps16dz_rx_buffer)); + ps16dz_byte_counter = 0; + + snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+SEND=ok")); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_tx_buffer ); + AddLog(LOG_LEVEL_DEBUG); + + PS16DZSerial->print(ps16dz_tx_buffer); + PS16DZSerial->write(0x1B); } - snprintf_P(ps16dz_buffer, sizeof(ps16dz_buffer), PSTR( "AT+SEND=ok")); - snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_buffer ); - AddLog(LOG_LEVEL_DEBUG); - - PS16DZSerial->print(ps16dz_buffer); - PS16DZSerial->write(0x1B); } } From e024ca3bebcbaa94e441962be31aa6ded16bf983 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sun, 25 Nov 2018 23:09:58 +0100 Subject: [PATCH 07/22] PS_16_DZ: start sequence with 1529000000000 --- sonoff/xdrv_19_ps16dz_dimmer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index d1cb69221..030f59f04 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -31,7 +31,7 @@ boolean ps16dz_ignore_dim = false; // Flag to skip serial send to pre boolean ps16dz_power = false; uint8_t ps16dz_bright = 0; -uint64_t ps16dz_seq = 0; +uint64_t ps16dz_seq = 1529000000000; char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer From 0f2ea2800eb75627b347480247846fd82819636b Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sun, 25 Nov 2018 23:39:44 +0100 Subject: [PATCH 08/22] PS_16_DZ: start must be 'A' --- sonoff/xdrv_19_ps16dz_dimmer.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index 030f59f04..271af64d3 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -150,6 +150,7 @@ void PS16DZSerialInput(void) //ps16dz_command = PS16DZSerial->readStringUntil(0x1B); byte serial_in_byte = PS16DZSerial->read(); if (serial_in_byte != 0x1B){ + if (ps16dz_byte_counter || (!ps16dz_byte_counter && serial_in_byte = 'A')); ps16dz_rx_buffer[ps16dz_byte_counter++] = serial_in_byte; } else { From 977822f131d0def8be63a94df7661ef012bdc86c Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sun, 25 Nov 2018 23:41:11 +0100 Subject: [PATCH 09/22] PS_16_DZ: start must be 'A' --- sonoff/xdrv_19_ps16dz_dimmer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index 271af64d3..78e2f7cfb 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -150,7 +150,7 @@ void PS16DZSerialInput(void) //ps16dz_command = PS16DZSerial->readStringUntil(0x1B); byte serial_in_byte = PS16DZSerial->read(); if (serial_in_byte != 0x1B){ - if (ps16dz_byte_counter || (!ps16dz_byte_counter && serial_in_byte = 'A')); + if (ps16dz_byte_counter || (!ps16dz_byte_counter && serial_in_byte == 'A')); ps16dz_rx_buffer[ps16dz_byte_counter++] = serial_in_byte; } else { From b7a18f7bcc4b2ea8e98f0476ba7a67cea5a06d9c Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 00:31:45 +0100 Subject: [PATCH 10/22] PS_16_DZ: tryfix dimming --- sonoff/xdrv_04_light.ino | 4 ++-- sonoff/xdrv_19_ps16dz_dimmer.ino | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 455adc4d0..b4f10a148 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -832,7 +832,7 @@ void LightAnimate(void) LightMy92x1Duty(cur_col[0], cur_col[1], cur_col[2], cur_col[3], cur_col[4]); } #ifdef USE_TUYA_DIMMER - if (light_type == LT_SERIAL1) { + if (light_type == LT_SERIAL1 && Settings.module == TUYA_DIMMER ) { LightSerialDuty(cur_col[0]); } #endif // USE_TUYA_DIMMER @@ -842,7 +842,7 @@ void LightAnimate(void) } #endif // USE_ARMTRONIX_DIMMERS #ifdef USE_PS_16_DZ - if (light_type == LT_SERIAL1) { + if (light_type == LT_SERIAL1 && Settings.module == PS_16_DZ) { PS16DZSerialDuty(cur_col[0]); } #endif // USE_PS_16_DZ diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index 78e2f7cfb..f3f219d60 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -31,7 +31,8 @@ boolean ps16dz_ignore_dim = false; // Flag to skip serial send to pre boolean ps16dz_power = false; uint8_t ps16dz_bright = 0; -uint64_t ps16dz_seq = 1529000000000; +//uint64_t ps16dz_seq = 1529000000000; +uint64_t ps16dz_seq = 0; char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer From 985db96f91a6656f39655c68011078009904e1b5 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 00:47:00 +0100 Subject: [PATCH 11/22] PS_16_DZ: print correct sequence --- sonoff/xdrv_19_ps16dz_dimmer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index f3f219d60..887f89a1e 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -193,7 +193,7 @@ void PS16DZSerialInput(void) } else if(!strncmp(token2, "\"sequence\"", 10)){ ps16dz_seq = strtoull(token3, NULL, 10); - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %0ld"), ps16dz_seq/1000000L, ps16dz_seq%1000000L); + snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %s"), token3); AddLog(LOG_LEVEL_DEBUG); } token = strtok_r(NULL, ",", &end_str); From 283f023f29caf209b0204a865660c7037000ed08 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 01:19:09 +0100 Subject: [PATCH 12/22] PS_16_DZ: move in nicelist --- sonoff/sonoff_template.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 98e329bdf..da7d99656 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -482,8 +482,9 @@ const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { NEO_COOLCAM, // Socket Relay Devices OBI, ESP_SWITCH, // Switch Devices - TUYA_DIMMER, // Dimmer Devices + TUYA_DIMMER, // Dimmer Devices ARMTRONIX_DIMMERS, + PS_16_DZ, H801, // Light Devices MAGICHOME, ARILUX_LC01, @@ -495,8 +496,7 @@ const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { AILIGHT, // Light Bulbs PHILIPS, WITTY, // Development Devices - WEMOS, - PS_16_DZ + WEMOS }; // Default module settings From 1dc7a5847c45aa2238b1ed6e97e7121964bef0ae Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 02:22:18 +0100 Subject: [PATCH 13/22] PS_16_DZ: correctly parse sequence --- sonoff/xdrv_19_ps16dz_dimmer.ino | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index 887f89a1e..b165d66a1 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -31,8 +31,7 @@ boolean ps16dz_ignore_dim = false; // Flag to skip serial send to pre boolean ps16dz_power = false; uint8_t ps16dz_bright = 0; -//uint64_t ps16dz_seq = 1529000000000; -uint64_t ps16dz_seq = 0; +uint64_t ps16dz_seq = 1530000000000; char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer @@ -192,7 +191,7 @@ void PS16DZSerialInput(void) } } else if(!strncmp(token2, "\"sequence\"", 10)){ - ps16dz_seq = strtoull(token3, NULL, 10); + ps16dz_seq = strtoull(token3+1, NULL, 10); snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %s"), token3); AddLog(LOG_LEVEL_DEBUG); } From 7203d6ad03e2aa57b9b82dfb014365b48ee91604 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 03:20:15 +0100 Subject: [PATCH 14/22] PS_16_DZ: wait for acknoledgement before sending more commands --- sonoff/xdrv_19_ps16dz_dimmer.ino | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index b165d66a1..862283d25 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -32,6 +32,7 @@ boolean ps16dz_ignore_dim = false; // Flag to skip serial send to pre boolean ps16dz_power = false; uint8_t ps16dz_bright = 0; uint64_t ps16dz_seq = 1530000000000; +boolean ps16dz_synced = true; char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer @@ -74,8 +75,9 @@ boolean PS16DZSetPower(void) uint8_t rpower = XdrvMailbox.index; int16_t source = XdrvMailbox.payload; - if (source != SRC_SWITCH && PS16DZSerial) { // ignore to prevent loop from pushing state from faceplate interaction + if (source != SRC_SWITCH && PS16DZSerial && ps16dz_synced) { // ignore to prevent loop from pushing state from faceplate interaction + ps16dz_synced = false; snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); print_uint64_t(ps16dz_seq++); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off"); @@ -92,11 +94,12 @@ boolean PS16DZSetPower(void) void PS16DZSerialDuty(uint8_t duty) { - if (duty > 0 && !ps16dz_ignore_dim && PS16DZSerial) { + if (duty > 0 && !ps16dz_ignore_dim && PS16DZSerial && ps16dz_synced) { if (duty < 25) { duty = 25; // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself } + ps16dz_synced = false; snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); print_uint64_t(ps16dz_seq++); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":\"%d\""), ps16dz_tx_buffer, round(duty * (100. / 255.))); @@ -191,9 +194,13 @@ void PS16DZSerialInput(void) } } else if(!strncmp(token2, "\"sequence\"", 10)){ - ps16dz_seq = strtoull(token3+1, NULL, 10); + uint64_t ps16dz_seq_tmp = strtoull(token3+1, NULL, 10); snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %s"), token3); AddLog(LOG_LEVEL_DEBUG); + if(ps16dz_seq_tmp >= ps16dz_seq){ + ps16dz_synced = true; + ps16dz_seq = ps16dz_seq_tmp; + } } token = strtok_r(NULL, ",", &end_str); } From a6124c376ec601d31bcacc8f314ff139dcf39925 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 13:27:30 +0100 Subject: [PATCH 15/22] Revert "PS_16_DZ: wait for acknoledgement before sending more commands" This reverts commit 7203d6ad03e2aa57b9b82dfb014365b48ee91604. --- sonoff/xdrv_19_ps16dz_dimmer.ino | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index 862283d25..b165d66a1 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -32,7 +32,6 @@ boolean ps16dz_ignore_dim = false; // Flag to skip serial send to pre boolean ps16dz_power = false; uint8_t ps16dz_bright = 0; uint64_t ps16dz_seq = 1530000000000; -boolean ps16dz_synced = true; char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer @@ -75,9 +74,8 @@ boolean PS16DZSetPower(void) uint8_t rpower = XdrvMailbox.index; int16_t source = XdrvMailbox.payload; - if (source != SRC_SWITCH && PS16DZSerial && ps16dz_synced) { // ignore to prevent loop from pushing state from faceplate interaction + if (source != SRC_SWITCH && PS16DZSerial) { // ignore to prevent loop from pushing state from faceplate interaction - ps16dz_synced = false; snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); print_uint64_t(ps16dz_seq++); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off"); @@ -94,12 +92,11 @@ boolean PS16DZSetPower(void) void PS16DZSerialDuty(uint8_t duty) { - if (duty > 0 && !ps16dz_ignore_dim && PS16DZSerial && ps16dz_synced) { + if (duty > 0 && !ps16dz_ignore_dim && PS16DZSerial) { if (duty < 25) { duty = 25; // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself } - ps16dz_synced = false; snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); print_uint64_t(ps16dz_seq++); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":\"%d\""), ps16dz_tx_buffer, round(duty * (100. / 255.))); @@ -194,13 +191,9 @@ void PS16DZSerialInput(void) } } else if(!strncmp(token2, "\"sequence\"", 10)){ - uint64_t ps16dz_seq_tmp = strtoull(token3+1, NULL, 10); + ps16dz_seq = strtoull(token3+1, NULL, 10); snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %s"), token3); AddLog(LOG_LEVEL_DEBUG); - if(ps16dz_seq_tmp >= ps16dz_seq){ - ps16dz_synced = true; - ps16dz_seq = ps16dz_seq_tmp; - } } token = strtok_r(NULL, ",", &end_str); } From 41ddab2cbe6220900f3c1a21cad2f9fdcaeb67c1 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 13:29:00 +0100 Subject: [PATCH 16/22] PS_16_DZ: flush serial after sending command --- sonoff/xdrv_19_ps16dz_dimmer.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index b165d66a1..a2d77c992 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -84,6 +84,7 @@ boolean PS16DZSetPower(void) PS16DZSerial->print(ps16dz_tx_buffer); PS16DZSerial->write(0x1B); + PS16DZSerial->flush(); status = true; } @@ -105,6 +106,7 @@ void PS16DZSerialDuty(uint8_t duty) PS16DZSerial->print(ps16dz_tx_buffer); PS16DZSerial->write(0x1B); + PS16DZSerial->flush(); } else { ps16dz_ignore_dim = false; // reset flag @@ -212,6 +214,7 @@ void PS16DZSerialInput(void) PS16DZSerial->print(ps16dz_tx_buffer); PS16DZSerial->write(0x1B); + PS16DZSerial->flush(); } } } From 3650ab5fd3de3dc62a3d5ee145d22844c8f404b7 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 13:49:21 +0100 Subject: [PATCH 17/22] PS_16_DZ: use unix-timestamp as sequence --- sonoff/xdrv_19_ps16dz_dimmer.ino | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index a2d77c992..fcfe3eb1e 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -67,6 +67,11 @@ size_t print_uint64_t(uint64_t number) return n; } +uint64_t getTimestamp(void) +{ + return (((uint64_t)LocalTime()) * 1000) + (millis()%1000); +} + boolean PS16DZSetPower(void) { boolean status = false; @@ -77,7 +82,8 @@ boolean PS16DZSetPower(void) if (source != SRC_SWITCH && PS16DZSerial) { // ignore to prevent loop from pushing state from faceplate interaction snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); - print_uint64_t(ps16dz_seq++); + ps16dz_seq = getTimestamp(); + print_uint64_t(ps16dz_seq); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off"); snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); @@ -99,7 +105,8 @@ void PS16DZSerialDuty(uint8_t duty) } snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); - print_uint64_t(ps16dz_seq++); + ps16dz_seq = getTimestamp(); + print_uint64_t(ps16dz_seq); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":\"%d\""), ps16dz_tx_buffer, round(duty * (100. / 255.))); snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); @@ -193,7 +200,7 @@ void PS16DZSerialInput(void) } } else if(!strncmp(token2, "\"sequence\"", 10)){ - ps16dz_seq = strtoull(token3+1, NULL, 10); + //ps16dz_seq = strtoull(token3+1, NULL, 10); snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %s"), token3); AddLog(LOG_LEVEL_DEBUG); } From 87d7609b970a7056ad6d8daaf4e8575357c25fd2 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 13:53:33 +0100 Subject: [PATCH 18/22] PS_16_DZ: init sequence as 0 --- sonoff/xdrv_19_ps16dz_dimmer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index fcfe3eb1e..a4a966e0b 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -31,7 +31,7 @@ boolean ps16dz_ignore_dim = false; // Flag to skip serial send to pre boolean ps16dz_power = false; uint8_t ps16dz_bright = 0; -uint64_t ps16dz_seq = 1530000000000; +uint64_t ps16dz_seq = 0; char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer From 6f6e4382ec2a51dfd053855d8c60435166f07e6b Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 26 Nov 2018 15:27:51 +0100 Subject: [PATCH 19/22] PS_16_DZ: change logprefix to PSZ --- sonoff/xdrv_19_ps16dz_dimmer.ino | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index a4a966e0b..e7e547e1c 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -85,7 +85,7 @@ boolean PS16DZSetPower(void) ps16dz_seq = getTimestamp(); print_uint64_t(ps16dz_seq); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off"); - snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_tx_buffer ); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); PS16DZSerial->print(ps16dz_tx_buffer); @@ -108,7 +108,7 @@ void PS16DZSerialDuty(uint8_t duty) ps16dz_seq = getTimestamp(); print_uint64_t(ps16dz_seq); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":\"%d\""), ps16dz_tx_buffer, round(duty * (100. / 255.))); - snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_tx_buffer ); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); PS16DZSerial->print(ps16dz_tx_buffer); @@ -118,7 +118,7 @@ void PS16DZSerialDuty(uint8_t duty) } else { ps16dz_ignore_dim = false; // reset flag - snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send Dim Level skipped due to 0 or already set. Value=%d"), duty); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send Dim Level skipped due to 0 or already set. Value=%d"), duty); AddLog(LOG_LEVEL_DEBUG); } @@ -164,7 +164,7 @@ void PS16DZSerialInput(void) } else { ps16dz_rx_buffer[ps16dz_byte_counter++] = 0x00; - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: command received: %s"), ps16dz_rx_buffer); + snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: command received: %s"), ps16dz_rx_buffer); AddLog(LOG_LEVEL_DEBUG); if(!strncmp(ps16dz_rx_buffer+3, "UPDATE", 6) || !strncmp(ps16dz_rx_buffer+3, "RESULT", 6)) { char *end_str; @@ -172,13 +172,13 @@ void PS16DZSerialInput(void) char* token = strtok_r(string, ",", &end_str); while (token != NULL) { char* end_token; - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: token = %s"), token); + snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: token = %s"), token); AddLog(LOG_LEVEL_DEBUG); char* token2 = strtok_r(token, ":", &end_token); char* token3 = strtok_r(NULL, ":", &end_token); if(!strncmp(token2, "\"switch\"", 8)){ ps16dz_power = !strncmp(token3, "\"on\"", 4)?true:false; - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: power received: %s"), token3); + snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: power received: %s"), token3); AddLog(LOG_LEVEL_DEBUG); if((power || Settings.light_dimmer > 0) && (power !=ps16dz_power)) { ExecuteCommandPower(1, ps16dz_power, SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction @@ -186,13 +186,13 @@ void PS16DZSerialInput(void) } else if(!strncmp(token2, "\"bright\"", 8)){ ps16dz_bright = atoi(token3); - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: brightness received: %d"), ps16dz_bright); + snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: brightness received: %d"), ps16dz_bright); AddLog(LOG_LEVEL_DEBUG); if(power && ps16dz_bright > 0) { snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), ps16dz_bright ); - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: Send CMND_DIMMER_STR=%s"), scmnd ); + snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: Send CMND_DIMMER_STR=%s"), scmnd ); AddLog(LOG_LEVEL_DEBUG); ps16dz_ignore_dim = true; @@ -201,14 +201,14 @@ void PS16DZSerialInput(void) } else if(!strncmp(token2, "\"sequence\"", 10)){ //ps16dz_seq = strtoull(token3+1, NULL, 10); - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: sequence received: %s"), token3); + snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: sequence received: %s"), token3); AddLog(LOG_LEVEL_DEBUG); } token = strtok_r(NULL, ",", &end_str); } } else if(!strncmp(ps16dz_rx_buffer+3, "SETTING", 7)) { - snprintf_P(log_data, sizeof(log_data), PSTR("PSD: Reset")); + snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: Reset")); AddLog(LOG_LEVEL_DEBUG); PS16DZResetWifi(); } @@ -216,7 +216,7 @@ void PS16DZSerialInput(void) ps16dz_byte_counter = 0; snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+SEND=ok")); - snprintf_P(log_data, sizeof(log_data), PSTR( "PSD: Send serial command: %s"), ps16dz_tx_buffer ); + snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); PS16DZSerial->print(ps16dz_tx_buffer); From 7931b3433a49b4c618db05e7537f4e57092b478b Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Tue, 27 Nov 2018 01:07:57 +0100 Subject: [PATCH 20/22] PS_16_DZ: bright as int --- sonoff/xdrv_19_ps16dz_dimmer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index e7e547e1c..b62d35eca 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -107,7 +107,7 @@ void PS16DZSerialDuty(uint8_t duty) snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); ps16dz_seq = getTimestamp(); print_uint64_t(ps16dz_seq); - snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":\"%d\""), ps16dz_tx_buffer, round(duty * (100. / 255.))); + snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":%d"), ps16dz_tx_buffer, round(duty * (100. / 255.))); snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); From 7e34f402c94b6298e77f9a07fa7e6b8c76b5b9f3 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Tue, 27 Nov 2018 01:30:05 +0100 Subject: [PATCH 21/22] PS_16_DZ: GPIO13 => LED1 --- sonoff/sonoff_template.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 150539abc..5b12a5ded 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -1281,12 +1281,12 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, GPIO_TXD, // GPIO01 MCU serial control GPIO_USER, - GPIO_RXD, // GPIO03 MCU serial control + GPIO_RXD, // GPIO03 MCU serial control GPIO_USER, GPIO_USER, 0, 0, 0, 0, 0, 0, // Flash connection GPIO_USER, - GPIO_USER, + GPIO_LED1, // GPIO13 WiFi LED GPIO_USER, GPIO_USER, GPIO_USER, From 281166841b74a1519fc1d424e16d7460eb2ce26f Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Tue, 27 Nov 2018 02:04:59 +0100 Subject: [PATCH 22/22] PS_16_DZ: cleanup code --- sonoff/xdrv_19_ps16dz_dimmer.ino | 39 ++++---------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index b62d35eca..aa6336bd6 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -31,7 +31,7 @@ boolean ps16dz_ignore_dim = false; // Flag to skip serial send to pre boolean ps16dz_power = false; uint8_t ps16dz_bright = 0; -uint64_t ps16dz_seq = 0; +//uint64_t ps16dz_seq = 0; char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer @@ -41,35 +41,9 @@ int ps16dz_byte_counter = 0; * Internal Functions \*********************************************************************************************/ - -size_t print_uint64_t(uint64_t number) +void printTimestamp(void) { - size_t n = 0; - unsigned char buf[21]; - uint8_t i = 0; - - if (number == 0) - { - n += snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s%c"), ps16dz_tx_buffer, (char)'0'); - return n; - } - - while (number > 0) - { - uint64_t q = number/10; - buf[i++] = number - q*10; - number = q; - } - - for (; i > 0; i--) - n += snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s%c"), ps16dz_tx_buffer, (char) ('0' + buf[i - 1])); - - return n; -} - -uint64_t getTimestamp(void) -{ - return (((uint64_t)LocalTime()) * 1000) + (millis()%1000); + snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s%d%03d"), ps16dz_tx_buffer, LocalTime(), millis()%1000); } boolean PS16DZSetPower(void) @@ -82,8 +56,7 @@ boolean PS16DZSetPower(void) if (source != SRC_SWITCH && PS16DZSerial) { // ignore to prevent loop from pushing state from faceplate interaction snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); - ps16dz_seq = getTimestamp(); - print_uint64_t(ps16dz_seq); + printTimestamp(); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off"); snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); @@ -105,8 +78,7 @@ void PS16DZSerialDuty(uint8_t duty) } snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\"")); - ps16dz_seq = getTimestamp(); - print_uint64_t(ps16dz_seq); + printTimestamp(); snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":%d"), ps16dz_tx_buffer, round(duty * (100. / 255.))); snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer ); AddLog(LOG_LEVEL_DEBUG); @@ -156,7 +128,6 @@ void PS16DZSerialInput(void) char scmnd[20]; while (PS16DZSerial->available()) { yield(); - //ps16dz_command = PS16DZSerial->readStringUntil(0x1B); byte serial_in_byte = PS16DZSerial->read(); if (serial_in_byte != 0x1B){ if (ps16dz_byte_counter || (!ps16dz_byte_counter && serial_in_byte == 'A'));