upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
ims.h
Go to the documentation of this file.
1 /*
2  * Author: Noel Eck <noel.eck@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 #pragma once
26 
27 #include <errno.h>
28 #include <stdint.h>
29 
30 #include "mraa/i2c.h"
31 #include "upm.h"
32 
33 #include "ims_defs.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
51 typedef struct {
52  /* mraa i2c context */
53  mraa_i2c_context _i2c_context;
54  /* Save the I2C bus (used when changing the device address) */
55  int16_t _i2c_bus;
56 } ims_context;
57 
64 ims_context* ims_init(int16_t i2c_bus, int16_t i2c_address);
65 
71 void ims_close(ims_context* dev);
72 
80 upm_result_t ims_read(const ims_context* dev, IMS_RD_COMMAND cmd, uint16_t* rd_data);
81 
89 upm_result_t ims_write(const ims_context* dev, IMS_WR_COMMAND cmd, uint8_t wr_data);
90 
97 upm_result_t ims_get_version(const ims_context* dev, uint16_t* rd_data);
98 
105 upm_result_t ims_get_moisture(const ims_context* dev, uint16_t* rd_data);
106 
117 upm_result_t ims_get_light(const ims_context* dev, uint16_t* rd_data);
118 
126 upm_result_t ims_get_temperature(const ims_context* dev, uint16_t* rd_data);
127 
133 upm_result_t ims_reset(const ims_context* dev);
134 
141 upm_result_t ims_reset_i2c_address(ims_context* dev, uint8_t address_new);
142 
148 upm_result_t ims_sleep(const ims_context* dev);
149 
150 #ifdef __cplusplus
151 }
152 #endif
upm_result_t ims_get_version(const ims_context *dev, uint16_t *rd_data)
Definition: ims.c:165
void ims_close(ims_context *dev)
Definition: ims.c:95
ims_context * ims_init(int16_t i2c_bus, int16_t i2c_address)
Definition: ims.c:66
upm_result_t ims_sleep(const ims_context *dev)
Definition: ims.c:227
upm_result_t ims_reset_i2c_address(ims_context *dev, uint8_t address_new)
Definition: ims.c:211
upm_result_t ims_read(const ims_context *dev, IMS_RD_COMMAND cmd, uint16_t *rd_data)
Definition: ims.c:104
upm_result_t ims_get_temperature(const ims_context *dev, uint16_t *rd_data)
Definition: ims.c:201
upm_result_t ims_get_light(const ims_context *dev, uint16_t *rd_data)
Definition: ims.c:175
upm_result_t ims_reset(const ims_context *dev)
Definition: ims.c:206
upm_result_t ims_write(const ims_context *dev, IMS_WR_COMMAND cmd, uint8_t wr_data)
Definition: ims.c:140
upm_result_t ims_get_moisture(const ims_context *dev, uint16_t *rd_data)
Definition: ims.c:170
Definition: ims.h:51