upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
am2315.h
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:
89  AM2315 (int bus, int devAddr=AM2315_I2C_ADDRESS);
90 
94  ~AM2315 ();
95 
102  float getHumidity(void);
103 
110  float getTemperature(void);
111 
118  float getTemperatureF(void);
119 
125  int testSensor(void);
126 
138  int i2cWriteReg_32(int reg, uint32_t ival);
139 
146  int i2cWriteReg_16(int reg, uint16_t ival);
147 
154  int i2cWriteReg_8(int reg, uint8_t ival);
155 
161  uint32_t i2cReadReg_32 (int reg);
162 
168  uint16_t i2cReadReg_16 (int reg);
169 
175  uint8_t i2cReadReg_8 (int reg);
176 
177  private:
178 
179  char* m_name;
180 
181  int m_controlAddr;
182  int m_bus;
183  mraa_i2c_context m_i2ControlCtx;
184 
185  void update_values(void);
186  uint8_t i2cReadReg(int reg, uint8_t* data, int ilen);
187  int i2cWriteReg(uint8_t reg, uint8_t* data, uint8_t ilen);
188  uint16_t crc16(uint8_t* ptr, uint8_t len);
189 
190  int32_t m_temperature;
191  int32_t m_humidity;
192 
193  uint16_t m_model;
194  uint16_t m_version;
195  uint32_t m_id;
196 
197  time_t m_last_time;
198 
199  int m_base_priority;
200  pthread_t this_thread;
201 };
202 
203 }
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.h: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