83 lines
No EOL
2.2 KiB
Python
83 lines
No EOL
2.2 KiB
Python
#
|
|
# Petcard Bootloader - v1.0
|
|
# Copyright (c) 2025 FreedTapestry21
|
|
#
|
|
# Licensed under the MIT license
|
|
#
|
|
|
|
from machine import Pin
|
|
import machine
|
|
#import network, urequest, machine
|
|
|
|
# Define variables
|
|
CONSOLE_WELCOME = """
|
|
Petcard Bootloader - v1.0
|
|
Copyright (c) 2025 FreedTapestry21
|
|
|
|
Licensed under the MIT license
|
|
"""
|
|
UPDATE = False
|
|
MIRROR = "https://mirror.pixelated.sh/dev/petcard"
|
|
|
|
# Initialize OK button (with pull down resistor)
|
|
ok = Pin(0, Pin.IN, Pin.PULL_DOWN)
|
|
|
|
# Define functions
|
|
def download(file, name):
|
|
print("Downloading " + name + "...")
|
|
f = open(file)
|
|
r = urequests.get(MIRROR + "/" + file)
|
|
f.write(r.text)
|
|
f.close()
|
|
r.close
|
|
print("Downloaded " + name + "!")
|
|
|
|
def connect(ssid, psk):
|
|
nic = network.WLAN(network.WLAN.IF_STA)
|
|
nic.active(True)
|
|
nic.connect(ssid, psk)
|
|
while not sta_if.isconnected():
|
|
pass
|
|
|
|
def boot():
|
|
print("Loading system...")
|
|
with open("petcard.py") as app:
|
|
exec(app.read())
|
|
|
|
def main():
|
|
print(CONSOLE_WELCOME)
|
|
UPDATE = False
|
|
if ok.value() == 1:
|
|
UPDATE = True
|
|
|
|
if UPDATE == True:
|
|
print("Petcard bootloader has been interupted by the OK button")
|
|
inp = input("Are you sure you want to enter the Petcard recovery process? (y/N)")
|
|
if inp == "" or inp == "n" or inp == "N":
|
|
print("Rebooting to resume boot process...")
|
|
machine.soft_reset()
|
|
if inp == "y" or inp == "Y":
|
|
print("Entering Petcard recovery process...")
|
|
print("Please enter your Wi-Fi credentials")
|
|
ssid = input("SSID: ")
|
|
psk = input("Password: ")
|
|
#connect(ssid, psk)
|
|
print('Connected to network "' + str(ssid) + '"')
|
|
|
|
# Downloading system.py
|
|
# Disabled due to being stuck with a Pico for now
|
|
#download("system.py", "Petcard system")
|
|
#download("petcard.py", "Petcard")
|
|
print("System recovery complete, restarting system...")
|
|
machine.soft_reset()
|
|
else:
|
|
print("'" + inp + "' is not recognized as an option! Rebooting...")
|
|
machine.soft_reset()
|
|
else:
|
|
boot()
|
|
|
|
|
|
|
|
# Check if button is pressed for recovery/update process
|
|
if __name__ == '__main__':
|
|
main() |