updates to options and debug apps allowing them to run side by side.
This commit is contained in:
+6
-4
@@ -14,10 +14,15 @@ class AppRouter(object):
|
|||||||
self.current_app = apps[self.app_index]
|
self.current_app = apps[self.app_index]
|
||||||
self.config = config
|
self.config = config
|
||||||
self.encoder_state = False
|
self.encoder_state = False
|
||||||
self.options_time = 1000000000 # .5 seconds in nanoseconds
|
self.options_time = 500000000 # .5 seconds in nanoseconds
|
||||||
self.click_time = 0
|
self.click_time = 0
|
||||||
|
|
||||||
def swap_to_app(self, app):
|
def swap_to_app(self, app):
|
||||||
|
"""
|
||||||
|
TODO: Calculate the size of the stack and the max size of hte stack and then fully close apps if need be.
|
||||||
|
:param app:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
print("Pausing current app")
|
print("Pausing current app")
|
||||||
self.current_app.pause()
|
self.current_app.pause()
|
||||||
print("Selecting new app")
|
print("Selecting new app")
|
||||||
@@ -55,9 +60,6 @@ class AppRouter(object):
|
|||||||
print("released encoder")
|
print("released encoder")
|
||||||
if self.encoder_state and self.click_time:
|
if self.encoder_state and self.click_time:
|
||||||
self.release_time = time.monotonic_ns()
|
self.release_time = time.monotonic_ns()
|
||||||
print(self.release_time)
|
|
||||||
print(self.click_time)
|
|
||||||
print(self.release_time - self.click_time)
|
|
||||||
if (time.monotonic_ns() - self.click_time) > self.options_time:
|
if (time.monotonic_ns() - self.click_time) > self.options_time:
|
||||||
self.macropad.play_tone(1000, .1)
|
self.macropad.play_tone(1000, .1)
|
||||||
self.swap_to_app(self.options)
|
self.swap_to_app(self.options)
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ class DebugApp(App):
|
|||||||
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 + 1
|
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))
|
||||||
|
|
||||||
|
|||||||
+5
-8
@@ -16,7 +16,7 @@ class OptionsApp(App):
|
|||||||
self.send_keyboard_inputs = 0
|
self.send_keyboard_inputs = 0
|
||||||
self.lit_keys = [False] * 12
|
self.lit_keys = [False] * 12
|
||||||
self.labels = []
|
self.labels = []
|
||||||
self.layout = GridLayout(x=0, y=9, width=128, height=54, grid_size=(4, 1), cell_padding=1)
|
self.layout = GridLayout(x=0, y=9, width=128, height=54, grid_size=(4, 4), cell_padding=1)
|
||||||
self.title = label.Label(
|
self.title = label.Label(
|
||||||
y=4,
|
y=4,
|
||||||
font=terminalio.FONT,
|
font=terminalio.FONT,
|
||||||
@@ -28,22 +28,19 @@ class OptionsApp(App):
|
|||||||
def on_start(self):
|
def on_start(self):
|
||||||
print("on start from the app!")
|
print("on start from the app!")
|
||||||
self.lit_keys = [False] * 4
|
self.lit_keys = [False] * 4
|
||||||
# self.macropad.display.show(self.display_group)
|
|
||||||
for _ in range(4):
|
for _ in range(4):
|
||||||
self.labels.append(label.Label(terminalio.FONT, text=""))
|
self.labels.append(label.Label(terminalio.FONT, text=""))
|
||||||
|
|
||||||
for index in range(4):
|
for index in range(4):
|
||||||
x = index % 3 + 1
|
x = 0
|
||||||
y = index // 3
|
y = index
|
||||||
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=(3, 1))
|
||||||
|
|
||||||
def on_resume(self):
|
def on_resume(self):
|
||||||
print("resume from the options app!")
|
print("resume from the options app!")
|
||||||
self.display_group.append(self.title)
|
self.display_group.append(self.title)
|
||||||
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)
|
||||||
print(self.display_group)
|
|
||||||
print(id(self.display_group))
|
|
||||||
|
|
||||||
def on_pause(self):
|
def on_pause(self):
|
||||||
print("Pausing")
|
print("Pausing")
|
||||||
@@ -60,7 +57,7 @@ class OptionsApp(App):
|
|||||||
def process_key_presses(self):
|
def process_key_presses(self):
|
||||||
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 < 4:
|
if key_event.key_number < 12:
|
||||||
if key_event.pressed :
|
if key_event.pressed :
|
||||||
self.labels[key_event.key_number].text = "KEY{}".format(key_event.key_number)
|
self.labels[key_event.key_number].text = "KEY{}".format(key_event.key_number)
|
||||||
print(self.macropad.keys)
|
print(self.macropad.keys)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import displayio
|
|||||||
|
|
||||||
from app import AppRouter, DebugApp
|
from app import AppRouter, DebugApp
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
from adafruit_macropad import MacroPad
|
from adafruit_macropad import MacroPad
|
||||||
|
|
||||||
macropad = MacroPad()
|
macropad = MacroPad()
|
||||||
@@ -9,7 +10,8 @@ config = Config("config.json")
|
|||||||
|
|
||||||
|
|
||||||
ar = AppRouter(macropad, config, [
|
ar = AppRouter(macropad, config, [
|
||||||
DebugApp(macropad, config, "debug 1"),
|
DebugApp(macropad, config, "DEBUG 1"),
|
||||||
|
DebugApp(macropad, config, "DEBUG 2"),
|
||||||
# DebugApp(macropad, config, "debug 2"),
|
# DebugApp(macropad, config, "debug 2"),
|
||||||
# DebugApp(macropad, config, "debug 3")
|
# DebugApp(macropad, config, "debug 3")
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user