Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
IrReceiverSampler.h
Go to the documentation of this file.
1#pragma once
2
3#include "IrReceiver.h"
4
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.
19public:
20
27 };
28
30 volatile ReceiverState_t receiverState; // previously rcvstate;
31
32 // Note: use the following ones instead of beginningTimeout and endingTimeout
33 // inherited from IrReader.
34 uint32_t endingTimeoutInTicks; // previously GAP_TICKS
35
36 uint32_t beginningTimeoutInTicks; // previously TIMEOUT_TICKS;
37
39 volatile uint32_t timer;
40
42 volatile microseconds_t *durationData; // previously rawbuf;
43
45 volatile size_t dataLength; // previously rawlen
46
47private:
48 static IrReceiverSampler *instance;
49 static uint32_t millisecs2ticks(milliseconds_t ms);
50 static milliseconds_t ticks2millisecs(uint32_t tix);
51
52protected:
54
55private:
56 IrReceiverSampler(size_t captureLength = defaultCaptureLength,
57 pin_t pin = defaultPin,
58 bool pullup = false,
62
63public:
77 pin_t pin = defaultPin,
78 bool pullup = false,
82
87 static void deleteInstance();
88
94 return instance;
95 }
96
97 void enable();
98
99 void disable();
100
101 void reset();
102
104
106
108
110
111 size_t getDataLength() const {
112 return dataLength;
113 }
114
115 microseconds_t getDuration(unsigned int i) const {
116 uint32_t bigvalue = Board::microsPerTick * static_cast<uint32_t>(durationData[i]) + (i & 1 ? markExcess : -markExcess);
117 return bigvalue <= MICROSECONDS_T_MAX ? (microseconds_t) bigvalue : MICROSECONDS_T_MAX;
118 }
119
120 bool isReady() const {
121 return receiverState == STATE_STOP;
122 }
123};
static constexpr microseconds_t MICROSECONDS_T_MAX
Largest microseconds_t number possible.
Definition: InfraredTypes.h:18
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:15
uint16_t milliseconds_t
Type for durations in milli seconds.
Definition: InfraredTypes.h:24
uint8_t pin_t
Type for GPIO pin, compatible with Arduino libs.
Definition: InfraredTypes.h:41
static const unsigned long microsPerTick
Definition: Board.h:57
static constexpr size_t defaultCaptureLength
Definition: IrReader.h:35
int16_t markExcess
Microseconds subtracted from pulses and added to gaps.
Definition: IrReader.h:44
milliseconds_t beginningTimeout
Definition: IrReader.h:38
static constexpr milliseconds_t defaultEndingTimeout
Definition: IrReader.h:34
static constexpr milliseconds_t defaultBeginningTimeout
Definition: IrReader.h:33
milliseconds_t endingTimeout
Definition: IrReader.h:39
This receiving class samples the input pin every 50 microseconds using a timer interrupt.
void enable()
Start reception of IR data.
milliseconds_t getBeginningTimeout() const
size_t getDataLength() const
Returns the number of collected durations.
ReceiverState_t
State space for the receiver state machine.
@ STATE_IDLE
Between signals; waiting for first mark.
@ STATE_STOP
Complete signal has been read.
@ STATE_MARK
Last read a mark.
@ STATE_SPACE
Last read a space.
uint32_t beginningTimeoutInTicks
milliseconds_t getEndingTimeout() const
volatile microseconds_t * durationData
Data buffer.
static IrReceiverSampler * newIrReceiverSampler(size_t captureLength=defaultCaptureLength, pin_t pin=defaultPin, bool pullup=false, microseconds_t markExcess=defaultMarkExcess, milliseconds_t beginningTimeout=defaultBeginningTimeout, milliseconds_t endingTimeout=defaultEndingTimeout)
This factory method replaces public constructors.
virtual ~IrReceiverSampler()
volatile ReceiverState_t receiverState
State of the state machine.
static IrReceiverSampler * getInstance()
Returns a pointer to the instance, or nullptr.
void setBeginningTimeout(milliseconds_t timeOut)
microseconds_t getDuration(unsigned int i) const
Returns the index-th duration, if possible.
volatile size_t dataLength
Number of entries in durationData.
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...
bool isReady() const
Returns true if there is collected data.
void disable()
Stop reception of IR data.
uint32_t endingTimeoutInTicks
void setEndingTimeout(milliseconds_t timeOut)
Abstract base class for demodulating IR receivers.
Definition: IrReceiver.h:12
static constexpr microseconds_t defaultMarkExcess
Definition: IrReceiver.h:20
static constexpr pin_t defaultPin
Definition: IrReceiver.h:19