|
| 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