From 474fb2518a12dbf654cf9b33d8d74ab40bf719c2 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 20 Aug 2020 17:58:58 +0200 Subject: [PATCH] Update status 13 --- tasmota/support.ino | 21 +++++++++++---------- tasmota/support_command.ino | 31 +++++++++++++++++-------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index ae662ad66..c7276ea47 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -117,16 +117,17 @@ String GetResetReason(void) * Miscellaneous \*********************************************************************************************/ -#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" -#define BYTE_TO_BINARY(byte) \ - (byte & 0x80 ? '1' : '0'), \ - (byte & 0x40 ? '1' : '0'), \ - (byte & 0x20 ? '1' : '0'), \ - (byte & 0x10 ? '1' : '0'), \ - (byte & 0x08 ? '1' : '0'), \ - (byte & 0x04 ? '1' : '0'), \ - (byte & 0x02 ? '1' : '0'), \ - (byte & 0x01 ? '1' : '0') +String GetBinary(const void* ptr, size_t count) { + uint32_t value = *(uint32_t*)ptr; + value <<= (32 - count); + String result; + result.reserve(count + 1); + for (uint32_t i = 0; i < count; i++) { + result += (value &0x80000000) ? '1' : '0'; + value <<= 1; + } + return result; +} // Get span until single character in string size_t strchrspn(const char *str1, int character) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 05247510b..703ee0a67 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -573,24 +573,27 @@ void CmndStatus(void) MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "12")); } } - + #ifdef USE_SHUTTER - if ((0 == payload) || (13 == payload)) { - Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS13_SHUTTER "\":")); - for (uint8_t i=0; i < MAX_SHUTTERS; i++) - { - if (Settings.shutter_startrelay[i]==0) break; - if (i>0) ResponseAppend_P(PSTR(",")); - ResponseAppend_P(PSTR("{\"" D_STATUS13_SHUTTER "%d\":{\"Relay1\":%d,\"Relay2\":%d,\"Open\":%d,\"Close\":%d,\"50perc\":%d,\"delay\":%d,\"opt\":"BYTE_TO_BINARY_PATTERN",\"calib\":\"%d:%d:%d:%d:%d\"}"), i, - Settings.shutter_startrelay[i],Settings.shutter_startrelay[i]+1,Settings.shutter_opentime[i], Settings.shutter_closetime[i], - Settings.shutter_set50percent[i],Settings.shutter_motordelay[i],BYTE_TO_BINARY(Settings.shutter_options[i]), - Settings.shuttercoeff[0][i], Settings.shuttercoeff[1][i], Settings.shuttercoeff[2][i], Settings.shuttercoeff[3][i], Settings.shuttercoeff[4][i]); + if (Settings.flag3.shutter_mode) { + if ((0 == payload) || (13 == payload)) { + Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS13_SHUTTER "\":")); + for (uint32_t i = 0; i < MAX_SHUTTERS; i++) { + if (0 == Settings.shutter_startrelay[i]) { break; } + if (i > 0) { ResponseAppend_P(PSTR(",")); } + ResponseAppend_P(PSTR("{\"" D_STATUS13_SHUTTER "%d\":{\"Relay1\":%d,\"Relay2\":%d,\"Open\":%d,\"Close\":%d," + "\"50perc\":%d,\"Delay\":%d,\"Opt\":\"%s\"," + "\"Calib\":\"%d:%d:%d:%d:%d\"}"), + i, Settings.shutter_startrelay[i], Settings.shutter_startrelay[i] +1, Settings.shutter_opentime[i], Settings.shutter_closetime[i], + Settings.shutter_set50percent[i], Settings.shutter_motordelay[i], GetBinary(&Settings.shutter_options[i], 4).c_str(), + Settings.shuttercoeff[0][i], Settings.shuttercoeff[1][i], Settings.shuttercoeff[2][i], Settings.shuttercoeff[3][i], Settings.shuttercoeff[4][i]); + } + ResponseJsonEnd(); + MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "13")); } - ResponseJsonEnd(); - MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "12")); } #endif - + #ifdef USE_SCRIPT_STATUS if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">U",2,mqtt_data); #endif