EMF_Camp_Badge/boot.py

47 lines
1.0 KiB
Python
Raw Permalink Normal View History

2018-08-24 18:00:09 -04:00
import os, tilda
2018-08-30 18:30:26 -04:00
from machine import Neopix
n=Neopix()
2018-08-31 07:13:08 -04:00
n.display([0,0,0])
n.display([0,0,0])
2018-07-15 06:53:48 -04:00
2018-08-28 13:44:53 -04:00
print("EMF: boot.py")
2018-07-16 18:04:42 -04:00
os.sync()
2018-07-15 06:53:48 -04:00
root = os.listdir()
def app(a):
if (a in root) and ("main.py" in os.listdir(a)):
return a + "/main.py"
def file(file, remove):
try:
2018-07-16 18:04:42 -04:00
a = None
2018-07-15 06:53:48 -04:00
with open(file, 'r') as f:
a = f.read().strip()
2018-07-16 18:04:42 -04:00
if remove:
os.remove(file)
return app(a)
2018-07-15 06:53:48 -04:00
except Exception as e:
2018-08-29 07:38:59 -04:00
print("Not found: %s" % file)
2018-07-15 06:53:48 -04:00
def any_home():
2018-08-26 15:27:23 -04:00
h = [a for a in root if a.startswith("home")]
return h[0] if len(h) else False
2018-07-15 06:53:48 -04:00
2018-08-05 17:14:31 -04:00
if "no_boot" in root:
os.remove("no_boot")
2018-08-28 13:44:53 -04:00
print("no_boot found, aborting boot sequence")
2018-08-30 14:17:08 -04:00
elif "bootstrap.py" in root:
print("Bootstrapping...")
tilda.main("bootstrap.py")
2018-08-28 13:44:53 -04:00
else:
2018-08-05 17:14:31 -04:00
start = None
if "main.py" in root:
start = "main.py"
2018-08-30 14:17:08 -04:00
start = start or file("once.txt", True) or file("default_app.txt", False) or any_home()
2018-08-29 10:36:45 -04:00
if ".py" not in start:
start += "/main.py"
2018-08-26 15:27:23 -04:00
print("Booting into %s" % start)
tilda.main(start)
2018-08-28 13:44:53 -04:00