Permalink
Browse files

Initial commit from Irremote.zip

  • Loading branch information...
0 parents commit 6ee0dffb4c9fc40fc14cd2a3e6dadbc1226caccd @shirriff shirriff committed Jan 23, 2010

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,94 @@
+/*
+ * 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
+ *
+ * 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 IRremote_h
+#define IRremote_h
+
+// 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
+
+// Results returned from the decoder
+class decode_results {
+public:
+ int decode_type; // NEC, SONY, RC5, UNKNOWN
+ unsigned long value; // Decoded value
+ int bits; // Number of bits in decoded value
+ volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
+ int rawlen; // Number of records in rawbuf.
+};
+
+// Values for decode_type
+#define NEC 1
+#define SONY 2
+#define RC5 3
+#define RC6 4
+#define UNKNOWN -1
+
+// Decoded value for NEC when a repeat code is received
+#define REPEAT 0xffffffff
+
+// 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);
+ long decodeNEC(decode_results *results);
+ long decodeSony(decode_results *results);
+ long decodeRC5(decode_results *results);
+ long decodeRC6(decode_results *results);
+}
+;
+
+// Only used for testing; can remove virtual for shorter code
+#ifdef TEST
+#define VIRTUAL virtual
+#else
+#define VIRTUAL
+#endif
+
+class IRsend
+{
+public:
+ IRsend() {}
+ void sendNEC(unsigned long data, int nbits);
+ void sendSony(unsigned long data, int nbits);
+ void sendRaw(unsigned int buf[], int len, int hz);
+ void sendRC5(unsigned long data, int nbits);
+ void sendRC6(unsigned long data, int nbits);
+ // private:
+ void enableIROut(int khz);
+ VIRTUAL void mark(int usec);
+ VIRTUAL void space(int usec);
+}
+;
+
+// Some useful constants
+
+#define USECPERTICK 50 // microseconds per clock interrupt tick
+#define RAWBUF 76 // Length of raw duration buffer
+
+// Marks tend to be 100us too long, and spaces 100us too short
+// when received due to sensor lag.
+#define MARK_EXCESS 100
+
+#endif
Binary file not shown.
@@ -0,0 +1,111 @@
+/*
+ * IRremote
+ * Version 0.1 July, 2009
+ * Copyright 2009 Ken Shirriff
+ * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
+ *
+ * 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 IRremoteint_h
+#define IRremoteint_h
+
+#include <WProgram.h>
+
+#define CLKFUDGE 5 // fudge factor for clock interrupt overhead
+#define CLK 256 // max value for clock (timer 2)
+#define PRESCALE 8 // timer2 clock prescale
+#define SYSCLOCK 16000000 // main Arduino clock
+#define CLKSPERUSEC (SYSCLOCK/PRESCALE/1000000) // timer clocks per microsecond
+
+#define ERR 0
+#define DECODED 1
+
+#define BLINKLED 13
+
+// defines for setting and clearing register bits
+#ifndef cbi
+#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
+#endif
+#ifndef sbi
+#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
+#endif
+
+// clock timer reset value
+#define INIT_TIMER_COUNT2 (CLK - USECPERTICK*CLKSPERUSEC + CLKFUDGE)
+#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT2
+
+// pulse parameters in usec
+#define NEC_HDR_MARK 9000
+#define NEC_HDR_SPACE 4500
+#define NEC_BIT_MARK 560
+#define NEC_ONE_SPACE 1600
+#define NEC_ZERO_SPACE 560
+#define NEC_RPT_SPACE 2250
+
+#define SONY_HDR_MARK 2400
+#define SONY_HDR_SPACE 600
+#define SONY_ONE_MARK 1200
+#define SONY_ZERO_MARK 600
+#define SONY_RPT_LENGTH 45000
+
+#define RC5_T1 889
+#define RC5_RPT_LENGTH 46000
+
+#define RC6_HDR_MARK 2666
+#define RC6_HDR_SPACE 889
+#define RC6_T1 444
+#define RC6_RPT_LENGTH 46000
+
+#define TOLERANCE 25 // percent tolerance in measurements
+#define LTOL (1.0 - TOLERANCE/100.)
+#define UTOL (1.0 + TOLERANCE/100.)
+
+#define _GAP 5000 // Minimum map between transmissions
+#define GAP_TICKS (_GAP/USECPERTICK)
+
+#define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK))
+#define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1))
+
+#ifndef DEBUG
+#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)
+// Debugging versions are in IRremote.cpp
+#endif
+
+// receiver states
+#define STATE_IDLE 2
+#define STATE_MARK 3
+#define STATE_SPACE 4
+#define STATE_STOP 5
+
+// information for the interrupt handler
+typedef struct {
+ uint8_t recvpin; // pin for IR data from detector
+ uint8_t rcvstate; // state machine
+ uint8_t blinkflag; // TRUE to enable blinking of pin 13 on IR processing
+ unsigned int timer; // state timer, counts 50uS ticks.
+ unsigned int rawbuf[RAWBUF]; // raw data
+ uint8_t rawlen; // counter of entries in rawbuf
+}
+irparams_t;
+
+// Defined in IRremote.cpp
+extern volatile irparams_t irparams;
+
+// IR detector output is active low
+#define MARK 0
+#define SPACE 1
+
+#define TOPBIT 0x80000000
+
+#define NEC_BITS 32
+#define SONY_BITS 12
+#define MIN_RC5_SAMPLES 11
+#define MIN_RC6_SAMPLES 1
+
+#endif
+
Oops, something went wrong.

0 comments on commit 6ee0dff

Please sign in to comment.