reformatting the default_app structure and worked on options menu.

This commit is contained in:
Lucas
2022-04-30 23:14:42 -04:00
parent 43104ac2d2
commit d8feab1636
10 changed files with 35 additions and 31 deletions
+2 -6
View File
@@ -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()
+1 -2
View File
@@ -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
from macropad_os.default_apps.debug_app import DebugApp
@@ -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):
@@ -0,0 +1 @@
from light_patterns import *
@@ -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)
]
@@ -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()
@@ -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]