Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
IrReceiverSampler Class Reference

This receiving class samples the input pin every 50 microseconds using a timer interrupt. More...

#include <IrReceiverSampler.h>

Inheritance diagram for IrReceiverSampler:
Inheritance graph
[legend]
Collaboration diagram for IrReceiverSampler:
Collaboration graph
[legend]

Public Types

enum  ReceiverState_t { STATE_IDLE , STATE_MARK , STATE_SPACE , STATE_STOP }
 State space for the receiver state machine. More...
 
- Public Types inherited from IrReceiver
enum  irdata_t { IR_MARK , IR_SPACE }
 Enum for the duration types. More...
 

Public Member Functions

void enable ()
 Start reception of IR data. More...
 
void disable ()
 Stop reception of IR data. More...
 
void reset ()
 
void setEndingTimeout (milliseconds_t timeOut)
 
milliseconds_t getEndingTimeout () const
 
void setBeginningTimeout (milliseconds_t timeOut)
 
milliseconds_t getBeginningTimeout () const
 
size_t getDataLength () const
 Returns the number of collected durations. More...
 
microseconds_t getDuration (unsigned int i) const
 Returns the index-th duration, if possible. More...
 
bool isReady () const
 Returns true if there is collected data. More...
 
- Public Member Functions inherited from IrReceiver
 IrReceiver (size_t bufSize, pin_t pin, bool pullup=false, microseconds_t markExcess=defaultMarkExcess)
 Constructor. More...
 
virtual ~IrReceiver ()
 
virtual frequency_t getFrequency () const
 Returns frequency of received signal. More...
 
virtual void receive ()
 Convenience function: enable, wait until data is collected or timeout has occured, disable. More...
 
pin_t getPin () const
 
- Public Member Functions inherited from IrReader
virtual void reset ()
 
virtual frequency_t getFrequency () const =0
 Returns frequency of received signal. More...
 
virtual void enable ()
 Start reception of IR data. More...
 
virtual void disable ()
 Stop reception of IR data. More...
 
virtual void receive ()=0
 Convenience function: enable, wait until data is collected or timeout has occured, disable. More...
 
virtual bool isReady () const =0
 Returns true if there is collected data. More...
 
 operator bool () const
 Same as isReady() More...
 
virtual size_t getDataLength () const =0
 Returns the number of collected durations. More...
 
virtual microseconds_t getDuration (unsigned int index) const =0
 Returns the index-th duration, if possible. More...
 
virtual void dump (Stream &stream) const
 Prints a textual representation of the received data to the Stream supplied. More...
 
IrSequencetoIrSequence () const
 Generates an IrSequence from the IrReader. More...
 
virtual bool isEmpty () const
 
virtual void setEndingTimeout (milliseconds_t timeOut)
 
virtual milliseconds_t getEndingTimeout () const
 
virtual void setBeginningTimeout (milliseconds_t timeOut)
 
virtual milliseconds_t getBeginningTimeout () const
 
unsigned int getBufferSize () const
 
void setMarkExcess (int16_t markExcess_)
 Sets the markExcess, a number (possibly negative) to be subtracted from the on-durations and added to the off.durations. More...
 
int16_t getMarkExcess () const
 Gets the markExcess, a number (possibly negative) to be subtracted from the on-durations and added to the off.durations. More...
 

Static Public Member Functions

static IrReceiverSamplernewIrReceiverSampler (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. More...
 
static void deleteInstance ()
 Deletes the instance, thereby freeing up the resources it occupied, and allowing for another instance to be created. More...
 
static IrReceiverSamplergetInstance ()
 Returns a pointer to the instance, or nullptr. More...
 

Public Attributes

volatile ReceiverState_t receiverState
 State of the state machine. More...
 
uint32_t endingTimeoutInTicks
 
uint32_t beginningTimeoutInTicks
 
volatile uint32_t timer
 state timer, counts 50uS ticks. More...
 
volatile microseconds_tdurationData
 Data buffer. More...
 
volatile size_t dataLength
 Number of entries in durationData. More...
 

Protected Member Functions

virtual ~IrReceiverSampler ()
 
- Protected Member Functions inherited from IrReader
 IrReader (size_t bufSize_)
 Constructs an IrReader with buffersize bufSize_, possibly increased to be even. More...
 
 IrReader ()
 
virtual ~IrReader ()
 

Additional Inherited Members

- Static Public Attributes inherited from IrReceiver
static constexpr pin_t defaultPin = 5
 
static constexpr microseconds_t defaultMarkExcess = 50U
 
static constexpr bool invertingSensor = true
 Are we using inverting sensor, like most TSOPs? More...
 
- Static Public Attributes inherited from IrReader
static constexpr milliseconds_t defaultBeginningTimeout = 2000U
 
static constexpr milliseconds_t defaultEndingTimeout = 30U
 
static constexpr size_t defaultCaptureLength = 100U
 
- Static Protected Member Functions inherited from IrReader
static unsigned int forceEven (unsigned int x)
 
- Protected Attributes inherited from IrReader
milliseconds_t beginningTimeout
 
milliseconds_t endingTimeout
 
size_t bufferSize
 
int16_t markExcess
 Microseconds subtracted from pulses and added to gaps. More...
 
bool timeouted
 True if last receive ended with a timeout. More...
 

Detailed Description

This receiving class samples the input pin every 50 microseconds using a timer interrupt.

Due to the ISP, this is a singleton class; it can only be instantiated once. This is enforced by the absence of public constructors: it has to be instantiated by the factory method newIrReceiverSampler.

Definition at line 18 of file IrReceiverSampler.h.

Member Enumeration Documentation

◆ ReceiverState_t

State space for the receiver state machine.

Enumerator
STATE_IDLE 

Between signals; waiting for first mark.

STATE_MARK 

Last read a mark.

STATE_SPACE 

Last read a space.

STATE_STOP 

Complete signal has been read.

Definition at line 22 of file IrReceiverSampler.h.

Constructor & Destructor Documentation

◆ ~IrReceiverSampler()

virtual IrReceiverSampler::~IrReceiverSampler ( )
protectedvirtual

Member Function Documentation

◆ deleteInstance()

static void IrReceiverSampler::deleteInstance ( )
static

Deletes the instance, thereby freeing up the resources it occupied, and allowing for another instance to be created.

◆ disable()

void IrReceiverSampler::disable ( )
virtual

Stop reception of IR data.

Reimplemented from IrReader.

◆ enable()

void IrReceiverSampler::enable ( )
virtual

Start reception of IR data.

Reimplemented from IrReader.

◆ getBeginningTimeout()

milliseconds_t IrReceiverSampler::getBeginningTimeout ( ) const
virtual

Reimplemented from IrReader.

◆ getDataLength()

size_t IrReceiverSampler::getDataLength ( ) const
inlinevirtual

Returns the number of collected durations.

Returns
number durations

Implements IrReader.

Definition at line 111 of file IrReceiverSampler.h.

◆ getDuration()

microseconds_t IrReceiverSampler::getDuration ( unsigned int  index) const
inlinevirtual

Returns the index-th duration, if possible.

Parameters
indexindex of duration
Returns
requested duration

Implements IrReader.

Definition at line 115 of file IrReceiverSampler.h.

◆ getEndingTimeout()

milliseconds_t IrReceiverSampler::getEndingTimeout ( ) const
virtual

Reimplemented from IrReader.

◆ getInstance()

static IrReceiverSampler * IrReceiverSampler::getInstance ( )
inlinestatic

Returns a pointer to the instance, or nullptr.

Returns
pointer to instance, possibly nullptr.

Definition at line 93 of file IrReceiverSampler.h.

◆ isReady()

bool IrReceiverSampler::isReady ( ) const
inlinevirtual

Returns true if there is collected data.

Returns
status

Implements IrReader.

Definition at line 120 of file IrReceiverSampler.h.

◆ newIrReceiverSampler()

static IrReceiverSampler * 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 
)
static

This factory method replaces public constructors.

Provided that no instance currently exists, it constructs a new instance and return a pointer to it, if possible. Otherwise, it returns nullptr.

Parameters
captureLengthbuffersize requested
pinGPIO pin to use
pulluptrue if the internal pullup resistor should be enabled
markExcessmarkExcess to use
beginningTimeoutbeginningTimeout to use
endingTimeoutendingTimeout to use
Returns
pointer to a valid instance, or nullptr.

◆ reset()

void IrReceiverSampler::reset ( )
virtual

Reimplemented from IrReader.

◆ setBeginningTimeout()

void IrReceiverSampler::setBeginningTimeout ( milliseconds_t  timeOut)
virtual

Reimplemented from IrReader.

◆ setEndingTimeout()

void IrReceiverSampler::setEndingTimeout ( milliseconds_t  timeOut)
virtual

Reimplemented from IrReader.

Member Data Documentation

◆ beginningTimeoutInTicks

uint32_t IrReceiverSampler::beginningTimeoutInTicks

Definition at line 36 of file IrReceiverSampler.h.

◆ dataLength

volatile size_t IrReceiverSampler::dataLength

Number of entries in durationData.

Definition at line 45 of file IrReceiverSampler.h.

◆ durationData

volatile microseconds_t* IrReceiverSampler::durationData

Data buffer.

Definition at line 42 of file IrReceiverSampler.h.

◆ endingTimeoutInTicks

uint32_t IrReceiverSampler::endingTimeoutInTicks

Definition at line 34 of file IrReceiverSampler.h.

◆ receiverState

volatile ReceiverState_t IrReceiverSampler::receiverState

State of the state machine.

Definition at line 30 of file IrReceiverSampler.h.

◆ timer

volatile uint32_t IrReceiverSampler::timer

state timer, counts 50uS ticks.

Definition at line 39 of file IrReceiverSampler.h.


The documentation for this class was generated from the following file: