atMETEO
An ATmega based weather station
hidekisensor.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 
36 #include <stdlib.h> // AVR toolchain doesn't offer cstdlib header
37 #include <string.h> // AVR toolchain doesn't offer cstring header
38 
39 #include "sensor.h"
40 #include "demodulator.h"
41 #include "bitdecoder.h"
42 #include "rfdevice.h"
43 #include "utils.h"
44 
45 namespace Sensors
46 {
47 
62 class HidekiSensor : public Sensor<HidekiSensor>
63 {
64  friend class Sensor<HidekiSensor>;
65 
66 public:
70  HidekiSensor();
71 
78  bool isValid() const;
79 
86  bool isPossiblyValid() const;
87 
103  uint8_t channel() const;
104 
114  uint8_t sensorId() const;
115 
121  bool batteryOk() const;
122 
130  uint8_t message() const;
131 
148  bool isThermoHygro() const;
149 
155  int8_t temperature() const;
156 
162  float temperatureF() const;
163 
169  uint8_t humidity() const;
170  // Thermo/Hygro
172 
173 private:
174  SensorStatus internalSetData(uint8_t *data, size_t length);
175  SensorStatus internalAddByte(uint8_t byte);
176  void internalReset();
177 
182  static const size_t c_length = 10;
183 
188  static const uint8_t c_header = 0x9F;
189 
203  static const uint8_t c_thermoHygro = 0x1E;
204 
208  static const uint8_t c_thermoHygroTempPositive = 0xC;
209 
213  static const uint8_t c_thermoHygroTempNegative = 0x4;
214  // Thermo/Hygro
216 
222  uint8_t header() const;
223 
231  uint8_t packageLength() const;
232 
238  uint8_t sensorType() const;
239 
245  uint8_t crc1() const;
246 
252  uint8_t crc2() const;
253 
257  uint8_t m_data[c_length];
258 
263  uint8_t m_byteIndex;
264 };
265 
283 template <uint16_t TShortMin, uint16_t TShortMax,
284  uint16_t TLongMin, uint16_t TLongMax>
285 using HidekiDevice = RfDevice<
288  HidekiSensor,
289  89>;
290 
302 {
303 public:
308  {
309  reset();
310  }
311 
317  void storeSensorValues(const HidekiSensor &sensor)
318  {
319  m_valid = sensor.isValid();
320  m_channel = sensor.channel();
321  m_batteryOk = sensor.batteryOk();
322  m_temperature = sensor.temperature();
323  m_temperatureF = sensor.temperatureF();
324  m_humidity = sensor.humidity();
325  }
326 
330  void reset()
331  {
332  m_channel = 0;
333  m_batteryOk = false;
334  m_temperature = 0;
335  m_temperatureF = 0.0;
336  m_humidity = 0;
337  m_valid = false;
338  }
339 
345  bool isValid() const
346  {
347  return m_valid;
348  }
349 
355  uint8_t channel() const
356  {
357  return m_channel;
358  }
359 
365  bool batteryOk() const
366  {
367  return m_batteryOk;
368  }
369 
375  int8_t temperature() const
376  {
377  return m_temperature;
378  }
379 
385  float temperatureF() const
386  {
387  return m_temperatureF;
388  }
389 
395  uint8_t humidity() const
396  {
397  return m_humidity;
398  }
399 
400 private:
401  bool m_valid;
402  uint8_t m_channel;
403  bool m_batteryOk;
404  int8_t m_temperature;
405  float m_temperatureF;
406  uint8_t m_humidity;
407 };
408  // \addtogroup libsensors_hideki
410 
411 } // namespace Sensors
float temperatureF() const
Gets the temperature value of the current message as float.
Definition: hidekisensor.cpp:197
HidekiSensor()
Initializes the Hideki sensor decoder.
Definition: hidekisensor.cpp:25
uint8_t channel() const
Gets the channel value.
Definition: hidekisensor.h:355
float temperatureF() const
Gets the temperature value as float.
Definition: hidekisensor.h:385
uint8_t sensorId() const
Returns the sensor id of the current message.
Definition: hidekisensor.cpp:119
Transforms continuous streams with pulse widths (for example from RF receivers) into bits...
Definition: demodulator.h:180
uint8_t message() const
Returns the number of the current message.
Definition: hidekisensor.cpp:129
void reset()
Resets the state of the sensor decoder for receiving a new data set.
Definition: sensor.h:148
bool isValid() const
Determines if the data object contains valid values.
Definition: hidekisensor.h:345
bool isPossiblyValid() const
Determines if the current data is possibly valid (but not complete).
Definition: hidekisensor.cpp:86
bool batteryOk() const
Determines if the battery is ok.
Definition: hidekisensor.cpp:124
Applies bit numbering and a parity method to transform continuous bit streams (for example from RF de...
Definition: bitdecoder.h:227
bool batteryOk() const
Determines if the battery is ok.
Definition: hidekisensor.h:365
Sensors::BitDecoder transforms continuous bit streams (for example from RF demodulation) into bytes...
Bit manipulation utilities.
Namespace containing all symbols of the Sensors library.
Definition: bitdecoder.h:40
Sensors::Sensor is the base class for sensor specific data decoding.
bool isThermoHygro() const
Determines if the current message contains a Thermo/Hygro data set.
Definition: hidekisensor.cpp:183
void reset()
Resets all values.
Definition: hidekisensor.h:330
Base class for sensor implementations.
Definition: sensor.h:118
uint8_t humidity() const
Gets the humidity value of the current message.
Definition: hidekisensor.cpp:206
Connects Demodulator, Bit Decoder and Sensor for decoding sensor data from RF receivers.
Definition: rfdevice.h:111
bool isValid() const
Determines if the current decoder state is valid.
Definition: hidekisensor.cpp:77
uint8_t humidity() const
Gets the humidity value.
Definition: hidekisensor.h:395
uint8_t channel() const
Returns the channel of the current message.
Definition: hidekisensor.cpp:106
HidekiData()
Definition: hidekisensor.h:307
Decodes data received from a Hideki RF 433 MHz sensor.
Definition: hidekisensor.h:62
int8_t temperature() const
Gets the temperature value of the current message.
Definition: hidekisensor.cpp:188
void storeSensorValues(const HidekiSensor &sensor)
Definition: hidekisensor.h:317
Sensors::Demodulator transforms continuous streams with pulse widths (for example from RF receivers) ...
int8_t temperature() const
Gets the temperature value.
Definition: hidekisensor.h:375
Data class for storing values of a HidekiSensor.
Definition: hidekisensor.h:301
SensorStatus
Sensor status returned from Sensor::setData() and Sensor::addByte().
Definition: sensor.h:49
Sensors::RfDevice is the base template for RF receivers connecting Demodulator, Bit Decoder and Senso...