Skip to content

Commit 37ce50b

Browse files
committed
added autoconnect wifi fuction and update system fuction
1 parent 79cdc4c commit 37ce50b

File tree

24 files changed

+2067
-36
lines changed

24 files changed

+2067
-36
lines changed

base/.tmp_update/updater

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,70 @@ else
134134
fi
135135
}
136136

137+
update() {
138+
139+
echo "Checking for updater Pico-FOX package"
140+
141+
if [ -f "${SDCARD_PATH}"/.deletes ]; then
142+
while IFS= read -r file_to_delete; do
143+
rm -rf "${file_to_delete}"
144+
done < "${SDCARD_PATH}"/.deletes
145+
rm "${SDCARD_PATH}"/.deletes
146+
fi
147+
148+
if [ -f "${SDCARD_PATH}/"update_pico-fox_*.zip ]; then
149+
150+
echo "update Pico-FOX package found"
151+
152+
for file in `ls "${SDCARD_PATH}"/update_pico-fox_*.zip`; do
153+
unzip -q -o "${file}" ".update_splash.png" -d "${SDCARD_PATH}"
154+
sync
155+
156+
show "${SDCARD_PATH}"/.update_splash.png
157+
158+
unzip -q -o "${file}" ".deletes" -d "${SDCARD_PATH}"
159+
160+
if [ -f "${SDCARD_PATH}"/.deletes ]; then
161+
while IFS= read -r file_to_delete; do
162+
if [ -f "${file_to_delete}" ]; then
163+
rm "${file_to_delete}"
164+
elif [ -d "${file_to_delete}" ]; then
165+
rm -rf "${file_to_delete}"
166+
fi
167+
done < "${SDCARD_PATH}"/.deletes
168+
fi
169+
170+
unzip -q -o "${file}" -d "${SDCARD_PATH}"
171+
172+
rm "${file}"
173+
174+
if [ -f "${SDCARD_PATH}"/.deletes ]; then
175+
rm "${SDCARD_PATH}"/.deletes
176+
fi
177+
178+
if [ -f "${SDCARD_PATH}"/.update_splash.png ]; then
179+
rm "${SDCARD_PATH}"/.update_splash.png
180+
fi
181+
182+
sleep 5s
183+
done
184+
185+
sync
186+
sleep 5s
187+
188+
if [ "$MODEL" == "MMP" ]; then
189+
poweroff
190+
else
191+
reboot
192+
fi
193+
194+
sleep 10s
195+
fi
196+
197+
echo "update Pico-FOX package not found"
198+
199+
}
200+
137201
killprocess() {
138202
pid=`ps | grep $1 | grep -v grep | cut -d' ' -f3`
139203
kill -9 $pid
@@ -218,6 +282,9 @@ resize
218282
# Charging screen
219283
"${SYSTEM_PATH}"/bin/charging
220284

285+
# Update opportunity
286+
update
287+
221288
# check swap size
222289
if [ -f "${SWAPFILE}" ]; then
223290
SWAPSIZE=`stat -c %s "${SWAPFILE}"`
@@ -420,7 +487,8 @@ while [ 1 ]; do
420487
fi
421488

422489
if ls "$BBS"* 1> /dev/null 2>&1; then
423-
cp "$BBS"* "$SPLORE"
490+
rm "$BBS"temp-*
491+
cp "$BBS"*.p8.png "$SPLORE"
424492
else
425493
echo "No BBS files found to copy."
426494
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
autoconnect_enabled=False

base/App/Wifi/wifi.py

Lines changed: 114 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
netconfdir = confdir+"networks/"
4545
sysconfdir = "/appconfigs/"
4646
datadir = "/mnt/SDCARD/App/Wifi/data/"
47+
autoconnect_enabled = False
4748

4849
surface = pygame.display.set_mode((320,240))
4950
selected_key = ''
@@ -144,6 +145,30 @@ def enableiface(iface):
144145
mac_addresses[iface] = getmac(iface)
145146
return True
146147

148+
def autoconnect(iface):
149+
check = checkinterfacestatus(iface)
150+
if check:
151+
return False
152+
153+
modal("Autoconnecting...")
154+
drawinterfacestatus()
155+
pygame.display.update()
156+
157+
SU.Popen(['/bin/sed', '-i', "s/\"wifi\":\s*[01]/\"wifi\": 1/", '/appconfigs/system.json'], close_fds=True).wait()
158+
SU.Popen(['/customer/app/axp_test', 'wifion'], close_fds=True).wait()
159+
SU.Popen(['sleep', '2'], close_fds=True).wait()
160+
SU.Popen(['pkill', '-9', 'wpa_supplicant'], close_fds=True).wait()
161+
SU.Popen(['pkill', '-9', 'udhcpc'], close_fds=True).wait()
162+
SU.Popen(['pkill', '-9', 'hostapd'], close_fds=True).wait()
163+
SU.Popen(['pkill', '-9', 'dnsmasq'], close_fds=True).wait()
164+
while True:
165+
if SU.Popen(['/sbin/ifconfig', iface, 'up'], close_fds=True).wait() == 0:
166+
break
167+
time.sleep(0.1);
168+
SU.Popen(['/mnt/SDCARD/Koriki/bin/wpa_supplicant', '-B', '-D', 'nl80211', '-i', iface, '-c', '/appconfigs/wpa_supplicant.conf'], close_fds=True).wait()
169+
mac_addresses[iface] = getmac(iface)
170+
return True
171+
147172
def disableiface(iface):
148173
SU.Popen(['pkill', '-9', 'wpa_supplicant'], close_fds=True).wait()
149174
SU.Popen(['pkill', '-9', 'udhcpc'], close_fds=True).wait()
@@ -455,33 +480,38 @@ def drawstatusbar(): # Set up the status bar
455480
wlan_text.topleft = (2, 225)
456481
surface.blit(wlantext, wlan_text)
457482

458-
def drawinterfacestatus(): # Interface status badge
459-
global colors
460-
wlanstatus = checkinterfacestatus(wlan)
461-
if not wlanstatus:
462-
wlanstatus = wlan+" is off."
463-
else:
464-
wlanstatus = getcurrentssid(wlan)
465-
466-
wlantext = font_mono_small.render(wlanstatus, True, colors['white'], colors['lightbg'])
467-
wlan_text = wlantext.get_rect()
468-
wlan_text.topleft = (2, 225)
469-
surface.blit(wlantext, wlan_text)
470-
471-
# Note that the leading space here is intentional, to more cleanly overdraw any overly-long
472-
# strings written to the screen beneath it (i.e. a very long ESSID)
473-
if checkinterfacestatus(wlan):
474-
text = font_mono_small.render(" "+getip(wlan), True, colors['white'], colors['lightbg'])
475-
interfacestatus_text = text.get_rect()
476-
interfacestatus_text.topright = (317, 225)
477-
surface.blit(text, interfacestatus_text)
478-
else:
479-
mac = mac_addresses.get(wlan) # grabbed by enableiface()
480-
if mac is not None:
481-
text = font_mono_small.render(" "+mac, True, colors['white'], colors['lightbg'])
482-
interfacestatus_text = text.get_rect()
483-
interfacestatus_text.topright = (317, 225)
484-
surface.blit(text, interfacestatus_text)
483+
def drawinterfacestatus(): # Interface status badge
484+
global colors
485+
wlanstatus = checkinterfacestatus(wlan)
486+
if not wlanstatus:
487+
wlanstatus = wlan+" is off."
488+
else:
489+
wlanstatus = getcurrentssid(wlan)
490+
491+
wlantext = font_mono_small.render(wlanstatus, True, colors['white'], colors['lightbg'])
492+
wlan_text = wlantext.get_rect()
493+
wlan_text.topleft = (2, 225)
494+
surface.blit(wlantext, wlan_text)
495+
496+
# Note that the leading space here is intentional, to more cleanly overdraw any overly-long
497+
# strings written to the screen beneath it (i.e. a very long ESSID)
498+
if checkinterfacestatus(wlan):
499+
ip_address = getip(wlan)
500+
if ip_address is None: # Handle case where no IP is assigned
501+
ip_address = " " # Display alternative message if no IP is available
502+
text = font_mono_small.render(" " + ip_address, True, colors['white'], colors['lightbg'])
503+
interfacestatus_text = text.get_rect()
504+
interfacestatus_text.topright = (317, 225)
505+
surface.blit(text, interfacestatus_text)
506+
else:
507+
mac = mac_addresses.get(wlan) # grabbed by enableiface()
508+
if mac is not None:
509+
text = font_mono_small.render(" " + mac, True, colors['white'], colors['lightbg'])
510+
else:
511+
text = font_mono_small.render(" ", True, colors['white'], colors['lightbg']) # Handle no MAC case
512+
interfacestatus_text = text.get_rect()
513+
interfacestatus_text.topright = (317, 225)
514+
surface.blit(text, interfacestatus_text)
485515

486516
def redraw():
487517
global colors
@@ -596,6 +626,44 @@ def writeconfig(): # Write wireless configuration to disk
596626
f2.write('}\n')
597627
f2.close()
598628

629+
def save_autoconnect_state():
630+
config_file = "/mnt/SDCARD/App/Wifi/autoconnect_state.txt"
631+
with open(config_file, 'w') as f:
632+
f.write("autoconnect_enabled={}\n".format(autoconnect_enabled))
633+
634+
def load_autoconnect_state():
635+
global autoconnect_enabled
636+
config_file = "/mnt/SDCARD/App/Wifi/autoconnect_state.txt"
637+
if os.path.exists(config_file):
638+
with open(config_file, 'r') as f:
639+
for line in f:
640+
key, value = line.strip().split("=")
641+
if key == "autoconnect_enabled":
642+
autoconnect_enabled = value == "True"
643+
644+
def toggle_autoconnect():
645+
global autoconnect_enabled
646+
if autoconnect_enabled:
647+
confirm = modal("Disable Autoconnect?", query=True)
648+
if confirm:
649+
autoconnect_enabled = False
650+
modal("Autoconnect is OFF", wait=True)
651+
redraw()
652+
else:
653+
active_menu = to_menu("main")
654+
redraw()
655+
else:
656+
confirm = modal("Enable Autoconnect?", query=True)
657+
if confirm:
658+
autoconnect_enabled = True
659+
modal("Autoconnect is ON", wait=True)
660+
redraw()
661+
else:
662+
active_menu = to_menu("main")
663+
redraw()
664+
665+
save_autoconnect_state()
666+
599667
## HostAP
600668
def startap():
601669
global wlan
@@ -1320,11 +1388,11 @@ def mainmenu():
13201388
if mac == ap:
13211389
elems = ['AP info'] + elems
13221390
except:
1323-
elems = ['Create ADHOC'] + elems
1391+
pass
13241392

1325-
elems = ["Saved Networks", 'Scan for APs', "Manual Setup"] + elems
1393+
elems = ["Saved Networks", 'Scan for APs', "Manual Setup", 'Autoconnect'] + elems
13261394

1327-
if checkinterfacestatus(wlan):
1395+
if checkinterfacestatus(wlan) and getcurrentssid(wlan) is not None:
13281396
elems = ['Disconnect'] + elems
13291397

13301398
menu.init(elems, surface)
@@ -1478,6 +1546,19 @@ def convert_file_names():
14781546
logoBar = LogoBar()
14791547

14801548
redraw()
1549+
1550+
load_autoconnect_state()
1551+
1552+
if autoconnect_enabled:
1553+
modal("Autoconnecting...")
1554+
autoconnect(wlan)
1555+
if not udhcpc_timeout(wlan, 30):
1556+
modal('Autoconnect failed!', wait=True)
1557+
else:
1558+
modal('Autoconnect successful!')
1559+
time.sleep(2)
1560+
sys.exit()
1561+
14811562
while True:
14821563
time.sleep(0.01)
14831564
for event in pygame.event.get():
@@ -1648,6 +1729,9 @@ def convert_file_names():
16481729

16491730
elif menu.get_selected() == 'Create ADHOC':
16501731
startap()
1732+
1733+
elif menu.get_selected() == 'Autoconnect':
1734+
toggle_autoconnect()
16511735

16521736
elif menu.get_selected() == 'AP info':
16531737
apinfo()

base/App/pico/.lexaloffle/pico-8/config.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
// :: Video Settings
1111

12-
window_size 640 480 // window width, height
13-
screen_size 640 480 // screen width, height (stretched to window)
12+
window_size 320 240 // window width, height
13+
screen_size 320 240 // screen width, height (stretched to window)
1414
show_fps 0 // Draw frames per second in the corner
1515

1616

@@ -30,7 +30,7 @@ foreground_sleep_ms 1 // number of milliseconds to sleep each frame. Try 10 to c
3030

3131
background_sleep_ms 10 // number of milliseconds to sleep each frame when running in the background
3232

33-
sessions 19 // number of times program has been run
33+
sessions 59 // number of times program has been run
3434

3535
// (scancode) hold this key down and left-click to simulate right-click
3636
rmb_key 0 // 0 for none 226 for LALT

base/Koriki/bin/pico.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ set_snd_level "${volume}" &
160160

161161
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
162162

163-
pico8_dyn -splore -width 640 -height 480 -root_path "/mnt/SDCARD/Roms/PICO/"
163+
pico8_dyn -splore -width 320 -height 240 -root_path "/mnt/SDCARD/Roms/PICO/"
164164

165165
sync
166166

base/Koriki/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.3
1+
1.5.4

src/Wifi/autoconnect_state.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
autoconnect_enabled=False

src/Wifi/data/Inconsolata.otf

57.2 KB
Binary file not shown.

src/Wifi/data/closed.png

394 Bytes
Loading

src/Wifi/data/gcwzero.ttf

23.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)