small formatting changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import storage
|
import storage
|
||||||
|
|
||||||
from config import Config, ConfigVars
|
from macropad_os.config import Config, ConfigVars
|
||||||
|
|
||||||
config = Config("config.json")
|
config = Config("config.json")
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from macropad_os import AppRouter, DebugApp
|
from macropad_os import AppRouter, DebugApp, SerialComms
|
||||||
from config import Config
|
from macropad_os.config import Config
|
||||||
|
|
||||||
from adafruit_macropad import MacroPad
|
from adafruit_macropad import MacroPad
|
||||||
|
|
||||||
|
|
||||||
macropad = MacroPad()
|
macropad = MacroPad()
|
||||||
config = Config("config.json")
|
config = Config("config.json")
|
||||||
|
|
||||||
@@ -12,4 +13,8 @@ ar = AppRouter(macropad, config, [
|
|||||||
DebugApp(macropad, config, "DEBUG 2")
|
DebugApp(macropad, config, "DEBUG 2")
|
||||||
])
|
])
|
||||||
|
|
||||||
|
sc = SerialComms(config)
|
||||||
|
|
||||||
|
# _thread.start_new_thread(sc.run, (sc))
|
||||||
|
|
||||||
ar.start()
|
ar.start()
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
xcopy .\* E:\ /s /d /exclude:excludedfileslist.txt /Y
|
xcopy .\* E:\ /s /d /exclude:excludedfileslist.txt /Y
|
||||||
|
xcopy .\* F:\ /s /d /exclude:excludedfileslist.txt /Y
|
||||||
@@ -2,3 +2,4 @@ from .abstract_app import App
|
|||||||
from .app_state import AppState, InvalidStateUpdateError
|
from .app_state import AppState, InvalidStateUpdateError
|
||||||
from .app_router import AppRouter
|
from .app_router import AppRouter
|
||||||
from macropad_os.default_apps.debug_app import DebugApp
|
from macropad_os.default_apps.debug_app import DebugApp
|
||||||
|
from .serial_communications import SerialComms
|
||||||
+36
-35
@@ -1,7 +1,6 @@
|
|||||||
import displayio
|
import displayio
|
||||||
import terminalio
|
import terminalio
|
||||||
from adafruit_display_text import label
|
from adafruit_display_text import label
|
||||||
from adafruit_hid.keycode import Keycode
|
|
||||||
|
|
||||||
from .app_state import AppState, InvalidStateUpdateError
|
from .app_state import AppState, InvalidStateUpdateError
|
||||||
|
|
||||||
@@ -39,14 +38,14 @@ class App(object):
|
|||||||
self._key_released_callbacks = []
|
self._key_released_callbacks = []
|
||||||
self._encoder_changed_callbacks = []
|
self._encoder_changed_callbacks = []
|
||||||
self._encoder_state = 0
|
self._encoder_state = 0
|
||||||
|
self._labels = []
|
||||||
|
|
||||||
self.macropad = macropad
|
self.macropad = macropad
|
||||||
self.config = config
|
self.config = config
|
||||||
self.name = "app"
|
self.name = "app"
|
||||||
self.state = AppState.STOPPED
|
self.state = AppState.STOPPED
|
||||||
|
|
||||||
def start(self):
|
def start(self) -> None:
|
||||||
print("Start from base class ")
|
print("Start from base class ")
|
||||||
if self.state is not AppState.STOPPED:
|
if self.state is not AppState.STOPPED:
|
||||||
raise InvalidStateUpdateError(f"Start called but the current app state is {self.state}")
|
raise InvalidStateUpdateError(f"Start called but the current app state is {self.state}")
|
||||||
@@ -55,13 +54,13 @@ class App(object):
|
|||||||
self.on_start()
|
self.on_start()
|
||||||
self.state = AppState.PAUSED
|
self.state = AppState.PAUSED
|
||||||
|
|
||||||
def _on_start(self):
|
def _on_start(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self) -> None:
|
||||||
raise NotImplementedError("on_start not implemented")
|
raise NotImplementedError("on_start not implemented")
|
||||||
|
|
||||||
def resume(self):
|
def resume(self) -> None:
|
||||||
if self.state is not AppState.PAUSED:
|
if self.state is not AppState.PAUSED:
|
||||||
raise InvalidStateUpdateError(f"Resume called but the current app state is {self.state}")
|
raise InvalidStateUpdateError(f"Resume called but the current app state is {self.state}")
|
||||||
self.state = AppState.RESUMING
|
self.state = AppState.RESUMING
|
||||||
@@ -69,13 +68,13 @@ class App(object):
|
|||||||
self.on_resume()
|
self.on_resume()
|
||||||
self.state = AppState.RUNNING
|
self.state = AppState.RUNNING
|
||||||
|
|
||||||
def _on_resume(self):
|
def _on_resume(self) -> None:
|
||||||
self.add_displays_to_group()
|
self.add_displays_to_group()
|
||||||
|
|
||||||
def on_resume(self):
|
def on_resume(self) -> None:
|
||||||
raise NotImplementedError("on_resume not implemented")
|
raise NotImplementedError("on_resume not implemented")
|
||||||
|
|
||||||
def pause(self):
|
def pause(self) -> None:
|
||||||
if self.state is not AppState.RUNNING:
|
if self.state is not AppState.RUNNING:
|
||||||
raise InvalidStateUpdateError(f"Pause called but the current app state is {self.state}")
|
raise InvalidStateUpdateError(f"Pause called but the current app state is {self.state}")
|
||||||
self.state = AppState.PAUSING
|
self.state = AppState.PAUSING
|
||||||
@@ -83,7 +82,7 @@ class App(object):
|
|||||||
self.on_pause()
|
self.on_pause()
|
||||||
self.state = AppState.PAUSED
|
self.state = AppState.PAUSED
|
||||||
|
|
||||||
def _on_pause(self):
|
def _on_pause(self) -> None:
|
||||||
self.macropad.keyboard.release_all()
|
self.macropad.keyboard.release_all()
|
||||||
self.macropad.consumer_control.release()
|
self.macropad.consumer_control.release()
|
||||||
self.macropad.mouse.release_all()
|
self.macropad.mouse.release_all()
|
||||||
@@ -91,24 +90,24 @@ class App(object):
|
|||||||
self.macropad.pixels.show()
|
self.macropad.pixels.show()
|
||||||
self.remove_displays_from_group()
|
self.remove_displays_from_group()
|
||||||
|
|
||||||
def on_pause(self):
|
def on_pause(self) -> None:
|
||||||
raise NotImplementedError("on_pause not implemented")
|
raise NotImplementedError("on_pause not implemented")
|
||||||
|
|
||||||
def loop(self):
|
def loop(self) -> None:
|
||||||
# We'll fire you if you override this method.
|
# We'll fire you if you override this method.
|
||||||
self._on_loop()
|
self._on_loop()
|
||||||
self.on_loop()
|
self.on_loop()
|
||||||
|
|
||||||
def on_loop(self):
|
def on_loop(self) -> None:
|
||||||
raise NotImplementedError("Not implemented")
|
raise NotImplementedError("Not implemented")
|
||||||
|
|
||||||
def _on_loop(self):
|
def _on_loop(self) -> None:
|
||||||
self._update_lighting()
|
self._update_lighting()
|
||||||
self._process_keys_pressed()
|
self._process_keys_pressed()
|
||||||
self._process_wheel_changes()
|
self._process_wheel_changes()
|
||||||
self.on_loop()
|
self.on_loop()
|
||||||
|
|
||||||
def _process_keys_pressed(self):
|
def _process_keys_pressed(self) -> None:
|
||||||
key_event = self.macropad.keys.events.get()
|
key_event = self.macropad.keys.events.get()
|
||||||
if key_event:
|
if key_event:
|
||||||
if key_event.key_number < 12:
|
if key_event.key_number < 12:
|
||||||
@@ -128,7 +127,7 @@ class App(object):
|
|||||||
for callback in self._key_pressed_callbacks:
|
for callback in self._key_pressed_callbacks:
|
||||||
callback(key_event.key_number)
|
callback(key_event.key_number)
|
||||||
|
|
||||||
def _process_wheel_changes(self):
|
def _process_wheel_changes(self) -> None:
|
||||||
encoder = self.macropad.encoder
|
encoder = self.macropad.encoder
|
||||||
if self._encoder_state != encoder:
|
if self._encoder_state != encoder:
|
||||||
for callback in self._encoder_changed_callbacks:
|
for callback in self._encoder_changed_callbacks:
|
||||||
@@ -138,7 +137,7 @@ class App(object):
|
|||||||
callback(1)
|
callback(1)
|
||||||
self._encoder_state = encoder
|
self._encoder_state = encoder
|
||||||
|
|
||||||
def stop(self):
|
def stop(self) -> None:
|
||||||
if self.state is not AppState.PAUSED:
|
if self.state is not AppState.PAUSED:
|
||||||
raise InvalidStateUpdateError(f"Stop called but the current app state is {self.state}")
|
raise InvalidStateUpdateError(f"Stop called but the current app state is {self.state}")
|
||||||
self.state = AppState.STOPPING
|
self.state = AppState.STOPPING
|
||||||
@@ -146,17 +145,17 @@ class App(object):
|
|||||||
self.on_stop()
|
self.on_stop()
|
||||||
self.state = AppState.STOPPED
|
self.state = AppState.STOPPED
|
||||||
|
|
||||||
def _on_stop(self):
|
def _on_stop(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_stop(self):
|
def on_stop(self) -> None:
|
||||||
raise NotImplementedError("on_stop not implemented.")
|
raise NotImplementedError("on_stop not implemented.")
|
||||||
|
|
||||||
def _update_lighting(self):
|
def _update_lighting(self) -> None:
|
||||||
for index, color in enumerate(self._key_lights):
|
for index, color in enumerate(self._key_lights):
|
||||||
self.macropad.pixels[index] = color
|
self.macropad.pixels[index] = color
|
||||||
|
|
||||||
def add_displays_to_group(self):
|
def add_displays_to_group(self) -> None:
|
||||||
self._display_group.append(self._title_label)
|
self._display_group.append(self._title_label)
|
||||||
self._display_group.append(self._layout)
|
self._display_group.append(self._layout)
|
||||||
self.macropad.display.show(self._display_group)
|
self.macropad.display.show(self._display_group)
|
||||||
@@ -165,14 +164,14 @@ class App(object):
|
|||||||
self._display_group.remove(self._title_label)
|
self._display_group.remove(self._title_label)
|
||||||
self._display_group.remove(self._layout)
|
self._display_group.remove(self._layout)
|
||||||
|
|
||||||
def set_color(self, x, y, color):
|
def set_color(self, x, y, color) -> None:
|
||||||
key_value = convert_to_keynum(x, y)
|
key_value = convert_to_keynum(x, y)
|
||||||
if key_value >= 12:
|
if key_value >= 12:
|
||||||
raise ValueError("color index out of range")
|
raise ValueError("color index out of range")
|
||||||
if len(color) != 3:
|
if len(color) != 3:
|
||||||
self._key_lights[key_value] = color
|
self._key_lights[key_value] = color
|
||||||
|
|
||||||
def set_colors(self, colors):
|
def set_colors(self, colors) -> None:
|
||||||
if len(colors) != 12:
|
if len(colors) != 12:
|
||||||
raise ValueError("Colors must be passed in as a 12 len array")
|
raise ValueError("Colors must be passed in as a 12 len array")
|
||||||
for color in colors:
|
for color in colors:
|
||||||
@@ -180,17 +179,17 @@ class App(object):
|
|||||||
raise ValueError("Color format error - color must be length 3")
|
raise ValueError("Color format error - color must be length 3")
|
||||||
self._key_lights = colors
|
self._key_lights = colors
|
||||||
|
|
||||||
def get_colors(self):
|
def get_colors(self) -> [(int, int, int)]:
|
||||||
return self._key_lights
|
return self._key_lights
|
||||||
|
|
||||||
def set_tone(self, keypad_num, tone):
|
def set_tone(self, keypad_num, tone) -> None:
|
||||||
if keypad_num >= 12:
|
if keypad_num >= 12:
|
||||||
raise ValueError("Tone index out of range")
|
raise ValueError("Tone index out of range")
|
||||||
if tone < 20 or tone > 20000:
|
if tone < 20 or tone > 20000:
|
||||||
raise ValueError("Tone format error - tone out of human hearing range (20 - 20000)")
|
raise ValueError("Tone format error - tone out of human hearing range (20 - 20000)")
|
||||||
self._key_tones[keypad_num] = tone
|
self._key_tones[keypad_num] = tone
|
||||||
|
|
||||||
def set_tones(self, tones):
|
def set_tones(self, tones) -> None:
|
||||||
if len(tones) != 12:
|
if len(tones) != 12:
|
||||||
raise ValueError("Tones must be passed in as a 12 len array")
|
raise ValueError("Tones must be passed in as a 12 len array")
|
||||||
for tone in tones:
|
for tone in tones:
|
||||||
@@ -198,13 +197,13 @@ class App(object):
|
|||||||
raise ValueError("Tone format error - tone out of human hearing range (20 - 20000)")
|
raise ValueError("Tone format error - tone out of human hearing range (20 - 20000)")
|
||||||
self._key_tones = tones
|
self._key_tones = tones
|
||||||
|
|
||||||
def set_tone_status(self, enable):
|
def set_tone_status(self, enable) -> None:
|
||||||
self._enabled_key_sounds = enable
|
self._enabled_key_sounds = enable
|
||||||
|
|
||||||
def get_tones(self):
|
def get_tones(self) -> [int]:
|
||||||
return self._key_tones
|
return self._key_tones
|
||||||
|
|
||||||
def set_title(self, title):
|
def set_title(self, title) -> None:
|
||||||
"""
|
"""
|
||||||
:string title: Title of your app - shown in the top bar.
|
:string title: Title of your app - shown in the top bar.
|
||||||
|
|
||||||
@@ -217,7 +216,7 @@ class App(object):
|
|||||||
diff = int((22 - len(title)) / 2)
|
diff = int((22 - len(title)) / 2)
|
||||||
self._title_label.text = f"{''.join([' ' for _ in range(diff)])}{self._title}{''.join([' ' for _ in range(diff)])}"
|
self._title_label.text = f"{''.join([' ' for _ in range(diff)])}{self._title}{''.join([' ' for _ in range(diff)])}"
|
||||||
|
|
||||||
def set_layout(self, layout):
|
def set_layout(self, layout) -> None:
|
||||||
"""
|
"""
|
||||||
:displayio.Group layout:
|
:displayio.Group layout:
|
||||||
|
|
||||||
@@ -225,13 +224,15 @@ class App(object):
|
|||||||
"""
|
"""
|
||||||
self._layout = layout
|
self._layout = layout
|
||||||
|
|
||||||
def register_on_key_pressed(self, function):
|
def set_labels(self, labels) -> None:
|
||||||
|
self._labels = labels
|
||||||
|
# if self._layout
|
||||||
|
|
||||||
|
def register_on_key_pressed(self, function) -> None:
|
||||||
self._key_pressed_callbacks.append(function)
|
self._key_pressed_callbacks.append(function)
|
||||||
|
|
||||||
def register_on_key_released(self, function):
|
def register_on_key_released(self, function) -> None:
|
||||||
self._key_released_callbacks.append(function)
|
self._key_released_callbacks.append(function)
|
||||||
|
|
||||||
def register_on_encoder_changed(self, function):
|
def register_on_encoder_changed(self, function) -> None:
|
||||||
self._encoder_changed_callbacks.append(function)
|
self._encoder_changed_callbacks.append(function)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import time
|
|||||||
from .app_state import AppState
|
from .app_state import AppState
|
||||||
from .default_apps.options_app import OptionsApp
|
from .default_apps.options_app import OptionsApp
|
||||||
|
|
||||||
|
|
||||||
class AppRouter(object):
|
class AppRouter(object):
|
||||||
def __init__(self, macropad, config, apps):
|
def __init__(self, macropad, config, apps):
|
||||||
print("app router")
|
print("app router")
|
||||||
@@ -34,7 +33,7 @@ class AppRouter(object):
|
|||||||
print("Starting new app")
|
print("Starting new app")
|
||||||
self.current_app.resume()
|
self.current_app.resume()
|
||||||
|
|
||||||
def start(self):
|
def start(self) -> None:
|
||||||
self.current_app.start()
|
self.current_app.start()
|
||||||
self.current_app.resume()
|
self.current_app.resume()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import terminalio
|
import terminalio
|
||||||
|
|
||||||
from adafruit_display_text import bitmap_label as label
|
from adafruit_display_text import bitmap_label as label
|
||||||
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
|
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
|
||||||
from rainbowio import colorwheel
|
from rainbowio import colorwheel
|
||||||
@@ -28,13 +29,13 @@ class DebugApp(App):
|
|||||||
self.set_layout(GridLayout(x=0, y=9, width=128, height=54, grid_size=(4, 4), cell_padding=1))
|
self.set_layout(GridLayout(x=0, y=9, width=128, height=54, grid_size=(4, 4), cell_padding=1))
|
||||||
self.set_title(self.title)
|
self.set_title(self.title)
|
||||||
self.lit_keys = [True] * 12
|
self.lit_keys = [True] * 12
|
||||||
|
|
||||||
for _ in range(12):
|
for _ in range(12):
|
||||||
self.labels.append(label.Label(terminalio.FONT, text=""))
|
self.labels.append(label.Label(terminalio.FONT, text=""))
|
||||||
|
for index in range(12):
|
||||||
# for index in range(12):
|
x = index % 3
|
||||||
# x = index % 3
|
y = index // 3
|
||||||
# y = index // 3
|
self._layout.add_content(self.labels[index], grid_position=(x, y), cell_size=(1, 1))
|
||||||
# self.layout.add_content(self.labels[index], grid_position=(x, y), cell_size=(1, 1))
|
|
||||||
self.set_tone_status(True)
|
self.set_tone_status(True)
|
||||||
self.set_tones([196, 220, 246, 262, 294, 330, 349, 392, 440, 494, 523, 587])
|
self.set_tones([196, 220, 246, 262, 294, 330, 349, 392, 440, 494, 523, 587])
|
||||||
self.register_on_key_pressed(self.process_keys_pressed_callback)
|
self.register_on_key_pressed(self.process_keys_pressed_callback)
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
class SerialComms(object):
|
||||||
|
def __init__(self, config):
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
def loop(self):
|
||||||
|
print("Hello")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while True:
|
||||||
|
self.loop()
|
||||||
|
time.sleep(.5)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user