Skip to content

Commit 22e64f1

Browse files
committed
Merge pull request Arduino-IRremote#207 from AnalysIR/master
Bug fixes as per Issue #167
2 parents cd02daf + 61f00b8 commit 22e64f1

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

examples/IRrecvDump/IRrecvDump.ino

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
#include <IRremote.h>
1212

13-
int RECV_PIN = 11;
13+
/*
14+
* Default is Arduino pin D11.
15+
* You can change this to another available Arduino Pin.
16+
* Your IR receiver should be connected to the pin defined here
17+
*/
18+
int RECV_PIN = 11;
1419

1520
IRrecv irrecv(RECV_PIN);
1621

@@ -22,18 +27,17 @@ void setup()
2227
irrecv.enableIRIn(); // Start the receiver
2328
}
2429

25-
// Dumps out the decode_results structure.
26-
// Call this after IRrecv::decode()
27-
// void * to work around compiler issue
28-
//void dump(void *v) {
29-
// decode_results *results = (decode_results *)v
30+
3031
void dump(decode_results *results) {
32+
// Dumps out the decode_results structure.
33+
// Call this after IRrecv::decode()
3134
int count = results->rawlen;
3235
if (results->decode_type == UNKNOWN) {
3336
Serial.print("Unknown encoding: ");
3437
}
3538
else if (results->decode_type == NEC) {
3639
Serial.print("Decoded NEC: ");
40+
3741
}
3842
else if (results->decode_type == SONY) {
3943
Serial.print("Decoded SONY: ");
@@ -46,21 +50,20 @@ void dump(decode_results *results) {
4650
}
4751
else if (results->decode_type == PANASONIC) {
4852
Serial.print("Decoded PANASONIC - Address: ");
49-
Serial.print(results->address,HEX);
53+
Serial.print(results->address, HEX);
5054
Serial.print(" Value: ");
5155
}
5256
else if (results->decode_type == LG) {
53-
Serial.print("Decoded LG: ");
57+
Serial.print("Decoded LG: ");
5458
}
5559
else if (results->decode_type == JVC) {
56-
Serial.print("Decoded JVC: ");
57-
60+
Serial.print("Decoded JVC: ");
5861
}
5962
else if (results->decode_type == AIWA_RC_T501) {
6063
Serial.print("Decoded AIWA RC T501: ");
6164
}
6265
else if (results->decode_type == WHYNTER) {
63-
Serial.print("Decoded Whynter: ");
66+
Serial.print("Decoded Whynter: ");
6467
}
6568
Serial.print(results->value, HEX);
6669
Serial.print(" (");
@@ -70,19 +73,19 @@ void dump(decode_results *results) {
7073
Serial.print(count, DEC);
7174
Serial.print("): ");
7275

73-
for (int i = 0; i < count; i++) {
74-
if ((i % 2) == 1) {
76+
for (int i = 1; i < count; i++) {
77+
if (i & 1) {
7578
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
7679
}
7780
else {
78-
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
81+
Serial.write('-');
82+
Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
7983
}
8084
Serial.print(" ");
8185
}
82-
Serial.println("");
86+
Serial.println();
8387
}
8488

85-
8689
void loop() {
8790
if (irrecv.decode(&results)) {
8891
Serial.println(results.value, HEX);

examples/IRrecvDumpV2/IRrecvDumpV2.ino

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//------------------------------------------------------------------------------
77
// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
88
//
9-
int recvPin = 6;
9+
int recvPin = 11;
1010
IRrecv irrecv(recvPin);
1111

1212
//+=============================================================================
@@ -92,10 +92,9 @@ void dumpRaw (decode_results *results)
9292
Serial.print("Timing[");
9393
Serial.print(results->rawlen, DEC);
9494
Serial.println("]: ");
95-
Serial.print(" -");
96-
Serial.println(results->rawbuf[0] * USECPERTICK, DEC);
95+
9796
for (int i = 1; i < results->rawlen; i++) {
98-
unsigned int x = results->rawbuf[i] * USECPERTICK;
97+
unsigned long x = results->rawbuf[i] * USECPERTICK;
9998
if (!(i & 1)) { // even
10099
Serial.print("-");
101100
if (x < 1000) Serial.print(" ") ;
@@ -109,7 +108,7 @@ void dumpRaw (decode_results *results)
109108
Serial.print(x, DEC);
110109
Serial.print(", ");
111110
}
112-
if (!(i%8)) Serial.println("");
111+
if (!(i % 8)) Serial.println("");
113112
}
114113
Serial.println(""); // Newline
115114
}
@@ -126,10 +125,10 @@ void dumpCode (decode_results *results)
126125
Serial.print("] = {"); // Start declaration
127126

128127
// Dump data
129-
for (int i = 0; i < results->rawlen; i++) {
128+
for (int i = 1; i < results->rawlen; i++) {
130129
Serial.print(results->rawbuf[i] * USECPERTICK, DEC);
131130
Serial.print(",");
132-
if (!(i&1)) Serial.print(" ");
131+
if (!(i & 1)) Serial.print(" ");
133132
}
134133

135134
// End declaration
@@ -143,17 +142,17 @@ void dumpCode (decode_results *results)
143142

144143
// Newline
145144
Serial.println("");
146-
145+
147146
// Now dump "known" codes
148147
if (results->decode_type != UNKNOWN) {
149-
148+
150149
// Some protocols have an address
151150
if (results->decode_type == PANASONIC) {
152151
Serial.print("unsigned int addr = 0x");
153152
Serial.print(results->address, HEX);
154153
Serial.println(";");
155154
}
156-
155+
157156
// All protocols have data
158157
Serial.print("unsigned int data = 0x");
159158
Serial.print(results->value, HEX);
@@ -166,14 +165,13 @@ void dumpCode (decode_results *results)
166165
//
167166
void loop ( )
168167
{
169-
decode_results results; // Somewhere to store the results
170-
171-
if (irrecv.decode(&results)) { // Grab an IR code
172-
dumpInfo(&results); // Output the results
173-
dumpRaw(&results); // Output the results in RAW format
174-
dumpCode(&results); // Output the results as source code
175-
Serial.println(""); // Blank line between entries
176-
irrecv.resume(); // Prepare for the next value
177-
}
168+
decode_results results; // Somewhere to store the results
169+
170+
if (irrecv.decode(&results)) { // Grab an IR code
171+
dumpInfo(&results); // Output the results
172+
dumpRaw(&results); // Output the results in RAW format
173+
dumpCode(&results); // Output the results as source code
174+
Serial.println(""); // Blank line between entries
175+
irrecv.resume(); // Prepare for the next value
176+
}
178177
}
179-

0 commit comments

Comments
 (0)