Add setting for IRremoteESP8266 tolerance

This commit is contained in:
Hristo Kapanakov 2022-01-21 17:24:32 +02:00
parent 7aedab59e7
commit 29723d5e9b
7 changed files with 28 additions and 1 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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"));

View File

@ -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
}