diff --git a/IRremote.cpp b/IRremote.cpp index 5f394cc..deb2307 100644 --- a/IRremote.cpp +++ b/IRremote.cpp @@ -14,6 +14,7 @@ * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ * * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) + * LG added by Darryl Smith (based on the JVC protocol) */ #include "IRremote.h" @@ -459,6 +460,12 @@ int IRrecv::decode(decode_results *results) { if (decodePanasonic(results)) { return DECODED; } +#ifdef DEBUG + Serial.println("Attempting LG decode"); +#endif + if (decodeLG(results)) { + return DECODED; + } #ifdef DEBUG Serial.println("Attempting JVC decode"); #endif @@ -876,6 +883,52 @@ long IRrecv::decodePanasonic(decode_results *results) { results->bits = PANASONIC_BITS; return DECODED; } + +long IRrecv::decodeLG(decode_results *results) { + long data = 0; + int offset = 1; // Skip first space + + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], LG_HDR_MARK)) { + return ERR; + } + offset++; + if (irparams.rawlen < 2 * LG_BITS + 1 ) { + return ERR; + } + // Initial space + if (!MATCH_SPACE(results->rawbuf[offset], LG_HDR_SPACE)) { + return ERR; + } + offset++; + for (int i = 0; i < LG_BITS; i++) { + if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)) { + return ERR; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], LG_ONE_SPACE)) { + data = (data << 1) | 1; + } + else if (MATCH_SPACE(results->rawbuf[offset], LG_ZERO_SPACE)) { + data <<= 1; + } + else { + return ERR; + } + offset++; + } + //Stop bit + if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)){ + return ERR; + } + // Success + results->bits = LG_BITS; + results->value = data; + results->decode_type = LG; + return DECODED; +} + + long IRrecv::decodeJVC(decode_results *results) { long data = 0; int offset = 1; // Skip first space diff --git a/IRremote.h b/IRremote.h index b626711..e4463e8 100644 --- a/IRremote.h +++ b/IRremote.h @@ -10,6 +10,7 @@ * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ * * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) +* LG added by Darryl Smith (based on the JVC protocol) */ #ifndef IRremote_h @@ -46,6 +47,7 @@ public: #define SANYO 9 #define MITSUBISHI 10 #define SAMSUNG 11 +#define LG 12 #define UNKNOWN -1 // Decoded value for NEC when a repeat code is received @@ -70,6 +72,7 @@ private: long decodeRC5(decode_results *results); long decodeRC6(decode_results *results); long decodePanasonic(decode_results *results); + long decodeLG(decode_results *results); long decodeJVC(decode_results *results); long decodeSAMSUNG(decode_results *results); long decodeHash(decode_results *results); diff --git a/IRremoteInt.h b/IRremoteInt.h index 8c43163..418904e 100644 --- a/IRremoteInt.h +++ b/IRremoteInt.h @@ -159,6 +159,13 @@ #define JVC_ZERO_SPACE 550 #define JVC_RPT_LENGTH 60000 +#define LG_HDR_MARK 8000 +#define LG_HDR_SPACE 4000 +#define LG_BIT_MARK 600 +#define LG_ONE_SPACE 1600 +#define LG_ZERO_SPACE 550 +#define LG_RPT_LENGTH 60000 + #define SAMSUNG_HDR_MARK 5000 #define SAMSUNG_HDR_SPACE 5000 #define SAMSUNG_BIT_MARK 560 diff --git a/examples/IRrecvDump/IRrecvDump.ino b/examples/IRrecvDump/IRrecvDump.ino index 6afcb0f..d66aee2 100644 --- a/examples/IRrecvDump/IRrecvDump.ino +++ b/examples/IRrecvDump/IRrecvDump.ino @@ -5,6 +5,7 @@ * Copyright 2009 Ken Shirriff * http://arcfn.com * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) + * LG added by Darryl Smith (based on the JVC protocol) */ #include @@ -48,6 +49,9 @@ void dump(decode_results *results) { Serial.print(results->panasonicAddress,HEX); Serial.print(" Value: "); } + else if (results->decode_type == LG) { + Serial.print("Decoded LG: "); + } else if (results->decode_type == JVC) { Serial.print("Decoded JVC: "); }