Commit 9f5ce25e authored by Chris Young's avatar Chris Young

upgrade from 1.1 to 1.3

Added IRrecvBase class so other receiver classes can be implemented.
Memory improvements.
New analysis tools include modulation frequency detection.
Examples for new protocols Samsung36, DirecTV, GIcable.
See changes.txt for complete list of changes.
parent 9513494e
Change Log for IRLib – an Arduino library for infrared encoding and decoding Change Log for IRLib – an Arduino library for infrared encoding and decoding
Copyright 2013 by Chris Young http://cyborg5.com Copyright 2013-2014 by Chris Young http://tech.cyborg5.com/irlib/
April 2013 Version 1.1 Constructor of IRsendBase now initializes output
pin and forces it low immediately.
New IRrecv::No_Output() method initializes output Version 1.3 – January 2014
pin and forces it low. Use this in sketches which NEW FILES
receive only by the have output hardware connected. Added new file IRLibRData.h and moved irparams structure and related items to that file. Allows users to create custom IRrecv classes
NEW EXAMPLES
Added examples IRservo and IRserial_remote Rewrote Samsung36 example to include both send and receive
Added new examples for new protocols DirecTV and GIcable
February 2013 Version 1.0a Removed debugging test switch which was accidentally Added new example IRanalyze gives more detailed analysis of timing. Useful in analyzing the protocols
left on in file "IRLib.h" Added new example IRfreq reports modulation frequency of a signal. Requires TSMP58000 IR learner chip
Cleanup of other example routines.
January 2013 Version 1.0 Initial Release NEW CLASSES
\ No newline at end of file Created IRrecvBase class to allow custom receiver classes. IRrecv is now a derived class from it.
Created IRrecvLoop class which receives IR signals without using any hardware interrupts or timers. Also created IRrecvPCI class which uses Pin Change Interrupts to receive IR signals. These new receivers are more accurate than the 50µs timing of the original IRrecv. However they also have other limitations described in comments.
New functions, variables and methods
In IRrecvBase added "unsigned char Mark_Excess" with default value 100. Was a define macro but now is user settable.
In IRrecvBase added method "unsigned char getPinNum(void);" which retrieves the pin number used from irparams.recvpin. This value not normally accessible to end user.
Globally available function "void do_Blink(void);" blinks pin 13 LED. For use by user created extensions of IRrecvBase.
INTERNAL CHANGES
Data collected by IRrecvBase classes in irparams.rawbuf is now converted to actual microseconds rather than clock ticks of 50 µs each. IRrecvBase::GetResults has a new parameter "Time_per_Ticks" that is used to convert ticks into actual microseconds if needed.
Adjustments to mark and space to deal with overreporting and underreporting of intervals is now done once in IRrecvBase::GetResults eliminating the need for MATCH_MARK(d,v) and MATCH_SPACE(d,v). Just use MATCH(d,v) everywhere.
Modified IRLibsendBase::mark() and IRLibsendBase::space() to overcome limitations of "delayMicroseconds()".
Changed many int to char or unsigned char to save memory
Eliminated DEBUG macro in IRLib.h and its use elsewhere. Macro TRACE is more useful.
Changed IRTYPES to unsigned char and a list of #defines rather than an enum (even though I still really like enums, changing it saves memory)
MEMORY EFFICIENCY
Code changes result in memory savings of approximately 54 bytes in code space and 39 bytes of RAM.
--------------------------------
Version 1.2 – July 2013
Internal version. No public release
--------------------------------
Version 1.1 – April 2013
Constructor of IRsendBase now initializes output pin and forces it low immediately.
New IRrecv::No_Output() method initializes output pin and forces it low. Use this in sketches which receive only by the have output hardware connected.
Added examples IRservo and IRserial_remote
--------------------------------
Version 1.0a – February 2013
Removed debugging test switch which was accidentally left on in file "IRLib.h"
--------------------------------
Version 1.0 – January 2013
Initial Release
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/* IRLibMatch.h from IRLib an Arduino library for infrared encoding and decoding /* IRLibMatch.h from IRLib an Arduino library for infrared encoding and decoding
* Version 1.0 January 2013 * Version 1.3 January 2014
* Copyright 2013 by Chris Young http://cyborg5.com * Copyright 2014 by Chris Young http://cyborg5.com
* *
* This library is a major rewrite of IRemote by Ken Shirriff which was covered by * This library is a major rewrite of IRemote by Ken Shirriff which was covered by
* GNU LESSER GENERAL PUBLIC LICENSE which as I read it allows me to make modified versions. * GNU LESSER GENERAL PUBLIC LICENSE which as I read it allows me to make modified versions.
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
* My purpose was to reorganize the code to make it easier to add or remove protocols. * My purpose was to reorganize the code to make it easier to add or remove protocols.
* As a result I have separated the act of receiving a set of raw timing codes from the act of decoding them * As a result I have separated the act of receiving a set of raw timing codes from the act of decoding them
* by making them separate classes. That way the receiving aspect can be more black box and implementers * by making them separate classes. That way the receiving aspect can be more black box and implementers
* of decoders and senders can just deal with the decoding of protocols. * of decoders and senders can just deal with the decoding of protocols. It also allows for alternative
* types of receivers independent of the decoding. This makes porting to different hardware platforms easier.
* Also added provisions to make the classes base classes that could be extended with new protocols * Also added provisions to make the classes base classes that could be extended with new protocols
* which would not require recompiling of the original library nor understanding of its detailed contents. * which would not require recompiling of the original library nor understanding of its detailed contents.
* Some of the changes were made to reduce code size such as unnecessary use of long versus bool. * Some of the changes were made to reduce code size such as unnecessary use of long versus bool.
...@@ -19,7 +20,7 @@ ...@@ -19,7 +20,7 @@
* IRremote * IRremote
* Version 0.1 July, 2009 * Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff * Copyright 2009 Ken Shirriff
* For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com * For details, see http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html http://www.righto.com/
* *
* Interrupt code based on NECIRrcv by Joe Knapp * Interrupt code based on NECIRrcv by Joe Knapp
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
...@@ -36,27 +37,20 @@ ...@@ -36,27 +37,20 @@
* don't need to be intimately familiar with the internal details. * don't need to be intimately familiar with the internal details.
*/ */
// Marks tend to be 100us too long, and spaces 100us too short
// when received due to sensor lag.
#define MARK_EXCESS 100
#define USECPERTICK 50 // microseconds per clock interrupt tick #define USECPERTICK 50 // microseconds per clock interrupt tick
#define TOLERANCE 25 // percent tolerance in measurements #define TOLERANCE 25 // percent tolerance in measurements
#define TICKS_LOW(us) (int) (((us)*(1.0 - TOLERANCE/100.)/USECPERTICK)) #define TICKS_LOW(us) (unsigned int) (((us)*(1.0 - TOLERANCE/100.)))
#define TICKS_HIGH(us) (int) (((us)*(1.0 + TOLERANCE/100.)/USECPERTICK + 1)) #define TICKS_HIGH(us) (unsigned int) (((us)*(1.0 + TOLERANCE/100.) + 1))
#ifdef DEBUG
int MATCH(int measured, int desired);
int MATCH_MARK(int measured_ticks, int desired_us);
int MATCH_SPACE(int measured_ticks, int desired_us);
#else
#define MATCH(measured_ticks, desired_us) ((measured_ticks) >= TICKS_LOW(desired_us) && (measured_ticks) <= TICKS_HIGH(desired_us))
#define MATCH_MARK(measured_ticks, desired_us) MATCH(measured_ticks, (desired_us) + MARK_EXCESS)
#define MATCH_SPACE(measured_ticks, desired_us) MATCH((measured_ticks), (desired_us) - MARK_EXCESS)
#endif
#define MATCH(measured_ticks, desired_us) ((measured_ticks) >= TICKS_LOW(desired_us) && (measured_ticks) <= TICKS_HIGH(desired_us))
//The following two routines are no longer necessary because mark/space adjustments are done elsewhere
//These definitions maintain backward compatibility.
#define MATCH_MARK(t,u) MATCH(t,u)
#define MATCH_SPACE(t,u) MATCH(t,u)
#ifdef TRACE #ifdef TRACE
void ATTEMPT_MESSAGE(const __FlashStringHelper * s); void ATTEMPT_MESSAGE(const __FlashStringHelper * s);
void TRACE_MESSAGE(const __FlashStringHelper * s);
byte REJECTION_MESSAGE(const __FlashStringHelper * s); byte REJECTION_MESSAGE(const __FlashStringHelper * s);
#define RAW_COUNT_ERROR REJECTION_MESSAGE(F("number of raw samples")); #define RAW_COUNT_ERROR REJECTION_MESSAGE(F("number of raw samples"));
#define HEADER_MARK_ERROR REJECTION_MESSAGE(F("header mark")); #define HEADER_MARK_ERROR REJECTION_MESSAGE(F("header mark"));
...@@ -66,6 +60,7 @@ byte REJECTION_MESSAGE(const __FlashStringHelper * s); ...@@ -66,6 +60,7 @@ byte REJECTION_MESSAGE(const __FlashStringHelper * s);
#define TRAILER_BIT_ERROR REJECTION_MESSAGE(F("RC5/RC6 trailer bit length")); #define TRAILER_BIT_ERROR REJECTION_MESSAGE(F("RC5/RC6 trailer bit length"));
#else #else
#define ATTEMPT_MESSAGE(s) #define ATTEMPT_MESSAGE(s)
#define TRACE_MESSAGE(s)
#define REJECTION_MESSAGE(s) false #define REJECTION_MESSAGE(s) false
#define RAW_COUNT_ERROR false #define RAW_COUNT_ERROR false
#define HEADER_MARK_ERROR false #define HEADER_MARK_ERROR false
......
/* IRLibRData.h from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.3 January 2014
* Copyright 2014 by Chris Young http://cyborg5.com
*
* This library is a major rewrite of IRemote by Ken Shirriff which was covered by
* GNU LESSER GENERAL PUBLIC LICENSE which as I read it allows me to make modified versions.
* That same license applies to this modified version. See his original copyright below.
* The latest Ken Shirriff code can be found at https://github.com/shirriff/Arduino-IRremote
* My purpose was to reorganize the code to make it easier to add or remove protocols.
* As a result I have separated the act of receiving a set of raw timing codes from the act of decoding them
* by making them separate classes. That way the receiving aspect can be more black box and implementers
* of decoders and senders can just deal with the decoding of protocols. It also allows for alternative
* types of receivers independent of the decoding. This makes porting to different hardware platforms easier.
* Also added provisions to make the classes base classes that could be extended with new protocols
* which would not require recompiling of the original library nor understanding of its detailed contents.
* Some of the changes were made to reduce code size such as unnecessary use of long versus bool.
* Some changes were just my weird programming style. Also extended debugging information added.
*/
/*
* IRremote
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* For details, see http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html http://www.righto.com/
*
* 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/
*/
#ifndef IRLibRData_h
#define IRLibRData_h
/*
* The structure contains a variety of variables needed by the receiver routines.
* Typically this data would be part of the IRrecv class however the interrupt service routine
* must have access to it and you cannot pass a parameter to such a routine. The data must be global.
* You need not include this file unless you are creating a custom receiver class or extending
* the provided IRrecv class.
*/
// receiver states
enum rcvstate_t {STATE_UNKNOWN, STATE_IDLE, STATE_MARK, STATE_SPACE, STATE_STOP, STATE_RUNNING};
// information for the interrupt handler
typedef struct {
unsigned char recvpin; // pin for IR data from detector
rcvstate_t rcvstate; // state machine
bool blinkflag; // TRUE to enable blinking of pin 13 on IR processing
unsigned long timer; // state timer, counts 50uS ticks.(and other uses)
unsigned int rawbuf[RAWBUF]; // raw data
unsigned char rawlen; // counter of entries in rawbuf
}
irparams_t;
extern volatile irparams_t irparams;
#endif
/* IRLibTimer.h from IRLib an Arduino library for infrared encoding and decoding /* IRLibTimer.h from IRLib an Arduino library for infrared encoding and decoding
* Version 1.0 January 2013 * Version 1.3 January 2014
* Copyright 2013 by Chris Young http://cyborg5.com * Copyright 2014 by Chris Young http://cyborg5.com
* *
* This library is a major rewrite of IRemote by Ken Shirriff which was covered by * This library is a major rewrite of IRemote by Ken Shirriff which was covered by
* GNU LESSER GENERAL PUBLIC LICENSE which as I read it allows me to make modified versions. * GNU LESSER GENERAL PUBLIC LICENSE which as I read it allows me to make modified versions.
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
* My purpose was to reorganize the code to make it easier to add or remove protocols. * My purpose was to reorganize the code to make it easier to add or remove protocols.
* As a result I have separated the act of receiving a set of raw timing codes from the act of decoding them * As a result I have separated the act of receiving a set of raw timing codes from the act of decoding them
* by making them separate classes. That way the receiving aspect can be more black box and implementers * by making them separate classes. That way the receiving aspect can be more black box and implementers
* of decoders and senders can just deal with the decoding of protocols. * of decoders and senders can just deal with the decoding of protocols. It also allows for alternative
* types of receivers independent of the decoding. This makes porting to different hardware platforms easier.
* Also added provisions to make the classes base classes that could be extended with new protocols * Also added provisions to make the classes base classes that could be extended with new protocols
* which would not require recompiling of the original library nor understanding of its detailed contents. * which would not require recompiling of the original library nor understanding of its detailed contents.
* Some of the changes were made to reduce code size such as unnecessary use of long versus bool. * Some of the changes were made to reduce code size such as unnecessary use of long versus bool.
...@@ -19,7 +20,7 @@ ...@@ -19,7 +20,7 @@
* IRremote * IRremote
* Version 0.1 July, 2009 * Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff * Copyright 2009 Ken Shirriff
* For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com * For details, see http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html http://www.righto.com/
* *
* Interrupt code based on NECIRrcv by Joe Knapp * Interrupt code based on NECIRrcv by Joe Knapp
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
......
IRLib – an Arduino library for infrared encoding and decoding IRLib – an Arduino library for infrared encoding and decoding
Version 1.1 april 2013 Version 1.3 January 2014
Copyright 2013 by Chris Young http://cyborg5.com Copyright 2013, 2014 by Chris Young http://cyborg5.com
This library is a major rewrite of IRemote by Ken Shirriff which was covered This library is a major rewrite of IRemote by Ken Shirriff which was covered
by GNU LESSER GENERAL PUBLIC LICENSE which as I read it allows me to make by GNU LESSER GENERAL PUBLIC LICENSE which as I read it allows me to make
...@@ -43,28 +43,36 @@ iRLibTimer.h Attempts to detect type of Arduino board and allows you to modify w ...@@ -43,28 +43,36 @@ iRLibTimer.h Attempts to detect type of Arduino board and allows you to modify w
library. Alternate board and timer information based on a fork of the library. Alternate board and timer information based on a fork of the
original KS library. That for can be found here. original KS library. That for can be found here.
https://github.com/TKJElectronics/Arduino-IRremote https://github.com/TKJElectronics/Arduino-IRremote
IRLibRData.h Moved irparams structure and related data to this header to facilitate
user created extensions to IRrecvBase.
Note: there is no "IRremoteInt.h" header as in the original library. Those values were Note: there is no "IRremoteInt.h" header as in the original library. Those values were
moved elsewhere. moved elsewhere.
The examples directory contains: The examples directory contains:
IRanalyze Dumps detailed information about a recent signal. Useful for analyzing
unknown protocols
IRfreq Reports modulation frequency of IR signal. Requires TSMP58000 IR learner
IRhashdecode Demonstrates hash decoder. IRhashdecode Demonstrates hash decoder.
IRrecord Recording incoming signal and play it back when a character is sent IRrecord Recording incoming signal and play it back when a character is sent
through the serial console. By using the console you no longer need through the serial console. By using the console you no longer need
to wire up a pushbutton to run this code. to wire up a pushbutton to run this code.
IRrecvDump Receives a code, attempts to decode it, produces well formatted IRrecvDump Receives a code, attempts to decode it, produces well formatted
output of the results using the new "dump" method. output of the results using the new "dump" method.
IRsendDemo Simplistic demo to send a Sony DVD power signal every time a IRsendDemo Simplistic demo to send a Sony DVD power signal every time a
character is received from the serial monitor. character is received from the serial monitor.
IRsendJVC Demonstrates sending a code using JVC protocol which is tricky. IRsendJVC Demonstrates sending a code using JVC protocol which is tricky.
Samsung36 Demonstrates how to expand the library without recompiling it.
Also demonstrates how to handle codes that are longer than 32 bits.
IRservo Demonstrates controlling a servo motor using an IR remote IRservo Demonstrates controlling a servo motor using an IR remote
IRserial_remote Demonstrates a Python application that runs on your PC and sends IRserial_remote Demonstrates a Python application that runs on your PC and sends
serial data to Arduino which in turn sends IR remote signals. serial data to Arduino which in turn sends IR remote signals.
Samsung36 Demonstrates how to expand the library without recompiling it.
Also demonstrates how to handle codes that are longer than 32 bits.
DirecTV Demonstrates additional protocol for DirecTV
GIcable Demonstrates additional protocol for GIcable used by Motorola cable boxes
Note: I did not port any of the other demo sketches although I may add IRTest later. Note: I did not port any of the other demo sketches although I may add IRTest later.
**************************************************** ****************************************************
The library handles the following protocols: The library handles the following protocols:
NEC, Sony, RC5, RC6, Raw all of which were supported in the KS version. NEC, Sony, RC5, RC6, Raw all of which were supported in the KS version.
Additionally added Panasonic_Old, JVC, NECx. Additionally added Panasonic_Old, JVC, NECx.
Also added KS hash code routines which he released separately. Also added KS hash code routines which he released separately.
Example code included but not in the library: Samsung36, DirecTV, GIcable.
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.3 January 2014
* Copyright 2014 by Chris Young http://cyborg5.com
* Based on original example sketch for IRremote library
* Version 0.11 September, 2009I know prescription and no
* Copyright 2009 Ken Shirriff
* http://www.righto.com/
*/
/*
* This example demonstrates how to extend this library to add a new protocol
* without actually modifying or recompiling the library itself. It implements the protocol
* used by DirecTV. This protocol actually comes in six different varieties.
* It uses three different frequencies 38, 40, or 57 kHz. It also uses two different varieties
* lead out times either 9000us or 30000us. The default is 38 kHz and 30000us.
* You can use a different constructor for the other varieties.
* This is a modified version of the IRecord example.
* If you would like to make this a permanent part of your library you could copy the class
* prototypes to IRLib.h and the code itself to IRLib.cpp. Search for the word "ADDITIONAL"
* to see where to add various pieces of code. Also see the Samsung36 example for details.
*/
#include <IRLib.h>
#include <IRLibMatch.h>
class IRdecodeDirecTV: public virtual IRdecodeBase
{
public:
bool decode(void);
bool Repeat;
};
class IRsendDirecTV: public virtual IRsendBase
{
public:
IRsendDirecTV (int khz= 38,bool LongLeadOut=true);
void send(unsigned long data, bool Repeat);
int Freq;
unsigned int LeadOut;
};
#define DIRECTV (LAST_PROTOCOL+1)
/*
* According to http://www.hifi-remote.com/johnsfine/DecodeIR.html#DirecTV
* The IRP notation for this protocol is:
*{38k,600,msb}<1,-1|1,-2|2,-1|2,-2>(5,(5,-2,D:4,F:8,C:4,1,-50)+) {C=7*(F:2:6)+5*(F:2:4)+3*(F:2:2)+(F:2)}
* Unlike most protocols which use a fixed length mark and a variable length or a variable length
* mark a fixed length space, this protocol varies both the mark and the space.
* The stream is still a series of marks and spaces but the length of either of those
* denotes a one or zero. A length of 1200us=logical 1 and length 600us=logical 0
* It also makes changes to the length of the header mark to devote repeat codes.
* The first header mark should be 6000us but repeat codes should only be 3000us.
*/
bool IRdecodeDirecTV::decode(void) {
long data; int offset;
ATTEMPT_MESSAGE(F("DirecTV"));
if (rawlen != 20) return RAW_COUNT_ERROR;
if (MATCH(rawbuf[1],3000))
Repeat=true;
else
if (!MATCH(rawbuf[1],6000)){
return HEADER_MARK_ERROR;
} else {
Repeat=false;
}
if (!MATCH(rawbuf[2],1200)) return HEADER_SPACE_ERROR;
offset=3; data=0;
while (offset < 18) {
if (MATCH(rawbuf[offset],1200)) {
data = (data << 1) | 1;
}
else if (MATCH(rawbuf[offset],600)) {
data <<= 1;
}
else return DATA_MARK_ERROR;
offset++;
if (MATCH(rawbuf[offset],1200)) {
data = (data << 1) | 1;
}
else if (MATCH (rawbuf[offset],600)) {
data <<= 1;
}
else return DATA_SPACE_ERROR;
offset++;
}
if (!MATCH(rawbuf[1],6000)) return DATA_MARK_ERROR;
bits = 16;//set bit length
value = data;//put remaining bits in value
decode_type= static_cast<IRTYPES>DIRECTV;
return true;
};
//See the comment at the top about different frequencies and lead out times
IRsendDirecTV::IRsendDirecTV (int khz, bool LongLeadOut){
Freq=khz;
if (LongLeadOut) LeadOut=50*600; else LeadOut=15*600;
};
void IRsendDirecTV::send(unsigned long data, bool Repeat) {
enableIROut(Freq);
if(Repeat) mark(3000); else mark(6000);
space(1200);//Send header
for (int i = 0; i < 8; i++) {
if (data & 0x8000) mark(1200); else mark(600);
data <<= 1;
if (data & 0x8000) space(1200); else space(600);
data <<= 1;
};
mark(600);
space(LeadOut);
};
//Create a custom class that combines this new protocol with all the others
class MyCustomSend:
public virtual IRsend,
public virtual IRsendDirecTV
{
public:
void send(IRTYPES Type, unsigned long data, int nbits);
};
void MyCustomSend::send(IRTYPES Type, unsigned long data, int nbits) {
if (Type==DIRECTV)
IRsendDirecTV::send(data,false);
else
IRsend::send(Type, data, nbits);
}
class MyCustomDecode:
public virtual IRdecode,
public virtual IRdecodeDirecTV
{
public:
virtual bool decode(void); // Calls each decode routine individually
void DumpResults(void);
};
bool MyCustomDecode::decode(void) {
if (IRdecodeDirecTV::decode()) return true;
return IRdecode::decode ();
}
void MyCustomDecode::DumpResults(void){
if(decode_type==DIRECTV) {
Serial.print(F("Decoded DirecTV: Value:")); Serial.print(value, HEX);
if (Repeat) Serial.print(F(" repeat flag"));
};
IRdecode::DumpResults();
};
MyCustomDecode My_Decoder;
MyCustomSend My_Sender;
int RECV_PIN = 11;
IRrecv My_Receiver(RECV_PIN);
IRTYPES codeType; // The type of code
unsigned long codeValue; // The data bits
int codeBits; // The length of the code in bits or for Samsung is storage for data2
bool GotOne;
void setup()
{
GotOne=false;
codeType=UNKNOWN;
codeValue=0;
codeBits=0;
Serial.begin(9600);
Serial.println(F("Send a code from your remote and we will record it."));
Serial.println(F("Type any character and press enter. We will send the recorded code."));
My_Receiver.enableIRIn(); // Start the receiver
}
void loop() {
if (Serial.read() != -1) {
if(GotOne) {
My_Sender.send(codeType,codeValue,codeBits);
Serial.print(F("Sent "));
if (codeType== DIRECTV) Serial.print(F("DirecTV")); else Serial.print(Pnames(codeType));
Serial.print(F(" Value:0x"));
Serial.print(codeValue, HEX);
Serial.print(F(" Bits:"));
Serial.println(codeBits, DEC);
My_Receiver.enableIRIn(); // Re-enable receiver
}
}
else if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if(My_Decoder.decode_type == UNKNOWN) {
Serial.println(F("Unknown type received. Ignoring."));
} else {
codeType= My_Decoder.decode_type;
codeValue= My_Decoder.value;
codeBits= My_Decoder.bits;
GotOne=true;
}
My_Decoder.DumpResults();
delay(1000);
My_Receiver.resume();
}
}
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.3 January 2014
* Copyright 2014 by Chris Young http://cyborg5.com
* Based on original example sketch for IRremote library
* Version 0.11 September, 2009I know prescription and no
* Copyright 2009 Ken Shirriff
* http://www.righto.com/
*/
/*
* This example demonstrates how to extend this library to add a new protocol
* without actually modifying or recompiling the library itself. It implements the protocol
* known as GIcable which is used by some Motorola cable boxes.
* This is a modified version of the IRecord example.
* If you would like to make this a permanent part of your library you could copy the class
* prototypes to IRLib.h and the code itself to IRLib.cpp. Search for the word "ADDITIONAL"
* to see where to add various pieces of code. Also see the Samsung36 example for details.
*/
#include <IRLib.h>
#include <IRLibMatch.h>
class IRdecodeGIcable: public virtual IRdecodeBase
{
public:
bool decode(void);
};
class IRsendGIcable: public virtual IRsendBase
{
public:
void send(unsigned long data, bool Repeat);
};
#define GICABLE (LAST_PROTOCOL+1)
/* The IRP notation for this protocol according to
* http://www.hifi-remote.com/johnsfine/DecodeIR.html#G.I. Cable
* is "{38.7k,490}<1,-4.5|1,-9>(18,-9,F:8,D:4,C:4,1,-84,(18,-4.5,1,-178)*) {C = -(D + F:4 + F:4:4)}"
*/
bool IRdecodeGIcable::decode(void) {
ATTEMPT_MESSAGE(F("GIcable"));
// Check for repeat
if (rawlen == 4 && MATCH(rawbuf[1], 490*18) && MATCH(rawbuf[2],2205)) {
bits = 0;
value = REPEAT;
decode_type= static_cast<IRTYPES>GICABLE;
return true;
}
if(!decodeGeneric(36, 18*490, 9*490, 0, 490, 9*490, 2205/*(4.5*490)*/)) return false;
decode_type= static_cast<IRTYPES>GICABLE;
return true;
};
void IRsendGIcable::send(unsigned long data, bool Repeat) {
ATTEMPT_MESSAGE(F("sending GIcable"));
if(Repeat) {
enableIROut(39);
mark (490*18); space (2205); mark (490); space(220);delay (87);//actually "space(87200);"
} else {
sendGeneric(data,16, 490*18, 490*9, 490, 490, 490*9, 2205, 39, true);
}
};
//Create a custom class that combines this new protocol with all the others
class MyCustomSend:
public virtual IRsend,
public virtual IRsendGIcable
{
public:
void send(IRTYPES Type, unsigned long data, int nbits);
};
void MyCustomSend::send(IRTYPES Type, unsigned long data, int nbits) {
if (Type==GICABLE){
IRsendGIcable::send(data,false);
//un-comment the line below to text repeats
//delay(3000); IRsendGIcable::send(data,true);
}
else
IRsend::send(Type, data, nbits);
}
class MyCustomDecode:
public virtual IRdecode,
public virtual IRdecodeGIcable
{
public:
virtual bool decode(void); // Calls each decode routine individually
void DumpResults(void);
};
bool MyCustomDecode::decode(void) {
if (IRdecodeGIcable::decode()) return true;
return IRdecode::decode ();
}
void MyCustomDecode::DumpResults(void){
if(decode_type==GICABLE) {
Serial.print(F("Decoded GIcable: Value:")); Serial.print(value, HEX);
};
IRdecode::DumpResults();
};
MyCustomDecode My_Decoder;
MyCustomSend My_Sender;
int RECV_PIN =11;
IRrecv My_Receiver(RECV_PIN);
IRTYPES codeType; // The type of code
unsigned long codeValue; // The data bits
int codeBits; // The length of the code in bits
bool GotOne;
void setup()
{
GotOne=false;
codeType=UNKNOWN;
codeValue=0;
codeBits=0;
Serial.begin(9600);
Serial.println(F("Send a code from your remote and we will record it."));
Serial.println(F("Type any character and press enter. We will send the recorded code."));
My_Receiver.enableIRIn(); // Start the receiver
}
void loop() {
if (Serial.read() != -1) {
if(GotOne) {
My_Sender.send(codeType,codeValue,codeBits);
Serial.print(F("Sent "));
if (codeType== GICABLE) Serial.print(F("GIcable")); else Serial.print(Pnames(codeType));
Serial.print(F(" Value:0x"));
Serial.print(codeValue, HEX);
Serial.print(F(" Bits:"));
Serial.println(codeBits, DEC);
My_Receiver.enableIRIn(); // Re-enable receiver
}
}
else if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if(My_Decoder.decode_type == UNKNOWN) {
Serial.println(F("Unknown type received. Ignoring."));
} else {
codeType= My_Decoder.decode_type;
codeValue= My_Decoder.value;
codeBits= My_Decoder.bits;
GotOne=true;
}
My_Decoder.DumpResults();
delay(1000);
My_Receiver.resume();
}
}
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.3 January 2014
* Copyright 2014 by Chris Young http://cyborg5.com
* Based on original example sketch for IRremote library
* Version 0.11 September, 2009
* Copyright 2009 Ken Shirriff
* http://www.righto.com/
*/
/* IRanalyze receives repeated values from a remote and averages the results. Should help in
* analyzing unknown protocols. You have to press the same key repeatedly. If you press a
* different key the totals reset and it computes new averages.
*/
#include <IRLib.h>
#include <IRLibRData.h>
int RECV_PIN = 11;
unsigned int Samples,i, LowSpace, LowMark, HighMark, HighSpace, interval,
balm,aalm,bahm,aahm,bals,aals,bahs,aahs;
unsigned char bacm,aacm,bacs,aacs, Mark_Count,Space_Count;
unsigned int Accumulated_Time[RAWBUF];
unsigned long Mark_Avg, Space_Avg,baam,aaam,baas,aaas;
//Try this program with various receivers
IRrecv My_Receiver(RECV_PIN);
//IRrecvLoop My_Receiver(RECV_PIN);
//Use interrupt=0. This is pin 2 on Arduino Uno and Mega, pin 3 on Leonardo
//IRrecvPCI My_Receiver(0);
IRdecode My_Decoder;
IRTYPES Old_Type;
unsigned long Old_Value;
void setup()
{
Serial.begin(9600);
delay(1000);while(!Serial);
My_Receiver.enableIRIn();
// My_Receiver.Mark_Excess=50;//Try different values here
Samples=0;Old_Value=0; Old_Type=UNKNOWN;
Serial.println(F("Send a signal repeatedly. We will report averages and statistics."));
}
void Tab(void) {Serial.print("\t");};
void loop() {
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if( (My_Decoder.decode_type != Old_Type) || (My_Decoder.value != Old_Value)) {
Serial.println(F("Resetting counters"));
for(i=0;i<RAWBUF;i++) {
Accumulated_Time[i]=0;
};
Samples=0;Old_Value= My_Decoder.value; Old_Type=My_Decoder.decode_type;
};
Samples++;
Serial.print(F("\nSamples=")); Serial.println(Samples,DEC);
LowSpace = LowMark=65535;
HighSpace = HighMark=0;
Mark_Avg= Space_Avg= Mark_Count= Space_Count=0;
for(i=0;i<My_Decoder.rawlen;i++){
Accumulated_Time[i]+=My_Decoder.rawbuf[i];
My_Decoder.rawbuf[i]= Accumulated_Time[i]/Samples;//Put back average so DumpResults can report
}
My_Decoder.DumpResults();
//Perform additional analysis
for(i=3;i<My_Decoder.rawlen;i++){ //Compute low, high and average mark and space
interval=My_Decoder.rawbuf[i];
if(i % 2) {
Mark_Avg += interval; LowMark=min(LowMark, interval); HighMark=max(HighMark, interval);Mark_Count++;
} else {
Space_Avg += interval; LowSpace=min(LowSpace, interval); HighSpace=max (HighSpace, interval);Space_Count++;
}
My_Decoder.rawbuf[i]= Accumulated_Time[i]/Samples;//Put back average so DumpResults can report
}
Mark_Avg /= Mark_Count; Space_Avg /= Space_Count;
//Now compute below average highs and lows and above average highs and lows
balm=bals=aalm=aals=32766;
bahm=bahs=aahm=aahs=baam=baas=aaam=aaas=0;
bacm=bacs=aacm=aacs=0;
for(i=3;