Added possibility to exclude non-necessary libraries by comment lines in IRremote.h

This commit is contained in:
sstefanov
2015-03-12 14:49:48 +02:00
parent 0de2d18bdb
commit 549d92d2f5
2 changed files with 127 additions and 2 deletions

View File

@@ -72,6 +72,7 @@ int MATCH_SPACE(int measured_ticks, int desired_us) {return MATCH(measured_ticks
// Debugging versions are in IRremote.cpp // Debugging versions are in IRremote.cpp
#endif #endif
#ifdef IRsendNEC
void IRsend::sendNEC(unsigned long data, int nbits) void IRsend::sendNEC(unsigned long data, int nbits)
{ {
enableIROut(38); enableIROut(38);
@@ -91,7 +92,9 @@ void IRsend::sendNEC(unsigned long data, int nbits)
mark(NEC_BIT_MARK); mark(NEC_BIT_MARK);
space(0); space(0);
} }
#endif
#ifdef IRsendSONY
void IRsend::sendSony(unsigned long data, int nbits) { void IRsend::sendSony(unsigned long data, int nbits) {
enableIROut(40); enableIROut(40);
mark(SONY_HDR_MARK); mark(SONY_HDR_MARK);
@@ -109,7 +112,9 @@ void IRsend::sendSony(unsigned long data, int nbits) {
data <<= 1; data <<= 1;
} }
} }
#endif
#ifdef IRsendRAW
void IRsend::sendRaw(unsigned int buf[], int len, int hz) void IRsend::sendRaw(unsigned int buf[], int len, int hz)
{ {
enableIROut(hz); enableIROut(hz);
@@ -123,7 +128,9 @@ void IRsend::sendRaw(unsigned int buf[], int len, int hz)
} }
space(0); // Just to be sure space(0); // Just to be sure
} }
#endif
#ifdef IRsendRC5
// Note: first bit must be a one (start bit) // Note: first bit must be a one (start bit)
void IRsend::sendRC5(unsigned long data, int nbits) void IRsend::sendRC5(unsigned long data, int nbits)
{ {
@@ -145,7 +152,9 @@ void IRsend::sendRC5(unsigned long data, int nbits)
} }
space(0); // Turn off at end space(0); // Turn off at end
} }
#endif
#ifdef IRsendRC6
// Caller needs to take care of flipping the toggle bit // Caller needs to take care of flipping the toggle bit
void IRsend::sendRC6(unsigned long data, int nbits) void IRsend::sendRC6(unsigned long data, int nbits)
{ {
@@ -177,6 +186,9 @@ void IRsend::sendRC6(unsigned long data, int nbits)
} }
space(0); // Turn off at end space(0); // Turn off at end
} }
#endif
#ifdef IRsendPANASONIC
void IRsend::sendPanasonic(unsigned int address, unsigned long data) { void IRsend::sendPanasonic(unsigned int address, unsigned long data) {
enableIROut(35); enableIROut(35);
mark(PANASONIC_HDR_MARK); mark(PANASONIC_HDR_MARK);
@@ -204,6 +216,9 @@ void IRsend::sendPanasonic(unsigned int address, unsigned long data) {
mark(PANASONIC_BIT_MARK); mark(PANASONIC_BIT_MARK);
space(0); space(0);
} }
#endif
#ifdef IRsendJVC
void IRsend::sendJVC(unsigned long data, int nbits, int repeat) void IRsend::sendJVC(unsigned long data, int nbits, int repeat)
{ {
enableIROut(38); enableIROut(38);
@@ -226,7 +241,9 @@ void IRsend::sendJVC(unsigned long data, int nbits, int repeat)
mark(JVC_BIT_MARK); mark(JVC_BIT_MARK);
space(0); space(0);
} }
#endif
#ifdef IRsendSAMSUNG
void IRsend::sendSAMSUNG(unsigned long data, int nbits) void IRsend::sendSAMSUNG(unsigned long data, int nbits)
{ {
enableIROut(38); enableIROut(38);
@@ -246,6 +263,7 @@ void IRsend::sendSAMSUNG(unsigned long data, int nbits)
mark(SAMSUNG_BIT_MARK); mark(SAMSUNG_BIT_MARK);
space(0); space(0);
} }
#endif
void IRsend::mark(int time) { void IRsend::mark(int time) {
// Sends an IR mark for the specified number of microseconds. // Sends an IR mark for the specified number of microseconds.
@@ -417,60 +435,87 @@ int IRrecv::decode(decode_results *results) {
if (irparams.rcvstate != STATE_STOP) { if (irparams.rcvstate != STATE_STOP) {
return ERR; return ERR;
} }
#ifdef NEC
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting NEC decode"); Serial.println("Attempting NEC decode");
#endif #endif
if (decodeNEC(results)) { if (decodeNEC(results)) {
return DECODED; return DECODED;
} }
#endif
#ifdef SONY
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting Sony decode"); Serial.println("Attempting Sony decode");
#endif #endif
if (decodeSony(results)) { if (decodeSony(results)) {
return DECODED; return DECODED;
} }
#endif
#ifdef SANYO
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting Sanyo decode"); Serial.println("Attempting Sanyo decode");
#endif #endif
if (decodeSanyo(results)) { if (decodeSanyo(results)) {
return DECODED; return DECODED;
} }
#endif
#ifdef MITSUBISHI
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting Mitsubishi decode"); Serial.println("Attempting Mitsubishi decode");
#endif #endif
if (decodeMitsubishi(results)) { if (decodeMitsubishi(results)) {
return DECODED; return DECODED;
} }
#endif
#ifdef RC5
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting RC5 decode"); Serial.println("Attempting RC5 decode");
#endif #endif
if (decodeRC5(results)) { if (decodeRC5(results)) {
return DECODED; return DECODED;
} }
#endif
#ifdef RC6
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting RC6 decode"); Serial.println("Attempting RC6 decode");
#endif #endif
if (decodeRC6(results)) { if (decodeRC6(results)) {
return DECODED; return DECODED;
} }
#endif
#ifdef PANASONIC
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting Panasonic decode"); Serial.println("Attempting Panasonic decode");
#endif #endif
if (decodePanasonic(results)) { if (decodePanasonic(results)) {
return DECODED; return DECODED;
} }
#endif
#ifdef JVC
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting JVC decode"); Serial.println("Attempting JVC decode");
#endif #endif
if (decodeJVC(results)) { if (decodeJVC(results)) {
return DECODED; return DECODED;
} }
#endif
#ifdef SAMSUNG
#ifdef DEBUG #ifdef DEBUG
Serial.println("Attempting SAMSUNG decode"); Serial.println("Attempting SAMSUNG decode");
#endif #endif
if (decodeSAMSUNG(results)) { if (decodeSAMSUNG(results)) {
return DECODED; return DECODED;
} }
#endif
// decodeHash returns a hash on any input. // decodeHash returns a hash on any input.
// Thus, it needs to be last in the list. // Thus, it needs to be last in the list.
// If you add any decodes, add them before this. // If you add any decodes, add them before this.
@@ -482,6 +527,7 @@ int IRrecv::decode(decode_results *results) {
return ERR; return ERR;
} }
#ifdef NEC
// NECs have a repeat only 4 items long // NECs have a repeat only 4 items long
long IRrecv::decodeNEC(decode_results *results) { long IRrecv::decodeNEC(decode_results *results) {
long data = 0; long data = 0;
@@ -530,7 +576,9 @@ long IRrecv::decodeNEC(decode_results *results) {
results->decode_type = NEC; results->decode_type = NEC;
return DECODED; return DECODED;
} }
#endif
#ifdef SONY
long IRrecv::decodeSony(decode_results *results) { long IRrecv::decodeSony(decode_results *results) {
long data = 0; long data = 0;
if (irparams.rawlen < 2 * SONY_BITS + 2) { if (irparams.rawlen < 2 * SONY_BITS + 2) {
@@ -544,7 +592,11 @@ long IRrecv::decodeSony(decode_results *results) {
// Serial.print("IR Gap found: "); // Serial.print("IR Gap found: ");
results->bits = 0; results->bits = 0;
results->value = REPEAT; results->value = REPEAT;
#ifdef SANYO
results->decode_type = SANYO; results->decode_type = SANYO;
#else
results->decode_type = UNKNOWN;
#endif
return DECODED; return DECODED;
} }
offset++; offset++;
@@ -582,7 +634,9 @@ long IRrecv::decodeSony(decode_results *results) {
results->decode_type = SONY; results->decode_type = SONY;
return DECODED; return DECODED;
} }
#endif
#ifdef SANYO
// I think this is a Sanyo decoder - serial = SA 8650B // I think this is a Sanyo decoder - serial = SA 8650B
// Looks like Sony except for timings, 48 chars of data and time/space different // Looks like Sony except for timings, 48 chars of data and time/space different
long IRrecv::decodeSanyo(decode_results *results) { long IRrecv::decodeSanyo(decode_results *results) {
@@ -646,7 +700,9 @@ long IRrecv::decodeSanyo(decode_results *results) {
results->decode_type = SANYO; results->decode_type = SANYO;
return DECODED; return DECODED;
} }
#endif
#ifdef MITSUBISHI
// Looks like Sony except for timings, 48 chars of data and time/space different // Looks like Sony except for timings, 48 chars of data and time/space different
long IRrecv::decodeMitsubishi(decode_results *results) { long IRrecv::decodeMitsubishi(decode_results *results) {
// Serial.print("?!? decoding Mitsubishi:");Serial.print(irparams.rawlen); Serial.print(" want "); Serial.println( 2 * MITSUBISHI_BITS + 2); // Serial.print("?!? decoding Mitsubishi:");Serial.print(irparams.rawlen); Serial.print(" want "); Serial.println( 2 * MITSUBISHI_BITS + 2);
@@ -710,8 +766,9 @@ long IRrecv::decodeMitsubishi(decode_results *results) {
results->decode_type = MITSUBISHI; results->decode_type = MITSUBISHI;
return DECODED; return DECODED;
} }
#endif
#if defined(RC5) || defined(RC6)
// Gets one undecoded level at a time from the raw buffer. // Gets one undecoded level at a time from the raw buffer.
// The RC5/6 decoding is easier if the data is broken into time intervals. // The RC5/6 decoding is easier if the data is broken into time intervals.
// E.g. if the buffer has MARK for 2 time intervals and SPACE for 1, // E.g. if the buffer has MARK for 2 time intervals and SPACE for 1,
@@ -757,7 +814,9 @@ int IRrecv::getRClevel(decode_results *results, int *offset, int *used, int t1)
#endif #endif
return val; return val;
} }
#endif
#ifdef RC5
long IRrecv::decodeRC5(decode_results *results) { long IRrecv::decodeRC5(decode_results *results) {
if (irparams.rawlen < MIN_RC5_SAMPLES + 2) { if (irparams.rawlen < MIN_RC5_SAMPLES + 2) {
return ERR; return ERR;
@@ -792,7 +851,9 @@ long IRrecv::decodeRC5(decode_results *results) {
results->decode_type = RC5; results->decode_type = RC5;
return DECODED; return DECODED;
} }
#endif
#ifdef RC6
long IRrecv::decodeRC6(decode_results *results) { long IRrecv::decodeRC6(decode_results *results) {
if (results->rawlen < MIN_RC6_SAMPLES) { if (results->rawlen < MIN_RC6_SAMPLES) {
return ERR; return ERR;
@@ -843,6 +904,9 @@ long IRrecv::decodeRC6(decode_results *results) {
results->decode_type = RC6; results->decode_type = RC6;
return DECODED; return DECODED;
} }
#endif
#ifdef PANASONIC
long IRrecv::decodePanasonic(decode_results *results) { long IRrecv::decodePanasonic(decode_results *results) {
unsigned long long data = 0; unsigned long long data = 0;
int offset = 1; int offset = 1;
@@ -876,6 +940,9 @@ long IRrecv::decodePanasonic(decode_results *results) {
results->bits = PANASONIC_BITS; results->bits = PANASONIC_BITS;
return DECODED; return DECODED;
} }
#endif
#ifdef JVC
long IRrecv::decodeJVC(decode_results *results) { long IRrecv::decodeJVC(decode_results *results) {
long data = 0; long data = 0;
int offset = 1; // Skip first space int offset = 1; // Skip first space
@@ -927,7 +994,9 @@ long IRrecv::decodeJVC(decode_results *results) {
results->decode_type = JVC; results->decode_type = JVC;
return DECODED; return DECODED;
} }
#endif
#ifdef SAMSUNG
// SAMSUNGs have a repeat only 4 items long // SAMSUNGs have a repeat only 4 items long
long IRrecv::decodeSAMSUNG(decode_results *results) { long IRrecv::decodeSAMSUNG(decode_results *results) {
long data = 0; long data = 0;
@@ -976,6 +1045,7 @@ long IRrecv::decodeSAMSUNG(decode_results *results) {
results->decode_type = SAMSUNG; results->decode_type = SAMSUNG;
return DECODED; return DECODED;
} }
#endif
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* hashdecode - decode an arbitrary IR code. * hashdecode - decode an arbitrary IR code.
@@ -1052,7 +1122,7 @@ For the DISH codes, only send the last for characters of the hex.
i.e. use 0x1C10 instead of 0x0000000000001C10 which is listed in the i.e. use 0x1C10 instead of 0x0000000000001C10 which is listed in the
linked LIRC file. linked LIRC file.
*/ */
#ifdef IRsendSHARP
void IRsend::sendSharp(unsigned long data, int nbits) { void IRsend::sendSharp(unsigned long data, int nbits) {
unsigned long invertdata = data ^ SHARP_TOGGLE_MASK; unsigned long invertdata = data ^ SHARP_TOGGLE_MASK;
enableIROut(38); enableIROut(38);
@@ -1086,7 +1156,9 @@ void IRsend::sendSharp(unsigned long data, int nbits) {
space(SHARP_ZERO_SPACE); space(SHARP_ZERO_SPACE);
delay(46); delay(46);
} }
#endif
#ifdef IRsendDISH
void IRsend::sendDISH(unsigned long data, int nbits) void IRsend::sendDISH(unsigned long data, int nbits)
{ {
enableIROut(56); enableIROut(56);
@@ -1104,3 +1176,4 @@ void IRsend::sendDISH(unsigned long data, int nbits)
data <<= 1; data <<= 1;
} }
} }
#endif

View File

@@ -34,6 +34,20 @@ public:
int rawlen; // Number of records in rawbuf. int rawlen; // Number of records in rawbuf.
}; };
// Send types
#define IRsendNEC
#define IRsendSONY
#define IRsendRC5
#define IRsendRC6
#define IRsendDISH
#define IRsendSHARP
#define IRsendPANASONIC
#define IRsendJVC
#define IRsendSANYO
#define IRsendMITSUBISHI
#define IRsendSAMSUNG
#define IRsendRAW
// Values for decode_type // Values for decode_type
#define NEC 1 #define NEC 1
#define SONY 2 #define SONY 2
@@ -63,15 +77,33 @@ public:
private: private:
// These are called by decode // These are called by decode
int getRClevel(decode_results *results, int *offset, int *used, int t1); int getRClevel(decode_results *results, int *offset, int *used, int t1);
#ifdef NEC
long decodeNEC(decode_results *results); long decodeNEC(decode_results *results);
#endif
#ifdef SONY
long decodeSony(decode_results *results); long decodeSony(decode_results *results);
#endif
#ifdef SANYO
long decodeSanyo(decode_results *results); long decodeSanyo(decode_results *results);
#endif
#ifdef MITSUBISHI
long decodeMitsubishi(decode_results *results); long decodeMitsubishi(decode_results *results);
#endif
#ifdef RC5
long decodeRC5(decode_results *results); long decodeRC5(decode_results *results);
#endif
#ifdef RC6
long decodeRC6(decode_results *results); long decodeRC6(decode_results *results);
#endif
#ifdef PANASONIC
long decodePanasonic(decode_results *results); long decodePanasonic(decode_results *results);
#endif
#ifdef JVC
long decodeJVC(decode_results *results); long decodeJVC(decode_results *results);
#endif
#ifdef SAMSUNG
long decodeSAMSUNG(decode_results *results); long decodeSAMSUNG(decode_results *results);
#endif
long decodeHash(decode_results *results); long decodeHash(decode_results *results);
int compare(unsigned int oldval, unsigned int newval); int compare(unsigned int oldval, unsigned int newval);
@@ -89,20 +121,40 @@ class IRsend
{ {
public: public:
IRsend() {} IRsend() {}
#ifdef IRsendNEC
void sendNEC(unsigned long data, int nbits); void sendNEC(unsigned long data, int nbits);
#endif
#ifdef IRsendSONY
void sendSony(unsigned long data, int nbits); void sendSony(unsigned long data, int nbits);
// Neither Sanyo nor Mitsubishi send is implemented yet // Neither Sanyo nor Mitsubishi send is implemented yet
// void sendSanyo(unsigned long data, int nbits); // void sendSanyo(unsigned long data, int nbits);
// void sendMitsubishi(unsigned long data, int nbits); // void sendMitsubishi(unsigned long data, int nbits);
#endif
#ifdef IRsendRAW
void sendRaw(unsigned int buf[], int len, int hz); void sendRaw(unsigned int buf[], int len, int hz);
#endif
#ifdef IRsendRC5
void sendRC5(unsigned long data, int nbits); void sendRC5(unsigned long data, int nbits);
#endif
#ifdef IRsendRC6
void sendRC6(unsigned long data, int nbits); void sendRC6(unsigned long data, int nbits);
#endif
#ifdef IRsendDISH
void sendDISH(unsigned long data, int nbits); void sendDISH(unsigned long data, int nbits);
#endif
#ifdef IRsendSHARP
void sendSharp(unsigned long data, int nbits); void sendSharp(unsigned long data, int nbits);
#endif
#ifdef IRsendPANASONIC
void sendPanasonic(unsigned int address, unsigned long data); void sendPanasonic(unsigned int address, unsigned long data);
#endif
#ifdef IRsendJVC
void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does. void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does.
// private: // private:
#endif
#ifdef IRsendSAMSUNG
void sendSAMSUNG(unsigned long data, int nbits); void sendSAMSUNG(unsigned long data, int nbits);
#endif
void enableIROut(int khz); void enableIROut(int khz);
VIRTUAL void mark(int usec); VIRTUAL void mark(int usec);
VIRTUAL void space(int usec); VIRTUAL void space(int usec);