Fix IR local echo

Fix IR local echo
This commit is contained in:
Theo Arends 2019-02-03 18:45:20 +01:00
parent 54aaaf50c9
commit 6ee3d1abc6
3 changed files with 21 additions and 8 deletions

View File

@ -1,6 +1,7 @@
/* 6.4.1.14 20190203 /* 6.4.1.14 20190203
* Add SetOption32 until SetOption49 diagnostic information to Status 3 report as replacement for second property value in SetOption property name * Add SetOption32 until SetOption49 diagnostic information to Status 3 report as replacement for second property value in SetOption property name
* Add Resolution property to Status 3 report providing previous SetOption second value property * Add Resolution property to Status 3 report providing previous SetOption second value property
* Fix IR local echo
* *
* 6.4.1.13 20190130 * 6.4.1.13 20190130
* Add command SetOption36 to control boot loop default restoration (#4645, #5063) * Add command SetOption36 to control boot loop default restoration (#4645, #5063)

View File

@ -2368,6 +2368,9 @@ void GpioInit(void)
if (XdrvCall(FUNC_MODULE_INIT)) { if (XdrvCall(FUNC_MODULE_INIT)) {
// Serviced // Serviced
} }
else if (YTF_IR_BRIDGE == Settings.module) {
ClaimSerial(); // Stop serial loopback mode
}
else if (SONOFF_DUAL == Settings.module) { else if (SONOFF_DUAL == Settings.module) {
Settings.flag.mqtt_serial = 0; Settings.flag.mqtt_serial = 0;
devices_present = 2; devices_present = 2;

View File

@ -58,7 +58,7 @@ IRMitsubishiAC *mitsubir = NULL;
const char kFanSpeedOptions[] = "A12345S"; const char kFanSpeedOptions[] = "A12345S";
const char kHvacModeOptions[] = "HDCA"; const char kHvacModeOptions[] = "HDCA";
#endif #endif // USE_IR_HVAC
/*********************************************************************************************\ /*********************************************************************************************\
* IR Send * IR Send
@ -67,6 +67,7 @@ const char kHvacModeOptions[] = "HDCA";
#include <IRsend.h> #include <IRsend.h>
IRsend *irsend = NULL; IRsend *irsend = NULL;
bool irsend_active = false;
void IrSendInit(void) void IrSendInit(void)
{ {
@ -113,13 +114,13 @@ void IrReceiveCheck(void)
if (irrecv->decode(&results)) { if (irrecv->decode(&results)) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_IRR "RawLen %d, Overflow %d, Bits %d, Value %08X, Decode %d"), snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_IRR "Echo %d, RawLen %d, Overflow %d, Bits %d, Value %08X, Decode %d"),
results.rawlen, results.overflow, results.bits, results.value, results.decode_type); irsend_active, results.rawlen, results.overflow, results.bits, results.value, results.decode_type);
AddLog(LOG_LEVEL_DEBUG); AddLog(LOG_LEVEL_DEBUG);
unsigned long now = millis(); unsigned long now = millis();
// if ((now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) && (UNKNOWN != results.decode_type) && (results.bits > 0)) { // if ((now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) && (UNKNOWN != results.decode_type) && (results.bits > 0)) {
if (now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) { if (!irsend_active && (now - ir_lasttime > IR_TIME_AVOID_DUPLICATE)) {
ir_lasttime = now; ir_lasttime = now;
iridx = results.decode_type; iridx = results.decode_type;
@ -262,10 +263,11 @@ bool IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, bool HVAC_Po
rawdata[i++] = HVAC_TOSHIBA_RPT_MARK; rawdata[i++] = HVAC_TOSHIBA_RPT_MARK;
rawdata[i++] = HVAC_TOSHIBA_RPT_SPACE; rawdata[i++] = HVAC_TOSHIBA_RPT_SPACE;
noInterrupts(); // noInterrupts();
irsend_active = true;
irsend->sendRaw(rawdata, i, 38); irsend->sendRaw(rawdata, i, 38);
irsend->sendRaw(rawdata, i, 38); irsend->sendRaw(rawdata, i, 38);
interrupts(); // interrupts();
return false; return false;
} }
@ -430,9 +432,10 @@ bool IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, bool HVAC_Power,
// AddLog(LOG_LEVEL_DEBUG); // AddLog(LOG_LEVEL_DEBUG);
// Send LG IR Code // Send LG IR Code
noInterrupts(); // noInterrupts();
irsend_active = true;
irsend->sendLG(LG_Code, 28); irsend->sendLG(LG_Code, 28);
interrupts(); // interrupts();
return false; return false;
} }
@ -451,6 +454,8 @@ bool IrHvacFujitsu(const char *HVAC_Mode, const char *HVAC_FanMode, bool HVAC_Po
IRFujitsuAC ac(pin[GPIO_IRSEND]); IRFujitsuAC ac(pin[GPIO_IRSEND]);
irsend_active = true;
if (0 == HVAC_Power) { if (0 == HVAC_Power) {
ac.off(); ac.off();
ac.send(); ac.send();
@ -540,6 +545,7 @@ bool IrSendCommand(void)
// count, freq, raw_array[0], raw_array[count -1]); // count, freq, raw_array[0], raw_array[count -1]);
// AddLog(LOG_LEVEL_DEBUG); // AddLog(LOG_LEVEL_DEBUG);
irsend_active = true;
irsend->sendRaw(raw_array, count, freq); irsend->sendRaw(raw_array, count, freq);
if (!count) { if (!count) {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_FAILED); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_FAILED);
@ -571,6 +577,7 @@ bool IrSendCommand(void)
protocol_text, protocol, bits, data, data, protocol_code); protocol_text, protocol, bits, data, data, protocol_code);
AddLog(LOG_LEVEL_DEBUG); AddLog(LOG_LEVEL_DEBUG);
irsend_active = true;
switch (protocol_code) { switch (protocol_code) {
case NEC: case NEC:
irsend->sendNEC(data, (bits > NEC_BITS) ? NEC_BITS : bits); break; irsend->sendNEC(data, (bits > NEC_BITS) ? NEC_BITS : bits); break;
@ -589,6 +596,7 @@ bool IrSendCommand(void)
case PANASONIC: case PANASONIC:
irsend->sendPanasonic(bits, data); break; irsend->sendPanasonic(bits, data); break;
default: default:
irsend_active = false;
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_PROTOCOL_NOT_SUPPORTED); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_PROTOCOL_NOT_SUPPORTED);
} }
} }
@ -688,6 +696,7 @@ bool Xdrv05(uint8_t function)
IrReceiveCheck(); // check if there's anything on IR side IrReceiveCheck(); // check if there's anything on IR side
} }
#endif // USE_IR_RECEIVE #endif // USE_IR_RECEIVE
irsend_active = false; // re-enable IR reception
break; break;
case FUNC_COMMAND: case FUNC_COMMAND:
if (pin[GPIO_IRSEND] < 99) { if (pin[GPIO_IRSEND] < 99) {