From ae477413dea8e99325bdea616a9227a388a9d30c Mon Sep 17 00:00:00 2001 From: Bluechip Date: Sat, 20 Jun 2015 22:03:00 +0100 Subject: [PATCH] Fixup old examples Add new example --- IRremote.h | 5 + examples/IRrecvDump/IRrecvDump.ino | 16 +-- examples/IRrecvDumpV2/IRrecvDumpV2.ino | 162 +++++++++++++++++++++++++ 3 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 examples/IRrecvDumpV2/IRrecvDumpV2.ino diff --git a/IRremote.h b/IRremote.h index f5f433a..47a0e06 100644 --- a/IRremote.h +++ b/IRremote.h @@ -18,6 +18,11 @@ #ifndef IRremote_h #define IRremote_h +//------------------------------------------------------------------------------ +// The ISR header contains several useful macros the user may wish to use +// +#include "IRremoteInt.h" + //------------------------------------------------------------------------------ // Supported IR protocols // Each protocol you include costs memory and, during decode, costs time diff --git a/examples/IRrecvDump/IRrecvDump.ino b/examples/IRrecvDump/IRrecvDump.ino index a1ba3b2..abfef54 100644 --- a/examples/IRrecvDump/IRrecvDump.ino +++ b/examples/IRrecvDump/IRrecvDump.ino @@ -31,22 +31,22 @@ void dump(decode_results *results) { int count = results->rawlen; if (results->decode_type == UNKNOWN) { Serial.print("Unknown encoding: "); - } + } else if (results->decode_type == NEC) { Serial.print("Decoded NEC: "); - } + } else if (results->decode_type == SONY) { Serial.print("Decoded SONY: "); - } + } else if (results->decode_type == RC5) { Serial.print("Decoded RC5: "); - } + } else if (results->decode_type == RC6) { Serial.print("Decoded RC6: "); } - else if (results->decode_type == PANASONIC) { + else if (results->decode_type == PANASONIC) { Serial.print("Decoded PANASONIC - Address: "); - Serial.print(results->panasonicAddress,HEX); + Serial.print(results->address,HEX); Serial.print(" Value: "); } else if (results->decode_type == LG) { @@ -54,7 +54,7 @@ void dump(decode_results *results) { } else if (results->decode_type == JVC) { Serial.print("Decoded JVC: "); - + } else if (results->decode_type == AIWA_RC_T501) { Serial.print("Decoded AIWA RC T501: "); @@ -73,7 +73,7 @@ void dump(decode_results *results) { for (int i = 0; i < count; i++) { if ((i % 2) == 1) { Serial.print(results->rawbuf[i]*USECPERTICK, DEC); - } + } else { Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); } diff --git a/examples/IRrecvDumpV2/IRrecvDumpV2.ino b/examples/IRrecvDumpV2/IRrecvDumpV2.ino new file mode 100644 index 0000000..c6f070c --- /dev/null +++ b/examples/IRrecvDumpV2/IRrecvDumpV2.ino @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// Include the IRremote library headers +// +#include +#include + +//------------------------------------------------------------------------------ +// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838) +// +IRrecv irrecv(6); + +//+============================================================================= +// Configure the Arduino +// +void setup ( ) +{ + Serial.begin(9600); // Status message will be sent to PC at 9600 baud + irrecv.enableIRIn(); // Start the receiver +} + +//+============================================================================= +// Display IR code +// +void ircode (decode_results *results) +{ + // Panasonic has an Address + if (results->decode_type == PANASONIC) { + Serial.print(results->address, HEX); + Serial.print(":"); + } + + // Print Code + Serial.print(results->value, HEX); +} + +//+============================================================================= +// Display encoding type +// +void encoding (decode_results *results) +{ + switch (results->decode_type) { + default: + case UNKNOWN: Serial.print("UNKNOWN"); break ; + case NEC: Serial.print("NEC"); break ; + case SONY: Serial.print("SONY"); break ; + case RC5: Serial.print("RC5"); break ; + case RC6: Serial.print("RC6"); break ; + case DISH: Serial.print("DISH"); break ; + case SHARP: Serial.print("SHARP"); break ; + case JVC: Serial.print("JVC"); break ; + case SANYO: Serial.print("SANYO"); break ; + case MITSUBISHI: Serial.print("MITSUBISHI"); break ; + case SAMSUNG: Serial.print("SAMSUNG"); break ; + case LG: Serial.print("LG"); break ; + case WHYNTER: Serial.print("WHYNTER"); break ; + case AIWA_RC_T501: Serial.print("AIWA_RC_T501"); break ; + case PANASONIC: Serial.print("PANASONIC"); break ; + } +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpInfo (decode_results *results) +{ + // Check if the buffer overflowed + if (results->overflow) { + Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWLEN"); + return; + } + + // Show Encoding standard + Serial.print("Encoding : "); + encoding(results); + Serial.println(""); + + // Show Code & length + Serial.print("Code : "); + ircode(results); + Serial.print(" ("); + Serial.print(results->bits, DEC); + Serial.println(" bits)"); +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpRaw (decode_results *results) +{ + // Print Raw data + Serial.print("Timing["); + Serial.print(results->rawlen, DEC); + Serial.println("]: "); + Serial.print(" -"); + Serial.println(results->rawbuf[0] * USECPERTICK, DEC); + for (int i = 1; i < results->rawlen; i++) { + int x = results->rawbuf[i] * USECPERTICK; + if (!(i & 1)) { // even + Serial.print("-"); + if (x < 1000) Serial.print(" ") ; + if (x < 100) Serial.print(" ") ; + Serial.print(x, DEC); + } else { // odd + Serial.print(" "); + Serial.print("+"); + if (x < 1000) Serial.print(" ") ; + if (x < 100) Serial.print(" ") ; + Serial.print(x, DEC); + Serial.print(", "); + } + if (!(i%8)) Serial.println(""); + } + Serial.println(""); // Newline +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpCode (decode_results *results) +{ + // Start declaration + Serial.print("unsigned int "); // variable type + Serial.print("rawData["); // array name + Serial.print(results->rawlen + 1, DEC); // array size + Serial.print("] = {"); // Start declaration + + // Dump data + for (int i = 0; i < results->rawlen; i++) { + Serial.print(results->rawbuf[i], DEC); + Serial.print(","); + if (!(i&1)) Serial.print(" "); + } + + // End declaration + Serial.print("0};"); // Turn LED off at the end + + // Comment + Serial.print(" // "); + encoding(results); + Serial.print(" "); + ircode(results); + + // Newline + Serial.println(""); +} + +//+============================================================================= +// The repeating section of the code +// +void loop ( ) +{ + decode_results results; // Somewhere to store the results + + if (irrecv.decode(&results)) { // Grab an IR code + dumpInfo(&results); // Output the results + dumpRaw(&results); // Output the results in RAW format + dumpCode(&results); // Output the results as source code + Serial.println(""); // Blank line between entries + irrecv.resume(); // Prepare for the next value + } +} +