diff --git a/platformio.ini b/platformio.ini index 9bdf58d341..3d23a88bb3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -139,7 +139,7 @@ upload_speed = 115200 lib_compat_mode = strict lib_deps = fastled/FastLED @ 3.6.0 - IRremoteESP8266 @ 2.8.2 + https://github.com/Arduino-IRremote/Arduino-IRremote.git#v4.4.2 makuna/NeoPixelBus @ 2.8.3 #https://github.com/makuna/NeoPixelBus.git#CoreShaderBeta https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.4.0 @@ -227,7 +227,7 @@ lib_deps_compat = ESPAsyncUDP ESP8266PWM fastled/FastLED @ 3.6.0 - IRremoteESP8266 @ 2.8.2 + https://github.com/Arduino-IRremote/Arduino-IRremote.git#v4.4.2 makuna/NeoPixelBus @ 2.7.9 https://github.com/blazoncek/QuickESPNow.git#optional-debug https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.4.0 diff --git a/wled00/ir.cpp b/wled00/ir.cpp index b2fec76f1f..b3bfbf4f73 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -1,13 +1,13 @@ #include "wled.h" #ifndef WLED_DISABLE_INFRARED +#include #include "ir_codes.h" /* * Infrared sensor support for several generic RGB remotes and custom JSON remote */ -IRrecv* irrecv; decode_results results; unsigned long irCheckedTime = 0; uint32_t lastValidCode = 0; @@ -698,34 +698,70 @@ static void decodeIR(uint32_t code) void initIR() { - if (irEnabled > 0) { - irrecv = new IRrecv(irPin); - if (irrecv) irrecv->enableIRIn(); - } else irrecv = nullptr; + if (irEnabled > 0 ) { + IrReceiver.begin(irPin, false); + } } void deInitIR() { - if (irrecv) { - irrecv->disableIRIn(); - delete irrecv; + IrReceiver.end(); +} + +// to make it easy to tell what's incoming when we're debugging +const char* decodeTypeToStr(uint8_t type) +{ + switch (type) { + case LG : return "LG"; + case NEC: return "NEC"; + case SONY: return "SONY"; + case SAMSUNG: return "SAMSUNG"; + case MAGIQUEST: return "MAGIQUEST"; + // Add other protocol cases as needed... + default: return "UNKNOWN"; } - irrecv = nullptr; } void handleIR() { unsigned long currentTime = millis(); unsigned timeDiff = currentTime - irCheckedTime; - if (timeDiff > 120 && irEnabled > 0 && irrecv) { + if (timeDiff > 120 && irEnabled > 0 ) { if (strip.isUpdating() && timeDiff < 240) return; // be nice, but not too nice irCheckedTime = currentTime; - if (irrecv->decode(&results)) { - if (results.value != 0 && serialCanTX) { // only print results if anything is received ( != 0 ) - Serial.printf_P(PSTR("IR recv: 0x%lX\n"), (unsigned long)results.value); + if (IrReceiver.decode()) { + auto &results = IrReceiver.decodedIRData; + + // we need to reverse the bits for NEC, SAMSUNG and SONY remotes to not break backwards compatability + uint32_t value; + if (results.protocol == NEC || results.protocol == SAMSUNG || results.protocol == SONY) + { + if ( results.decodedRawData == 0 ) { + value = 0xFFFFFFFF; // if we get a 0, we assume it is a repeat code + } + else { + value = bitreverse32Bit(results.decodedRawData); + } + } + else { + value = results.decodedRawData; } - decodeIR(results.value); - irrecv->resume(); + + // all the returns for IR in case we need to debug a remote + DEBUG_PRINTF_P(PSTR("IR Protocol Received: %s\n"), decodeTypeToStr(results.protocol)); + DEBUG_PRINTF_P(PSTR(" Raw Data: %d\n"), results.decodedRawData); + DEBUG_PRINTF_P(PSTR(" Address: 0x%X\n"), results.address); + DEBUG_PRINTF_P(PSTR(" Command: 0x%lX\n"), (unsigned long)results.command); + DEBUG_PRINTF_P(PSTR(" Num Bits: %d\n"), results.numberOfBits); + DEBUG_PRINTF_P(PSTR(" Value: 0x%0lX\n"), (unsigned long)value); + + #ifndef WLED_DEBUG + if (results.numberOfBits != 0 && serialCanTX) { // only print results if anything is received ( != 0 ) + Serial.printf_P(PSTR(" Protocol Received: %s, Value: 0x%0lX\n"), decodeTypeToStr(results.protocol), (unsigned long)value); + } + #endif + decodeIR(value); + IrReceiver.resume(); } } } diff --git a/wled00/wled.h b/wled00/wled.h index 52bb2f9366..99b51ef586 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -230,12 +230,6 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument; Comment out this error message to build regardless. #endif -#ifndef WLED_DISABLE_INFRARED - #include - #include - #include -#endif - //Filesystem to use for preset and config files. SPIFFS or LittleFS on ESP8266, SPIFFS only on ESP32 (now using LITTLEFS port by lorol) #ifdef ESP8266 #define WLED_FS LittleFS