Skip to content

Commit

Permalink
Add hex/decimal receive control for RF and IR
Browse files Browse the repository at this point in the history
6.0.0a
* Add command SetOption28 to switch between hex or decimal Sonoff Bridge
RF received data format (arendst#3008)
* Add command SetOption29 to switch between hex or decimal IR received
data format
  • Loading branch information
arendst committed Jun 25, 2018
1 parent aea4b87 commit 5731b8f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions sonoff/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
5 changes: 4 additions & 1 deletion sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions sonoff/xdrv_05_irremote.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions sonoff/xdrv_06_snfbridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5731b8f

Please sign in to comment.