@@ -2,6 +2,13 @@ const VERSION() = "1.0.0"
22const WIFI_MODE_STA = 1
33const WIFI_MODE_AP = 2
44
5+ const RESET_DELAY = 3000
6+
7+ const HANDLE_MOTOR_RUN = 0
8+ const HANDLE_MOTOR_STOP = 1
9+ const HANDLE_RESET_PUSH = 2
10+ export const HANDLE_STATUS_NOTIFICATION = 3
11+
512export const APP_MODE_CONFIG = 0
613export const APP_MODE_AP = 1
714export const APP_MODE_STA = 2
@@ -34,6 +41,7 @@ export dim result
3441export dim flash_result_len
3542export dim flash_result_data(255)
3643
44+ import "leds.bgs"
3745import "config.bgs"
3846
3947procedure init_motors()
5058
5159export procedure run()
5260 motor_index = 0
53- call hardware_set_soft_timer(25, 0 , 1)
61+ call hardware_set_soft_timer(25, HANDLE_MOTOR_RUN , 1)
5462end
5563
5664procedure show_info()
@@ -172,23 +180,39 @@ procedure run_motor(index)
172180 end if
173181end
174182
183+ procedure check_reset()
184+ call hardware_io_port_read(3, $0001)(result, port, data) # read reset button
185+ if data = 0 then
186+ call endpoint_send(0, 19, "[DBG]Resetting...\r\n")
187+ call flash_ps_save(FLASH_PS_KEY_APP_MODE, 1, APP_MODE_CONFIG)
188+ call system_reset(0)
189+ end if
190+ end
191+
175192event hardware_soft_timer(handle)
176- if handle = 0 then
193+ if handle = HANDLE_MOTOR_RUN then
177194 if memcmp(targets(0), positions(0), 7) != 1 then
178195 if motor_index = 0 then
179- call hardware_set_soft_timer(25, 1 , 1)
196+ call hardware_set_soft_timer(25, HANDLE_MOTOR_STOP , 1)
180197 else
181- call hardware_set_soft_timer(20, 1 , 1)
198+ call hardware_set_soft_timer(20, HANDLE_MOTOR_STOP , 1)
182199 end if
183200 end if
184201 call run_motor(motor_index)
185202 motor_index = motor_index + 1
186203 if motor_index = 7 then
187204 motor_index = 0
188205 end if
189- else
206+ end if
207+ if handle = HANDLE_MOTOR_STOP then
190208 call turn_motors_off()
191- call hardware_set_soft_timer(5, 0, 1)
209+ call hardware_set_soft_timer(5, HANDLE_MOTOR_RUN, 1)
210+ end if
211+ if handle = HANDLE_RESET_PUSH then
212+ call check_reset()
213+ end if
214+ if handle = HANDLE_STATUS_NOTIFICATION then
215+ call next_status_notification()
192216 end if
193217end
194218
@@ -214,12 +238,15 @@ end
214238
215239event sme_wifi_is_on(state)
216240 if mode = APP_MODE_CLI || mode = APP_MODE_STA then
241+ call start_status_notification(LED_BLUE, INTERVAL_CONNECTING)
217242 call connect_to_ssid()
218243 end if
219244 if mode = APP_MODE_AP then
245+ call start_status_notification(LED_BLUE, INTERVAL_CONNECTING)
220246 call start_ap_mode()
221247 end if
222248 if mode = APP_MODE_CONFIG then
249+ call start_status_notification(LED_ORANGE, INTERVAL_CONNECTING)
223250 call sme_start_ssid_scan(0, "")
224251 end if
225252end
235262
236263event sme_connected(status, hw_interface, bssid)
237264 call endpoint_send(0, 20, "[DBG]sme connected\r\n")
265+ call start_status_notification(LED_BLUE, INTERVAL_CONNECTED)
238266 if mode = APP_MODE_STA then
239267 call sta_sme_connected(status, hw_interface, bssid(0:6))
240268 end if
282310event hardware_external_interrupt(irq, interrupt)
283311 if irq = 0 then
284312 call endpoint_send(0, 20, "[DBG]Reset pressed\r\n")
285- call flash_ps_save(FLASH_PS_KEY_APP_MODE, 1, APP_MODE_CONFIG)
286- call system_reset(0)
313+ call hardware_set_soft_timer(RESET_DELAY, HANDLE_RESET_PUSH, 1)
287314 else
288315 call endpoint_send(0, 18, "[DBG]WPS pressed\r\n")
289316 end if
0 commit comments