From 14f4c7af77a353e9a07240598d3b7c47078e8847 Mon Sep 17 00:00:00 2001 From: Rafi Khan Date: Sun, 8 Mar 2015 00:02:22 -0600 Subject: [PATCH] Merging Sharp --- IRremote.cpp | 71 ++++++++++++++++++++++++++---- IRremote.h | 11 +++-- IRremoteInt.h | 2 +- examples/IRrecvDump/IRrecvDump.ino | 5 +++ keywords.txt | 1 + 5 files changed, 78 insertions(+), 12 deletions(-) diff --git a/IRremote.cpp b/IRremote.cpp index af5a3c8..0fbec22 100644 --- a/IRremote.cpp +++ b/IRremote.cpp @@ -458,6 +458,12 @@ int IRrecv::decode(decode_results *results) { if (decodeSanyo(results)) { return DECODED; } +#ifdef DEBUG + Serial.println("Attempting Sharp decode"); +#endif + if (decodeSharp(results)) { + return DECODED; + } #ifdef DEBUG Serial.println("Attempting Mitsubishi decode"); #endif @@ -618,6 +624,7 @@ long IRrecv::decodeSony(decode_results *results) { return DECODED; } +<<<<<<< HEAD long IRrecv::decodeWhynter(decode_results *results) { long data = 0; @@ -657,14 +664,7 @@ long IRrecv::decodeWhynter(decode_results *results) { data = (data << 1) | 1; } else if (MATCH_SPACE(results->rawbuf[offset],WHYNTER_ZERO_SPACE)) { - data <<= 1; - } - else { - return ERR; - } - offset++; - } - + // trailing mark if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) { return ERR; @@ -677,6 +677,61 @@ long IRrecv::decodeWhynter(decode_results *results) { } +======= +long IRrecv::decodeSharp(decode_results *results) { + long data = 0; + if (irparams.rawlen < 32) { + return ERR; + } + + int offset = 0; // Dont skip first space, check its size + + if (results->rawbuf[offset] < SHARP_RPT_SPACE) { + // Serial.print("IR Gap found: "); + results->bits = 0; + results->value = REPEAT; + results->decode_type = SHARP; + return DECODED; + } + + offset++; + + while (offset + 1 < irparams.rawlen) { + if (!MATCH_MARK(results->rawbuf[offset], SHARP_BIT_MARK)) { + break; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], SHARP_ONE_SPACE)) { + data = (data << 1) | 1; + } + else if (MATCH_SPACE(results->rawbuf[offset], SHARP_ZERO_SPACE)) { + data <<= 1; + } + else { + return ERR; + } + offset++; + } + + + if (data & 1 || !(data & 2)) { + return ERR; + } + + // Success + results->bits = (offset - 1) / 2; + if (results->bits < 15) { + results->bits = 0; + return ERR; + } + + results->sharpAddress = (data >> 10) & 0b11111; + results->value = (data >> 2) & 0xff; + results->decode_type = SHARP; + return DECODED; +} + +>>>>>>> 0b9d907da992bbb56493164e79d37006ec52e777 // I think this is a Sanyo decoder - serial = SA 8650B // Looks like Sony except for timings, 48 chars of data and time/space different long IRrecv::decodeSanyo(decode_results *results) { diff --git a/IRremote.h b/IRremote.h index e4b274e..9c5d872 100644 --- a/IRremote.h +++ b/IRremote.h @@ -29,9 +29,9 @@ class decode_results { public: int decode_type; // NEC, SONY, RC5, UNKNOWN - union { // This is used for decoding Panasonic and Sharp data - unsigned int panasonicAddress; - unsigned int sharpAddress; + union { + unsigned int panasonicAddress; // This is only used for decoding Panasonic data + unsigned int sharpAddress; // This is only used for decoding Panasonic data }; unsigned long value; // Decoded value int bits; // Number of bits in decoded value @@ -52,7 +52,11 @@ public: #define MITSUBISHI 10 #define SAMSUNG 11 #define LG 12 +<<<<<<< HEAD #define WHYNTER 13 +======= +#define SHARP 13 +>>>>>>> 0b9d907da992bbb56493164e79d37006ec52e777 #define UNKNOWN -1 // Decoded value for NEC when a repeat code is received @@ -72,6 +76,7 @@ private: int getRClevel(decode_results *results, int *offset, int *used, int t1); long decodeNEC(decode_results *results); long decodeSony(decode_results *results); + long decodeSharp(decode_results *results); long decodeSanyo(decode_results *results); long decodeMitsubishi(decode_results *results); long decodeRC5(decode_results *results); diff --git a/IRremoteInt.h b/IRremoteInt.h index 53167c2..fc1e7d3 100644 --- a/IRremoteInt.h +++ b/IRremoteInt.h @@ -149,7 +149,7 @@ #define SHARP_ZERO_SPACE 795 #define SHARP_GAP 600000 #define SHARP_TOGGLE_MASK 0x3FF -#define SHARP_RPT_SPACE 3000 +#define SHARP_RPT_SPACE 950 // 40ms #define DISH_HDR_MARK 400 #define DISH_HDR_SPACE 6100 diff --git a/examples/IRrecvDump/IRrecvDump.ino b/examples/IRrecvDump/IRrecvDump.ino index 0f8e4f1..a5ac34d 100644 --- a/examples/IRrecvDump/IRrecvDump.ino +++ b/examples/IRrecvDump/IRrecvDump.ino @@ -49,6 +49,11 @@ void dump(decode_results *results) { Serial.print(results->panasonicAddress,HEX); Serial.print(" Value: "); } + else if (results->decode_type == SHARP) { + Serial.print("Decoded SHARP - Address: "); + Serial.print(results->sharpAddress,HEX); + Serial.print(" Value: "); + } else if (results->decode_type == LG) { Serial.print("Decoded LG: "); } diff --git a/keywords.txt b/keywords.txt index 8eab9d1..026367f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -48,5 +48,6 @@ SHARP LITERAL1 PANASONIC LITERAL1 JVC LITERAL1 LG LITERAL1 +SHARP LITERAL1 UNKNOWN LITERAL1 REPEAT LITERAL1