Infrared4Arduino
IrReceiverSampler.h
Go to the documentation of this file.
1 #ifndef IRRECEIVERSAMPLE_H
2 #define IRRECEIVERSAMPLE_H
3 
4 #include "IrReceiver.h"
5 
15 // The interrupt routine must have access to some stuff here.
16 // This needs to be public, and, since the interrupt routing
17 // fumbles with it, volatile.
18 class IrReceiverSampler : public IrReceiver {
19 public:
20 
22  static const unsigned long microsPerTick = 50; // was USECPERTICK
23 
30  };
31 
33  volatile ReceiverState_t receiverState; // previously rcvstate;
34 
35  // Note: use the following ones instead of beginningTimeout and endingTimeout
36  // inherited from IrReader.
37  uint32_t endingTimeoutInTicks; // previously GAP_TICKS
38 
39  uint32_t beginningTimeoutInTicks; // previously TIMEOUT_TICKS;
40 
42  volatile uint32_t timer;
43 
45  volatile microseconds_t *durationData; // previously rawbuf;
46 
48  volatile size_t dataLength; // previously rawlen
49 
50 private:
51  static IrReceiverSampler *instance;
52  static uint32_t millisecs2ticks(milliseconds_t ms);
53  static milliseconds_t ticks2millisecs(uint32_t tix);
54 
55 protected:
56  virtual ~IrReceiverSampler();
57 
58 private:
59  IrReceiverSampler(size_t captureLength = defaultCaptureLength,
60  pin_t pin = defaultPin,
61  boolean pullup = false,
65 
66 public:
79  static IrReceiverSampler *newIrReceiverSampler(size_t captureLength = defaultCaptureLength,
80  pin_t pin = defaultPin,
81  boolean pullup = false,
85 
90  static void deleteInstance();
91 
97  return instance;
98  }
99 
100  void enable();
101 
102  void disable();
103 
104  void reset();
105 
106  void setEndingTimeout(milliseconds_t timeOut);
107 
109 
110  void setBeginningTimeout(milliseconds_t timeOut);
111 
113 
114  size_t getDataLength() const {
115  return dataLength;
116  }
117 
118  microseconds_t getDuration(unsigned int i) const {
119  return (microseconds_t) (microsPerTick * durationData[i] + (i & 1 ? markExcess : -markExcess));
120  }
121 
122  boolean isReady() const {
123  return receiverState == STATE_STOP;
124  }
125 };
126 
127 #endif /* IRRECEIVERSAMPLE_H */
Between signals; waiting for first mark.
static const unsigned long microsPerTick
microseconds per clock interrupt
static const milliseconds_t defaultBeginningTimeout
Definition: IrReader.h:33
void setBeginningTimeout(milliseconds_t timeOut)
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:16
static const microseconds_t defaultMarkExcess
Definition: IrReceiver.h:19
volatile ReceiverState_t receiverState
State of the state machine.
static const milliseconds_t defaultEndingTimeout
Definition: IrReader.h:34
uint8_t pin_t
Type for GPIO pin, compatible with Arduino libs.
Definition: InfraredTypes.h:40
volatile size_t dataLength
Number of entries in durationData.
ReceiverState_t
State space for the receiver state machine.
void setEndingTimeout(milliseconds_t timeOut)
This receiving class samples the input pin every 50 microseconds using a timer interrupt.
uint16_t milliseconds_t
Type for durations in milli seconds.
Definition: InfraredTypes.h:26
Abstract base class for demodulating IR receivers.
Definition: IrReceiver.h:11
microseconds_t getDuration(unsigned int i) const
Returns the index-th duration, if possible.
void enable()
Start reception of IR data.
static IrReceiverSampler * newIrReceiverSampler(size_t captureLength=defaultCaptureLength, pin_t pin=defaultPin, boolean pullup=false, microseconds_t markExcess=defaultMarkExcess, milliseconds_t beginningTimeout=defaultBeginningTimeout, milliseconds_t endingTimeout=defaultEndingTimeout)
This factory method replaces public constructors.
volatile uint32_t timer
state timer, counts 50uS ticks.
static void deleteInstance()
Deletes the instance, thereby freeing up the resources it occupied, and allowing for another instance...
size_t getDataLength() const
Returns the number of collected durations.
volatile microseconds_t * durationData
Data buffer.
milliseconds_t endingTimeout
Definition: IrReader.h:39
void disable()
Stop reception of IR data.
static const pin_t defaultPin
Definition: IrReceiver.h:18
Complete signal has been read.
milliseconds_t beginningTimeout
Definition: IrReader.h:38
milliseconds_t getBeginningTimeout() const
static const size_t defaultCaptureLength
Definition: IrReader.h:35
uint32_t beginningTimeoutInTicks
int16_t markExcess
Microseconds subtracted from pulses and added to gaps.
Definition: IrReader.h:44
milliseconds_t getEndingTimeout() const
boolean isReady() const
Returns true if there is collected data.
uint32_t endingTimeoutInTicks
static IrReceiverSampler * getInstance()
Returns a pointer to the instance, or NULL.