LibDriver AGS02MA
Loading...
Searching...
No Matches
driver_ags02ma_read_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static ags02ma_handle_t gs_handle;
41
50uint8_t ags02ma_read_test(uint32_t times)
51{
52 uint8_t res;
53 uint8_t version;
54 uint8_t addr_7bit;
55 double ohm;
56 uint32_t i;
57 uint32_t raw;
58 uint32_t ppb;
59 ags02ma_info_t info;
60
61 /* link interface function */
70
71 /* get ags02ma information */
72 res = ags02ma_info(&info);
73 if (res != 0)
74 {
75 ags02ma_interface_debug_print("ags02ma: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print ags02ma information */
82 ags02ma_interface_debug_print("ags02ma: chip is %s.\n", info.chip_name);
83 ags02ma_interface_debug_print("ags02ma: manufacturer is %s.\n", info.manufacturer_name);
84 ags02ma_interface_debug_print("ags02ma: interface is %s.\n", info.interface);
85 ags02ma_interface_debug_print("ags02ma: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 ags02ma_interface_debug_print("ags02ma: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 ags02ma_interface_debug_print("ags02ma: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 ags02ma_interface_debug_print("ags02ma: max current is %0.2fmA.\n", info.max_current_ma);
89 ags02ma_interface_debug_print("ags02ma: max temperature is %0.1fC.\n", info.temperature_max);
90 ags02ma_interface_debug_print("ags02ma: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start basic read test */
94 ags02ma_interface_debug_print("ags02ma: start read test.\n");
95
96 /* ags02ma init */
97 res = ags02ma_init(&gs_handle);
98 if (res != 0)
99 {
100 ags02ma_interface_debug_print("ags02ma: init failed.\n");
101
102 return 1;
103 }
104
105 /* get version */
106 res = ags02ma_get_version(&gs_handle, &version);
107 if (res != 0)
108 {
109 ags02ma_interface_debug_print("ags02ma: get version failed.\n");
110 (void)ags02ma_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* print result */
116 ags02ma_interface_debug_print("ags02ma: version is 0x%02X.\n", version);
117
118 /* delay 2000 ms for read */
120 for (i = 0; i < times; i++)
121 {
122 /* read tvoc */
123 res = ags02ma_read_tvoc(&gs_handle, (uint32_t *)&raw, (uint32_t *)&ppb);
124 if (res != 0)
125 {
126 ags02ma_interface_debug_print("ags02ma: read tvoc failed.\n");
127 (void)ags02ma_deinit(&gs_handle);
128
129 return 1;
130 }
131
132 /* print result */
133 ags02ma_interface_debug_print("ags02ma: tvoc is %dppb.\n", ppb);
134
135 /* delay 2000 ms*/
137 }
138
139 /* get resistance */
140 res = ags02ma_get_resistance(&gs_handle, &raw, &ohm);
141 if (res != 0)
142 {
143 ags02ma_interface_debug_print("ags02ma: get resistance failed.\n");
144 (void)ags02ma_deinit(&gs_handle);
145
146 return 1;
147 }
148
149 /* print result */
150 ags02ma_interface_debug_print("ags02ma: resistance is %0.2fohm.\n", ohm);
151
152 /* delay 2000 ms*/
154
155 addr_7bit = 0x1A;
156 res = ags02ma_modify_slave_address(&gs_handle, addr_7bit);
157 if (res != 0)
158 {
159 ags02ma_interface_debug_print("ags02ma: modify slave address failed.\n");
160 (void)ags02ma_deinit(&gs_handle);
161
162 return 1;
163 }
164
165 /* print result */
166 ags02ma_interface_debug_print("ags02ma: modify slave address 0x%02X.\n", addr_7bit);
167
168 /* finish read test */
169 ags02ma_interface_debug_print("ags02ma: finish read test.\n");
170 (void)ags02ma_deinit(&gs_handle);
171
172 return 0;
173}
driver ags02ma read test header file
uint8_t ags02ma_info(ags02ma_info_t *info)
get chip's information
uint8_t ags02ma_modify_slave_address(ags02ma_handle_t *handle, uint8_t addr_7bit)
modify slave address
uint8_t ags02ma_get_version(ags02ma_handle_t *handle, uint8_t *version)
get version
uint8_t ags02ma_read_tvoc(ags02ma_handle_t *handle, uint32_t *raw, uint32_t *ppb)
read tvoc
struct ags02ma_info_s ags02ma_info_t
ags02ma information structure definition
uint8_t ags02ma_deinit(ags02ma_handle_t *handle)
close the chip
uint8_t ags02ma_get_resistance(ags02ma_handle_t *handle, uint32_t *raw, double *ohm)
get resistance
uint8_t ags02ma_init(ags02ma_handle_t *handle)
initialize the chip
struct ags02ma_handle_s ags02ma_handle_t
ags02ma handle structure definition
void ags02ma_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ags02ma_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t ags02ma_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
uint8_t ags02ma_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t ags02ma_interface_iic_init(void)
interface iic bus init
uint8_t ags02ma_interface_iic_deinit(void)
interface iic bus deinit
void ags02ma_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ags02ma_read_test(uint32_t times)
read test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v