LibDriver MAX44009
Loading...
Searching...
No Matches
driver_max44009_read_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static max44009_handle_t gs_handle;
41
51uint8_t max44009_read_test(max44009_address_t addr, uint32_t times)
52{
53 uint8_t res;
54 uint16_t raw;
55 float lux;
56 uint32_t i;
57 max44009_info_t info;
58
59 /* link interface function */
67
68 /* get information */
69 res = max44009_info(&info);
70 if (res != 0)
71 {
72 max44009_interface_debug_print("max44009: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print chip info */
79 max44009_interface_debug_print("max44009: chip is %s.\n", info.chip_name);
80 max44009_interface_debug_print("max44009: manufacturer is %s.\n", info.manufacturer_name);
81 max44009_interface_debug_print("max44009: interface is %s.\n", info.interface);
82 max44009_interface_debug_print("max44009: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 max44009_interface_debug_print("max44009: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 max44009_interface_debug_print("max44009: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 max44009_interface_debug_print("max44009: max current is %0.3fmA.\n", info.max_current_ma);
86 max44009_interface_debug_print("max44009: max temperature is %0.1fC.\n", info.temperature_max);
87 max44009_interface_debug_print("max44009: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start read test */
91 max44009_interface_debug_print("max44009: start read test.\n");
92
93 /* set addr pin */
94 res = max44009_set_addr_pin(&gs_handle, addr);
95 if (res != 0)
96 {
97 max44009_interface_debug_print("max44009: set addr pin test.\n");
98
99 return 1;
100 }
101
102 /* init */
103 res = max44009_init(&gs_handle);
104 if (res != 0)
105 {
106 max44009_interface_debug_print("max44009: init failed.\n");
107
108 return 1;
109 }
110
111 /* enable auto range */
113 if (res != 0)
114 {
115 max44009_interface_debug_print("max44009: set auto range failed.\n");
116 (void)max44009_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* enable continuous mode */
123 if (res != 0)
124 {
125 max44009_interface_debug_print("max44009: set continuous mode failed.\n");
126 (void)max44009_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* disable interrupt */
133 if (res != 0)
134 {
135 max44009_interface_debug_print("max44009: set interrupt failed.\n");
136 (void)max44009_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 for (i = 0; i < times; i++)
142 {
143 res = max44009_read(&gs_handle, &raw, &lux);
144 if (res != 0)
145 {
146 max44009_interface_debug_print("max44009: read failed.\n");
147 (void)max44009_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 /* output */
153 max44009_interface_debug_print("max44009: data is %0.2flux.\n", lux);
154
155 /* delay 1000ms */
157 }
158
159 /* finish read test */
160 max44009_interface_debug_print("max44009: finish read test.\n");
161 (void)max44009_deinit(&gs_handle);
162
163 return 0;
164}
driver max44009 read test header file
uint8_t max44009_read(max44009_handle_t *handle, uint16_t *raw, float *lux)
read data
struct max44009_handle_s max44009_handle_t
max44009 handle structure definition
uint8_t max44009_set_addr_pin(max44009_handle_t *handle, max44009_address_t addr_pin)
set the address pin
uint8_t max44009_info(max44009_info_t *info)
get chip's information
struct max44009_info_s max44009_info_t
max44009 information structure definition
uint8_t max44009_set_continuous_mode(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable continuous mode
max44009_address_t
max44009 address enumeration definition
uint8_t max44009_set_interrupt(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable interrupt
uint8_t max44009_deinit(max44009_handle_t *handle)
close the chip
uint8_t max44009_init(max44009_handle_t *handle)
initialize the chip
uint8_t max44009_set_auto_range(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable auto range
@ MAX44009_BOOL_TRUE
@ MAX44009_BOOL_FALSE
void max44009_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t max44009_interface_iic_init(void)
interface iic bus init
uint8_t max44009_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t max44009_interface_iic_deinit(void)
interface iic bus deinit
uint8_t max44009_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void max44009_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t max44009_read_test(max44009_address_t addr, uint32_t times)
read test
char manufacturer_name[32]