upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "upm/iCO2Sensor.hpp"
28 
29 namespace upm {
30 
56 namespace t6713_co2
57 {
58  /* COMMAND VALUES */
59  typedef enum
60  {
61  T6713_COMMAND_RESET,
62  T6713_COMMAND_STATUS,
63  T6713_COMMAND_GET_FIRMWARE_REVISION,
64  T6713_COMMAND_GET_GAS_PPM
65  }MODBUS_COMMANDS;
66 
67 
68 
69  typedef enum
70  {
71  ERROR_CONDITION,
72  FLASH_ERROR,
73  CALIBRATION_ERROR,
74  WARMUP_MODE,
75  SINGLE_POINT_CALIBRATION,
76  RS232,
77  I2C,
78  RS485
79  }STATUS;
80 
81  typedef struct
82  {
83  uint8_t function_code;
84  uint8_t register_address_msb;
85  uint8_t register_address_lsb;
86  uint8_t input_registers_to_read_msb;
87  uint8_t input_registers_to_read_lsb;
88 
89  }COMMAND;
90 
91  typedef struct
92  {
93  uint8_t function_code;
94  uint8_t byte_count;
95  uint8_t status_msb;
96  uint8_t status_lsb;
97 
98  }RESPONSE;
99 
100 
101  typedef enum
102  {
103  READ_INPUT_REGISTERS = 4,
104  WRITE_SINGLE_COIL,
105  WRITE_SINGLE_HOLDING_REGISTER
106  }FUNCTION_CODES;
107 }//namespace t6713_co2
108 
109 
110 class T6713 : public ICO2Sensor {
111  public:
117  T6713 (int bus);
118 
122  ~T6713 ();
123 
127  const char* getModuleName();
128 
132  uint16_t getPpm ();
136  uint16_t getFirmwareRevision();
137 
138 
139  private:
140  mraa::Result runCommand(t6713_co2::MODBUS_COMMANDS command);
141  uint16_t getSensorData (t6713_co2::MODBUS_COMMANDS cmd);
142  t6713_co2::STATUS getStatus();
143 
144  int bus;
145  mraa::I2c* i2c;
146  mraa::Result status;
147 };
148 
149 
150 }//namespace upm
T6713(int bus)
Definition: t6713.cxx:52
Definition: t6713.hpp:81
~T6713()
Definition: t6713.cxx:61
Definition: t6713.hpp:91
Interface for CO Sensor.
Definition: iCO2Sensor.hpp:36
const char * getModuleName()
Definition: t6713.cxx:66
uint16_t getPpm()
Definition: t6713.cxx:76
Definition: t6713.hpp:110
uint16_t getFirmwareRevision()
Definition: t6713.cxx:71