Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
IrSignal.h
Go to the documentation of this file.
1#pragma once
2
3#include "InfraredTypes.h"
4#include "IrSequence.h"
5#include "version.h"
6
11class IrSignal {
12public:
13 static constexpr frequency_t defaultFrequency = 38000U;
14 static constexpr frequency_t invalidFrequency = static_cast<frequency_t>(-1);
15 static constexpr dutycycle_t noDutyCycle = static_cast<dutycycle_t>(-1);
17 static constexpr const char *version = VERSION;
18
19private:
20 // Maintainer note: the members being const prohibits assignment operators.
21 // Alternatively, the members can be made non-const and assignments allowed.
22 const frequency_t frequency = defaultFrequency;
23 const dutycycle_t dutyCycle = defaultDutyCycle;
24 const IrSequence intro;
25 const IrSequence repeat;
26 const IrSequence ending;
27
28public:
33 IrSignal(const IrSignal& orig) = default;
34 IrSignal(IrSignal&& orig) = default;
35 IrSignal& operator=(const IrSignal& rhs) = default;
36 IrSignal& operator=(IrSignal&& rhs) = default;
37
38 virtual ~IrSignal() = default;
39
53 IrSignal(const microseconds_t *intro, size_t lengthIntro,
54 const microseconds_t *repeat, size_t lengthRepeat,
55 const microseconds_t *ending, size_t lengthEnding,
56 frequency_t frequency = defaultFrequency,
57 dutycycle_t dutyCycle = defaultDutyCycle);
58
70 IrSignal(const microseconds_t *intro, size_t lengthIntro,
71 const microseconds_t *repeat, size_t lengthRepeat,
72 frequency_t frequency = defaultFrequency,
73 dutycycle_t dutyCycle = defaultDutyCycle);
74
83 IrSignal(const IrSequence& intro, const IrSequence& repeat, const IrSequence& ending,
85
95 IrSignal(IrSequence&& intro, IrSequence&& repeat, IrSequence&& ending,
97
106 IrSignal(const IrSequence& intro, const IrSequence& repeat,
108
116 IrSignal(IrSequence&& intro, IrSequence&& repeat,
118
119 static IrSignal* readFlash(const microseconds_t *intro, size_t lengthIntro,
120 const microseconds_t *repeat, size_t lengthRepeat,
121 const microseconds_t *ending, size_t lengthEnding,
122 frequency_t frequency = defaultFrequency,
123 dutycycle_t dutyCycle = defaultDutyCycle);
124
125 static IrSignal* readFlash(const microseconds_t *intro, size_t lengthIntro,
126 const microseconds_t *repeat, size_t lengthRepeat,
127 frequency_t frequency = defaultFrequency,
128 dutycycle_t dutyCycle = defaultDutyCycle);
129
131 return frequency;
132 }
133
135 return dutyCycle;
136 }
137
138 const IrSequence& getEnding() const {
139 return ending;
140 }
141
142 const IrSequence& getRepeat() const {
143 return repeat;
144 }
145
146 const IrSequence& getIntro() const {
147 return intro;
148 }
149
154 operator bool() const { return intro || repeat || ending; }
155
161 void dump(Stream& stream, bool usingSigns = false) const;
162
167 void dumpWithSigns(Stream& stream) const {
168 dump(stream, true);
169 };
170
176 bool dumpFrequency(Stream& stream) const {
177 return dumpFrequency(stream, frequency);
178 };
179
185 static bool dumpFrequency(Stream& stream, frequency_t frequency);
186
193 bool dumpDutyCycle(Stream& stream) const {
194 return dumpDutyCycle(stream, dutyCycle);
195 }
196
202 static bool dumpDutyCycle(Stream& stream, dutycycle_t dutyCycle);
203
209 unsigned int noRepetitions(unsigned int noSends) const {
210 return noSends == 0 ? 0
211 : intro ? noSends -1 : noSends;
212 }
213};
This file defines some general data types that are used in the library.
int8_t dutycycle_t
Type for duty cycle in percent.
Definition: InfraredTypes.h:36
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:15
uint32_t frequency_t
Type for modulation frequency in Hz.
Definition: InfraredTypes.h:31
This class consists of a vector of durations.
Definition: IrSequence.h:11
This class models an IR signal with intro-, repeat-, and ending sequences.
Definition: IrSignal.h:11
void dump(Stream &stream, bool usingSigns=false) const
Print a human readable representation of the IrSignal on the Stream supplied.
Definition: IrSignal.cpp:68
static constexpr frequency_t invalidFrequency
Definition: IrSignal.h:14
IrSignal & operator=(const IrSignal &rhs)=default
bool dumpDutyCycle(Stream &stream) const
If the duty cycle is sensible, print it to the stream and return true.
Definition: IrSignal.h:193
bool dumpFrequency(Stream &stream) const
If the frequency is sensible, print it to the stream and return true.
Definition: IrSignal.h:176
static constexpr const char * version
Definition: IrSignal.h:17
virtual ~IrSignal()=default
frequency_t getFrequency() const
Definition: IrSignal.h:130
const IrSequence & getIntro() const
Definition: IrSignal.h:146
const IrSequence & getRepeat() const
Definition: IrSignal.h:142
void dumpWithSigns(Stream &stream) const
Print a human readable representation of the IrSignal on the Stream supplied, using signs.
Definition: IrSignal.h:167
unsigned int noRepetitions(unsigned int noSends) const
Implementation of the count semantics, i.e., how many repetitions should be sent if the signal is sen...
Definition: IrSignal.h:209
IrSignal()
Constructs an empty IrSignal.
Definition: IrSignal.h:32
IrSignal & operator=(IrSignal &&rhs)=default
IrSignal(const IrSignal &orig)=default
static constexpr frequency_t defaultFrequency
Definition: IrSignal.h:13
static constexpr dutycycle_t defaultDutyCycle
Definition: IrSignal.h:16
const IrSequence & getEnding() const
Definition: IrSignal.h:138
static IrSignal * readFlash(const microseconds_t *intro, size_t lengthIntro, const microseconds_t *repeat, size_t lengthRepeat, const microseconds_t *ending, size_t lengthEnding, frequency_t frequency=defaultFrequency, dutycycle_t dutyCycle=defaultDutyCycle)
static IrSignal * readFlash(const microseconds_t *intro, size_t lengthIntro, const microseconds_t *repeat, size_t lengthRepeat, frequency_t frequency=defaultFrequency, dutycycle_t dutyCycle=defaultDutyCycle)
static constexpr dutycycle_t noDutyCycle
Definition: IrSignal.h:15
dutycycle_t getDutyCycle() const
Definition: IrSignal.h:134
IrSignal(IrSignal &&orig)=default
#define VERSION
Version of the current library.
Definition: version.h:7