From d8feab163698c2a2184139fdd86aaff0ec0974e7 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sat, 30 Apr 2022 23:14:42 -0400 Subject: [PATCH] reformatting the default_app structure and worked on options menu. --- code.py | 8 ++---- {app => macropad_os}/__init__.py | 3 +-- {app => macropad_os}/abstract_app.py | 0 {app => macropad_os}/app_router.py | 2 +- {app => macropad_os}/app_state.py | 0 macropad_os/default_apps/__init__.py | 0 macropad_os/default_apps/common/__init__.py | 1 + .../default_apps/common/light_patterns.py | 20 ++++++++++++++ .../default_apps}/debug_app.py | 5 ++-- .../default_apps}/options_app.py | 27 ++++++------------- 10 files changed, 35 insertions(+), 31 deletions(-) rename {app => macropad_os}/__init__.py (64%) rename {app => macropad_os}/abstract_app.py (100%) rename {app => macropad_os}/app_router.py (98%) rename {app => macropad_os}/app_state.py (100%) create mode 100644 macropad_os/default_apps/__init__.py create mode 100644 macropad_os/default_apps/common/__init__.py create mode 100644 macropad_os/default_apps/common/light_patterns.py rename {app => macropad_os/default_apps}/debug_app.py (97%) rename {app => macropad_os/default_apps}/options_app.py (63%) diff --git a/code.py b/code.py index cba28df..fb06014 100644 --- a/code.py +++ b/code.py @@ -1,6 +1,4 @@ -import displayio - -from app import AppRouter, DebugApp +from macropad_os import AppRouter, DebugApp from config import Config from adafruit_macropad import MacroPad @@ -11,9 +9,7 @@ config = Config("config.json") ar = AppRouter(macropad, config, [ DebugApp(macropad, config, "DEBUG 1"), - DebugApp(macropad, config, "DEBUG 2"), - # DebugApp(macropad, config, "debug 2"), - # DebugApp(macropad, config, "debug 3") + DebugApp(macropad, config, "DEBUG 2") ]) ar.start() diff --git a/app/__init__.py b/macropad_os/__init__.py similarity index 64% rename from app/__init__.py rename to macropad_os/__init__.py index 5741353..7b72f8d 100644 --- a/app/__init__.py +++ b/macropad_os/__init__.py @@ -1,5 +1,4 @@ from .abstract_app import App from .app_state import AppState, InvalidStateUpdateError from .app_router import AppRouter -from .debug_app import DebugApp -from .options_app import OptionsApp \ No newline at end of file +from macropad_os.default_apps.debug_app import DebugApp diff --git a/app/abstract_app.py b/macropad_os/abstract_app.py similarity index 100% rename from app/abstract_app.py rename to macropad_os/abstract_app.py diff --git a/app/app_router.py b/macropad_os/app_router.py similarity index 98% rename from app/app_router.py rename to macropad_os/app_router.py index 5d8ed38..86df051 100644 --- a/app/app_router.py +++ b/macropad_os/app_router.py @@ -1,7 +1,7 @@ import time from .app_state import AppState -from .options_app import OptionsApp +from app.options.options_app import OptionsApp class AppRouter(object): diff --git a/app/app_state.py b/macropad_os/app_state.py similarity index 100% rename from app/app_state.py rename to macropad_os/app_state.py diff --git a/macropad_os/default_apps/__init__.py b/macropad_os/default_apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/macropad_os/default_apps/common/__init__.py b/macropad_os/default_apps/common/__init__.py new file mode 100644 index 0000000..039d423 --- /dev/null +++ b/macropad_os/default_apps/common/__init__.py @@ -0,0 +1 @@ +from light_patterns import * \ No newline at end of file diff --git a/macropad_os/default_apps/common/light_patterns.py b/macropad_os/default_apps/common/light_patterns.py new file mode 100644 index 0000000..86f5cc8 --- /dev/null +++ b/macropad_os/default_apps/common/light_patterns.py @@ -0,0 +1,20 @@ +arrows_with_enter = [ + (0, 0, 0), (0, 0, 0), (0, 0, 0), + (0, 0, 0), (0, 0, 100), (0, 0, 0), + (0, 0, 100), (100, 0, 0), (0, 0, 100), + (0, 0, 0), (0, 0, 100), (0, 0, 0) +] + +up_down_enter = [ + (0, 0, 0), (0, 0, 0), (0, 0, 0), + (0, 0, 0), (0, 0, 100), (0, 0, 0), + (0, 0, 0), (100, 0, 0), (0, 0, 0), + (0, 0, 0), (0, 0, 100), (0, 0, 0) +] + +arrows_yes_no = [ + (0, 0, 0), (0, 0, 0), (0, 0, 0), + (0, 0, 0), (0, 0, 100), (0, 0, 0), + (0, 0, 0), (100, 0, 0), (0, 0, 0), + (0, 100, 0), (0, 0, 100), (100, 0, 0) +] diff --git a/app/debug_app.py b/macropad_os/default_apps/debug_app.py similarity index 97% rename from app/debug_app.py rename to macropad_os/default_apps/debug_app.py index cceae90..5b03f96 100644 --- a/app/debug_app.py +++ b/macropad_os/default_apps/debug_app.py @@ -3,7 +3,7 @@ from adafruit_display_text import bitmap_label as label from adafruit_displayio_layout.layouts.grid_layout import GridLayout from rainbowio import colorwheel -from .abstract_app import App +from macropad_os.abstract_app import App def rgb_from_int(rgb): @@ -56,10 +56,8 @@ class DebugApp(App): def on_pause(self): print("Pausing") - self.display_group.remove(self.title) self.display_group.remove(self.layout) - # self.macropad.display.show(None) def on_stop(self): @@ -68,6 +66,7 @@ class DebugApp(App): def loop(self): self.process_key_presses() self.light_keys() + self.light_keys() def process_key_presses(self): key_event = self.macropad.keys.events.get() diff --git a/app/options_app.py b/macropad_os/default_apps/options_app.py similarity index 63% rename from app/options_app.py rename to macropad_os/default_apps/options_app.py index 2085e95..f0b44a9 100644 --- a/app/options_app.py +++ b/macropad_os/default_apps/options_app.py @@ -1,22 +1,19 @@ import terminalio from adafruit_display_text import label from adafruit_displayio_layout.layouts.grid_layout import GridLayout -from rainbowio import colorwheel -from .abstract_app import App -from .debug_app import rgb_from_int +from common.light_patterns import arrows_yes_no +from ..abstract_app import App class OptionsApp(App): def __init__(self, macropad, config): super().__init__(macropad, config) - self.tones = [196, 220, 246, 262, 294, 330, 349, 392, 440, 494, 523, 587] - self.wheel_offset = 0 self.send_keyboard_inputs = 0 - self.lit_keys = [False] * 12 self.labels = [] self.layout = GridLayout(x=0, y=9, width=128, height=54, grid_size=(4, 4), cell_padding=1) + self.key_colors = arrows_yes_no self.title = label.Label( y=4, font=terminalio.FONT, @@ -58,21 +55,13 @@ class OptionsApp(App): key_event = self.macropad.keys.events.get() if key_event: if key_event.key_number < 12: - if key_event.pressed : - self.labels[key_event.key_number].text = "KEY{}".format(key_event.key_number) - print(self.macropad.keys) - self.lit_keys[key_event.key_number] = not self.lit_keys[key_event.key_number] + if key_event.pressed: self.macropad.stop_tone() - self.macropad.start_tone(self.tones[key_event.key_number]) + self.macropad.start_tone(200) else: - self.labels[key_event.key_number].text = "" self.macropad.stop_tone() def light_keys(self): - self.wheel_offset += 1 - for pixel in range(4): - if self.lit_keys[pixel]: - (r, g, b) = rgb_from_int(colorwheel((pixel / 4 * 256) + self.wheel_offset)) - self.macropad.pixels[pixel] = (r * .1, g * .1, b * .1) - else: - self.macropad.pixels[pixel] = 0 + for pixel in range(12): + print(pixel) + self.macropad.pixels[pixel] = self.key_colors[pixel]