Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
66 changes: 51 additions & 15 deletions wled00/ir.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "wled.h"

#ifndef WLED_DISABLE_INFRARED
#include <IRremote.hpp>
#include "ir_codes.h"

/*
* Infrared sensor support for several generic RGB remotes and custom JSON remote
*/

IRrecv* irrecv;
decode_results results;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove unused variable.

The global decode_results results variable appears to be unused after the migration to Arduino-IRremote, as the new library uses IrReceiver.decodedIRData instead.

-decode_results results;
 unsigned long irCheckedTime = 0;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
decode_results results;
unsigned long irCheckedTime = 0;
🤖 Prompt for AI Agents
In wled00/ir.cpp at line 11, remove the declaration of the unused global
variable `decode_results results` since the code now uses
`IrReceiver.decodedIRData` from the Arduino-IRremote library and no longer
requires this variable.

unsigned long irCheckedTime = 0;
uint32_t lastValidCode = 0;
Expand Down Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the encoding type is of any use to the average user and may add more questions than it answers as this is auto-detected and nothing that is selectable. Or what's the reasoning to add it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the encoding type for users to be able to do an easy sanity check that the IR signal they received is from the remote device they're using. If you're trying to add a Samsung remote, you'd expect to see SAMSUNG as the encoding device. Also, since platformio.ini only enables a very small set of brand remotes, for folks who are trying to add a LG based remote, they would get UNKNOWN with their code - which could prompt them to dig deeper into what's going on. Remote brands that aren't covered wouldn't be decoded properly and would most likely be treated as a HASH based decode.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to agree with @DedeHai . "Regular" user, who may be instructed to monitor serial port to see IR codes, doesn't need to know which brand his/her/its remote belongs to, he/she/it only needs to know IR code itself (to construct JSON file, for example).

However, if you insist on providing this information to the enduser, please move all of the strings into flash.

}
#endif
decodeIR(value);
IrReceiver.resume();
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,6 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument<PSRAM_Allocator>;
Comment out this error message to build regardless.
#endif

#ifndef WLED_DISABLE_INFRARED
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
#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
Expand Down