finished making Macropad OS 1.0
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
from .light_patterns import *
|
||||
from .sound_patterns import *
|
||||
from .sound_patterns import *
|
||||
from .helper_funcs import *
|
||||
@@ -1,20 +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)
|
||||
[(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)
|
||||
[(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)
|
||||
[(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)]
|
||||
]
|
||||
|
||||
@@ -18,74 +18,59 @@ class DebugApp(App):
|
||||
def __init__(self, macropad, config, name):
|
||||
super().__init__(macropad, config)
|
||||
self.name = name
|
||||
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.title = label.Label(
|
||||
y=4,
|
||||
font=terminalio.FONT,
|
||||
color=0x0,
|
||||
text=f" {self.name} MENU ",
|
||||
background_color=0xFFFFFF,
|
||||
)
|
||||
self.title = "Debug App!"
|
||||
|
||||
def on_start(self):
|
||||
print("on start from the app!")
|
||||
self.lit_keys = [False] * 12
|
||||
self.macropad.display.show(self.display_group)
|
||||
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.lit_keys = [True] * 12
|
||||
for _ in range(12):
|
||||
self.labels.append(label.Label(terminalio.FONT, text=""))
|
||||
|
||||
for index in range(12):
|
||||
x = index % 3
|
||||
y = index // 3
|
||||
self.layout.add_content(self.labels[index], grid_position=(x, y), cell_size=(1, 1))
|
||||
|
||||
# for index in range(12):
|
||||
# x = index % 3
|
||||
# y = index // 3
|
||||
# self.layout.add_content(self.labels[index], grid_position=(x, y), cell_size=(1, 1))
|
||||
self.set_tone_status(True)
|
||||
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_released(self.process_keys_released_callback)
|
||||
self.register_on_encoder_changed(self.process_enbcoder_changed)
|
||||
|
||||
def on_resume(self):
|
||||
print("resume from the debug app!")
|
||||
|
||||
print(id(self.display_group))
|
||||
print(self.display_group)
|
||||
self.display_group.append(self.title)
|
||||
self.display_group.append(self.layout)
|
||||
self.macropad.display.show(self.display_group)
|
||||
|
||||
def on_pause(self):
|
||||
print("Pausing")
|
||||
self.display_group.remove(self.title)
|
||||
self.display_group.remove(self.layout)
|
||||
|
||||
|
||||
def on_stop(self):
|
||||
print("Stopping")
|
||||
|
||||
def loop(self):
|
||||
self.process_key_presses()
|
||||
self.light_keys()
|
||||
self.light_keys()
|
||||
def on_loop(self):
|
||||
self.update_key_colors()
|
||||
|
||||
def process_key_presses(self):
|
||||
key_event = self.macropad.keys.events.get()
|
||||
if key_event:
|
||||
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]
|
||||
self.macropad.stop_tone()
|
||||
self.macropad.start_tone(self.tones[key_event.key_number])
|
||||
else:
|
||||
self.labels[key_event.key_number].text = ""
|
||||
self.macropad.stop_tone()
|
||||
|
||||
def light_keys(self):
|
||||
def update_key_colors(self):
|
||||
self.wheel_offset += 1
|
||||
colors = self.get_colors()
|
||||
for pixel in range(12):
|
||||
if self.lit_keys[pixel]:
|
||||
(r, g, b) = rgb_from_int(colorwheel((pixel / 12 * 256) + self.wheel_offset))
|
||||
self.macropad.pixels[pixel] = (r * .1, g * .1, b * .1)
|
||||
colors[pixel] = (r, g, b)
|
||||
else:
|
||||
self.macropad.pixels[pixel] = 0
|
||||
colors[pixel] = 0
|
||||
self.set_colors(colors)
|
||||
|
||||
def process_keys_pressed_callback(self, keyevent):
|
||||
print("PROCESS KEYS CALLBACK FROM DEBUG")
|
||||
print(keyevent)
|
||||
|
||||
def process_keys_released_callback(self, keyevent):
|
||||
print("PROCESS KEYS RELEASED CALLBACK FROM DEBUG")
|
||||
print(keyevent)
|
||||
def process_enbcoder_changed(self, keyevent):
|
||||
print("PROCESS Encoder Changed Callback FROM DEBUG")
|
||||
print(keyevent)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import terminalio
|
||||
from adafruit_display_text import label
|
||||
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
|
||||
|
||||
from .common import arrows_yes_no, arrows_with_enter, up_down_enter
|
||||
@@ -12,59 +10,40 @@ class OptionsApp(App):
|
||||
super().__init__(macropad, config)
|
||||
self.send_keyboard_inputs = 0
|
||||
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.possible_key_colors = [arrows_yes_no, arrows_with_enter, up_down_enter]
|
||||
self.title = label.Label(
|
||||
y=4,
|
||||
font=terminalio.FONT,
|
||||
color=0x0,
|
||||
text=f" OPTIONS MENU ",
|
||||
background_color=0xFFFFFF,
|
||||
)
|
||||
self.counter = 0
|
||||
self.title = "Options"
|
||||
|
||||
def on_start(self):
|
||||
print("on start from the app!")
|
||||
self.lit_keys = [False] * 4
|
||||
for _ in range(4):
|
||||
self.labels.append(label.Label(terminalio.FONT, text=""))
|
||||
|
||||
for index in range(4):
|
||||
x = 0
|
||||
y = index
|
||||
self.layout.add_content(self.labels[index], grid_position=(x, y), cell_size=(3, 1))
|
||||
print("on start from the options app!")
|
||||
self.set_title(self.title)
|
||||
self.set_layout(GridLayout(x=0, y=9, width=128, height=54, grid_size=(4, 4), cell_padding=1))
|
||||
|
||||
def on_resume(self):
|
||||
print("resume from the options app!")
|
||||
self.display_group.append(self.title)
|
||||
self.display_group.append(self.layout)
|
||||
self.macropad.display.show(self.display_group)
|
||||
|
||||
def on_pause(self):
|
||||
print("Pausing")
|
||||
self.display_group.remove(self.title)
|
||||
self.display_group.remove(self.layout)
|
||||
|
||||
|
||||
def on_stop(self):
|
||||
print("Stopping")
|
||||
|
||||
def loop(self):
|
||||
self.process_key_presses()
|
||||
self.light_keys()
|
||||
self.key_colors = self.possible_key_colors[self.counter % len(self.possible_key_colors)]
|
||||
self.counter+=1
|
||||
def on_loop(self):
|
||||
pass
|
||||
|
||||
def on_key_pressed(self, keyevent):
|
||||
print("ON KEY PRESSED CALLBACK FROM OPTIONS")
|
||||
print(keyevent)
|
||||
|
||||
def on_key_released(self, keyevent):
|
||||
print("ON KEY RELEASED CALLBACK FROM OPTIONS")
|
||||
print(keyevent)
|
||||
|
||||
def on_wheel_change(self, event):
|
||||
print("ON WHEEL CHANGED CALLBACK")
|
||||
print(event)
|
||||
|
||||
|
||||
def process_key_presses(self):
|
||||
key_event = self.macropad.keys.events.get()
|
||||
if key_event:
|
||||
if key_event.key_number < 12:
|
||||
if key_event.pressed:
|
||||
self.macropad.stop_tone()
|
||||
self.macropad.start_tone(440)
|
||||
else:
|
||||
self.macropad.stop_tone()
|
||||
|
||||
def light_keys(self):
|
||||
for pixel in range(12):
|
||||
self.macropad.pixels[pixel] = self.key_colors[pixel]
|
||||
|
||||
Reference in New Issue
Block a user