Finished the menu demo
This commit is contained in:
parent
fc2af7031e
commit
1be6e12b54
5 changed files with 643 additions and 51 deletions
115
main.py
115
main.py
|
@ -2,70 +2,83 @@
|
|||
# Petcard Bootloader - v1.0
|
||||
# Copyright (c) 2025 FreedTapestry21
|
||||
#
|
||||
# Licensed under the MIT license
|
||||
#
|
||||
|
||||
#
|
||||
# Importing libraries
|
||||
#
|
||||
|
||||
from machine import Pin
|
||||
import network, urequest, machine
|
||||
import time
|
||||
|
||||
#
|
||||
# Define global variables
|
||||
#
|
||||
|
||||
# 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)
|
||||
ok = Pin(1, 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 + "!")
|
||||
#
|
||||
# Function(s)
|
||||
#
|
||||
|
||||
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)
|
||||
def main():
|
||||
# Check if a boot interuption was triggered (you can trigger this by holding down the OK button) and wait for 10 seconds
|
||||
# In later revisions I'd like this to trigger some kind of update screen to easily update the Petcard
|
||||
INTERUPT = False
|
||||
if ok.value() == 1:
|
||||
UPDATE = True
|
||||
INTERUPT = 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()
|
||||
if INTERUPT == True: return 1
|
||||
else: return 0
|
||||
|
||||
#
|
||||
# Classes
|
||||
#
|
||||
|
||||
class Instance:
|
||||
def __init__(self):
|
||||
self.config_manager = system.ConfigurationManager()
|
||||
self.logger = system.Logger(self.config_manager.config)
|
||||
self.input_controller = system.InputController(self.config_manager.config["controls"], self.logger)
|
||||
|
||||
# Select display driver
|
||||
if self.config_manager.config["display"] == "SSD1306":
|
||||
self.display_driver = system.SSD1306Driver()
|
||||
else:
|
||||
print("'" + inp + "' is not recognized as an option! Rebooting...")
|
||||
machine.reset()
|
||||
else:
|
||||
boot()
|
||||
self.logger.log(f"No available driver was found for display {self.config_manager.config['display']}!", 0)
|
||||
self.display_driver = system.DisplayDriver() # DO NOT REMOVE
|
||||
|
||||
self.display = system.Display(self.display_driver, 128, 64, self.logger)
|
||||
self.ui = system.UserInterface(self.display, self.input_controller, self.logger)
|
||||
self.power = system.Power(self.display, self.input_controller, self.logger)
|
||||
|
||||
#
|
||||
# Entry point
|
||||
#
|
||||
|
||||
if __name__ == '__main__':
|
||||
if main() == 1:
|
||||
time.sleep(10)
|
||||
machine.soft_reset()
|
||||
print(CONSOLE_WELCOME)
|
||||
print("Importing SYSTEM module...")
|
||||
import system
|
||||
print("Importing APP module...")
|
||||
import petcard
|
||||
print("Starting Petcard")
|
||||
instance = Instance()
|
||||
app = petcard.Application(instance.config_manager, instance.logger, instance.display_driver, instance.display, instance.input_controller, instance.ui, instance.power)
|
||||
app.run()
|
||||
|
||||
#
|
||||
# End Of File (EOF)
|
||||
#
|
Loading…
Add table
Add a link
Reference in a new issue