feat: Adding support for json apps. Updated Macropad_os.py to automatically load in the python and json apps at launch.

This commit is contained in:
Lucas Oskorep
2022-09-20 12:56:41 -04:00
parent 6724f8a4f3
commit 1cc9348d24
10 changed files with 302 additions and 152 deletions
+7 -24
View File
@@ -10,31 +10,14 @@ default_config = Config("default_config.json").load()
config = Config("config.json").load(default_config)
PYTHON_APP_FOLDER = "./macropad_apps/python"
JSON_APP_FOLDER = "./macropad_apps/json"
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)
ar = MacropadOS(
macropad,
config,
python_apps=PYTHON_APP_FOLDER,
json_apps=JSON_APP_FOLDER
)
# sc = SerialComms(config)
# _thread.start_new_thread(sc.run, (sc))
ar.start()