to github
[svn42.git] / rf433ctl / IRremote / examples / IRrecvDump / IRrecvDump.pde
1 /*
2  * IRremote: IRrecvDump - dump details of IR codes with IRrecv
3  * An IR detector/demodulator must be connected to the input RECV_PIN.
4  * Version 0.1 July, 2009
5  * Copyright 2009 Ken Shirriff
6  * http://arcfn.com
7  */
8
9 #include <IRremote.h>
10
11 int RECV_PIN = 11;
12
13 IRrecv irrecv(RECV_PIN);
14
15 decode_results results;
16
17 void setup()
18 {
19   Serial.begin(9600);
20   irrecv.enableIRIn(); // Start the receiver
21 }
22
23 // Dumps out the decode_results structure.
24 // Call this after IRrecv::decode()
25 // void * to work around compiler issue
26 //void dump(void *v) {
27 //  decode_results *results = (decode_results *)v
28 void dump(decode_results *results) {
29   int count = results->rawlen;
30   if (results->decode_type == UNKNOWN) {
31     Serial.println("Could not decode message");
32   } 
33   else {
34     if (results->decode_type == NEC) {
35       Serial.print("Decoded NEC: ");
36     } 
37     else if (results->decode_type == SONY) {
38       Serial.print("Decoded SONY: ");
39     } 
40     else if (results->decode_type == RC5) {
41       Serial.print("Decoded RC5: ");
42     } 
43     else if (results->decode_type == RC6) {
44       Serial.print("Decoded RC6: ");
45     }
46     Serial.print(results->value, HEX);
47     Serial.print(" (");
48     Serial.print(results->bits, DEC);
49     Serial.println(" bits)");
50   }
51   Serial.print("Raw (");
52   Serial.print(count, DEC);
53   Serial.print("): ");
54
55   for (int i = 0; i < count; i++) {
56     if ((i % 2) == 1) {
57       Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
58     } 
59     else {
60       Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
61     }
62     Serial.print(" ");
63   }
64   Serial.println("");
65 }
66
67
68 void loop() {
69   if (irrecv.decode(&results)) {
70     Serial.println(results.value, HEX);
71     dump(&results);
72     irrecv.resume(); // Receive the next value
73   }
74 }\r