Infrared4Arduino
IrReader.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2015 Bengt Martensson.
3 
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or (at
7 your option) any later version.
8 
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see http://www.gnu.org/licenses/.
16 */
17 
18 #include "IrReader.h"
19 
20 // Cannot use IrSequence.dump directly!
21 void IrReader::dump(Stream &stream) const {
22  size_t count = getDataLength();
23  for (unsigned int i = 0U; i < count; i++) {
24  if (i > 0U)
25  stream.print(" ");
26  stream.print((i & 1U) ? '-' : '+');
27  stream.print(getDuration(i), DEC);
28  }
29  stream.println();
30 }
31 
33  microseconds_t *durations = new microseconds_t[getDataLength()];
34  for (unsigned int i = 0; i < getDataLength(); i++)
35  durations[i] = getDuration(i);
36  return new IrSequence(durations, getDataLength(), true);
37 }
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:16
virtual microseconds_t getDuration(unsigned int index) const =0
Returns the index-th duration, if possible.
virtual size_t getDataLength() const =0
Returns the number of collected durations.
virtual void dump(Stream &stream) const
Prints a textual representation of the received data to the Stream supplied.
Definition: IrReader.cpp:21
IrSequence * toIrSequence() const
Generates an IrSequence from the IrReader.
Definition: IrReader.cpp:32
This class consists of a vector of durations.
Definition: IrSequence.h:12