upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
t6713.hpp
1 /*
2  * Author: Henry Bruce <henry.bruce@intel.com>
3  * Copyright (c) 2015 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 
25 
26 #include "mraa/i2c.hpp"
27 #include "interfaces/iCO2Sensor.hpp"
28 
29 namespace upm {
57 namespace t6713_co2
58 {
59  /* COMMAND VALUES */
60  typedef enum
61  {
62  T6713_COMMAND_RESET,
63  T6713_COMMAND_STATUS,
64  T6713_COMMAND_GET_FIRMWARE_REVISION,
65  T6713_COMMAND_GET_GAS_PPM
66  }MODBUS_COMMANDS;
67 
68  typedef enum
69  {
70  ERROR_CONDITION,
71  FLASH_ERROR,
72  CALIBRATION_ERROR,
73  WARMUP_MODE,
74  SINGLE_POINT_CALIBRATION,
75  RS232,
76  I2C,
77  RS485
78  }STATUS;
79 
80  typedef struct
81  {
82  uint8_t function_code;
83  uint8_t register_address_msb;
84  uint8_t register_address_lsb;
85  uint8_t input_registers_to_read_msb;
86  uint8_t input_registers_to_read_lsb;
87 
88  }COMMAND;
89 
90  typedef struct
91  {
92  uint8_t function_code;
93  uint8_t byte_count;
94  uint8_t status_msb;
95  uint8_t status_lsb;
96 
97  }RESPONSE;
98 
99  typedef enum
100  {
101  READ_INPUT_REGISTERS = 4,
102  WRITE_SINGLE_COIL,
103  WRITE_SINGLE_HOLDING_REGISTER
104  }FUNCTION_CODES;
105 }//namespace t6713_co2
106 
107 class T6713 : public ICO2Sensor {
108  public:
114  T6713 (int bus);
115 
119  virtual ~T6713 () {};
120 
124  virtual const char* getModuleName() { return "t6713"; }
125 
129  uint16_t getPpm ();
133  uint16_t getFirmwareRevision();
134 
135 
136  private:
137  mraa::Result runCommand(t6713_co2::MODBUS_COMMANDS command);
138  uint16_t getSensorData(t6713_co2::MODBUS_COMMANDS cmd);
139  t6713_co2::STATUS getStatus();
140 
141  mraa::I2c i2c;
142  mraa::Result status;
143 };
144 
145 }//namespace upm
virtual ~T6713()
Definition: t6713.hpp:119
Definition: t6713.hpp:80
Definition: t6713.hpp:90
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
Interface for CO Sensor.
Definition: iCO2Sensor.hpp:35
virtual const char * getModuleName()
Definition: t6713.hpp:124
Definition: t6713.hpp:107