LibDriver AFS01
Loading...
Searching...
No Matches
driver_afs01_read_test.c
Go to the documentation of this file.
1
36
38
39static afs01_handle_t gs_handle;
40
49uint8_t afs01_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint8_t id[4];
53 uint32_t i;
54 afs01_info_t info;
55
56 /* link interface function */
63
64 /* get information */
65 res = afs01_info(&info);
66 if (res != 0)
67 {
68 afs01_interface_debug_print("afs01: get info failed.\n");
69
70 return 1;
71 }
72 else
73 {
74 /* print chip information */
75 afs01_interface_debug_print("afs01: chip is %s.\n", info.chip_name);
76 afs01_interface_debug_print("afs01: manufacturer is %s.\n", info.manufacturer_name);
77 afs01_interface_debug_print("afs01: interface is %s.\n", info.interface);
78 afs01_interface_debug_print("afs01: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
79 afs01_interface_debug_print("afs01: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
80 afs01_interface_debug_print("afs01: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
81 afs01_interface_debug_print("afs01: max current is %0.2fmA.\n", info.max_current_ma);
82 afs01_interface_debug_print("afs01: max temperature is %0.1fC.\n", info.temperature_max);
83 afs01_interface_debug_print("afs01: min temperature is %0.1fC.\n", info.temperature_min);
84 }
85
86 /* start read test */
87 afs01_interface_debug_print("afs01: start read test.\n");
88
89 /* afs01 init */
90 res = afs01_init(&gs_handle);
91 if (res != 0)
92 {
93 afs01_interface_debug_print("afs01: init failed.\n");
94
95 return 1;
96 }
97
98 /* get chip id */
99 res = afs01_get_chip_id(&gs_handle, id);
100 if (res != 0)
101 {
102 afs01_interface_debug_print("afs01: get chip id failed.\n");
103 (void)afs01_deinit(&gs_handle);
104
105 return 1;
106 }
107
108 /* output */
109 afs01_interface_debug_print("afs01: chip id is 0x%02X 0x%02X 0x%02X 0x%02X.\n", id[0], id[1], id[2], id[3]);
110
111 for (i = 0; i < times; i++)
112 {
113 uint16_t raw;
114 float sccm;
115
116 /* delay 1000ms */
118
119 /* read data */
120 res = afs01_read(&gs_handle, &raw, &sccm);
121 if (res != 0)
122 {
123 afs01_interface_debug_print("afs01: read data failed.\n");
124 (void)afs01_deinit(&gs_handle);
125
126 return 1;
127 }
128
129 /* output */
130 afs01_interface_debug_print("afs01: gas flow is %0.1fsccm.\n", sccm);
131 }
132
133 /* finish read test */
134 afs01_interface_debug_print("afs01: finish read test.\n");
135 (void)afs01_deinit(&gs_handle);
136
137 return 0;
138}
driver afs01 read test header file
uint8_t afs01_info(afs01_info_t *info)
get chip's information
struct afs01_info_s afs01_info_t
afs01 information structure definition
uint8_t afs01_get_chip_id(afs01_handle_t *handle, uint8_t id[4])
get chip id
uint8_t afs01_read(afs01_handle_t *handle, uint16_t *raw, float *sccm)
read data
uint8_t afs01_deinit(afs01_handle_t *handle)
close the chip
uint8_t afs01_init(afs01_handle_t *handle)
initialize the chip
struct afs01_handle_s afs01_handle_t
afs01 handle structure definition
void afs01_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t afs01_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with 16 bits register address
uint8_t afs01_interface_iic_init(void)
interface iic bus init
void afs01_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t afs01_interface_iic_deinit(void)
interface iic bus deinit
uint8_t afs01_read_test(uint32_t times)
read test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]