LibDriver MULTI_BUTTON
Loading...
Searching...
No Matches
driver_multi_button_trigger_test.c
Go to the documentation of this file.
1
36
38
39static multi_button_handle_t gs_handle;
40static volatile uint16_t gs_flag;
41
49static void a_receive_callback(uint16_t row, uint16_t col, multi_button_t *data)
50{
51 switch (data->status)
52 {
54 {
55 gs_flag |= 1 << 0;
56
57 break;
58 }
60 {
61 gs_flag |= 1 << 1;
62
63 break;
64 }
66 {
67 gs_flag |= 1 << 2;
68 multi_button_interface_debug_print("multi_button: row %d col %d irq single click.\n", row, col);
69
70 break;
71 }
73 {
74 gs_flag |= 1 << 3;
75 multi_button_interface_debug_print("multi_button: row %d col %d irq double click.\n", row, col);
76
77 break;
78 }
80 {
81 gs_flag |= 1 << 4;
82 multi_button_interface_debug_print("multi_button: row %d col %d irq triple click.\n", row, col);
83
84 break;
85 }
87 {
88 gs_flag |= 1 << 5;
89 multi_button_interface_debug_print("multi_button: row %d col %d irq repeat click with %d times.\n", row, col, data->times);
90
91 break;
92 }
94 {
95 gs_flag |= 1 << 6;
96 multi_button_interface_debug_print("multi_button: row %d col %d irq short press start.\n", row, col);
97
98 break;
99 }
101 {
102 gs_flag |= 1 << 7;
103 multi_button_interface_debug_print("multi_button: row %d col %d irq short press end.\n", row, col);
104
105 break;
106 }
108 {
109 gs_flag |= 1 << 8;
110 multi_button_interface_debug_print("multi_button: row %d col %d irq long press start.\n", row, col);
111
112 break;
113 }
115 {
116 gs_flag |= 1 << 9;
117 multi_button_interface_debug_print("multi_button: row %d col %d irq long press hold.\n", row, col);
118
119 break;
120 }
122 {
123 gs_flag |= 1 << 10;
124 multi_button_interface_debug_print("multi_button: row %d col %d irq long press end.\n", row, col);
125
126 break;
127 }
128 default :
129 {
130 multi_button_interface_debug_print("multi_button: row %d col %d irq unknown status.\n", row, col);
131
132 break;
133 }
134 }
135}
136
146uint8_t multi_button_trigger_test(uint8_t row, uint8_t col)
147{
148 uint8_t res;
149 uint32_t timeout;
151
152 /* link interface function */
161 DRIVER_MULTI_BUTTON_LINK_RECEIVE_CALLBACK(&gs_handle, a_receive_callback);
162
163 /* get information */
164 res = multi_button_info(&info);
165 if (res != 0)
166 {
167 multi_button_interface_debug_print("multi_button: get info failed.\n");
168
169 return 1;
170 }
171 else
172 {
173 /* print chip info */
174 multi_button_interface_debug_print("multi_button: chip is %s.\n", info.chip_name);
175 multi_button_interface_debug_print("multi_button: manufacturer is %s.\n", info.manufacturer_name);
176 multi_button_interface_debug_print("multi_button: interface is %s.\n", info.interface);
177 multi_button_interface_debug_print("multi_button: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
178 multi_button_interface_debug_print("multi_button: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
179 multi_button_interface_debug_print("multi_button: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
180 multi_button_interface_debug_print("multi_button: max current is %0.2fmA.\n", info.max_current_ma);
181 multi_button_interface_debug_print("multi_button: max temperature is %0.1fC.\n", info.temperature_max);
182 multi_button_interface_debug_print("multi_button: min temperature is %0.1fC.\n", info.temperature_min);
183 }
184
185 /* init */
186 res = multi_button_init(&gs_handle, row, col);
187 if (res != 0)
188 {
189 multi_button_interface_debug_print("multi_button: init failed.\n");
190
191 return 1;
192 }
193
194 /* start trigger test */
195 multi_button_interface_debug_print("multi_button: start trigger test.\n");
196
197 /* 100s timeout */
198 timeout = 10000;
199
200 /* init 0 */
201 gs_flag = 0;
202
203 /* check timeout */
204 while (timeout != 0)
205 {
206 /* check the flag */
207 if ((gs_flag & 0x07FF) == 0x07FF)
208 {
209 break;
210 }
211
212 /* timeout -- */
213 timeout--;
214
215 /* delay 5ms */
217
218 /* process */
219 (void)multi_button_process(&gs_handle);
220 }
221
222 /* check the timeout */
223 if (timeout == 0)
224 {
225 /* receive timeout */
226 multi_button_interface_debug_print("multi_button: trigger timeout.\n");
227 (void)multi_button_deinit(&gs_handle);
228
229 return 1;
230 }
231
232 /* finish trigger test */
233 multi_button_interface_debug_print("multi_button: finish trigger test.\n");
234 (void)multi_button_deinit(&gs_handle);
235
236 return 0;
237}
driver multi_button trigger test header file
uint8_t multi_button_init(multi_button_handle_t *handle, uint8_t row, uint8_t col)
initialize the chip
uint8_t multi_button_process(multi_button_handle_t *handle)
process
uint8_t multi_button_deinit(multi_button_handle_t *handle)
close the chip
struct multi_button_handle_s multi_button_handle_t
multi_button handle structure definition
uint8_t multi_button_info(multi_button_info_t *info)
get chip's information
struct multi_button_s multi_button_t
multi_button structure definition
struct multi_button_info_s multi_button_info_t
multi_button information structure definition
@ MULTI_BUTTON_STATUS_SHORT_PRESS_END
@ MULTI_BUTTON_STATUS_REPEAT_CLICK
@ MULTI_BUTTON_STATUS_DOUBLE_CLICK
@ MULTI_BUTTON_STATUS_LONG_PRESS_END
@ MULTI_BUTTON_STATUS_SINGLE_CLICK
@ MULTI_BUTTON_STATUS_LONG_PRESS_HOLD
@ MULTI_BUTTON_STATUS_TRIPLE_CLICK
@ MULTI_BUTTON_STATUS_PRESS
@ MULTI_BUTTON_STATUS_SHORT_PRESS_START
@ MULTI_BUTTON_STATUS_RELEASE
@ MULTI_BUTTON_STATUS_LONG_PRESS_START
uint8_t multi_button_interface_matrix_init(void)
interface matrix init
uint8_t multi_button_interface_matrix_write_row(uint16_t num, uint8_t level)
interface matrix write row
void multi_button_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t multi_button_interface_timestamp_read(multi_button_time_t *t)
interface timestamp read
uint8_t multi_button_interface_matrix_read_row(uint32_t *col_array)
interface matrix read row
void multi_button_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t multi_button_interface_matrix_deinit(void)
interface matrix deinit
uint8_t multi_button_trigger_test(uint8_t row, uint8_t col)
trigger test