LibDriver IR_REMOTE
Loading...
Searching...
No Matches
driver_ir_remote_receive_test.c
Go to the documentation of this file.
1
36
38
39static ir_remote_handle_t gs_handle;
40static volatile uint8_t gs_flag;
41
50{
51 if (ir_remote_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55 else
56 {
57 return 0;
58 }
59}
60
66static void a_receive_callback(ir_remote_t *data)
67{
68 switch (data->status)
69 {
71 {
72 ir_remote_interface_debug_print("ir_remote: irq ok.\n");
73 ir_remote_interface_debug_print("ir_remote: add is 0x%02X and cmd is 0x%02X.\n", data->address, data->command);
74 gs_flag = 1;
75
76 break;
77 }
79 {
80 ir_remote_interface_debug_print("ir_remote: irq repeat.\n");
81 ir_remote_interface_debug_print("ir_remote: add is 0x%02X and cmd is 0x%02X.\n", data->address, data->command);
82
83 break;
84 }
86 {
87 ir_remote_interface_debug_print("ir_remote: irq addr error.\n");
88
89 break;
90 }
92 {
93 ir_remote_interface_debug_print("ir_remote: irq cmd error.\n");
94
95 break;
96 }
98 {
99 ir_remote_interface_debug_print("ir_remote: irq frame invalid.\n");
100
101 break;
102 }
103 default :
104 {
105 ir_remote_interface_debug_print("ir_remote: irq unknown status.\n");
106
107 break;
108 }
109 }
110}
111
120uint8_t ir_remote_receive_test(uint32_t times)
121{
122 uint8_t res;
123 uint16_t timeout;
124 uint32_t i;
125 ir_remote_info_t info;
126
127 /* link interface function */
132 DRIVER_IR_REMOTE_LINK_RECEIVE_CALLBACK(&gs_handle, a_receive_callback);
133
134 /* get information */
135 res = ir_remote_info(&info);
136 if (res != 0)
137 {
138 ir_remote_interface_debug_print("ir_remote: get info failed.\n");
139
140 return 1;
141 }
142 else
143 {
144 /* print chip info */
145 ir_remote_interface_debug_print("ir_remote: chip is %s.\n", info.chip_name);
146 ir_remote_interface_debug_print("ir_remote: manufacturer is %s.\n", info.manufacturer_name);
147 ir_remote_interface_debug_print("ir_remote: interface is %s.\n", info.interface);
148 ir_remote_interface_debug_print("ir_remote: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
149 ir_remote_interface_debug_print("ir_remote: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
150 ir_remote_interface_debug_print("ir_remote: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
151 ir_remote_interface_debug_print("ir_remote: max current is %0.2fmA.\n", info.max_current_ma);
152 ir_remote_interface_debug_print("ir_remote: max temperature is %0.1fC.\n", info.temperature_max);
153 ir_remote_interface_debug_print("ir_remote: min temperature is %0.1fC.\n", info.temperature_min);
154 }
155
156 /* init */
157 res = ir_remote_init(&gs_handle);
158 if (res != 0)
159 {
160 ir_remote_interface_debug_print("ir_remote: init failed.\n");
161
162 return 1;
163 }
164
165 /* start receive test */
166 ir_remote_interface_debug_print("ir_remote: start receive test.\n");
167
168 /* loop */
169 for (i = 0; i < times; i++)
170 {
171 /* 5s timeout */
172 timeout = 500;
173
174 /* init 0 */
175 gs_flag = 0;
176
177 /* check timeout */
178 while (timeout != 0)
179 {
180 /* check the flag */
181 if (gs_flag != 0)
182 {
183 break;
184 }
185
186 /* timeout -- */
187 timeout--;
188
189 /* delay 10ms */
191 }
192
193 /* check the timeout */
194 if (timeout == 0)
195 {
196 /* receive timeout */
197 ir_remote_interface_debug_print("ir_remote: receive timeout.\n");
198 (void)ir_remote_deinit(&gs_handle);
199
200 return 1;
201 }
202 }
203
204 /* finish receive test */
205 ir_remote_interface_debug_print("ir_remote: finish receive test.\n");
206 (void)ir_remote_deinit(&gs_handle);
207
208 return 0;
209}
driver ir remote receive test header file
uint8_t ir_remote_irq_handler(ir_remote_handle_t *handle)
irq handler
uint8_t ir_remote_init(ir_remote_handle_t *handle)
initialize the chip
uint8_t ir_remote_info(ir_remote_info_t *info)
get chip's information
struct ir_remote_info_s ir_remote_info_t
ir_remote information structure definition
struct ir_remote_handle_s ir_remote_handle_t
ir_remote handle structure definition
uint8_t ir_remote_deinit(ir_remote_handle_t *handle)
close the chip
struct ir_remote_s ir_remote_t
ir_remote structure definition
@ IR_REMOTE_STATUS_REPEAT
@ IR_REMOTE_STATUS_OK
@ IR_REMOTE_STATUS_FRAME_INVALID
@ IR_REMOTE_STATUS_CMD_ERR
@ IR_REMOTE_STATUS_ADDR_ERR
uint8_t ir_remote_interface_timestamp_read(ir_remote_time_t *t)
interface timestamp read
void ir_remote_interface_delay_ms(uint32_t ms)
interface delay ms
void ir_remote_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ir_remote_receive_test_irq_handler(void)
receive test irq
uint8_t ir_remote_receive_test(uint32_t times)
receive test