LibDriver BH1750FVI  1.0.0
BH1750FVI full-featured driver
driver_bh1750fvi_shot.c
Go to the documentation of this file.
1 
37 #include "driver_bh1750fvi_shot.h"
38 
39 static bh1750fvi_handle_t gs_handle;
50 {
51  uint8_t res;
52 
53  /* link interface function */
61 
62  /* set the addr pin */
63  res = bh1750fvi_set_addr_pin(&gs_handle, addr_pin);
64  if (res != 0)
65  {
66  bh1750fvi_interface_debug_print("bh1750fvi: set addr pin failed.\n");
67 
68  return 1;
69  }
70 
71  /* init */
72  res = bh1750fvi_init(&gs_handle);
73  if (res != 0)
74  {
75  bh1750fvi_interface_debug_print("bh1750fvi: init failed.\n");
76 
77  return 1;
78  }
79 
80  /* power on */
81  res = bh1750fvi_power_on(&gs_handle);
82  if (res != 0)
83  {
84  bh1750fvi_interface_debug_print("bh1750fvi: power on failed.\n");
85  (void)bh1750fvi_deinit(&gs_handle);
86 
87  return 1;
88  }
89 
90  /* set mode */
92  if (res != 0)
93  {
94  bh1750fvi_interface_debug_print("bh1750fvi: set mode failed.\n");
95  (void)bh1750fvi_deinit(&gs_handle);
96 
97  return 1;
98  }
99 
100  /* set measurement time */
102  if (res != 0)
103  {
104  bh1750fvi_interface_debug_print("bh1750fvi: set measurement time failed.\n");
105  (void)bh1750fvi_deinit(&gs_handle);
106 
107  return 1;
108  }
109 
110  return 0;
111 }
112 
121 uint8_t bh1750fvi_shot_read(float *lux)
122 {
123  uint8_t res;
124  uint16_t raw;
125 
126  /* continuous read */
127  res = bh1750fvi_single_read(&gs_handle, &raw, lux);
128  if (res != 0)
129  {
130  return 1;
131  }
132  else
133  {
134  return 0;
135  }
136 }
137 
146 {
147  uint8_t res;
148 
149  /* deinit */
150  res = bh1750fvi_deinit(&gs_handle);
151  if (res != 0)
152  {
153  return 1;
154  }
155 
156  return 0;
157 }
driver bh1750fvi shot header file
uint8_t bh1750fvi_single_read(bh1750fvi_handle_t *handle, uint16_t *raw, float *lux)
read data from the chip once
uint8_t bh1750fvi_deinit(bh1750fvi_handle_t *handle)
close the chip
uint8_t bh1750fvi_set_measurement_time(bh1750fvi_handle_t *handle, uint8_t t)
set the measurement time
uint8_t bh1750fvi_set_addr_pin(bh1750fvi_handle_t *handle, bh1750fvi_address_t addr_pin)
set the address pin
uint8_t bh1750fvi_power_on(bh1750fvi_handle_t *handle)
power on
uint8_t bh1750fvi_init(bh1750fvi_handle_t *handle)
initialize the chip
bh1750fvi_address_t
bh1750fvi address enumeration definition
uint8_t bh1750fvi_set_mode(bh1750fvi_handle_t *handle, bh1750fvi_mode_t mode)
set the mode
#define BH1750FVI_SHOT_DEFAULT_MODE
bh1750fvi shot example default definition
uint8_t bh1750fvi_shot_init(bh1750fvi_address_t addr_pin)
shot example init
uint8_t bh1750fvi_shot_read(float *lux)
shot example read
uint8_t bh1750fvi_shot_deinit(void)
shot example deinit
#define BH1750FVI_SHOT_DEFAULT_MEASUREMENT_TIME
void bh1750fvi_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bh1750fvi_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bh1750fvi_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t bh1750fvi_interface_iic_init(void)
interface iic bus init
uint8_t bh1750fvi_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
void bh1750fvi_interface_debug_print(const char *const fmt,...)
interface print format data
bh1750fvi handle structure definition