mirror of
https://github.com/Theaninova/Arduino-IRremote.git
synced 2025-12-11 08:56:14 +00:00
More cleanup and a few minor optimisations
This commit is contained in:
419
IRremote.h
419
IRremote.h
@@ -1,17 +1,104 @@
|
||||
|
||||
//******************************************************************************
|
||||
// IRremote
|
||||
// Version 0.1 July, 2009
|
||||
// Copyright 2009 Ken Shirriff
|
||||
// For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com
|
||||
// Edited by Mitra to add new controller SANYO
|
||||
//
|
||||
// Interrupt code based on NECIRrcv by Joe Knapp
|
||||
// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
|
||||
// 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)
|
||||
// Whynter A/C ARC-110WD added by Francesco Meschia
|
||||
//******************************************************************************
|
||||
|
||||
#ifndef IRremote_h
|
||||
#define IRremote_h
|
||||
|
||||
#define DEBUG
|
||||
#undef DEBUG
|
||||
//------------------------------------------------------------------------------
|
||||
// Supported IR protocols
|
||||
// Each protocol you include costs memory and, during decode, costs time
|
||||
// Disable (set to 0) all the protocols you do not need/want!
|
||||
//
|
||||
#define DECODE_RC5 1
|
||||
#define SEND_RC5 1
|
||||
|
||||
#define DECODE_RC6 1
|
||||
#define SEND_RC6 1
|
||||
|
||||
#define DECODE_NEC 1
|
||||
#define SEND_NEC 1
|
||||
|
||||
#define DECODE_SONY 1
|
||||
#define SEND_SONY 1
|
||||
|
||||
#define DECODE_PANASONIC 1
|
||||
#define SEND_PANASONIC 1
|
||||
|
||||
#define DECODE_JVC 1
|
||||
#define SEND_JVC 1
|
||||
|
||||
#define DECODE_SAMSUNG 1
|
||||
#define SEND_SAMSUNG 1
|
||||
|
||||
#define DECODE_WHYNTER 1
|
||||
#define SEND_WHYNTER 1
|
||||
|
||||
#define DECODE_AIWA_RC_T501 1
|
||||
#define SEND_AIWA_RC_T501 1
|
||||
|
||||
#define DECODE_LG 1
|
||||
#define SEND_LG 0 // NOT WRITTEN
|
||||
|
||||
#define DECODE_SANYO 1
|
||||
#define SEND_SANYO 0 // NOT WRITTEN
|
||||
|
||||
#define DECODE_MITSUBISHI 1
|
||||
#define SEND_MITSUBISHI 0 // NOT WRITTEN
|
||||
|
||||
#define DECODE_DISH 0 // NOT WRITTEN
|
||||
#define SEND_DISH 1
|
||||
|
||||
#define DECODE_SHARP 0 // NOT WRITTEN
|
||||
#define SEND_SHARP 1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
int MATCH_SPACE (int measured_ticks, int desired_us) ;
|
||||
int MATCH_MARK (int measured_ticks, int desired_us) ;
|
||||
int MATCH (int measured, int desired) ;
|
||||
// An enumerated list of all supported formats
|
||||
// You do NOT need to remove entries from this list when disabling protocols!
|
||||
//
|
||||
typedef
|
||||
enum {
|
||||
UNKNOWN = -1,
|
||||
UNUSED = 0,
|
||||
RC5 = 1,
|
||||
RC6 = 2,
|
||||
NEC = 3,
|
||||
SONY = 4,
|
||||
PANASONIC = 5,
|
||||
JVC = 6,
|
||||
SAMSUNG = 7,
|
||||
WHYNTER = 8,
|
||||
AIWA_RC_T501 = 9,
|
||||
LG = 10,
|
||||
SANYO = 11,
|
||||
MITSUBISHI = 12,
|
||||
DISH = 13,
|
||||
SHARP = 14,
|
||||
}
|
||||
decode_type_t;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Set DEBUG to 1 for lots of lovely debug output
|
||||
//
|
||||
#define DEBUG 0
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Debug directives
|
||||
#ifdef DEBUG
|
||||
//
|
||||
#if DEBUG
|
||||
# define DBG_PRINT(...) Serial.print(__VA_ARGS__)
|
||||
# define DBG_PRINTLN(...) Serial.println(__VA_ARGS__)
|
||||
#else
|
||||
@@ -20,77 +107,11 @@ int MATCH (int measured, int desired) ;
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define SEND_NEC
|
||||
#define DECODE_NEC
|
||||
#define SEND_WHYNTER
|
||||
#define DECODE_WHYNTER
|
||||
#define SEND_SONY
|
||||
#define DECODE_SONY
|
||||
#define DECODE_SANYO
|
||||
#define SEND_RC5
|
||||
#define DECODE_RC5
|
||||
#define SEND_RC6
|
||||
#define DECODE_RC6
|
||||
#define SEND_PANASONIC
|
||||
#define DECODE_PANASONIC
|
||||
#define SEND_JVC
|
||||
#define DECODE_JVC
|
||||
#define SEND_SAMSUNG
|
||||
#define DECODE_SAMSUNG
|
||||
#define DECODE_LG
|
||||
#define DECODE_MITSUBISHI
|
||||
#define SEND_AIWA_RC_T501
|
||||
#define DECODE_AIWA_RC_T501
|
||||
#define SEND_SHARP
|
||||
#define SEND_DISH
|
||||
|
||||
/*
|
||||
* IRremote
|
||||
* Version 0.1 July, 2009
|
||||
* Copyright 2009 Ken Shirriff
|
||||
* For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com
|
||||
* Edited by Mitra to add new controller SANYO
|
||||
*
|
||||
* Interrupt code based on NECIRrcv by Joe Knapp
|
||||
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
|
||||
* 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)
|
||||
* Whynter A/C ARC-110WD added by Francesco Meschia
|
||||
*/
|
||||
|
||||
// The following are compile-time library options.
|
||||
// If you change them, recompile the library.
|
||||
// If DEBUG is defined, a lot of debugging output will be printed during decoding.
|
||||
// TEST must be defined for the IRtest unittests to work. It will make some
|
||||
// methods virtual, which will be slightly slower, which is why it is optional.
|
||||
//#define DEBUG
|
||||
// #define TEST
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// An enumerated list of all supported formats
|
||||
// Mark & Space matching functions
|
||||
//
|
||||
typedef
|
||||
enum {
|
||||
UNKNOWN = -1,
|
||||
UNUSED = 0,
|
||||
NEC = 1,
|
||||
SONY = 2,
|
||||
RC5 = 3,
|
||||
RC6 = 4,
|
||||
DISH = 5,
|
||||
SHARP = 6,
|
||||
PANASONIC = 7,
|
||||
JVC = 8,
|
||||
SANYO = 9,
|
||||
MITSUBISHI = 10,
|
||||
SAMSUNG = 11,
|
||||
LG = 12,
|
||||
WHYNTER = 13,
|
||||
AIWA_RC_T501 = 14,
|
||||
}
|
||||
decode_type_t;
|
||||
int MATCH (int measured, int desired) ;
|
||||
int MATCH_MARK (int measured_ticks, int desired_us) ;
|
||||
int MATCH_SPACE (int measured_ticks, int desired_us) ;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Results returned from the decoder
|
||||
@@ -99,130 +120,168 @@ class decode_results
|
||||
{
|
||||
public:
|
||||
decode_type_t decode_type; // UNKNOWN, NEC, SONY, RC5, ...
|
||||
unsigned int address; // Used by Panasonic & Sharp
|
||||
unsigned long value; // Decoded value
|
||||
unsigned int address; // Used by Panasonic & Sharp [16-bits]
|
||||
unsigned long value; // Decoded value [max 32-bits]
|
||||
int bits; // Number of bits in decoded value
|
||||
volatile unsigned int *rawbuf; // Raw intervals in 50uS ticks
|
||||
int rawlen; // Number of records in rawbuf.
|
||||
int rawlen; // Number of records in rawbuf
|
||||
int overflow; // true iff IR raw code too long
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Decoded value for NEC when a repeat code is received
|
||||
//
|
||||
#define REPEAT 0xffffffff
|
||||
#define REPEAT 0xFFFFFFFF
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// main class for receiving IR
|
||||
// Main class for receiving IR
|
||||
//
|
||||
class IRrecv
|
||||
{
|
||||
public:
|
||||
IRrecv(int recvpin);
|
||||
void blink13(int blinkflag);
|
||||
int decode(decode_results *results);
|
||||
void enableIRIn();
|
||||
void resume();
|
||||
private:
|
||||
// These are called by decode
|
||||
int getRClevel(decode_results *results, int *offset, int *used, int t1);
|
||||
#ifdef DECODE_NEC
|
||||
long decodeNEC(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_SONY
|
||||
long decodeSony(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_SANYO
|
||||
long decodeSanyo(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_MITSUBISHI
|
||||
long decodeMitsubishi(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_RC5
|
||||
long decodeRC5(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_RC6
|
||||
long decodeRC6(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_PANASONIC
|
||||
long decodePanasonic(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_LG
|
||||
long decodeLG(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_JVC
|
||||
long decodeJVC(decode_results *results);
|
||||
#endif
|
||||
#ifdef DECODE_SAMSUNG
|
||||
long decodeSAMSUNG(decode_results *results);
|
||||
#endif
|
||||
public:
|
||||
IRrecv (int recvpin) ;
|
||||
|
||||
#ifdef DECODE_WHYNTER
|
||||
long decodeWhynter(decode_results *results);
|
||||
#endif
|
||||
void blink13 (int blinkflag) ;
|
||||
int decode (decode_results *results) ;
|
||||
void enableIRIn ( ) ;
|
||||
void resume ( ) ;
|
||||
|
||||
#ifdef DECODE_AIWA_RC_T501
|
||||
long decodeAiwaRCT501(decode_results *results);
|
||||
#endif
|
||||
|
||||
long decodeHash(decode_results *results);
|
||||
int compare(unsigned int oldval, unsigned int newval);
|
||||
private:
|
||||
long decodeHash (decode_results *results) ;
|
||||
int compare (unsigned int oldval, unsigned int newval) ;
|
||||
|
||||
//......................................................................
|
||||
# if (DECODE_RC5 || DECODE_RC6)
|
||||
// This helper function is shared by RC5 and RC6
|
||||
int getRClevel (decode_results *results, int *offset, int *used, int t1) ;
|
||||
# endif
|
||||
# if DECODE_RC5
|
||||
bool decodeRC5 (decode_results *results) ;
|
||||
# endif
|
||||
# if DECODE_RC6
|
||||
bool decodeRC6 (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_NEC
|
||||
bool decodeNEC (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_SONY
|
||||
bool decodeSony (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_PANASONIC
|
||||
bool decodePanasonic (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_JVC
|
||||
bool decodeJVC (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_SAMSUNG
|
||||
bool decodeSAMSUNG (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_WHYNTER
|
||||
bool decodeWhynter (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_AIWA_RC_T501
|
||||
bool decodeAiwaRCT501 (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_LG
|
||||
bool decodeLG (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_SANYO
|
||||
bool decodeSanyo (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_MITSUBISHI
|
||||
bool decodeMitsubishi (decode_results *results) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_DISH
|
||||
bool decodeDish (decode_results *results) ; // NOT WRITTEN
|
||||
# endif
|
||||
//......................................................................
|
||||
# if DECODE_SHARP
|
||||
bool decodeSharp (decode_results *results) ; // NOT WRITTEN
|
||||
# endif
|
||||
} ;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Only used for testing; can remove virtual for shorter code
|
||||
#ifdef TEST
|
||||
#define VIRTUAL virtual
|
||||
#else
|
||||
#define VIRTUAL
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
class IRsend
|
||||
{
|
||||
public:
|
||||
IRsend() {}
|
||||
void sendRaw(unsigned int buf[], int len, int hz);
|
||||
#ifdef SEND_RC5
|
||||
void sendRC5(unsigned long data, int nbits);
|
||||
#endif
|
||||
#ifdef SEND_RC6
|
||||
void sendRC6(unsigned long data, int nbits);
|
||||
#endif
|
||||
#ifdef SEND_WHYNTER
|
||||
void sendWhynter(unsigned long data, int nbits);
|
||||
#endif
|
||||
#ifdef SEND_NEC
|
||||
void sendNEC(unsigned long data, int nbits);
|
||||
#endif
|
||||
#ifdef SEND_SONY
|
||||
void sendSony(unsigned long data, int nbits);
|
||||
// Neither Sanyo nor Mitsubishi send is implemented yet
|
||||
// void sendSanyo(unsigned long data, int nbits);
|
||||
// void sendMitsubishi(unsigned long data, int nbits);
|
||||
#endif
|
||||
#ifdef SEND_DISH
|
||||
void sendDISH(unsigned long data, int nbits);
|
||||
#endif
|
||||
#ifdef SEND_SHARP
|
||||
void sendSharpRaw(unsigned long data, int nbits);
|
||||
void sendSharp(unsigned int address, unsigned int command);
|
||||
#endif
|
||||
#ifdef SEND_PANASONIC
|
||||
void sendPanasonic(unsigned int address, unsigned long data);
|
||||
#endif
|
||||
#ifdef SEND_JVC
|
||||
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.
|
||||
#endif
|
||||
#ifdef SEND_AIWA_RC_T501
|
||||
void sendAiwaRCT501(int code);
|
||||
#endif
|
||||
#ifdef SEND_SAMSUNG
|
||||
void sendSAMSUNG(unsigned long data, int nbits);
|
||||
#endif
|
||||
void enableIROut(int khz);
|
||||
VIRTUAL void mark(int usec);
|
||||
VIRTUAL void space(int usec);
|
||||
public:
|
||||
IRsend () { }
|
||||
|
||||
void enableIROut (int khz) ;
|
||||
void mark (int usec) ;
|
||||
void space (int usec) ;
|
||||
void sendRaw (unsigned int buf[], int len, int hz) ;
|
||||
|
||||
//......................................................................
|
||||
# if SEND_RC5
|
||||
void sendRC5 (unsigned long data, int nbits) ;
|
||||
# endif
|
||||
# if SEND_RC6
|
||||
void sendRC6 (unsigned long data, int nbits) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_NEC
|
||||
void sendNEC (unsigned long data, int nbits) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_SONY
|
||||
void sendSony (unsigned long data, int nbits) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_PANASONIC
|
||||
void sendPanasonic (unsigned int address, unsigned long data) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_JVC
|
||||
// JVC does NOT repeat by sending a separate code (like NEC does).
|
||||
// The JVC protocol repeats by skipping the header.
|
||||
// To send a JVC repeat signal, send the original code value
|
||||
// and set 'repeat' to true
|
||||
void sendJVC (unsigned long data, int nbits, bool repeat) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_SAMSUNG
|
||||
void sendSAMSUNG (unsigned long data, int nbits) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_WHYNTER
|
||||
void sendWhynter (unsigned long data, int nbits) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_AIWA_RC_T501
|
||||
void sendAiwaRCT501 (int code) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_LG
|
||||
void sendLG ( ) ; // NOT WRITTEN
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_SANYO
|
||||
void sendSanyo ( ) ; // NOT WRITTEN
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_MISUBISHI
|
||||
void sendMitsubishi ( ) ; // NOT WRITTEN
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_DISH
|
||||
void sendDISH (unsigned long data, int nbits) ;
|
||||
# endif
|
||||
//......................................................................
|
||||
# if SEND_SHARP
|
||||
void sendSharpRaw (unsigned long data, int nbits) ;
|
||||
void sendSharp (unsigned int address, unsigned int command) ;
|
||||
# endif
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user