Made first version of bootloader
This commit is contained in:
parent
3b04b90c74
commit
fc2af7031e
3 changed files with 79 additions and 0 deletions
71
main.py
Normal file
71
main.py
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
#
|
||||||
|
# Petcard Bootloader - v1.0
|
||||||
|
# Copyright (c) 2025 FreedTapestry21
|
||||||
|
#
|
||||||
|
|
||||||
|
from machine import Pin
|
||||||
|
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():
|
||||||
|
import system
|
||||||
|
init()
|
||||||
|
|
||||||
|
# Check if button is pressed for recovery/update process
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print(CONSOLE_WELCOME)
|
||||||
|
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...")
|
||||||
|
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
|
||||||
|
download("system.py", "Petcard system")
|
||||||
|
download("petcard.py", "Petcard")
|
||||||
|
print("System recovery complete, restarting system...")
|
||||||
|
machine.reset()
|
||||||
|
else:
|
||||||
|
print("'" + inp + "' is not recognized as an option! Rebooting...")
|
||||||
|
machine.reset()
|
||||||
|
else:
|
||||||
|
boot()
|
4
petcard.py
Normal file
4
petcard.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#
|
||||||
|
# Petcard - v1.0
|
||||||
|
# Copyright (c) 2025 FreedTapestry21
|
||||||
|
#
|
4
system.py
Normal file
4
system.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#
|
||||||
|
# Petcard System - v1.0
|
||||||
|
# Copyright (c) 2025 FreedTapestry21
|
||||||
|
#
|
Loading…
Add table
Add a link
Reference in a new issue