Infrared4Arduino
IrReader.h
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 #ifndef IRREADER_H
19 #define IRREADER_H
20 #include <Arduino.h>
21 
22 #include "InfraredTypes.h"
23 #include "IrSequence.h"
24 
30 class IrReader {
31 public:
32  // Defaults
35  static const size_t defaultCaptureLength = 100U;
36 
37 protected:
40 
41  size_t bufferSize;
42 
44  int16_t markExcess;
45 
47  boolean timeouted;
48 
49  static unsigned int forceEven(unsigned int x) {
50  return (x & 1) ? x + 1 : x;
51  }
52 
57  IrReader(size_t bufSize_) : bufferSize(forceEven(bufSize_)),timeouted(false) {
58  }
59 
61  }
62 
63  virtual ~IrReader() {
64  };
65 
66 public:
67  virtual void reset() {
68  timeouted = false;
69  };
70 
74  virtual void enable() {
75  };
76 
80  virtual void disable() {
81  };
82 
86  virtual void receive() = 0;
87 
92  virtual boolean isReady() const = 0;
93 
98  virtual size_t getDataLength() const = 0;
99 
105  virtual microseconds_t getDuration(unsigned int index) const = 0;
106 
111  virtual void dump(Stream &stream) const;
112 
117  IrSequence *toIrSequence() const;
118 
119  virtual boolean isEmpty() const {
120  return getDataLength() == 0;
121  }
122 
123  virtual void setEndingTimeout(milliseconds_t timeOut) {
124  endingTimeout = timeOut;
125  }
126 
128  return endingTimeout;
129  }
130 
131  virtual void setBeginningTimeout(milliseconds_t timeOut) {
132  beginningTimeout = timeOut;
133  }
134 
136  return beginningTimeout;
137  }
138 
139  unsigned int getBufferSize() const {
140  return bufferSize;
141  }
142 
148  void setMarkExcess(int16_t markExcess_) {
149  markExcess = markExcess_;
150  }
151 
157  int16_t getMarkExcess() const {
158  return markExcess;
159  }
160 };
161 
162 #endif /* IRCAPTURER_H */
virtual void setBeginningTimeout(milliseconds_t timeOut)
Definition: IrReader.h:131
static const milliseconds_t defaultBeginningTimeout
Definition: IrReader.h:33
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:16
static const milliseconds_t defaultEndingTimeout
Definition: IrReader.h:34
void setMarkExcess(int16_t markExcess_)
Sets the markExcess, a number (possibly negative) to be subtracted from the on-durations and added to...
Definition: IrReader.h:148
virtual microseconds_t getDuration(unsigned int index) const =0
Returns the index-th duration, if possible.
virtual void enable()
Start reception of IR data.
Definition: IrReader.h:74
virtual size_t getDataLength() const =0
Returns the number of collected durations.
virtual void disable()
Stop reception of IR data.
Definition: IrReader.h:80
virtual boolean isEmpty() const
Definition: IrReader.h:119
size_t bufferSize
Definition: IrReader.h:41
uint16_t milliseconds_t
Type for durations in milli seconds.
Definition: InfraredTypes.h:26
IrReader()
Definition: IrReader.h:60
unsigned int getBufferSize() const
Definition: IrReader.h:139
int16_t getMarkExcess() const
Gets the markExcess, a number (possibly negative) to be subtracted from the on-durations and added to...
Definition: IrReader.h:157
Abstract base class for all IR readers, capturing or receiving.
Definition: IrReader.h:30
virtual void dump(Stream &stream) const
Prints a textual representation of the received data to the Stream supplied.
Definition: IrReader.cpp:21
boolean timeouted
True if last receive ended with a timeout.
Definition: IrReader.h:47
virtual milliseconds_t getBeginningTimeout() const
Definition: IrReader.h:135
virtual void setEndingTimeout(milliseconds_t timeOut)
Definition: IrReader.h:123
milliseconds_t endingTimeout
Definition: IrReader.h:39
IrReader(size_t bufSize_)
Constructs an IrReader with buffersize bufSize_, possibly increased to be even.
Definition: IrReader.h:57
IrSequence * toIrSequence() const
Generates an IrSequence from the IrReader.
Definition: IrReader.cpp:32
milliseconds_t beginningTimeout
Definition: IrReader.h:38
This class consists of a vector of durations.
Definition: IrSequence.h:12
static const size_t defaultCaptureLength
Definition: IrReader.h:35
This file defines some general data types that are used in the library.
virtual ~IrReader()
Definition: IrReader.h:63
static unsigned int forceEven(unsigned int x)
Definition: IrReader.h:49
virtual void reset()
Definition: IrReader.h:67
int16_t markExcess
Microseconds subtracted from pulses and added to gaps.
Definition: IrReader.h:44
virtual boolean isReady() const =0
Returns true if there is collected data.
virtual milliseconds_t getEndingTimeout() const
Definition: IrReader.h:127
virtual void receive()=0
Convenience function: enable, wait until data is collected or timeout has occured, disable.