upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bh1750.h
Go to the documentation of this file.
1 /*
2  * Authors: 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 
29 #include "mraa/i2c.h"
30 
31 #include "upm.h"
32 #include "upm_types.h"
33 
34 #include "bh1750_defs.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif // __cplusplus
39 
51 typedef struct _bh1750_context
52 {
53  int bus;
54  mraa_i2c_context i2c;
55 
56  // these are set by bh1750_set_opmode()
57  uint8_t opmode;
58  bool is_continuous;
59  int delayms;
61 
70 bh1750_context bh1750_init(int bus, uint8_t addr, BH1750_OPMODES_T mode);
71 
77 void bh1750_close(const bh1750_context dev);
78 
86 upm_result_t bh1750_get_lux(const bh1750_context dev, float* lux);
87 
94 bool bh1750_power_up(const bh1750_context dev);
95 
102 bool bh1750_power_down(const bh1750_context dev);
103 
112 bool bh1750_reset(const bh1750_context dev);
113 
121 upm_result_t bh1750_send_command(const bh1750_context dev, uint8_t cmd);
122 
130 upm_result_t bh1750_read_data(const bh1750_context dev, uint16_t* data);
131 
140 upm_result_t bh1750_set_opmode(const bh1750_context dev,
141  BH1750_OPMODES_T mode);
142 
143 #ifdef __cplusplus
144 }
145 #endif // __cplusplus
upm_result_t bh1750_set_opmode(const bh1750_context dev, BH1750_OPMODES_T mode)
Definition: bh1750.c:223
bh1750_context bh1750_init(int bus, uint8_t addr, BH1750_OPMODES_T mode)
Definition: bh1750.c:31
upm_result_t bh1750_get_lux(const bh1750_context dev, float *lux)
Definition: bh1750.c:96
bool bh1750_power_down(const bh1750_context dev)
Definition: bh1750.c:133
upm_result_t bh1750_read_data(const bh1750_context dev, uint16_t *data)
Definition: bh1750.c:175
upm_result_t bh1750_send_command(const bh1750_context dev, uint8_t cmd)
Definition: bh1750.c:161
bool bh1750_power_up(const bh1750_context dev)
Definition: bh1750.c:119
struct _bh1750_context * bh1750_context
bool bh1750_reset(const bh1750_context dev)
Definition: bh1750.c:147
void bh1750_close(const bh1750_context dev)
Definition: bh1750.c:86
Definition: bh1750.h:51