Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
IrSequence.cpp
Go to the documentation of this file.
1#include "IrSequence.h"
2#include "Board.h"
3#include <string.h>
4
5IrSequence::IrSequence(const microseconds_t *durations_, size_t length_) : durations(durations_),length(length_) {
6}
7
8IrSequence::IrSequence(IrSequence&& orig) : durations(orig.durations),length(orig.length) {
9 orig.durations = nullptr;
10 orig.length = 0U;
11}
12
13IrSequence::IrSequence(const IrSequence& orig) : length(orig.length) {
14 microseconds_t* data = new microseconds_t[orig.length];
15 for (unsigned int i = 0U; i < orig.length; i++)
16 data[i] = orig.durations[i];
17 durations = data;
18}
19
21 if (this != &rhs) {
22 delete [] durations;
23 durations = rhs.durations;
24 length = rhs.length;
25 rhs.durations = nullptr;
26 rhs.length = 0;
27 }
28 return *this;
29}
30
32 delete [] durations;
33 microseconds_t* data = new microseconds_t[rhs.length];
34 for (unsigned int i = 0U; i < rhs.length; i++)
35 data[i] = rhs.durations[i];
36 durations = data;
37 length = rhs.length;
38 return *this;
39}
40
42 delete [] durations;
43}
44
46
47void IrSequence::dump(Stream& stream, bool usingSigns) const {
48 for (unsigned int i = 0U; i < length; i++) {
49 if (i > 0U)
50 stream.print(' ');
51 if (usingSigns)
52 stream.print((i & 1) ? '-' : '+');
53 stream.print(durations[i], DEC);
54 }
55 stream.println();
56}
57
58// If ! HAS_FLASH_READ, allow compiling, but let linking bail out, if using it.
59#if HAS_FLASH_READ
60IrSequence* IrSequence::readFlash(const microseconds_t *flashData, size_t length) {
61 microseconds_t* data = new microseconds_t[length];
62 memcpy_PF(data, (uint_farptr_t) flashData, sizeof(microseconds_t) * length);
63 return new IrSequence(data, length);
64}
65#endif
void * uint_farptr_t
Definition: Board.h:288
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:15
This class consists of a vector of durations.
Definition: IrSequence.h:11
void dump(Stream &stream, bool usingSigns=false) const
Prints the IrSequence on the stream provided.
Definition: IrSequence.cpp:47
static const IrSequence emptyInstance
Definition: IrSequence.h:53
virtual ~IrSequence()
Definition: IrSequence.cpp:41
static IrSequence * readFlash(const microseconds_t *flashData, size_t length)
Create an IrSequence from data in PROGMEM.
IrSequence()
Create an empty sequence.
Definition: IrSequence.h:18
IrSequence & operator=(const IrSequence &rhs)
Copy assignment.
Definition: IrSequence.cpp:31