Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
IrSignal.cpp
Go to the documentation of this file.
1#include "IrSignal.h"
2#include "IrSender.h"
3
4IrSignal::IrSignal(const IrSequence& intro_, const IrSequence& repeat_, const IrSequence& ending_,
5 frequency_t frequency_, dutycycle_t dutyCycle_)
6: frequency(frequency_),dutyCycle(dutyCycle_),intro(intro_),repeat(repeat_),ending(ending_) {
7}
8
9IrSignal::IrSignal(IrSequence&& intro_, IrSequence&& repeat_, IrSequence&& ending_,
10 frequency_t frequency_, dutycycle_t dutyCycle_)
11: frequency(frequency_),dutyCycle(dutyCycle_),intro(intro_),repeat(repeat_),ending(ending_) {
12}
13
14IrSignal::IrSignal(const IrSequence& intro_, const IrSequence& repeat_,
15 frequency_t frequency_, dutycycle_t dutyCycle_)
16: frequency(frequency_), dutyCycle(dutyCycle_), intro(intro_), repeat(repeat_), ending() {
17}
18
20 frequency_t frequency_, dutycycle_t dutyCycle_)
21: frequency(frequency_), dutyCycle(dutyCycle_), intro(intro_), repeat(repeat_), ending() {
22}
23
24IrSignal::IrSignal(const microseconds_t *intro_, size_t introLength,
25 const microseconds_t *repeat_, size_t repeatLength,
26 const microseconds_t *ending_, size_t endingLength,
27 frequency_t frequency_, dutycycle_t dutyCycle_)
28: frequency(frequency_),
29dutyCycle(dutyCycle_),
30intro(intro_, introLength),
31repeat(repeat_, repeatLength),
32ending(ending_, endingLength) {
33}
34
35IrSignal::IrSignal(const microseconds_t *intro_, size_t introLength,
36 const microseconds_t *repeat_, size_t repeatLength,
37 frequency_t frequency_, dutycycle_t dutyCycle_)
38: frequency(frequency_),
39dutyCycle(dutyCycle_),
40intro(intro_, introLength),
41repeat(repeat_, repeatLength),
42ending() {
43}
44
45#if HAS_FLASH_READ
46
47IrSignal* IrSignal::readFlash(const microseconds_t *intro, size_t lengthIntro,
48 const microseconds_t *repeat, size_t lengthRepeat,
49 const microseconds_t *ending, size_t lengthEnding,
50 frequency_t frequency_,
51 dutycycle_t dutyCycle_) {
52 return new IrSignal(*IrSequence::readFlash(intro, lengthIntro),
53 *IrSequence::readFlash(repeat, lengthRepeat),
54 *IrSequence::readFlash(ending, lengthEnding),
55 frequency_, dutyCycle_);
56}
57
58IrSignal* IrSignal::readFlash(const microseconds_t *intro, size_t lengthIntro,
59 const microseconds_t *repeat, size_t lengthRepeat,
60 frequency_t frequency_,
61 dutycycle_t dutyCycle_) {
62 return new IrSignal(*IrSequence::readFlash(intro, lengthIntro),
63 *IrSequence::readFlash(repeat, lengthRepeat),
64 frequency_, dutyCycle_);
65}
66#endif
67
68void IrSignal::dump(Stream& stream, bool usingSigns) const {
69 bool printedSomething = dumpFrequency(stream);
70 if (printedSomething)
71 stream.print(" ");
72 printedSomething = dumpDutyCycle(stream);
73 if (printedSomething)
74 stream.print(" ");
75 intro.dump(stream, usingSigns);
76 repeat.dump(stream, usingSigns);
77 ending.dump(stream, usingSigns);
78}
79
80bool IrSignal::dumpFrequency(Stream& stream, frequency_t frequency) {
81 if (frequency > 0 && frequency != invalidFrequency) {
82 stream.print(F("f="));
83 stream.print(frequency);
84 return true;
85 }
86 return false;
87}
88
89bool IrSignal::dumpDutyCycle(Stream& stream, dutycycle_t dutyCycle) {
90 if (dutyCycle > 0 && dutyCycle < 100) {
91 stream.print(dutyCycle);
92 stream.print("%");
93 return true;
94 }
95 return false;
96}
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
static IrSequence * readFlash(const microseconds_t *flashData, size_t length)
Create an IrSequence from data in PROGMEM.
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
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
IrSignal()
Constructs an empty IrSignal.
Definition: IrSignal.h:32
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)