Skip to content

Commit d88855d

Browse files
committed
Fix ir_receiver to use IRremote 4.x built-in functions
Replace manual raw buffer access with library helper functions: - Use printIRResultShort() for formatted output - Use printIRSendUsage() to print C array format for sender - Remove custom dump() function that accessed rawDataPtr - Simplify code to use only well-documented API functions This should fix compilation errors by using stable, documented IRremote 4.x API instead of trying to access internal structures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f2e5fd2 commit d88855d

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed
Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#define sprint Serial.print
22
#define sprintln Serial.println
33
#include <IRremote.hpp> // IRremote 4.1.2 from Library Manager
4-
int RECV_PIN = 11;
54

5+
int RECV_PIN = 11;
66
unsigned long timeBegin;
77
int c = 1;
88

@@ -11,55 +11,33 @@ void setup()
1111
Serial.begin(9600);
1212
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
1313
timeBegin = micros();
14+
Serial.println(F("Ready to receive IR signals"));
1415
}
1516

1617
void loop() {
1718
if (IrReceiver.decode()) {
18-
dump();
19-
// ========
20-
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
21-
Serial.print("rawlen ");
22-
Serial.println(IrReceiver.decodedIRData.rawDataPtr->rawlen);
23-
Serial.print("decode type ");
19+
// Print counter
20+
sprintln(c);
21+
c++;
22+
23+
// Use built-in print functions from IRremote library
24+
IrReceiver.printIRResultShort(&Serial);
25+
Serial.println();
26+
27+
// Print as C array for use in sender
28+
IrReceiver.printIRSendUsage(&Serial);
29+
30+
// Additional details
31+
Serial.print("Protocol: ");
2432
Serial.println(IrReceiver.decodedIRData.protocol);
33+
Serial.print("Decoded value: 0x");
34+
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
2535

2636
unsigned long timeEnd = micros();
2737
unsigned long duration = timeEnd - timeBegin;
2838
double averageDuration = (double)duration / 1000.0;
2939
Serial.println(averageDuration);
30-
// if(IrReceiver.decodedIRData.decodedRawData==0xA1026EFF) {
31-
// Serial.println("turning off");
32-
// }
40+
3341
IrReceiver.resume(); // Receive the next value
3442
}
3543
}
36-
37-
void dump() {
38-
int count = IrReceiver.decodedIRData.rawDataPtr->rawlen;
39-
sprintln(c);
40-
c++;
41-
sprintln("For IR Scope: ");
42-
for (int i = 1; i < count; i++) {
43-
sprint("0x");
44-
sprint((unsigned int)IrReceiver.decodedIRData.rawDataPtr->rawbuf[i] * MICROS_PER_TICK, HEX);
45-
sprint(" ");
46-
}
47-
48-
sprintln("");
49-
sprintln("For Arduino sketch: ");
50-
sprint("uint16_t raw[");
51-
sprint(count, DEC);
52-
sprint("] = {");
53-
for (int i = 1; i < count; i++) {
54-
sprint("0x");
55-
sprint((unsigned int)IrReceiver.decodedIRData.rawDataPtr->rawbuf[i] * MICROS_PER_TICK, HEX);
56-
sprint(",");
57-
}
58-
sprint("};");
59-
sprintln("");
60-
sprint("IrSender.sendRaw(raw,");
61-
sprint(count, DEC);
62-
sprint(",38);");
63-
sprintln("");
64-
sprintln("");
65-
}

0 commit comments

Comments
 (0)