upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
sht1x.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 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 <stdint.h>
28 #include "upm.h"
29 #include "mraa/gpio.h"
30 
31 #include "sht1x_defs.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
48  typedef struct _sht1x_context {
49  mraa_gpio_context gpio_clk;
50  mraa_gpio_context gpio_data;
51 
52  // high res? (temp/hum 14/12b vs. 12/8b)
53  bool hires;
54 
55  // our data
56  float temperature;
57  float humidity;
58 
59  // temperature coeff (we only care about C)
60  float coeff_d1;
61  float coeff_d2;
62 
63  // humidity coeff
64  float coeff_c1;
65  float coeff_c2;
66  float coeff_c3;
67 
68  float coeff_t1;
69  float coeff_t2;
70  } *sht1x_context;
71 
79  sht1x_context sht1x_init(unsigned int clk_pin, unsigned int data_pin);
80 
84  void sht1x_close(sht1x_context dev);
85 
92  void sht1x_reset(const sht1x_context dev);
93 
101  upm_result_t sht1x_update(const sht1x_context dev);
102 
110  float sht1x_get_temperature(const sht1x_context dev);
111 
119  float sht1x_get_humidity(const sht1x_context dev);
120 
129  upm_result_t sht1x_read_status(const sht1x_context dev, uint8_t *status);
130 
138  upm_result_t sht1x_write_status(const sht1x_context dev, uint8_t status);
139 
150  void sht1x_set_volts(const sht1x_context dev, SHT1X_VOLTS_T volts);
151 
161  upm_result_t sht1x_send_command(const sht1x_context dev, SHT1X_CMD_T cmd);
162 
171  upm_result_t sht1x_wait_for_response(const sht1x_context dev);
172 
181  void sht1x_start_xmit(const sht1x_context dev);
182 
192  void sht1x_read_8bits(const sht1x_context dev, uint8_t *value);
193 
203  upm_result_t sht1x_write_8bits(const sht1x_context dev, uint8_t byte);
204 
205 #ifdef __cplusplus
206 }
207 #endif
void sht1x_close(sht1x_context dev)
Definition: sht1x.c:119
float sht1x_get_humidity(const sht1x_context dev)
Definition: sht1x.c:336
upm_result_t sht1x_read_status(const sht1x_context dev, uint8_t *status)
Definition: sht1x.c:351
upm_result_t sht1x_write_status(const sht1x_context dev, uint8_t status)
Definition: sht1x.c:367
upm_result_t sht1x_wait_for_response(const sht1x_context dev)
Definition: sht1x.c:258
void sht1x_read_8bits(const sht1x_context dev, uint8_t *value)
Definition: sht1x.c:288
float sht1x_get_temperature(const sht1x_context dev)
Definition: sht1x.c:329
struct _sht1x_context * sht1x_context
sht1x_context sht1x_init(unsigned int clk_pin, unsigned int data_pin)
Definition: sht1x.c:31
upm_result_t sht1x_update(const sht1x_context dev)
Definition: sht1x.c:131
void sht1x_reset(const sht1x_context dev)
Definition: sht1x.c:343
upm_result_t sht1x_write_8bits(const sht1x_context dev, uint8_t byte)
Definition: sht1x.c:201
void sht1x_set_volts(const sht1x_context dev, SHT1X_VOLTS_T volts)
Definition: sht1x.c:382
upm_result_t sht1x_send_command(const sht1x_context dev, SHT1X_CMD_T cmd)
Definition: sht1x.c:248
Definition: sht1x.h:48
void sht1x_start_xmit(const sht1x_context dev)
Definition: sht1x.c:184