upm  1.1.0
Sensor/Actuator repository for libmraa (v1.5.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 "interfaces/iCO2Sensor.hpp"
28 
29 namespace upm {
30 
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 
69 
70  typedef enum
71  {
72  ERROR_CONDITION,
73  FLASH_ERROR,
74  CALIBRATION_ERROR,
75  WARMUP_MODE,
76  SINGLE_POINT_CALIBRATION,
77  RS232,
78  I2C,
79  RS485
80  }STATUS;
81 
82  typedef struct
83  {
84  uint8_t function_code;
85  uint8_t register_address_msb;
86  uint8_t register_address_lsb;
87  uint8_t input_registers_to_read_msb;
88  uint8_t input_registers_to_read_lsb;
89 
90  }COMMAND;
91 
92  typedef struct
93  {
94  uint8_t function_code;
95  uint8_t byte_count;
96  uint8_t status_msb;
97  uint8_t status_lsb;
98 
99  }RESPONSE;
100 
101 
102  typedef enum
103  {
104  READ_INPUT_REGISTERS = 4,
105  WRITE_SINGLE_COIL,
106  WRITE_SINGLE_HOLDING_REGISTER
107  }FUNCTION_CODES;
108 }//namespace t6713_co2
109 
110 
111 class T6713 : public ICO2Sensor {
112  public:
118  T6713 (int bus);
119 
123  ~T6713 ();
124 
128  const char* getModuleName();
129 
133  uint16_t getPpm ();
137  uint16_t getFirmwareRevision();
138 
139 
140  private:
141  mraa::Result runCommand(t6713_co2::MODBUS_COMMANDS command);
142  uint16_t getSensorData (t6713_co2::MODBUS_COMMANDS cmd);
143  t6713_co2::STATUS getStatus();
144 
145  mraa::I2c* i2c;
146  mraa::Result status;
147 };
148 
149 
150 }//namespace upm
T6713(int bus)
Definition: t6713.cxx:54
Definition: t6713.hpp:82
~T6713()
Definition: t6713.cxx:63
Definition: t6713.hpp:92
Interface for CO Sensor.
Definition: iCO2Sensor.hpp:36
const char * getModuleName()
Definition: t6713.cxx:68
uint16_t getPpm()
Definition: t6713.cxx:78
Definition: t6713.hpp:111
uint16_t getFirmwareRevision()
Definition: t6713.cxx:73