Skip to content

Commit 6ee0dff

Browse files
committed
Initial commit from Irremote.zip
0 parents  commit 6ee0dff

File tree

12 files changed

+1878
-0
lines changed

12 files changed

+1878
-0
lines changed

IRremote.cpp

Lines changed: 601 additions & 0 deletions
Large diffs are not rendered by default.

IRremote.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* IRremote
3+
* Version 0.1 July, 2009
4+
* Copyright 2009 Ken Shirriff
5+
* For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com
6+
*
7+
* Interrupt code based on NECIRrcv by Joe Knapp
8+
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
9+
* Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
10+
*/
11+
12+
#ifndef IRremote_h
13+
#define IRremote_h
14+
15+
// The following are compile-time library options.
16+
// If you change them, recompile the library.
17+
// If DEBUG is defined, a lot of debugging output will be printed during decoding.
18+
// TEST must be defined for the IRtest unittests to work. It will make some
19+
// methods virtual, which will be slightly slower, which is why it is optional.
20+
// #define DEBUG
21+
// #define TEST
22+
23+
// Results returned from the decoder
24+
class decode_results {
25+
public:
26+
int decode_type; // NEC, SONY, RC5, UNKNOWN
27+
unsigned long value; // Decoded value
28+
int bits; // Number of bits in decoded value
29+
volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
30+
int rawlen; // Number of records in rawbuf.
31+
};
32+
33+
// Values for decode_type
34+
#define NEC 1
35+
#define SONY 2
36+
#define RC5 3
37+
#define RC6 4
38+
#define UNKNOWN -1
39+
40+
// Decoded value for NEC when a repeat code is received
41+
#define REPEAT 0xffffffff
42+
43+
// main class for receiving IR
44+
class IRrecv
45+
{
46+
public:
47+
IRrecv(int recvpin);
48+
void blink13(int blinkflag);
49+
int decode(decode_results *results);
50+
void enableIRIn();
51+
void resume();
52+
private:
53+
// These are called by decode
54+
int getRClevel(decode_results *results, int *offset, int *used, int t1);
55+
long decodeNEC(decode_results *results);
56+
long decodeSony(decode_results *results);
57+
long decodeRC5(decode_results *results);
58+
long decodeRC6(decode_results *results);
59+
}
60+
;
61+
62+
// Only used for testing; can remove virtual for shorter code
63+
#ifdef TEST
64+
#define VIRTUAL virtual
65+
#else
66+
#define VIRTUAL
67+
#endif
68+
69+
class IRsend
70+
{
71+
public:
72+
IRsend() {}
73+
void sendNEC(unsigned long data, int nbits);
74+
void sendSony(unsigned long data, int nbits);
75+
void sendRaw(unsigned int buf[], int len, int hz);
76+
void sendRC5(unsigned long data, int nbits);
77+
void sendRC6(unsigned long data, int nbits);
78+
// private:
79+
void enableIROut(int khz);
80+
VIRTUAL void mark(int usec);
81+
VIRTUAL void space(int usec);
82+
}
83+
;
84+
85+
// Some useful constants
86+
87+
#define USECPERTICK 50 // microseconds per clock interrupt tick
88+
#define RAWBUF 76 // Length of raw duration buffer
89+
90+
// Marks tend to be 100us too long, and spaces 100us too short
91+
// when received due to sensor lag.
92+
#define MARK_EXCESS 100
93+
94+
#endif

IRremote.zip

23.2 KB
Binary file not shown.

IRremoteInt.h

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* IRremote
3+
* Version 0.1 July, 2009
4+
* Copyright 2009 Ken Shirriff
5+
* For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
6+
*
7+
* Interrupt code based on NECIRrcv by Joe Knapp
8+
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
9+
* Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
10+
*/
11+
12+
#ifndef IRremoteint_h
13+
#define IRremoteint_h
14+
15+
#include <WProgram.h>
16+
17+
#define CLKFUDGE 5 // fudge factor for clock interrupt overhead
18+
#define CLK 256 // max value for clock (timer 2)
19+
#define PRESCALE 8 // timer2 clock prescale
20+
#define SYSCLOCK 16000000 // main Arduino clock
21+
#define CLKSPERUSEC (SYSCLOCK/PRESCALE/1000000) // timer clocks per microsecond
22+
23+
#define ERR 0
24+
#define DECODED 1
25+
26+
#define BLINKLED 13
27+
28+
// defines for setting and clearing register bits
29+
#ifndef cbi
30+
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
31+
#endif
32+
#ifndef sbi
33+
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
34+
#endif
35+
36+
// clock timer reset value
37+
#define INIT_TIMER_COUNT2 (CLK - USECPERTICK*CLKSPERUSEC + CLKFUDGE)
38+
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT2
39+
40+
// pulse parameters in usec
41+
#define NEC_HDR_MARK 9000
42+
#define NEC_HDR_SPACE 4500
43+
#define NEC_BIT_MARK 560
44+
#define NEC_ONE_SPACE 1600
45+
#define NEC_ZERO_SPACE 560
46+
#define NEC_RPT_SPACE 2250
47+
48+
#define SONY_HDR_MARK 2400
49+
#define SONY_HDR_SPACE 600
50+
#define SONY_ONE_MARK 1200
51+
#define SONY_ZERO_MARK 600
52+
#define SONY_RPT_LENGTH 45000
53+
54+
#define RC5_T1 889
55+
#define RC5_RPT_LENGTH 46000
56+
57+
#define RC6_HDR_MARK 2666
58+
#define RC6_HDR_SPACE 889
59+
#define RC6_T1 444
60+
#define RC6_RPT_LENGTH 46000
61+
62+
#define TOLERANCE 25 // percent tolerance in measurements
63+
#define LTOL (1.0 - TOLERANCE/100.)
64+
#define UTOL (1.0 + TOLERANCE/100.)
65+
66+
#define _GAP 5000 // Minimum map between transmissions
67+
#define GAP_TICKS (_GAP/USECPERTICK)
68+
69+
#define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK))
70+
#define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1))
71+
72+
#ifndef DEBUG
73+
#define MATCH(measured_ticks, desired_us) ((measured_ticks) >= TICKS_LOW(desired_us) && (measured_ticks) <= TICKS_HIGH(desired_us))
74+
#define MATCH_MARK(measured_ticks, desired_us) MATCH(measured_ticks, (desired_us) + MARK_EXCESS)
75+
#define MATCH_SPACE(measured_ticks, desired_us) MATCH((measured_ticks), (desired_us) - MARK_EXCESS)
76+
// Debugging versions are in IRremote.cpp
77+
#endif
78+
79+
// receiver states
80+
#define STATE_IDLE 2
81+
#define STATE_MARK 3
82+
#define STATE_SPACE 4
83+
#define STATE_STOP 5
84+
85+
// information for the interrupt handler
86+
typedef struct {
87+
uint8_t recvpin; // pin for IR data from detector
88+
uint8_t rcvstate; // state machine
89+
uint8_t blinkflag; // TRUE to enable blinking of pin 13 on IR processing
90+
unsigned int timer; // state timer, counts 50uS ticks.
91+
unsigned int rawbuf[RAWBUF]; // raw data
92+
uint8_t rawlen; // counter of entries in rawbuf
93+
}
94+
irparams_t;
95+
96+
// Defined in IRremote.cpp
97+
extern volatile irparams_t irparams;
98+
99+
// IR detector output is active low
100+
#define MARK 0
101+
#define SPACE 1
102+
103+
#define TOPBIT 0x80000000
104+
105+
#define NEC_BITS 32
106+
#define SONY_BITS 12
107+
#define MIN_RC5_SAMPLES 11
108+
#define MIN_RC6_SAMPLES 1
109+
110+
#endif
111+

0 commit comments

Comments
 (0)