Skip to content

Commit c5b971d

Browse files
committed
feat: simple led status + delay reset
1 parent 09a8d16 commit c5b971d

7 files changed

Lines changed: 80 additions & 12 deletions

File tree

client.bgs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dim ip_address_len
77
dim endpoint_ip(4)
88
dim result_endpoint
99
dim connected
10+
dim server_up
1011
dim auth_sent
1112
dim debug(32)
1213
dim auth_command(50)
@@ -15,7 +16,9 @@ dim while_counter
1516
# event sme_connected
1617
export procedure cli_sme_connected(status, hw_interface, bssid)
1718
call endpoint_send(0 , 24, "[DBG]cli sme connected\r\n")
19+
call start_status_notification(LED_GREEN, INTERVAL_CONNECTING)
1820
connected = 1
21+
server_up = 0
1922
end
2023

2124
export procedure cli_sme_disconnected(reason, hw_interface)
@@ -63,6 +66,8 @@ event endpoint_data(endpoint, data_len, data_data)
6366
end if
6467
if data_data(4:4) = ok_type then
6568
call endpoint_send(0, 18, "[DBG]ok received\r\n")
69+
call start_status_notification(LED_GREEN, INTERVAL_CONNECTED)
70+
server_up = 1
6671
end if
6772
end if
6873
if data_len = 15 && data_data(4:4) = set_counter_value_type then
@@ -91,12 +96,16 @@ event endpoint_status(endpoint, type, streaming, destination, active)
9196
call endpoint_send(0, flash_result_len, debug(0:flash_result_len))
9297
call endpoint_send(0, 2, "\r\n")
9398

94-
if type = 128 then
99+
if type = 128 then # type 128 = endpoint_wait_close
95100
call endpoint_close(endpoint)
96101
call tcpip_tcp_connect(ip_address(0:4), 443, -1)
102+
if server_up = 1 then
103+
call start_status_notification(LED_GREEN, INTERVAL_CONNECTING)
104+
server_up = 0
105+
end if
97106
end if
98107

99-
if type = 4 && active = 1 then
108+
if type = 4 && active = 1 then # type 4 = endpoint_tcp
100109
auth_command(0:4) = $2e000000 # message length
101110
auth_command(4:4) = $05000000 # message type
102111
auth_command(8:4) = $0F000000 # serial length

config.bgs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export procedure config_sme_ap_mode_started(hw_interface)
6767
call flash_ps_save(FLASH_PS_KEY_DNSS_ANY_URL, 1, 1)
6868
call https_enable(1, 1, 1)
6969
call endpoint_send(0, 22, "[DBG]AP mode started\r\n")
70+
call start_status_notification(LED_ORANGE, INTERVAL_CONNECTED)
7071
end
7172

7273
procedure handle_ssids_request(request)

flasher/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>FlapOS Flasher</title>
55
<link rel="stylesheet" href="style.css" media="screen"/>
66
<meta charset="UTF-8">
7-
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
88
</head>
99
<body>
1010
<h1><span>F</span><span>L</span><span>A</span><span>P</span><span>_</span><span>O</span><span>S</span></h1>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>FlapOS</title>
55
<link rel="stylesheet" href="style.css" media="screen"/>
66
<meta charset="UTF-8">
7-
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
88
</head>
99
<body>
1010
<h1><span>F</span><span>L</span><span>A</span><span>P</span><span>_</span><span>O</span><span>S</span></h1>

leds.bgs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export const INTERVAL_CONNECTED = 0
2+
export const INTERVAL_CONNECTING = 500
3+
export const LED_ORANGE = $8000
4+
export const LED_GREEN = $2000
5+
export const LED_BLUE = $1000
6+
7+
dim pin_status
8+
dim pin_index
9+
dim pin_interval
10+
11+
export procedure next_status_notification()
12+
pin_status = pin_status ^ 1
13+
if pin_status = 1 || pin_interval = 0 then
14+
call hardware_io_port_write(1, pin_index, $0000)
15+
else
16+
call hardware_io_port_write(1, pin_index, pin_index)
17+
end if
18+
19+
if pin_interval > 0 then
20+
call hardware_set_soft_timer(pin_interval, HANDLE_STATUS_NOTIFICATION, 1)
21+
end if
22+
end
23+
24+
export procedure start_status_notification(pin, interval)
25+
pin_index = pin
26+
pin_interval = interval
27+
pin_status = 0
28+
call next_status_notification()
29+
end

main.bgs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ const VERSION() = "1.0.0"
22
const WIFI_MODE_STA = 1
33
const 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+
512
export const APP_MODE_CONFIG = 0
613
export const APP_MODE_AP = 1
714
export const APP_MODE_STA = 2
@@ -34,6 +41,7 @@ export dim result
3441
export dim flash_result_len
3542
export dim flash_result_data(255)
3643

44+
import "leds.bgs"
3745
import "config.bgs"
3846

3947
procedure init_motors()
@@ -50,7 +58,7 @@ end
5058

5159
export 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)
5462
end
5563

5664
procedure show_info()
@@ -172,23 +180,39 @@ procedure run_motor(index)
172180
end if
173181
end
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+
175192
event 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
193217
end
194218

@@ -214,12 +238,15 @@ end
214238

215239
event 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
225252
end
@@ -235,6 +262,7 @@ end
235262

236263
event 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
@@ -282,8 +310,7 @@ end
282310
event 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

server.bgs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export procedure sta_sme_connected(status, hw_interface, bssid)
1818
call endpoint_send(0 , 24, "[DBG]sta sme connected\r\n")
1919
call https_add_path(1, 1, "/")
2020
call https_enable(1, 0, 0)
21+
call start_status_notification(LED_GREEN, INTERVAL_CONNECTED)
2122
end
2223

2324
export procedure start_ap_mode()
@@ -37,6 +38,7 @@ export procedure server_sme_ap_mode_started(hw_interface)
3738
call endpoint_send(0, 22, "[DBG]ap mode started\r\n")
3839
call https_add_path(1, 1, "/")
3940
call https_enable(1, 1, 0)
41+
call start_status_notification(LED_GREEN, INTERVAL_CONNECTED)
4042
end
4143

4244
procedure handle_request()

0 commit comments

Comments
 (0)