atMETEO
An ATmega based weather station
sensor.h
Go to the documentation of this file.
1 /*
2  * atMETEO - An ATmega based weather station
3  * Copyright (C) 2014-2015 Christian Fetzer
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
35 #include <inttypes.h> // AVR toolchain doesn't offer cinttypes header
36 #include <stdlib.h> // AVR toolchain doesn't offer cstdlib header
37 
38 namespace Sensors
39 {
40 
49 enum class SensorStatus : uint8_t {
54  Complete = 0,
55 
60  Incomplete,
61 
67 
73 };
74 
117 template <typename TSensor>
118 class Sensor
119 {
120 public:
128  SensorStatus setData(uint8_t *data, size_t length)
129  {
130  return static_cast<TSensor *>(this)->internalSetData(data, length);
131  }
132 
139  SensorStatus addByte(uint8_t byte)
140  {
141  return static_cast<TSensor *>(this)->internalAddByte(byte);
142  }
143 
148  void reset()
149  {
150  return static_cast<TSensor *>(this)->internalReset();
151  }
152 };
153  // \addtogroup libsensors_sensor
155 
156 } // namespace Sensor
SensorStatus setData(uint8_t *data, size_t length)
Sets the sensor state to the given data buffer.
Definition: sensor.h:128
SensorStatus addByte(uint8_t byte)
Adds the byte to the sensor state.
Definition: sensor.h:139
void reset()
Resets the state of the sensor decoder for receiving a new data set.
Definition: sensor.h:148
Namespace containing all symbols of the Sensors library.
Definition: bitdecoder.h:40
Base class for sensor implementations.
Definition: sensor.h:118
SensorStatus
Sensor status returned from Sensor::setData() and Sensor::addByte().
Definition: sensor.h:49