From 29723d5e9b2801132e3c58eac282f49d51e0afed Mon Sep 17 00:00:00 2001 From: Hristo Kapanakov Date: Fri, 21 Jan 2022 17:24:32 +0200 Subject: [PATCH 1/2] Add setting for IRremoteESP8266 tolerance --- tasmota/my_user_config.h | 1 + tasmota/settings.ino | 1 + tasmota/support_command.ino | 3 +++ tasmota/tasmota.h | 2 +- tasmota/tasmota_globals.h | 4 ++++ tasmota/xdrv_05_irremote.ino | 9 +++++++++ tasmota/xdrv_05_irremote_full.ino | 9 +++++++++ 7 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 110919d4c..6a4f6df4d 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -858,6 +858,7 @@ #define IR_RCV_TIMEOUT 15 // Number of milli-Seconds of no-more-data before we consider a message ended (default 15) #define IR_RCV_MIN_UNKNOWN_SIZE 6 // Set the smallest sized "UNKNOWN" message packets we actually care about (default 6, max 255) #define IR_RCV_WHILE_SENDING 0 // Turns on receiver while sending messages, i.e. receive your own. This is unreliable and can cause IR timing issues + #define IR_RCV_TOLERANCE 25 // Base tolerance percentage for matching incoming IR messages (default 25, max 100) // -- Zigbee interface ---------------------------- //#define USE_ZIGBEE // Enable serial communication with Zigbee CC2530/CC2652 flashed with ZNP or EFR32 flashed with EZSP (+49k code, +3k mem) diff --git a/tasmota/settings.ino b/tasmota/settings.ino index d9f37dfc9..774b5dadf 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -1032,6 +1032,7 @@ void SettingsDefaultSet2(void) { flag.ir_receive_decimal |= IR_DATA_RADIX; flag3.receive_raw |= IR_ADD_RAW_DATA; Settings->param[P_IR_UNKNOW_THRESHOLD] = IR_RCV_MIN_UNKNOWN_SIZE; + Settings->param[P_IR_TOLERANCE] = IR_RCV_TOLERANCE; // RF Bridge flag.rf_receive_decimal |= RF_DATA_RADIX; diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 88f3e1729..92274dc55 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -992,6 +992,9 @@ void CmndSetoptionBase(bool indexed) { if (P_IR_UNKNOW_THRESHOLD == pindex) { IrReceiveUpdateThreshold(); // SetOption38 } + if (P_IR_TOLERANCE == pindex) { + IrReceiveUpdateTolerance(); // SetOption44 + } #endif #ifdef ROTARY_V1 if (P_ROTARY_MAX_STEP == pindex) { diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 9aa5c1b27..3b5ea3597 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -320,7 +320,7 @@ enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; enum SettingsParamIndex { P_HOLD_TIME, P_MAX_POWER_RETRY, P_BACKLOG_DELAY, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, // SetOption32 .. SetOption38 P_CSE7766_INVALID_POWER, P_HOLD_IGNORE, P_ARP_GRATUITOUS, P_OVER_TEMP, // SetOption39 .. SetOption42 - P_ROTARY_MAX_STEP, P_ex_TUYA_VOLTAGE_ID, P_ex_TUYA_CURRENT_ID, P_ex_TUYA_POWER_ID, // SetOption43 .. SetOption46 + P_ROTARY_MAX_STEP, P_IR_TOLERANCE, P_ex_TUYA_CURRENT_ID, P_ex_TUYA_POWER_ID, // SetOption43 .. SetOption46 P_ex_ENERGY_TARIFF1, P_ex_ENERGY_TARIFF2, // SetOption47 .. SetOption48 P_MAX_PARAM8 }; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index 3056dd974..c8a60acda 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -306,6 +306,10 @@ String EthernetMacAddress(void); #define IR_RCV_MIN_UNKNOWN_SIZE 6 // Set the smallest sized "UNKNOWN" message packets we actually care about (default 6, max 255) #endif +#ifndef IR_RCV_TOLERANCE +#define IR_RCV_TOLERANCE 25 // Base tolerance percentage for matching incoming IR messages (default 25, max 100) +#endif + #ifndef ENERGY_OVERTEMP #define ENERGY_OVERTEMP 90 // Overtemp in Celsius #endif diff --git a/tasmota/xdrv_05_irremote.ino b/tasmota/xdrv_05_irremote.ino index 6917c8a21..72147fa19 100644 --- a/tasmota/xdrv_05_irremote.ino +++ b/tasmota/xdrv_05_irremote.ino @@ -195,11 +195,20 @@ void IrReceiveUpdateThreshold(void) } } +void IrReceiveUpdateTolerance(void) +{ + if (irrecv != nullptr) { + if (Settings->param[P_IR_TOLERANCE] > 100) { Settings->param[P_IR_TOLERANCE] = 100; } + irrecv->setTolerance(Settings->param[P_IR_TOLERANCE]); + } +} + void IrReceiveInit(void) { // an IR led is at GPIO_IRRECV irrecv = new IRrecv(Pin(GPIO_IRRECV), IR_RCV_BUFFER_SIZE, IR_RCV_TIMEOUT, IR_RCV_SAVE_BUFFER); irrecv->setUnknownThreshold(Settings->param[P_IR_UNKNOW_THRESHOLD]); + irrecv->setTolerance(Settings->param[P_IR_TOLERANCE]); irrecv->enableIRIn(); // Start the receiver // AddLog(LOG_LEVEL_DEBUG, PSTR("IrReceive initialized")); diff --git a/tasmota/xdrv_05_irremote_full.ino b/tasmota/xdrv_05_irremote_full.ino index ccec40ab0..9a9703b9f 100644 --- a/tasmota/xdrv_05_irremote_full.ino +++ b/tasmota/xdrv_05_irremote_full.ino @@ -193,11 +193,20 @@ void IrReceiveUpdateThreshold(void) } } +void IrReceiveUpdateTolerance(void) +{ + if (irrecv != nullptr) { + if (Settings->param[P_IR_TOLERANCE] > 100) { Settings->param[P_IR_TOLERANCE] = 100; } + irrecv->setTolerance(Settings->param[P_IR_TOLERANCE]); + } +} + void IrReceiveInit(void) { // an IR led is at GPIO_IRRECV irrecv = new IRrecv(Pin(GPIO_IRRECV), IR_FULL_BUFFER_SIZE, IR__FULL_RCV_TIMEOUT, IR_FULL_RCV_SAVE_BUFFER); irrecv->setUnknownThreshold(Settings->param[P_IR_UNKNOW_THRESHOLD]); + irrecv->setTolerance(Settings->param[P_IR_TOLERANCE]); irrecv->enableIRIn(); // Start the receiver } From f9b0947d67788ea1b90ad82999869e279b5554bb Mon Sep 17 00:00:00 2001 From: Hristo Kapanakov Date: Fri, 21 Jan 2022 18:56:19 +0200 Subject: [PATCH 2/2] Set default IR receive tolerance (25%) if set to zero --- tasmota/xdrv_05_irremote.ino | 1 + tasmota/xdrv_05_irremote_full.ino | 1 + 2 files changed, 2 insertions(+) diff --git a/tasmota/xdrv_05_irremote.ino b/tasmota/xdrv_05_irremote.ino index 72147fa19..7983436d6 100644 --- a/tasmota/xdrv_05_irremote.ino +++ b/tasmota/xdrv_05_irremote.ino @@ -198,6 +198,7 @@ void IrReceiveUpdateThreshold(void) void IrReceiveUpdateTolerance(void) { if (irrecv != nullptr) { + if (Settings->param[P_IR_TOLERANCE] == 0) { Settings->param[P_IR_TOLERANCE] = IR_RCV_TOLERANCE; } if (Settings->param[P_IR_TOLERANCE] > 100) { Settings->param[P_IR_TOLERANCE] = 100; } irrecv->setTolerance(Settings->param[P_IR_TOLERANCE]); } diff --git a/tasmota/xdrv_05_irremote_full.ino b/tasmota/xdrv_05_irremote_full.ino index 9a9703b9f..aa85e82a0 100644 --- a/tasmota/xdrv_05_irremote_full.ino +++ b/tasmota/xdrv_05_irremote_full.ino @@ -196,6 +196,7 @@ void IrReceiveUpdateThreshold(void) void IrReceiveUpdateTolerance(void) { if (irrecv != nullptr) { + if (Settings->param[P_IR_TOLERANCE] == 0) { Settings->param[P_IR_TOLERANCE] = IR_RCV_TOLERANCE; } if (Settings->param[P_IR_TOLERANCE] > 100) { Settings->param[P_IR_TOLERANCE] = 100; } irrecv->setTolerance(Settings->param[P_IR_TOLERANCE]); }