upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
hwxpxx.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 
28 #include <modbus/modbus.h>
29 
30 namespace upm {
31 
67  class HWXPXX {
68  public:
69  // MODBUS input registers
70  typedef enum {
71  INPUT_HUMIDITY = 0x0000,
72  // optional temp sensor
73  INPUT_TEMPERATURE = 0x0001,
74  // optional slider input
75  INPUT_SLIDER = 0x0002
76  } INPUT_REGS_T;
77 
78  // MODBUS coil registers
79  typedef enum {
80  // device reports in C or F?
81  COIL_TEMP_SCALE = 0x0000,
82 
83  // optional override button status
84  COIL_OVERRIDE = 0x0001
85  } COIL_REGS_T;
86 
87  // MODBUS holding registers
88  typedef enum {
89  HOLDING_TEMP_OFFSET = 0x0000,
90  HOLDING_HUM_OFFSET = 0x0001
91  } HOLDING_REGS_T;
92 
104  HWXPXX(std::string device, int address, int baud=19200, int bits=8,
105  char parity='N', int stopBits=2);
106 
110  ~HWXPXX();
111 
118  void update();
119 
131  float getTemperature(bool fahrenheit=false);
132 
139  float getHumidity();
140 
150  int getSlider();
151 
164 
171  void clearOverrideSwitch();
172 
182  int getTemperatureOffset();
183 
192  int getHumidityOffset();
193 
202  void setTemperatureOffset(int offset);
203 
212  void setHumidityOffset(int offset);
213 
224  void setTemperatureScale(bool fahrenheit);
225 
233  std::string getSlaveID();
234 
243  void setSlaveAddress(int addr);
244 
251  void setDebug(bool enable);
252 
253  protected:
254  // input registers
255  int readInputRegs(INPUT_REGS_T reg, int len, uint16_t *buf);
256  uint16_t readInputReg(INPUT_REGS_T reg);
257 
258  // coils
259  int readCoils(COIL_REGS_T reg, int numBits, uint8_t *buf);
260  bool readCoil(COIL_REGS_T reg);
261  void writeCoil(COIL_REGS_T reg, bool val);
262 
263  // holding registers
264  int readHoldingRegs(HOLDING_REGS_T reg, int len, uint16_t *buf);
265  uint16_t readHoldingReg(HOLDING_REGS_T reg);
266  void writeHoldingReg(HOLDING_REGS_T reg, int value);
267 
268  // MODBUS context
269  modbus_t *m_mbContext;
270 
271  // is the device reporting in C or F?
272  bool m_isCelsius;
273 
274  private:
275  bool m_debugging;
276 
277  // data
278  float m_temperature;
279  float m_humidity; // relative
280  int m_slider; // optional slider value
281  bool m_override; // status of override switch
282  };
283 }
float getTemperature(bool fahrenheit=false)
Definition: hwxpxx.cxx:258
void setHumidityOffset(int offset)
Definition: hwxpxx.cxx:302
bool getOverrideSwitchStatus()
Definition: hwxpxx.cxx:276
UPM API for the Veris HWXPXX Hardware Protocol Humidity and Temperature Sensor.
Definition: hwxpxx.hpp:67
int getHumidityOffset()
Definition: hwxpxx.cxx:286
void setTemperatureScale(bool fahrenheit)
Definition: hwxpxx.cxx:318
int getTemperatureOffset()
Definition: hwxpxx.cxx:281
int getSlider()
Definition: hwxpxx.cxx:271
void setTemperatureOffset(int offset)
Definition: hwxpxx.cxx:291
std::string getSlaveID()
Definition: hwxpxx.cxx:329
void setDebug(bool enable)
Definition: hwxpxx.cxx:371
void setSlaveAddress(int addr)
Definition: hwxpxx.cxx:353
float getHumidity()
Definition: hwxpxx.cxx:266
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void clearOverrideSwitch()
Definition: hwxpxx.cxx:313
HWXPXX(std::string device, int address, int baud=19200, int bits=8, char parity='N', int stopBits=2)
Definition: hwxpxx.cxx:47
void update()
Definition: hwxpxx.cxx:228
~HWXPXX()
Definition: hwxpxx.cxx:121