-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Maint: convert IR library to Arduino-IRremote #4732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f379755
f09b8f9
89cb10f
1430cb2
b0dce70
c8b446e
59f829b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused variable. The global -decode_results results;
unsigned long irCheckedTime = 0; 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||
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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.