From 176c39dfe39a5284389f1c93c6f7aab6b252e86e Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Mon, 25 Jun 2018 12:33:23 +0200 Subject: [PATCH] Add hex/decimal receive control for RF and IR 6.0.0a * Add command SetOption28 to switch between hex or decimal Sonoff Bridge RF received data format (#3008) * Add command SetOption29 to switch between hex or decimal IR received data format --- sonoff/_releasenotes.ino | 3 +++ sonoff/settings.h | 4 ++-- sonoff/sonoff.ino | 5 ++++- sonoff/xdrv_05_irremote.ino | 12 ++++++++++-- sonoff/xdrv_06_snfbridge.ino | 10 ++++++++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index b0d96ac8e..62c28b7ed 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,7 @@ /* 6.0.0a + * Add command SetOption28 to switch between hex or decimal Sonoff Bridge RF received data format (#3008) + * Add command SetOption29 to switch between hex or decimal IR received data format + * Add performance improvement when updating multiple individual WS2812 pixels (#3007) * Add debug facilities using optional xdrv_99_debug.ino to enable in user_config.h * Add KNX support for DS18S20 Temperature sensor * Add CRC to Settings making future upgrades more fail-safe diff --git a/sonoff/settings.h b/sonoff/settings.h index bf947d350..4704d598c 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -53,8 +53,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t knx_enabled : 1; // bit 25 (v5.12.0l) KNX uint32_t device_index_enable : 1; // bit 26 (v5.13.1a) uint32_t knx_enable_enhancement : 1; // bit 27 (v5.14.0a) KNX - uint32_t spare28 : 1; - uint32_t spare29 : 1; + uint32_t rf_receive_decimal : 1; // bit 28 (v6.0.0a) + uint32_t ir_receive_decimal : 1; // bit 29 (v6.0.0a) uint32_t spare30 : 1; uint32_t spare31 : 1; }; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index de3935c07..e5ad17e7a 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -569,7 +569,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) XsnsCall(FUNC_COMMAND); // if (!XsnsCall(FUNC_COMMAND)) type = NULL; } - else if ((CMND_SETOPTION == command_code) && ((index <= 26) || ((index > 31) && (index <= P_MAX_PARAM8 + 31)))) { + else if ((CMND_SETOPTION == command_code) && ((index <= 29) || ((index > 31) && (index <= P_MAX_PARAM8 + 31)))) { if (index <= 31) { ptype = 0; // SetOption0 .. 31 } else { @@ -604,6 +604,9 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) // case 24: // rules_once // case 25: // knx_enabled case 26: // device_index_enable +// case 27: // knx_enable_enhancement + case 28: // rf_receive_decimal + case 29: // ir_receive_decimal bitWrite(Settings.flag.data, index, payload); } if (12 == index) { // stop_flash_rotate diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 2688d6c2f..83cde7419 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -89,6 +89,7 @@ void IrReceiveInit(void) void IrReceiveCheck() { char sirtype[14]; // Max is AIWA_RC_T501 + char stemp[16]; int8_t iridx = 0; decode_results results; @@ -107,8 +108,15 @@ void IrReceiveCheck() if ((iridx < 0) || (iridx > 14)) { iridx = 0; } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_IRRECEIVED "\":{\"" D_JSON_IR_PROTOCOL "\":\"%s\",\"" D_JSON_IR_BITS "\":%d,\"" D_JSON_IR_DATA "\":\"%lX\"}}"), - GetTextIndexed(sirtype, sizeof(sirtype), iridx, kIrRemoteProtocols), results.bits, (uint32_t)results.value); + + if (Settings.flag.ir_receive_decimal) { + snprintf_P(stemp, sizeof(stemp), PSTR("%u"), (uint32_t)results.value); + } else { + snprintf_P(stemp, sizeof(stemp), PSTR("\"%lX\""), (uint32_t)results.value); + } + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_IRRECEIVED "\":{\"" D_JSON_IR_PROTOCOL "\":\"%s\",\"" D_JSON_IR_BITS "\":%d,\"" D_JSON_IR_DATA "\":%s}}"), + GetTextIndexed(sirtype, sizeof(sirtype), iridx, kIrRemoteProtocols), results.bits, stemp); + MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED)); XdrvRulesProcess(); #ifdef USE_DOMOTICZ diff --git a/sonoff/xdrv_06_snfbridge.ino b/sonoff/xdrv_06_snfbridge.ino index 155944005..729cd51dc 100644 --- a/sonoff/xdrv_06_snfbridge.ino +++ b/sonoff/xdrv_06_snfbridge.ino @@ -252,6 +252,7 @@ void SonoffBridgeReceived() uint16_t high_time = 0; uint32_t received_id = 0; char rfkey[8]; + char stemp[16]; AddLogSerial(LOG_LEVEL_DEBUG); @@ -295,8 +296,13 @@ void SonoffBridgeReceived() } } } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_SYNC "\":%d,\"" D_JSON_LOW "\":%d,\"" D_JSON_HIGH "\":%d,\"" D_JSON_DATA "\":\"%06X\",\"" D_CMND_RFKEY "\":%s}}"), - sync_time, low_time, high_time, received_id, rfkey); + if (Settings.flag.rf_receive_decimal) { + snprintf_P(stemp, sizeof(stemp), PSTR("%u"), received_id); + } else { + snprintf_P(stemp, sizeof(stemp), PSTR("\"%06X\""), received_id); + } + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_SYNC "\":%d,\"" D_JSON_LOW "\":%d,\"" D_JSON_HIGH "\":%d,\"" D_JSON_DATA "\":%s,\"" D_CMND_RFKEY "\":%s}}"), + sync_time, low_time, high_time, stemp, rfkey); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_RFRECEIVED)); XdrvRulesProcess(); #ifdef USE_DOMOTICZ