Fixed IR crash on ESP32 (#16173)

This commit is contained in:
Stephan Hadinger 2022-08-08 14:11:57 +02:00
parent 86cba4acb1
commit 603dd28944
6 changed files with 30 additions and 16 deletions

View File

@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
### Fixed ### Fixed
- Restore EnergyToday after using command ``restart 2`` and power cycle (#16118) - Restore EnergyToday after using command ``restart 2`` and power cycle (#16118)
- Fixed IR crash on ESP32 (#16173)
### Removed ### Removed

View File

@ -405,6 +405,17 @@ void IRrecv::disableIRIn(void) {
#endif // UNIT_TEST #endif // UNIT_TEST
} }
/// Pause collection of received IR data.
/// @see IRrecv class constructor
void IRrecv::pause(void) {
params.rcvstate = kStopState;
params.rawlen = 0;
params.overflow = false;
#if defined(ESP32)
gpio_intr_disable((gpio_num_t)params.recvpin);
#endif // ESP32
}
/// Resume collection of received IR data. /// Resume collection of received IR data.
/// @note This is required if `decode()` is successful and `save_buffer` was /// @note This is required if `decode()` is successful and `save_buffer` was
/// not set when the class was instanciated. /// not set when the class was instanciated.
@ -415,6 +426,7 @@ void IRrecv::resume(void) {
params.overflow = false; params.overflow = false;
#if defined(ESP32) #if defined(ESP32)
timerAlarmDisable(timer); timerAlarmDisable(timer);
gpio_intr_enable((gpio_num_t)params.recvpin);
#endif // ESP32 #endif // ESP32
} }

View File

@ -137,6 +137,7 @@ class IRrecv {
uint8_t max_skip = 0, uint16_t noise_floor = 0); uint8_t max_skip = 0, uint16_t noise_floor = 0);
void enableIRIn(const bool pullup = false); void enableIRIn(const bool pullup = false);
void disableIRIn(void); void disableIRIn(void);
void pause(void);
void resume(void); void resume(void);
uint16_t getBufSize(void); uint16_t getBufSize(void);
#if DECODE_HASH #if DECODE_HASH

View File

@ -171,7 +171,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t gui_module_name : 1; // bit 27 (v11.1.0.3) - SetOption141 - (GUI) Disable display of GUI module name (1) uint32_t gui_module_name : 1; // bit 27 (v11.1.0.3) - SetOption141 - (GUI) Disable display of GUI module name (1)
uint32_t wait_for_wifi_result : 1; // bit 28 (v11.1.0.4) - SetOption142 - (Wifi) Wait 1 second for wifi connection solving some FRITZ!Box modem issues (1) uint32_t wait_for_wifi_result : 1; // bit 28 (v11.1.0.4) - SetOption142 - (Wifi) Wait 1 second for wifi connection solving some FRITZ!Box modem issues (1)
uint32_t zigbee_no_batt_autoprobe : 1; // bit 29 (v12.0.2.4) - SetOption143 - (Zigbee) Disable Battery auto-probe and using auto-binding uint32_t zigbee_no_batt_autoprobe : 1; // bit 29 (v12.0.2.4) - SetOption143 - (Zigbee) Disable Battery auto-probe and using auto-binding
uint32_t spare30 : 1; // bit 30 uint32_t ir_rcv_while_sending : 1; // bit 30 (v12.0.2.4) - SetOption144 - (IR) Receive IR while sending IR and decode our own signals
uint32_t spare31 : 1; // bit 31 uint32_t spare31 : 1; // bit 31
}; };
} SOBitfield5; } SOBitfield5;

View File

@ -349,7 +349,7 @@ uint32_t IrRemoteCmndIrSendJson(void)
// protocol_text, protocol, bits, ulltoa(data, dvalue, 10), Uint64toHex(data, hvalue, bits), repeat, protocol_code); // protocol_text, protocol, bits, ulltoa(data, dvalue, 10), Uint64toHex(data, hvalue, bits), repeat, protocol_code);
#ifdef USE_IR_RECEIVE #ifdef USE_IR_RECEIVE
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->disableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->pause(); }
#endif // USE_IR_RECEIVE #endif // USE_IR_RECEIVE
switch (protocol_code) { // Equals IRremoteESP8266.h enum decode_type_t switch (protocol_code) { // Equals IRremoteESP8266.h enum decode_type_t
@ -367,12 +367,12 @@ uint32_t IrRemoteCmndIrSendJson(void)
#endif #endif
default: default:
#ifdef USE_IR_RECEIVE #ifdef USE_IR_RECEIVE
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->enableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->resume(); }
#endif // USE_IR_RECEIVE #endif // USE_IR_RECEIVE
return IE_PROTO_UNSUPPORTED; return IE_PROTO_UNSUPPORTED;
} }
#ifdef USE_IR_RECEIVE #ifdef USE_IR_RECEIVE
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->enableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->resume(); }
#endif // USE_IR_RECEIVE #endif // USE_IR_RECEIVE
return IE_NO_ERROR; return IE_NO_ERROR;

View File

@ -469,7 +469,7 @@ uint32_t IrRemoteCmndIrHvacJson(void)
state.sleep = root.getInt(PSTR(D_JSON_IRHVAC_SLEEP), state.sleep); state.sleep = root.getInt(PSTR(D_JSON_IRHVAC_SLEEP), state.sleep);
//if (json[D_JSON_IRHVAC_CLOCK]) { state.clock = json[D_JSON_IRHVAC_CLOCK]; } // not sure it's useful to support 'clock' //if (json[D_JSON_IRHVAC_CLOCK]) { state.clock = json[D_JSON_IRHVAC_CLOCK]; } // not sure it's useful to support 'clock'
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->disableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->pause(); }
if (stateMode == StateModes::SEND_ONLY || stateMode == StateModes::SEND_STORE) { if (stateMode == StateModes::SEND_ONLY || stateMode == StateModes::SEND_STORE) {
int8_t channel = root.getUInt(PSTR(D_JSON_IR_CHANNEL), 1) - 1; int8_t channel = root.getUInt(PSTR(D_JSON_IR_CHANNEL), 1) - 1;
if (channel < 0) { channel = GPIO_ANY; } // take first available GPIO if (channel < 0) { channel = GPIO_ANY; } // take first available GPIO
@ -485,7 +485,7 @@ uint32_t IrRemoteCmndIrHvacJson(void)
if (stateMode == StateModes::STORE_ONLY || stateMode == StateModes::SEND_STORE) { // store state in memory if (stateMode == StateModes::STORE_ONLY || stateMode == StateModes::SEND_STORE) { // store state in memory
irac_prev_state = state; irac_prev_state = state;
} }
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->enableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->resume(); }
Response_P(PSTR("{\"" D_CMND_IRHVAC "\":%s}"), sendACJsonState(state).c_str()); Response_P(PSTR("{\"" D_CMND_IRHVAC "\":%s}"), sendACJsonState(state).c_str());
return IE_RESPONSE_PROVIDED; return IE_RESPONSE_PROVIDED;
@ -544,10 +544,10 @@ uint32_t IrRemoteCmndIrSendJson(void)
// AddLog(LOG_LEVEL_DEBUG, PSTR("IRS: protocol %d, bits %d, data 0x%s (%s), repeat %d"), // AddLog(LOG_LEVEL_DEBUG, PSTR("IRS: protocol %d, bits %d, data 0x%s (%s), repeat %d"),
// protocol, bits, ulltoa(data, dvalue, 10), Uint64toHex(data, hvalue, bits), repeat); // protocol, bits, ulltoa(data, dvalue, 10), Uint64toHex(data, hvalue, bits), repeat);
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->disableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->pause(); }
IRsend irsend = IrSendInitGPIO(channel); IRsend irsend = IrSendInitGPIO(channel);
bool success = irsend.send(protocol, data, bits, repeat); bool success = irsend.send(protocol, data, bits, repeat);
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->enableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->resume(); }
if (!success) { if (!success) {
ResponseCmndChar(D_JSON_PROTOCOL_NOT_SUPPORTED); ResponseCmndChar(D_JSON_PROTOCOL_NOT_SUPPORTED);
@ -570,12 +570,12 @@ uint32_t IrRemoteSendGC(char ** pp, uint32_t count, uint32_t repeat) {
GC[i] = strtol(strtok_r(nullptr, ",", pp), nullptr, 0); GC[i] = strtol(strtok_r(nullptr, ",", pp), nullptr, 0);
if (!GC[i]) { return IE_INVALID_RAWDATA; } if (!GC[i]) { return IE_INVALID_RAWDATA; }
} }
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->disableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->pause(); }
IRsend irsend = IrSendInitGPIO(); IRsend irsend = IrSendInitGPIO();
for (uint32_t r = 0; r <= repeat; r++) { for (uint32_t r = 0; r <= repeat; r++) {
irsend.sendGC(GC, count+1); irsend.sendGC(GC, count+1);
} }
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->enableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->resume(); }
return IE_NO_ERROR; return IE_NO_ERROR;
} }
@ -626,7 +626,7 @@ uint32_t IrRemoteSendRawFormatted(char ** pp, uint32_t count, uint32_t repeat) {
raw_array[i++] = mark; // Mark raw_array[i++] = mark; // Mark
} }
} }
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->disableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->pause(); }
IRsend irsend = IrSendInitGPIO(); IRsend irsend = IrSendInitGPIO();
for (uint32_t r = 0; r <= repeat; r++) { for (uint32_t r = 0; r <= repeat; r++) {
// AddLog(LOG_LEVEL_DEBUG, PSTR("sendRaw count=%d, space=%d, mark=%d, freq=%d"), count, space, mark, freq); // AddLog(LOG_LEVEL_DEBUG, PSTR("sendRaw count=%d, space=%d, mark=%d, freq=%d"), count, space, mark, freq);
@ -635,7 +635,7 @@ uint32_t IrRemoteSendRawFormatted(char ** pp, uint32_t count, uint32_t repeat) {
irsend.space(40000); // since we don't know the inter-message gap, place an arbitrary 40ms gap irsend.space(40000); // since we don't know the inter-message gap, place an arbitrary 40ms gap
} }
} }
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->enableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->resume(); }
} else if (6 == count) { // NEC Protocol } else if (6 == count) { // NEC Protocol
// IRsend raw,0,8620,4260,544,411,1496,010101101000111011001110000000001100110000000001100000000000000010001100 // IRsend raw,0,8620,4260,544,411,1496,010101101000111011001110000000001100110000000001100000000000000010001100
uint16_t raw_array[strlen(*pp)*2+3]; // Header + bits + end uint16_t raw_array[strlen(*pp)*2+3]; // Header + bits + end
@ -654,7 +654,7 @@ uint32_t IrRemoteSendRawFormatted(char ** pp, uint32_t count, uint32_t repeat) {
} }
} }
raw_array[i++] = parm[2]; // Trailing mark raw_array[i++] = parm[2]; // Trailing mark
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->disableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->pause(); }
IRsend irsend = IrSendInitGPIO(); IRsend irsend = IrSendInitGPIO();
for (uint32_t r = 0; r <= repeat; r++) { for (uint32_t r = 0; r <= repeat; r++) {
// AddLog(LOG_LEVEL_DEBUG, PSTR("sendRaw %d %d %d %d %d %d"), raw_array[0], raw_array[1], raw_array[2], raw_array[3], raw_array[4], raw_array[5]); // AddLog(LOG_LEVEL_DEBUG, PSTR("sendRaw %d %d %d %d %d %d"), raw_array[0], raw_array[1], raw_array[2], raw_array[3], raw_array[4], raw_array[5]);
@ -663,7 +663,7 @@ uint32_t IrRemoteSendRawFormatted(char ** pp, uint32_t count, uint32_t repeat) {
irsend.space(inter_message); // since we don't know the inter-message gap, place an arbitrary 40ms gap irsend.space(inter_message); // since we don't know the inter-message gap, place an arbitrary 40ms gap
} }
} }
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->enableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->resume(); }
} }
else { return IE_INVALID_RAWDATA; } // Invalid number of parameters else { return IE_INVALID_RAWDATA; } // Invalid number of parameters
return IE_NO_ERROR; return IE_NO_ERROR;
@ -732,12 +732,12 @@ uint32_t IrRemoteSendRawStandard(char ** pp, uint16_t freq, uint32_t count, uint
// AddLog(LOG_LEVEL_DEBUG, PSTR("Arr %d %d %d %d %d %d %d %d"), arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7]); // AddLog(LOG_LEVEL_DEBUG, PSTR("Arr %d %d %d %d %d %d %d %d"), arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7]);
if (0 == count) { return IE_INVALID_RAWDATA; } if (0 == count) { return IE_INVALID_RAWDATA; }
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->disableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->pause(); }
IRsend irsend = IrSendInitGPIO(); IRsend irsend = IrSendInitGPIO();
for (uint32_t r = 0; r <= repeat; r++) { for (uint32_t r = 0; r <= repeat; r++) {
irsend.sendRaw(arr, count, freq); irsend.sendRaw(arr, count, freq);
} }
if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->enableIRIn(); } if (!IR_RCV_WHILE_SENDING && (irrecv != nullptr)) { irrecv->resume(); }
if (nullptr != arr) { if (nullptr != arr) {
free(arr); free(arr);