LibDriver OPT300X
Loading...
Searching...
No Matches
driver_opt300x_shot.c
Go to the documentation of this file.
1
36
37#include "driver_opt300x_shot.h"
38
39static opt300x_handle_t gs_handle;
40
51{
52 uint8_t res;
53
54 /* link interface function */
63
64 /* set chip type */
65 res = opt300x_set_type(&gs_handle, type);
66 if (res != 0)
67 {
68 opt300x_interface_debug_print("opt300x: set type failed.\n");
69
70 return 1;
71 }
72
73 /* set iic address */
74 res = opt300x_set_addr_pin(&gs_handle, addr_pin);
75 if (res != 0)
76 {
77 opt300x_interface_debug_print("opt300x: set addr pin failed.\n");
78
79 return 1;
80 }
81
82 /* opt300x init */
83 res = opt300x_init(&gs_handle);
84 if (res != 0)
85 {
86 opt300x_interface_debug_print("opt300x: init failed.\n");
87
88 return 1;
89 }
90
91 /* set default range */
92 if (type == OPT3002)
93 {
95 if (res != 0)
96 {
97 opt300x_interface_debug_print("opt3002: set range failed.\n");
98 (void)opt300x_deinit(&gs_handle);
99
100 return 1;
101 }
102 }
103 else if (type == OPT3005)
104 {
106 if (res != 0)
107 {
108 opt300x_interface_debug_print("opt3005: set range failed.\n");
109 (void)opt300x_deinit(&gs_handle);
110
111 return 1;
112 }
113 }
114 else
115 {
117 if (res != 0)
118 {
119 opt300x_interface_debug_print("opt300x: set range failed.\n");
120 (void)opt300x_deinit(&gs_handle);
121
122 return 1;
123 }
124 }
125
126 /* set default conversion time */
128 if (res != 0)
129 {
130 opt300x_interface_debug_print("opt300x: set conversion time failed.\n");
131 (void)opt300x_deinit(&gs_handle);
132
133 return 1;
134 }
135
136 /* set default mask exponent */
138 if (res != 0)
139 {
140 opt300x_interface_debug_print("opt300x: set mask exponent failed.\n");
141 (void)opt300x_deinit(&gs_handle);
142
143 return 1;
144 }
145
146 /* set default fault count */
148 if (res != 0)
149 {
150 opt300x_interface_debug_print("opt300x: set fault count failed.\n");
151 (void)opt300x_deinit(&gs_handle);
152
153 return 1;
154 }
155
156 return 0;
157}
158
167uint8_t opt300x_shot_read(float *lux)
168{
169 uint16_t raw;
170
171 /* read data */
172 if (opt300x_single_read(&gs_handle, (uint16_t *)&raw, lux) != 0)
173 {
174 return 1;
175 }
176
177 return 0;
178}
179
188uint8_t opt3002_shot_read(float *nw_cm2)
189{
190 uint16_t raw;
191
192 /* read data */
193 if (opt3002_single_read(&gs_handle, (uint16_t *)&raw, nw_cm2) != 0)
194 {
195 return 1;
196 }
197
198 return 0;
199}
200
209{
210 /* close opt300x */
211 if (opt300x_deinit(&gs_handle) != 0)
212 {
213 return 1;
214 }
215
216 return 0;
217}
driver opt300x shot header file
uint8_t opt300x_set_fault_count(opt300x_handle_t *handle, opt300x_fault_count_t count)
set fault count
uint8_t opt3005_set_range(opt300x_handle_t *handle, opt3005_range_t range)
set range
uint8_t opt3002_single_read(opt300x_handle_t *handle, uint16_t *raw, float *nw_cm2)
read data from the chip
uint8_t opt300x_set_type(opt300x_handle_t *handle, opt300x_t type)
set the chip type
uint8_t opt300x_set_mask_exponent(opt300x_handle_t *handle, opt300x_bool_t enable)
enable or disable mask exponent
opt300x_address_t
opt300x address enumeration definition
opt300x_t
opt300x type enumeration definition
uint8_t opt300x_set_conversion_time(opt300x_handle_t *handle, opt300x_conversion_time_t t)
set conversion time
uint8_t opt300x_set_range(opt300x_handle_t *handle, opt300x_range_t range)
set range
uint8_t opt300x_deinit(opt300x_handle_t *handle)
close the chip
uint8_t opt300x_set_addr_pin(opt300x_handle_t *handle, opt300x_address_t addr_pin)
set the iic address pin
uint8_t opt300x_init(opt300x_handle_t *handle)
initialize the chip
uint8_t opt3002_set_range(opt300x_handle_t *handle, opt3002_range_t range)
set range
uint8_t opt300x_single_read(opt300x_handle_t *handle, uint16_t *raw, float *lux)
read data from the chip
struct opt300x_handle_s opt300x_handle_t
opt300x handle structure definition
@ OPT3002
@ OPT3005
#define OPT300X_SHOT_DEFAULT_RANGE
#define OPT3002_SHOT_DEFAULT_RANGE
opt300x shot example default definition
uint8_t opt3002_shot_read(float *nw_cm2)
shot example read
uint8_t opt300x_shot_read(float *lux)
shot example read
#define OPT300X_SHOT_DEFAULT_CONVERSION_TIME
uint8_t opt300x_shot_init(opt300x_t type, opt300x_address_t addr_pin)
shot example init
#define OPT300X_SHOT_DEFAULT_MASK_EXPONENT
uint8_t opt300x_shot_deinit(void)
shot example deinit
#define OPT300X_SHOT_DEFAULT_FAULT_COUNT
#define OPT3005_SHOT_DEFAULT_RANGE
void opt300x_interface_delay_ms(uint32_t ms)
interface delay ms
void opt300x_interface_receive_callback(uint8_t type)
interface receive callback
void opt300x_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t opt300x_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t opt300x_interface_iic_init(void)
interface iic bus init
uint8_t opt300x_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t opt300x_interface_iic_deinit(void)
interface iic bus deinit