diff --git a/CircuitPython_Touch_Deck/code.py b/CircuitPython_Touch_Deck/code.py index 0918dbab8..0e84cc26a 100644 --- a/CircuitPython_Touch_Deck/code.py +++ b/CircuitPython_Touch_Deck/code.py @@ -8,15 +8,23 @@ This version runs on Feather RP2040 with a 3.5" FeatherWing import time import displayio import terminalio -from adafruit_display_text import label, bitmap_label +from adafruit_display_text import bitmap_label from adafruit_displayio_layout.layouts.grid_layout import GridLayout -from touch_deck_layers import touch_deck_config, KEY, STRING, MEDIA, KEY_PRESS, KEY_RELEASE +from adafruit_displayio_layout.widgets.icon_widget import IconWidget +from adafruit_featherwing import tft_featherwing_35 import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS from adafruit_hid.consumer_control import ConsumerControl -from adafruit_displayio_layout.widgets.icon_widget import IconWidget -from adafruit_featherwing import tft_featherwing_35 +from touch_deck_layers import ( + touch_deck_config, + KEY, + STRING, + MEDIA, + KEY_PRESS, + KEY_RELEASE, +) + # seems to help the touchscreen not get stuck with chip not found time.sleep(3) @@ -53,13 +61,17 @@ display.show(main_group) loading_group = displayio.Group() # black background, screen size minus side buttons -loading_background = displayio.Bitmap((display.width-40)//20, display.height//20, 1) +loading_background = displayio.Bitmap( + (display.width - 40) // 20, display.height // 20, 1 +) loading_palette = displayio.Palette(1) loading_palette[0] = 0x0 # scaled group to match screen size minus side buttons loading_background_scale_group = displayio.Group(scale=20) -loading_background_tilegrid = displayio.TileGrid(loading_background, pixel_shader=loading_palette) +loading_background_tilegrid = displayio.TileGrid( + loading_background, pixel_shader=loading_palette +) loading_background_scale_group.append(loading_background_tilegrid) # loading screen label @@ -98,31 +110,19 @@ layer_label.anchored_position = (display.width // 2, 4) main_group.append(layer_label) # right side layer buttons -next_layer_btn = IconWidget( - "", - "touch_deck_icons/layer_next.bmp", - on_disk=True -) +next_layer_btn = IconWidget("", "touch_deck_icons/layer_next.bmp", on_disk=True) next_layer_btn.x = display.width - 40 next_layer_btn.y = display.height - 100 next_layer_btn.resize = (40, 100) main_group.append(next_layer_btn) -prev_layer_btn = IconWidget( - "", - "touch_deck_icons/layer_prev.bmp", - on_disk=True -) +prev_layer_btn = IconWidget("", "touch_deck_icons/layer_prev.bmp", on_disk=True) prev_layer_btn.x = display.width - 40 prev_layer_btn.y = 110 prev_layer_btn.resize = (40, 100) main_group.append(prev_layer_btn) -home_layer_btn = IconWidget( - "", - "touch_deck_icons/layer_home.bmp", - on_disk=True -) +home_layer_btn = IconWidget("", "touch_deck_icons/layer_home.bmp", on_disk=True) home_layer_btn.x = display.width - 40 home_layer_btn.y = 0 home_layer_btn.resize = (40, 100) @@ -202,7 +202,10 @@ while True: # print(p) # Next layer button pressed - if next_layer_btn.contains(p) and NEXT_LAYER_INDEX not in _pressed_icons: + if ( + next_layer_btn.contains(p) + and NEXT_LAYER_INDEX not in _pressed_icons + ): # increment layer current_layer += 1 @@ -219,7 +222,10 @@ while True: _pressed_icons.append(NEXT_LAYER_INDEX) # home layer button pressed - if home_layer_btn.contains(p) and HOME_LAYER_INDEX not in _pressed_icons: + if ( + home_layer_btn.contains(p) + and HOME_LAYER_INDEX not in _pressed_icons + ): # 0 index is home layer current_layer = 0 # load the home layer @@ -232,7 +238,10 @@ while True: _pressed_icons.append(HOME_LAYER_INDEX) # Previous layer button pressed - if prev_layer_btn.contains(p) and PREV_LAYER_INDEX not in _pressed_icons: + if ( + prev_layer_btn.contains(p) + and PREV_LAYER_INDEX not in _pressed_icons + ): # decrement layer current_layer -= 1 @@ -258,8 +267,9 @@ while True: # print("pressed {}".format(index)) # get actions for this icon from config object - _cur_actions = touch_deck_config["layers"][current_layer]["shortcuts"][index][ - "actions"] + _cur_actions = touch_deck_config["layers"][ + current_layer + ]["shortcuts"][index]["actions"] # tuple means it's a single action if isinstance(_cur_actions, tuple): @@ -302,4 +312,4 @@ while True: else: # screen not touched # empty the pressed icons list - _pressed_icons.clear() \ No newline at end of file + _pressed_icons.clear() diff --git a/CircuitPython_Touch_Deck/touch_deck_layers.py b/CircuitPython_Touch_Deck/touch_deck_layers.py index 9870f7915..e28850bec 100644 --- a/CircuitPython_Touch_Deck/touch_deck_layers.py +++ b/CircuitPython_Touch_Deck/touch_deck_layers.py @@ -8,71 +8,71 @@ KEY_PRESS = 4 KEY_RELEASE = 5 touch_deck_config = { - "layers":[ + "layers": [ { "name": "Youtube Controls", "shortcuts": [ { "label": "Play", "icon": "touch_deck_icons/pr_play.bmp", - "actions": (KEY, [Keycode.K]) + "actions": (KEY, [Keycode.K]), }, { "label": "Pause", "icon": "touch_deck_icons/pr_pause.bmp", - "actions": (KEY, [Keycode.K]) + "actions": (KEY, [Keycode.K]), }, { "label": "Rewind", "icon": "touch_deck_icons/pr_rewind.bmp", - "actions": (KEY, [Keycode.LEFT_ARROW]) + "actions": (KEY, [Keycode.LEFT_ARROW]), }, { "label": "FastForward", "icon": "touch_deck_icons/pr_ffwd.bmp", - "actions": (KEY, [Keycode.RIGHT_ARROW]) + "actions": (KEY, [Keycode.RIGHT_ARROW]), }, { "label": "Previous", "icon": "touch_deck_icons/pr_previous.bmp", - "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.P]) + "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.P]), }, { "label": "Next", "icon": "touch_deck_icons/pr_next.bmp", - "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.N]) + "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.N]), }, { "label": "Vol -", "icon": "touch_deck_icons/pr_voldown.bmp", - "actions": (MEDIA, ConsumerControlCode.VOLUME_DECREMENT) + "actions": (MEDIA, ConsumerControlCode.VOLUME_DECREMENT), }, { "label": "Vol +", "icon": "touch_deck_icons/pr_volup.bmp", - "actions": (MEDIA, ConsumerControlCode.VOLUME_INCREMENT) + "actions": (MEDIA, ConsumerControlCode.VOLUME_INCREMENT), }, - { + { "label": "Fullscreen", "icon": "touch_deck_icons/pr_fullscreen.bmp", - "actions": (KEY, [Keycode.F]) + "actions": (KEY, [Keycode.F]), }, { "label": "Slow", "icon": "touch_deck_icons/pr_slow.bmp", - "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.COMMA]) + "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.COMMA]), }, { "label": "Fast", "icon": "touch_deck_icons/pr_fast.bmp", - "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.PERIOD]) + "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.PERIOD]), }, { "label": "Mute", "icon": "touch_deck_icons/pr_mute.bmp", - "actions": (KEY, [Keycode.M]) - } - ] + "actions": (KEY, [Keycode.M]), + }, + ], }, { "name": "Discord", @@ -80,104 +80,129 @@ touch_deck_config = { { "label": "Blinka", "icon": "touch_deck_icons/af_blinka.bmp", - "actions": (STRING, ":blinka:") + "actions": (STRING, ":blinka:"), }, { "label": "Adabot", "icon": "touch_deck_icons/af_adabot.bmp", - "actions": (STRING, ":adabot:") + "actions": (STRING, ":adabot:"), }, { "label": "Billie", "icon": "touch_deck_icons/af_billie.bmp", - "actions": (STRING, ":billie:") + "actions": (STRING, ":billie:"), }, { "label": "Cappy", "icon": "touch_deck_icons/af_cappy.bmp", - "actions": (STRING, ":cappy:") + "actions": (STRING, ":cappy:"), }, { "label": "Connie", "icon": "touch_deck_icons/af_connie.bmp", - "actions": (STRING, ":connie:") + "actions": (STRING, ":connie:"), }, { "label": "Gus", "icon": "touch_deck_icons/af_gus.bmp", - "actions": (STRING, ":gus:") + "actions": (STRING, ":gus:"), }, { "label": "Hans", "icon": "touch_deck_icons/af_hans.bmp", - "actions": (STRING, ":hans:") + "actions": (STRING, ":hans:"), }, { "label": "Mho", "icon": "touch_deck_icons/af_mho.bmp", - "actions": (STRING, ":mho:") + "actions": (STRING, ":mho:"), }, { "label": "Minerva", "icon": "touch_deck_icons/af_minerva.bmp", - "actions": (STRING, ":minerva:") + "actions": (STRING, ":minerva:"), }, { "label": "NeoTrellis", "icon": "touch_deck_icons/af_neotrellis.bmp", - "actions": (STRING, ":neotrellis:") + "actions": (STRING, ":neotrellis:"), }, { "label": "Ruby", "icon": "touch_deck_icons/af_ruby.bmp", - "actions": (STRING, ":ruby:") + "actions": (STRING, ":ruby:"), }, { "label": "Sparky", "icon": "touch_deck_icons/af_sparky.bmp", - "actions": (STRING, ":sparky:") - } - ] + "actions": (STRING, ":sparky:"), + }, + ], }, { - "name": "Test Third Layer", + "name": "Symbols", "shortcuts": [ { - "label": "Flameshot", - "icon": "touch_deck_icons/test48_icon.bmp", - # \n can be used in the string for enter key - "actions": [(KEY, [Keycode.GUI]), (STRING, "flameshot\n")] + "label": "Infinity", # ∞ + "icon": "touch_deck_icons/sy_infinity.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.FIVE]), }, { - "label": "Calculator", - "icon": "touch_deck_icons/test48_icon.bmp", - "actions": [(KEY, [Keycode.GUI, Keycode.SPACE]), (STRING, "Calculator")] + "label": "Degree", # º + "icon": "touch_deck_icons/sy_degree.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.ZERO]), }, { - "label": "Test (D)", - "icon": "touch_deck_icons/test48_icon.bmp", - "actions": [(KEY, [Keycode.CONTROL, Keycode.SHIFT, Keycode.U]), (STRING, "221e\n")] + "label": "Pi", # π + "icon": "touch_deck_icons/sy_pi.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.P]), }, { - "label": "Test (L)", - "icon": "touch_deck_icons/test48_icon.bmp", - "actions": [ - (KEY_PRESS, [Keycode.SHIFT]), - (KEY, [Keycode.B]), - (KEY, [Keycode.L]), - (KEY, [Keycode.I]), - (KEY, [Keycode.N]), - (KEY, [Keycode.K]), - (KEY, [Keycode.A]), - (KEY_RELEASE, [Keycode.SHIFT]) - ] + "label": "Sigma", # ∑ + "icon": "touch_deck_icons/sy_sigma.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.W]), }, { - "label": "Test [:)]", - "icon": "touch_deck_icons/test48_icon.bmp", - "actions": (KEY, [Keycode.RIGHT_SHIFT, Keycode.SEMICOLON, Keycode.ZERO]) - } - ] - } + "label": "Partial diff", # + "icon": "touch_deck_icons/sy_pdiff.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.D]), + }, + { + "label": "Increment", # ∆ + "icon": "touch_deck_icons/sy_increment.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.J]), + }, + { + "label": "Omega", # Ω + "icon": "touch_deck_icons/sy_omega.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.Z]), + }, + { + "label": "Mu", # µ + "icon": "touch_deck_icons/sy_micro.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.M]), + }, + { + "label": "Rad O", # Ø + "icon": "touch_deck_icons/sy_rado.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.SHIFT, Keycode.O]), + }, + { + "label": "Square root", # √ + "icon": "touch_deck_icons/sy_sqrrt.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.V]), + }, + { + "label": "Approx", # ≈ + "icon": "touch_deck_icons/sy_approx.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.X]), + }, + { + "label": "Plus minus", # ± + "icon": "touch_deck_icons/sy_plusminus.bmp", + "actions": (KEY, [Keycode.ALT, Keycode.SHIFT, Keycode.EQUALS]), + }, + ], + }, ] -} \ No newline at end of file +}