feat: Added automatic loading of Apps from the macropad_apps/python directory at load time.
Performance improvements to the lighting system. Renamed app_router to macropad_os.
This commit is contained in:
@@ -1,22 +1,40 @@
|
||||
from macropad_os import AppRouter, SerialComms, Config
|
||||
import os
|
||||
|
||||
from macropad_os import MacropadOS, SerialComms, Config, App
|
||||
|
||||
from adafruit_macropad import MacroPad
|
||||
|
||||
from macropad_apps.python import NumpadApp
|
||||
|
||||
macropad = MacroPad()
|
||||
|
||||
default_config = Config("default_config.json").load()
|
||||
config = Config("config.json").load(default_config)
|
||||
|
||||
ar = AppRouter(macropad, config, [
|
||||
NumpadApp(macropad, config),
|
||||
# Arrow Keys
|
||||
# Script Runner
|
||||
])
|
||||
PYTHON_APP_FOLDER = "./macropad_apps/python"
|
||||
|
||||
sc = SerialComms(config)
|
||||
apps = []
|
||||
|
||||
files = os.listdir(PYTHON_APP_FOLDER)
|
||||
files.sort()
|
||||
|
||||
app_classes = []
|
||||
for filename in files:
|
||||
if filename.endswith('.py') and not filename.startswith('._'):
|
||||
try:
|
||||
print(filename)
|
||||
module = __import__(PYTHON_APP_FOLDER + '/' + filename[:-3])
|
||||
classes = [getattr(module, a) for a in dir(module)
|
||||
if isinstance(getattr(module, a), type)]
|
||||
for cls in classes:
|
||||
if issubclass(cls, App) and cls.__name__ != "App":
|
||||
app_classes.append(cls)
|
||||
print(app_classes)
|
||||
except (SyntaxError, ImportError, AttributeError, KeyError, NameError, IndexError, TypeError) as err:
|
||||
print("ERROR in", filename)
|
||||
import traceback
|
||||
|
||||
traceback.print_exception(err, err, err.__traceback__)
|
||||
|
||||
ar = MacropadOS(macropad, config, apps=app_classes)
|
||||
# sc = SerialComms(config)
|
||||
# _thread.start_new_thread(sc.run, (sc))
|
||||
|
||||
ar.start()
|
||||
|
||||
Reference in New Issue
Block a user