Update status 13

This commit is contained in:
Theo Arends 2020-08-20 17:58:58 +02:00
parent 7691abea41
commit 474fb2518a
2 changed files with 28 additions and 24 deletions

View File

@ -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)

View File

@ -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