upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
am2315.hpp
1 /*
2  * Author: William Penner <william.penner@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE.
22  */
23 
24 #pragma once
25 
26 #include <string>
27 #include <mraa/i2c.h>
28 #include <math.h>
29 
30 #define AM2315_NAME "am2315"
31 #define AM2315_I2C_ADDRESS 0x5c
32 
33 #define AM2315_READ 0x03
34 #define AM2315_WRITE 0x10
35 
36 /* AM2315 Commands */
37 #define AM2315_HUMIDITY 0x00
38 #define AM2315_TEMP 0x02
39 #define AM2315_MODEL 0x08
40 #define AM2315_VERSION 0x0A
41 #define AM2315_ID 0x0B
42 #define AM2315_STATUS 0x0F
43 #define AM2315_USER_A 0x10
44 #define AM2315_USER_B 0x12
45 
46 #define AM2315_SAMPLE 2
47 
48 #define HIGH_PRIORITY 99
49 
50 namespace upm {
51 
80 class AM2315 {
81  public:
88  AM2315 (int bus, int devAddr=AM2315_I2C_ADDRESS);
89 
93  ~AM2315 ();
94 
101  float getHumidity(void);
102 
109  float getTemperature(void);
110 
117  float getTemperatureF(void);
118 
124  int testSensor(void);
125 
137  int i2cWriteReg_32(int reg, uint32_t ival);
138 
145  int i2cWriteReg_16(int reg, uint16_t ival);
146 
153  int i2cWriteReg_8(int reg, uint8_t ival);
154 
160  uint32_t i2cReadReg_32 (int reg);
161 
167  uint16_t i2cReadReg_16 (int reg);
168 
174  uint8_t i2cReadReg_8 (int reg);
175 
176  private:
177 
178  char* m_name;
179 
180  int m_controlAddr;
181  int m_bus;
182  mraa_i2c_context m_i2ControlCtx;
183 
184  void update_values(void);
185  uint8_t i2cReadReg(int reg, uint8_t* data, int ilen);
186  int i2cWriteReg(uint8_t reg, uint8_t* data, uint8_t ilen);
187  uint16_t crc16(uint8_t* ptr, uint8_t len);
188 
189  int32_t m_temperature;
190  int32_t m_humidity;
191 
192  uint16_t m_model;
193  uint16_t m_version;
194  uint32_t m_id;
195 
196  time_t m_last_time;
197 
198  int m_base_priority;
199 };
200 
201 }
int i2cWriteReg_32(int reg, uint32_t ival)
Definition: am2315.cpp:273
AM2315(int bus, int devAddr=AM2315_I2C_ADDRESS)
Definition: am2315.cpp:39
~AM2315()
Definition: am2315.cpp:72
float getHumidity(void)
Definition: am2315.cpp:107
API for the AM2315 Temperature & Humidity Sensor.
Definition: am2315.hpp:80
uint8_t i2cReadReg_8(int reg)
Definition: am2315.cpp:314
float getTemperatureF(void)
Definition: am2315.cpp:101
int testSensor(void)
Definition: am2315.cpp:120
float getTemperature(void)
Definition: am2315.cpp:94
int i2cWriteReg_8(int reg, uint8_t ival)
Definition: am2315.cpp:291
uint32_t i2cReadReg_32(int reg)
Definition: am2315.cpp:299
uint16_t i2cReadReg_16(int reg)
Definition: am2315.cpp:307
int i2cWriteReg_16(int reg, uint16_t ival)
Definition: am2315.cpp:283