From e4830f110597a94e1922e288134fd94f71c5e07c Mon Sep 17 00:00:00 2001 From: Tom Charnock Date: Fri, 3 Jan 2025 19:22:13 +0100 Subject: [PATCH] Working keyboard and all fonts --- characters.py | 267 +++++----- code.py | 315 ++++++------ .../VictorMonoNerdFont-SemiBoldItalic-32.bdf | 454 ++++++++++++++++-- .../VictorMonoNerdFont-SemiBoldItalic-32.pcf | Bin 28180 -> 126776 bytes fonts/flake.nix | 2 +- 5 files changed, 709 insertions(+), 329 deletions(-) diff --git a/characters.py b/characters.py index a678af9..438bb01 100644 --- a/characters.py +++ b/characters.py @@ -1,4 +1,124 @@ -from adafruit_hid.keycode import Keycode +try: + from adafruit_hid.keycode import Keycode + keycodes = { + "\ue31e": [Keycode.SPACEBAR], + "\u002e": [Keycode.PERIOD], + "\u003c": [Keycode.SHIFT, Keycode.COMMA], + "\u0031": [Keycode.ONE], + "\u21b9": [Keycode.TAB], + "\u002c": [Keycode.COMMA], + "\u0032": [Keycode.TWO], + "\u0065": [Keycode.E], + "\u0045": [Keycode.SHIFT, Keycode.E], + "\u0045": [Keycode.EQUALS], + "\u0035": [Keycode.FIVE], + "\u21dc": [Keycode.BACKSPACE], + "\u003a": [Keycode.SHIFT, Keycode.SEMICOLON], + "\u0033": [Keycode.THREE], + "\u0061": [Keycode.A], + "\u0041": [Keycode.SHIFT, Keycode.A], + "\u002b": [Keycode.SHIFT, Keycode.EQUALS], + "\u0036": [Keycode.SIX], + "\u0072": [Keycode.R], + "\u0052": [Keycode.SHIFT, Keycode.R], + "\u002f": [Keycode.FORWARD_SLASH], + "\uea6d": [Keycode.LEFT_CONTROL, Keycode.F], + "\u0075": [Keycode.U], + "\u0055": [Keycode.SHIFT, Keycode.U], + "\u0027": [Keycode.QUOTE], + "\u0038": [Keycode.EIGHT], + "\u21af": [Keycode.ESCAPE], + "\u003b": [Keycode.SEMICOLON], + "\u0034": [Keycode.FOUR], + "\u0069": [Keycode.I], + "\u0049": [Keycode.SHIFT, Keycode.I], + "\u002a": [Keycode.SHIFT, Keycode.EIGHT], + "\u0037": [Keycode.SEVEN], + "\u0063": [Keycode.C], + "\u0043": [Keycode.SHIFT, Keycode.C], + "\u005c": [Keycode.BACKSLASH], + "\u2229": [Keycode.LEFT_CONTROL, Keycode.A], + "\u0078": [Keycode.X], + "\u0058": [Keycode.SHIFT, Keycode.X], + "\u0022": [Keycode.SHIFT, Keycode.QUOTE], + "\u0039": [Keycode.NINE], + "\u006c": [Keycode.L], + "\u004c": [Keycode.SHIFT, Keycode.L], + "\u007e": [Keycode.SHIFT, Keycode.GRAVE_ACCENT], + "\u21da": [Keycode.APPLICATION, Keycode.LEFT_ARROW], + "\u007a": [Keycode.Z], + "\u005a": [Keycode.SHIFT, Keycode.Z], + "\u003e": [Keycode.SHIFT, Keycode.PERIOD], + "\u21db": [Keycode.APPLICATION, Keycode.RIGHT_ARROW], + "\u0064": [Keycode.D], + "\u0044": [Keycode.SHIFT, Keycode.D], + "\u0060": [Keycode.GRAVE_ACCENT], + "\uebd2": [Keycode.LEFT_CONTROL, Keycode.V], + "\u0068": [Keycode.H], + "\u0048": [Keycode.SHIFT, Keycode.H], + "\u0040": [Keycode.SHIFT, Keycode.TWO], + "\u0030": [Keycode.ZERO], + "\u21b5": [Keycode.RETURN], + "\u21ab": [Keycode.SHIFT, Keycode.RETURN], + "\u002d": [Keycode.MINUS], + "\u21ff": [Keycode.PRINT_SCREEN], + "\u006f": [Keycode.O], + "\u004f": [Keycode.SHIFT, Keycode.O], + "\u0029": [Keycode.SHIFT, Keycode.ZERO], + "\u2193": [Keycode.DOWN_ARROW], + "\u006d": [Keycode.M], + "\u004d": [Keycode.SHIFT, Keycode.M], + "\u0028": [Keycode.SHIFT, Keycode.NINE], + "\u2192": [Keycode.RIGHT_ARROW], + "\u0070": [Keycode.P], + "\u0050": [Keycode.SHIFT, Keycode.P], + "\u005f": [Keycode.SHIFT, Keycode.MINUS], + "\u0066": [Keycode.F], + "\u0046": [Keycode.SHIFT, Keycode.F], + "\u0023": [Keycode.SHIFT, Keycode.THREE], + "\u2191": [Keycode.UP_ARROW], + "\u0077": [Keycode.W], + "\u0057": [Keycode.SHIFT, Keycode.W], + "\u007c": [Keycode.SHIFT, Keycode.BACKSLASH], + "\u006a": [Keycode.J], + "\u004a": [Keycode.SHIFT, Keycode.J], + "\u0025": [Keycode.SHIFT, Keycode.FIVE], + "\u0071": [Keycode.Q], + "\u0051": [Keycode.SHIFT, Keycode.Q], + "\u003f": [Keycode.SHIFT, Keycode.FORWARD_SLASH], + "\u0079": [Keycode.Y], + "\u0059": [Keycode.SHIFT, Keycode.Y], + "\u0024": [Keycode.SHIFT, Keycode.FOUR], + "\u2190": [Keycode.LEFT_ARROW], + "\u0062": [Keycode.B], + "\u0042": [Keycode.SHIFT, Keycode.B], + "\u007d": [Keycode.SHIFT, Keycode.RIGHT_BRACKET], + "\u006b": [Keycode.K], + "\u004b": [Keycode.SHIFT, Keycode.K], + "\u007b": [Keycode.SHIFT, Keycode.LEFT_BRACKET], + "\u0067": [Keycode.G], + "\u0047": [Keycode.SHIFT, Keycode.G], + "\u0021": [Keycode.SHIFT, Keycode.ONE], + "\u0073": [Keycode.S], + "\u0053": [Keycode.SHIFT, Keycode.S], + "\u005e": [Keycode.SHIFT, Keycode.SIX], + "\u21e4": [Keycode.HOME], + "\u0076": [Keycode.V], + "\u0056": [Keycode.SHIFT, Keycode.V], + "\u005d": [Keycode.RIGHT_BRACKET], + "\u21e5": [Keycode.END], + "\u006e": [Keycode.N], + "\u004e": [Keycode.SHIFT, Keycode.N], + "\u005b": [Keycode.LEFT_BRACKET], + "\uebcc": [Keycode.LEFT_CONTROL, Keycode.C], + "\u0074": [Keycode.T], + "\u0054": [Keycode.SHIFT, Keycode.T], + "\u0026": [Keycode.SHIFT, Keycode.SEVEN], + "\uf31a": [Keycode.APPLICATION], + } +except: + pass + characters = [ [ @@ -6,7 +126,7 @@ characters = [ [ [ [None, None, None, None], #00000 - ["\u2423", "\u002e", "\u003c", "\u0031"], #00001 [SPACE, FULLSTOP, LESS THAN, 1] + ["\ue31e", "\u002e", "\u003c", "\u0031"], #00001 [SPACE, FULLSTOP, LESS THAN, 1] ], [ ["\u21b9", "\u002c", None, "\u0032"], #00010 [TAB, COMMA, None, 2] @@ -15,11 +135,11 @@ characters = [ ], [ [ - ["\u232b", "\u003a", None, "\u0033"], #00100 [BACKSPACE, COLON, None, 3] + ["\u21dc", "\u003a", None, "\u0033"], #00100 [BACKSPACE, COLON, None, 3] ["\u0061", "\u0041", "\u002b", "\u0036"], #00101 [a, A, PLUS, 6] ], [ - ["\u0072", "\u0052", "\u002f", "\u1f50e"], #00110 [r, R, SLASH, CTRL+F] + ["\u0072", "\u0052", "\u002f", "\uea6d"], #00110 [r, R, SLASH, CTRL+F] ["\u0075", "\u0055", "\u0027", "\u0038"], #00111 [u, U, APOSTROPHE, 8] ], ], @@ -27,21 +147,21 @@ characters = [ [ [ [ - ["\u238b", "\u003b", None, "\u0034"], #01000 [ESCAPE, SEMICOLON, None, 4] + ["\u21af", "\u003b", None, "\u0034"], #01000 [ESCAPE, SEMICOLON, None, 4] ["\u0069", "\u0049", "\u002a", "\u0037"], #01001 [i, I, ASTERISK, 7] ], [ - ["\u0063", "\u0043", "\u005c", "\u261d"], #01010 [c, C, BACKSLASH, CTRL+A] + ["\u0063", "\u0043", "\u005c", "\u2229"], #01010 [c, C, BACKSLASH, CTRL+A] ["\u0078", "\u0058", "\u0022", "\u0039"], #01011 [x, X, DOUBLE QUOTES, 9] ], ], [ [ - ["\u006c", "\u004c", "\u007e", "\u2190\u2318"], #01100 [l, L, TILDE, SUPER LEFT] - ["\u007a", "\u005a", "\u003e", "\u2192\u2318"], #01101 [z, Z, GREATER THAN, SUPER RIGHT] + ["\u006c", "\u004c", "\u007e", "\u21da"], #01100 [l, L, TILDE, SUPER LEFT] + ["\u007a", "\u005a", "\u003e", "\u21db"], #01101 [z, Z, GREATER THAN, SUPER RIGHT] ], [ - ["\u0064", "\u0044", "\u0060", "\u29c8"], #01110 [d, D, TICK, PASTE] + ["\u0064", "\u0044", "\u0060", "\uebd2"], #01110 [d, D, TICK, CTRL+V] ["\u0068", "\u0048", "\u0040", "\u0030"], #01111 [h, H, AT, 0] ], ], @@ -51,7 +171,7 @@ characters = [ [ [ [ - ["\u23ce", "\u21e7\u23ce", "\u002d", "\u2399"], #10000 [RETURN, SHIFT RETURN, MINUS, PRINT SCREEN] + ["\u21b5", "\u21ab", "\u002d", "\u21ff"], #10000 [RETURN, SHIFT RETURN, MINUS, PRINT SCREEN] ["\u006f", "\u004f", "\u0029", "\u2193"], #10001 [o, O, CLOSE BRACKET, DOWN] ], [ @@ -73,7 +193,7 @@ characters = [ [ [ [ - ["\u0079", "\u0059", "\u0024", "\u2318"], #11000 [y, Y, DOLLAR, LEFT] + ["\u0079", "\u0059", "\u0024", "\u2190"], #11000 [y, Y, DOLLAR, LEFT] ["\u0062", "\u0042", "\u007d", None], #11001 [b, B, CLOSE CURLY BRACKET, None] ], [ @@ -87,132 +207,15 @@ characters = [ ["\u0076", "\u0056", "\u005d", "\u21e5"], #11101 [v, V, CLOSE SQUARE BRACKET, END] ], [ - ["\u006e", "\u004e", "\u005b", "\u29c9"], #11110 [n, N, OPEN SQUARE BRACKET, CTRL+C] - ["\u0074", "\u0054", "\u0026", "\u2318"], #11111 [t, T, AMPERSAND, SUPER] + ["\u006e", "\u004e", "\u005b", "\uebcc"], #11110 [n, N, OPEN SQUARE BRACKET, CTRL+C] + ["\u0074", "\u0054", "\u0026", "\uf31a"], #11111 [t, T, AMPERSAND, SUPER] ], ], ], ], ] -keycodes = { - "\u2423": [Keycode.SPACEBAR], - "\u002e": [Keycode.PERIOD], - "\u003c": [Keycode.SHIFT, Keycode.COMMA], - "\u0031": [Keycode.ONE], - "\u21b9": [Keycode.TAB], - "\u002c": [Keycode.COMMA], - "\u0032": [Keycode.TWO], - "\u0065": [Keycode.E], - "\u0045": [Keycode.SHIFT, Keycode.E], - "\u0045": [Keycode.EQUALS], - "\u0035": [Keycode.FIVE], - "\u232b": [Keycode.BACKSPACE], - "\u003a": [Keycode.SHIFT, Keycode.SEMICOLON], - "\u0033": [Keycode.THREE], - "\u0061": [Keycode.A], - "\u0041": [Keycode.SHIFT, Keycode.A], - "\u002b": [Keycode.SHIFT, Keycode.EQUALS], - "\u0036": [Keycode.SIX], - "\u0072": [Keycode.R], - "\u0052": [Keycode.SHIFT, Keycode.R], - "\u002f": [Keycode.FORWARD_SLASH], - "\u1f50e": [Keycode.LEFT_CONTROL, Keycode.F], - "\u0075": [Keycode.U], - "\u0055": [Keycode.SHIFT, Keycode.U], - "\u0027": [Keycode.QUOTE], - "\u0038": [Keycode.EIGHT], - "\u238b": [Keycode.ESCAPE], - "\u003b": [Keycode.SEMICOLON], - "\u0034": [Keycode.FOUR], - "\u0069": [Keycode.I], - "\u0049": [Keycode.SHIFT, Keycode.I], - "\u002a": [Keycode.SHIFT, Keycode.EIGHT], - "\u0037": [Keycode.SEVEN], - "\u0063": [Keycode.C], - "\u0043": [Keycode.SHIFT, Keycode.C], - "\u005c": [Keycode.BACKSLASH], - "\u261d": [Keycode.LEFT_CONTROL, Keycode.A], - "\u0078": [Keycode.X], - "\u0058": [Keycode.SHIFT, Keycode.X], - "\u0022": [Keycode.SHIFT, Keycode.QUOTE], - "\u0039": [Keycode.NINE], - "\u006c": [Keycode.L], - "\u004c": [Keycode.SHIFT, Keycode.L], - "\u007e": [Keycode.SHIFT, Keycode.GRAVE_ACCENT], - "\u2190\u2318": [Keycode.APPLICATION, Keycode.LEFT_ARROW], - "\u007a": [Keycode.Z], - "\u005a": [Keycode.SHIFT, Keycode.Z], - "\u003e": [Keycode.SHIFT, Keycode.PERIOD], - "\u2192\u2318": [Keycode.APPLICATION, Keycode.RIGHT_ARROW], - "\u0064": [Keycode.D], - "\u0044": [Keycode.SHIFT, Keycode.D], - "\u0060": [Keycode.GRAVE_ACCENT], - "\u29c8": [Keycode.LEFT_CONTROL, Keycode.V], - "\u0068": [Keycode.H], - "\u0048": [Keycode.SHIFT, Keycode.H], - "\u0040": [Keycode.SHIFT, Keycode.TWO], - "\u0030": [Keycode.ZERO], - "\u23ce": [Keycode.RETURN], - "\u21e7\u23ce": [Keycode.SHIFT, Keycode.RETURN], - "\u002d": [Keycode.MINUS], - "\u2399": [Keycode.PRINT_SCREEN], - "\u006f": [Keycode.O], - "\u004f": [Keycode.SHIFT, Keycode.O], - "\u0029": [Keycode.SHIFT, Keycode.ZERO], - "\u2193": [Keycode.DOWN_ARROW], - "\u006d": [Keycode.M], - "\u004d": [Keycode.SHIFT, Keycode.M], - "\u0028": [Keycode.SHIFT, Keycode.NINE], - "\u2192": [Keycode.RIGHT_ARROW], - "\u0070": [Keycode.P], - "\u0050": [Keycode.SHIFT, Keycode.P], - "\u005f": [Keycode.SHIFT, Keycode.MINUS], - "\u0066": [Keycode.F], - "\u0046": [Keycode.SHIFT, Keycode.F], - "\u0023": [Keycode.SHIFT, Keycode.THREE], - "\u2191": [Keycode.UP_ARROW], - "\u0077": [Keycode.W], - "\u0057": [Keycode.SHIFT, Keycode.W], - "\u007c": [Keycode.SHIFT, Keycode.BACKSLASH], - "\u006a": [Keycode.J], - "\u004a": [Keycode.SHIFT, Keycode.J], - "\u0025": [Keycode.SHIFT, Keycode.FIVE], - "\u0071": [Keycode.Q], - "\u0051": [Keycode.SHIFT, Keycode.Q], - "\u003f": [Keycode.SHIFT, Keycode.FORWARD_SLASH], - "\u0079": [Keycode.Y], - "\u0059": [Keycode.SHIFT, Keycode.Y], - "\u0024": [Keycode.SHIFT, Keycode.FOUR], - "\u2318": [Keycode.LEFT_ARROW], - "\u0062": [Keycode.B], - "\u0042": [Keycode.SHIFT, Keycode.B], - "\u007d": [Keycode.SHIFT, Keycode.RIGHT_BRACKET], - "\u006b": [Keycode.K], - "\u004b": [Keycode.SHIFT, Keycode.K], - "\u007b": [Keycode.SHIFT, Keycode.LEFT_BRACKET], - "\u0067": [Keycode.G], - "\u0047": [Keycode.SHIFT, Keycode.G], - "\u0021": [Keycode.SHIFT, Keycode.ONE], - "\u0073": [Keycode.S], - "\u0053": [Keycode.SHIFT, Keycode.S], - "\u005e": [Keycode.SHIFT, Keycode.SIX], - "\u21e4": [Keycode.HOME], - "\u0076": [Keycode.V], - "\u0056": [Keycode.SHIFT, Keycode.V], - "\u005d": [Keycode.RIGHT_BRACKET], - "\u21e5": [Keycode.END], - "\u006e": [Keycode.N], - "\u004e": [Keycode.SHIFT, Keycode.N], - "\u005b": [Keycode.LEFT_BRACKET], - "\u29c9": [Keycode.LEFT_CONTROL, Keycode.C], - "\u0074": [Keycode.T], - "\u0054": [Keycode.SHIFT, Keycode.T], - "\u0026": [Keycode.SHIFT, Keycode.SEVEN], - "\u2318": [Keycode.APPLICATION], -} +extra_characters = ["\u00e9", "\u00e7"] def get_character_set(): - return sorted(list(set(sum([list(a) for a in sum(sum(sum(sum(sum(characters, []), []), []), []), []) if a is not None], [])))) - -missing = ["-", "_"] + return sorted(list(set(sum([list(a) for a in sum(sum(sum(sum(sum(characters, []), []), []), []), []) if a is not None], []) + extra_characters))) diff --git a/code.py b/code.py index 47605bc..b4d6c1d 100644 --- a/code.py +++ b/code.py @@ -15,17 +15,16 @@ from adafruit_hid.keyboard import Keyboard kbd = Keyboard(usb_hid.devices) - font = bitmap_font.load_font("fonts/VictorMonoNerdFont-SemiBoldItalic-32.pcf") displayio.release_displays() mode_labels = [ - ["Letters", "Words", "Predictive"], - ["Lettres", "Mots", "Predictif"] + ["Letters", "Shortcuts", "Words", "Predictive"], + ["Lettres", "Raccourcis", "Mots", "Prédictif"] ] -language_labels = ["English", "Francais"] -backlight_labels = ["Backlight", "Retroeclairage"] +language_labels = ["English", "Français"] +backlight_labels = ["Backlight", "Rétroéclairage"] tft_clk = board.GP14 tft_mosi= board.GP15 @@ -61,164 +60,117 @@ main_display = displayio.Group() display.root_group = main_display label_position_radius = 90 +circle_radius = 16 -top_text = label.Label( - font, - text=" "*10, - color=0xffffff, - anchor_point=(0.5, 0.5), - anchored_position=(0, 0) -) -top = displayio.Group(scale=1) -top.x, top.y = 120, 50 -top.append(top_text) -main_display.append(top) +def create_settings_text(y): + text = label.Label( + font, + text="", + color=0xffffff, + anchor_point=(0.5, 0.5), + anchored_position=(0, 0) + ) + text_group = displayio.Group(scale=1) + text_group.x = 120 + text_group.y = y + text_group.append(text) + main_display.append(text_group) + return text -middle_text = label.Label( - font, - text=" "*8, - color=0xffffff, - anchor_point=(0.5, 0.5), - anchored_position=(0, 0) -) -middle = displayio.Group(scale=1) -middle.x, middle.y = 120, 110 -middle.append(middle_text) -main_display.append(middle) +top_text = create_settings_text(50) +middle_text = create_settings_text(110) +bottom_text = create_settings_text(170) -bottom_text = label.Label( - font, - text=" "*14, - color=0xffffff, - anchor_point=(0.5, 0.5), - anchored_position=(0, 0) -) -bottom = displayio.Group(scale=1) -bottom.x, bottom.y = 120, 170 -bottom.append(bottom_text) -main_display.append(bottom) +def calculate_text_position(key_angle, label_position_radius=label_position_radius): + x = int(120 + label_position_radius * math.sin(key_angle)) + y = int(120 - label_position_radius * math.cos(key_angle)) + return x, y + +def create_text_area_angle(key_angle, text_colour=0xffffff, label_position_radius=label_position_radius): + return create_text_area(*calculate_text_position(key_angle, text_colour=text_colour, label_position_radius=label_position_radius)) -key0_text = label.Label( - font, - text = " ", - color=0xffffff, - anchor_point=(0.5, 0.5), - anchored_position=(0, 0) -) -key0_colour = (219, 97, 71) -key0_palette = displayio.Palette(1) -key0_palette[0] = (0, 0, 0) -key0_display = displayio.Group(scale=1) -key0_angle = - 2. * math.pi / 3. -key0_display.x = int(120 + label_position_radius * math.sin(key0_angle)) -key0_display.y = int(120 - label_position_radius * math.cos(key0_angle)) -key0_display.append(key0_text) -main_display.append(Circle(pixel_shader=key0_palette, radius=16, x=key0_display.x, y=key0_display.y)) -main_display.append(key0_display) +def create_text_area(x, y, text_colour=0xffffff): + key_display = displayio.Group(scale=1) + key_display.x = x + key_display.y = y + key_text = label.Label( + font, + text = " ", + color=text_colour, + anchor_point=(0.5, 0.5), + anchored_position=(0, 0) + ) + key_display.append(key_text) + main_display.append(key_display) + return key_text -key1_text = label.Label( - font, - text = " ", - color=0xffffff, - anchor_point=(0.5, 0.5), - anchored_position=(0, 0) -) -key1_colour = (100, 150, 40) -key1_palette = displayio.Palette(1) -key1_palette[0] = (0, 0, 0) -key1_display = displayio.Group(scale=1) -key1_angle = - math.pi / 3. -key1_display.x = int(120 + label_position_radius * math.sin(key1_angle)) -key1_display.y = int(120 - label_position_radius * math.cos(key1_angle)) -key1_display.append(key1_text) -main_display.append(Circle(pixel_shader=key1_palette, radius=16, x=key1_display.x, y=key1_display.y)) -main_display.append(key1_display) +def create_circle(x, y, key_colour, circle_radius=circle_radius): + key_palette = displayio.Palette(1) + key_circle = Circle(pixel_shader=key_palette, radius=circle_radius, x=x, y=y) + main_display.append(key_circle) + return key_palette, key_circle + +def create_key_display(key_angle, key_colour, text_colour=0xffffff, circle_radius=circle_radius, label_position_radius=label_position_radius): + x, y = calculate_text_position(key_angle, label_position_radius=label_position_radius) + key_palette, key_circle = create_circle(x, y, key_colour, circle_radius=circle_radius) + key_text = create_text_area(x, y, text_colour=text_colour) + return key_text, key_palette, key_colour, key_circle -key2_text = label.Label( - font, - text = " ", - color=0xffffff, - anchor_point=(0.5, 0.5), - anchored_position=(0, 0) -) -key2_colour = (40, 150, 100) -key2_palette = displayio.Palette(1) -key2_palette[0] = (0, 0, 0) -key2_display = displayio.Group(scale=1) -key2_angle = 0 -key2_display.x = int(120 + label_position_radius * math.sin(key2_angle)) -key2_display.y = int(120 - label_position_radius * math.cos(key2_angle)) -key2_display.append(key2_text) -main_display.append(Circle(pixel_shader=key2_palette, radius=16, x=key2_display.x, y=key2_display.y)) -main_display.append(key2_display) - -key3_text = label.Label( - font, - text = " ", - color=0xffffff, - anchor_point=(0.5, 0.5), - anchored_position=(0, 0) -) -key3_colour = (100, 40, 150) -key3_palette = displayio.Palette(1) -key3_palette[0] = (0, 0, 0) -key3_display = displayio.Group(scale=1) -key3_angle = math.pi / 3. -key3_display.x = int(120 + label_position_radius * math.sin(key3_angle)) -key3_display.y = int(120 - label_position_radius * math.cos(key3_angle)) -key3_display.append(key3_text) -main_display.append(Circle(pixel_shader=key3_palette, radius=16, x=key3_display.x, y=key3_display.y)) -main_display.append(key3_display) - -key4_text = label.Label( - font, - text = " ", - color=0xffffff, - anchor_point=(0.5, 0.5), - anchored_position=(0, 0) -) -key4_colour = (40, 40, 150) -key4_palette = displayio.Palette(1) -key4_palette[0] = (0, 0, 0) -key4_display = displayio.Group(scale=1) -key4_angle = 2. * math.pi / 3. -key4_display.x = int(120 + label_position_radius * math.sin(key4_angle)) -key4_display.y = int(120 - label_position_radius * math.cos(key4_angle)) -key4_display.append(key4_text) -main_display.append(Circle(pixel_shader=key4_palette, radius=16, x=key4_display.x, y=key4_display.y)) -main_display.append(key4_display) +key0_text, key0_palette, key0_colour, key0_circle = create_key_display(-2.*math.pi/3., (219, 97, 71)) +key1_text, key1_palette, key1_colour, key1_circle = create_key_display(-math.pi/3., (100, 150, 40)) +key2_text, key2_palette, key2_colour, key2_circle = create_key_display(0., (40, 150, 100)) +key3_text, key3_palette, key3_colour, key3_circle = create_key_display(math.pi/3., (100, 40, 150)) +key4_text, key4_palette, key4_colour, key4_circle = create_key_display(2.*math.pi/3., (40, 40, 150)) +selected_circle_radius=32 +selected_text, selected_palette, selected_colour, selected_circle = create_key_display(math.pi, (255, 255, 255), text_colour=0x000000, circle_radius=selected_circle_radius, label_position_radius=60) key5_colour = (0, 100, 30) key5_palette = displayio.Palette(1) -key5_palette[0] = (0, 0, 0) -main_display.append(Circle(pixel_shader=key5_palette, radius=16, x=120-32, y=120)) +key5_circle = Circle(pixel_shader=key5_palette, radius=circle_radius, x=120-32, y=120) +main_display.append(key5_circle) key6_colour = (15, 100, 200) key6_palette = displayio.Palette(1) -key6_palette[0] = (0, 0, 0) -main_display.append(Circle(pixel_shader=key6_palette, radius=16, x=120+32, y=120)) +key6_circle = Circle(pixel_shader=key6_palette, radius=circle_radius, x=120+32, y=120) +main_display.append(key6_circle) def swap_to_settings_display(): + tft_bl.value = True key0_text.text = "" key1_text.text = "" key2_text.text = "" key3_text.text = "" key4_text.text = "" + selected_text = "" + key0_circle.radius = 0 + key1_circle.radius = 0 + key2_circle.radius = 0 + key3_circle.radius = 0 + key4_circle.radius = 0 + key5_circle.radius = 0 + key6_circle.radius = 0 + selected_circle.radius = 0 -def settings_display(mode, language, location): - print(mode, language, location, mode_labels[language][mode]) - display.refresh() +def settings_display(mode, language, backlight, location): top_text.text = mode_labels[language][mode] top_text.color = 0x1c4d2d if location == 0 else 0xffffff middle_text.text = language_labels[language] middle_text.color = 0x1c4d2d if location == 1 else 0xffffff bottom_text.text = backlight_labels[language] - bottom_text.color = 0x1c4d2d if location == 2 else 0xffffff + bottom_text.color = (0x1c4d2d if backlight else 0xff0000) if location == 2 else 0xffffff def swap_to_character_display(): top_text.text = "" middle_text.text = "" bottom_text.text = "" + key0_circle.radius = circle_radius + key1_circle.radius = circle_radius + key2_circle.radius = circle_radius + key3_circle.radius = circle_radius + key4_circle.radius = circle_radius + key5_circle.radius = circle_radius + key6_circle.radius = circle_radius + selected_circle.radius = selected_circle_radius def edit_character(pin, character, key_text, key_palette, colour): if not pin: @@ -230,14 +182,25 @@ def edit_character(pin, character, key_text, key_palette, colour): else: key_text.text = "" key_palette[0] = colour - + def character_display(pin0, pin1, pin2, pin3, pin4, selection): - display.refresh() edit_character(pin0, characters[1][pin1][pin2][pin3][pin4][selection], key0_text, key0_palette, key0_colour) edit_character(pin1, characters[pin0][1][pin2][pin3][pin4][selection], key1_text, key1_palette, key1_colour) edit_character(pin2, characters[pin0][pin1][1][pin3][pin4][selection], key2_text, key2_palette, key2_colour) edit_character(pin3, characters[pin0][pin1][pin2][1][pin4][selection], key3_text, key3_palette, key3_colour) edit_character(pin4, characters[pin0][pin1][pin2][pin3][1][selection], key4_text, key4_palette, key4_colour) + if any([pin0, pin1, pin2, pin3, pin4]): + character = characters[pin0][pin1][pin2][pin3][pin4][selection] + if character is None: + selected_palette[0] = (0, 0, 0) + selected_text.text = "" + else: + selected_text.text = character + selected_palette[0] = selected_colour + else: + selected_text.text = "" + selected_palette[0] = (0, 0, 0) + def mode_display(selection): if selection is 0: @@ -267,42 +230,82 @@ def toggle(_p, p, t): def update(_p, p): return [___p != __p for ___p, __p in zip(_p, p)] -def _get_time(p, t): +def get_time(p, t): return [_t+1 if _p else 0 for _p, _t in zip(p, t)] -def get_time(p, t, m, tm): - return _get_time(p, t), _get_time(m, tm) - def get_character(p, s): return characters[p[0]][p[1]][p[2]][p[3]][p[4]][s] - -def main(): + +def release_countdown(p, t, start=3): + return [max(_t-1, 0) if not _p else start for _p, _t in zip(p, t)] + +def main(rate=0.05, start=3): p = [False]*5 - #t = [0]*5 + t = [0]*5 m = [False]*2 - #tm = [0]*2 + tm = [0]*2 toggles = [False]*2 selection = 0 + settings = False + mode = 0 + language = 0 + backlight = True while True: _p, _m = poll() - #t, tm = get_time(_p, t, _m, tm) - u = any(update(_p, p)) - um, toggles = toggle(_m, m, toggles) + t = release_countdown(_p, t, start=start) + tm = get_time(_m, tm) - if um: - selection = toggles[0] + 2 * toggles[1] - mode_display(selection) + if all([_tm > 60 for _tm in tm]): + if not settings: + settings = True + toggles = [False] * 2 + swap_to_settings_display() + location = 0 + tm = [0]*2 + elif settings: + u = update(_m, m) + if u[0] and _m[0]: + location += 1 + if location > 2: + location = 0 + settings = not settings + if u[1] and _m[1]: + if location == 0: + mode += 1 + if mode > 3: + mode = 0 + elif location == 1: + language += 1 + if language > 1: + language = 0 + elif location == 2: + backlight = not backlight + if settings: + if any(u): + settings_display(mode, language, backlight, location) + else: + tft_bl.value = backlight + swap_to_character_display() + elif not settings: + u = any(update(_p, p)) + um, toggles = toggle(_m, m, toggles) + if um: + selection = toggles[0] + 2 * toggles[1] + if backlight: + mode_display(selection) - if u or um: - character_display(*_p, selection) + if u or um and backlight: + character_display(*_p, selection) - if u and not any(_p): - c = get_character(p, selection) - if c is not None: - kbd.send(*keycodes[c]) + if u and not any(_p): + pressed = [_t > 0 for _t in t] + if mode == 0: + c = get_character(pressed, selection) + if c is not None: + kbd.send(*keycodes[c]) p = _p m = _m - time.sleep(0.05) + time.sleep(rate) main() diff --git a/fonts/VictorMonoNerdFont-SemiBoldItalic-32.bdf b/fonts/VictorMonoNerdFont-SemiBoldItalic-32.bdf index 853eb36..eef4334 100644 --- a/fonts/VictorMonoNerdFont-SemiBoldItalic-32.bdf +++ b/fonts/VictorMonoNerdFont-SemiBoldItalic-32.bdf @@ -1,7 +1,7 @@ STARTFONT 2.1 FONT -FontForge-VictorMono NF SemiBold-Demi-I-Normal--32-240-96-96-M-170-ISO10646-1 SIZE 24 96 96 -FONTBOUNDINGBOX 28 35 -3 -6 +FONTBOUNDINGBOX 33 36 -3 -7 COMMENT "Generated by fontforge, http://fontforge.sourceforge.net" COMMENT "Copyright (c) 2024 by Rune Bjrneras. All rights reserved." STARTPROPERTIES 40 @@ -43,10 +43,10 @@ SUBSCRIPT_X 0 SUBSCRIPT_Y 2 SUBSCRIPT_SIZE 19 FIGURE_WIDTH 17 -AVG_LOWERCASE_WIDTH 308 +AVG_LOWERCASE_WIDTH 307 AVG_UPPERCASE_WIDTH 308 ENDPROPERTIES -CHARS 103 +CHARS 116 STARTCHAR exclam ENCODING 33 SWIDTH 545 0 @@ -2827,6 +2827,72 @@ E1FF00 E0FE00 007C00 ENDCHAR +STARTCHAR ccedilla +ENCODING 231 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 16 26 1 -7 +BITMAP +01F8 +03FE +0FFE +0E0F +1C06 +3800 +3800 +7000 +7000 +6000 +E000 +E000 +E000 +E000 +E018 +F07C +FFF8 +7FE0 +3FC0 +0E00 +0F00 +0F00 +0380 +3F00 +7F00 +3E00 +ENDCHAR +STARTCHAR eacute +ENCODING 233 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 17 26 0 0 +BITMAP +000200 +000700 +000F80 +003E00 +007800 +003000 +000000 +000000 +00FE00 +03FE00 +07CF00 +0F0700 +0E0700 +1C0700 +1C0E00 +1C1E00 +187C00 +3FF800 +7FE000 +FF0000 +F80000 +780600 +380E00 +1E7E00 +1FF800 +0FF000 +ENDCHAR STARTCHAR arrowleft ENCODING 8592 SWIDTH 545 0 @@ -2929,6 +2995,83 @@ F3BC 0F00 0600 ENDCHAR +STARTCHAR uni21AB +ENCODING 8619 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 19 15 0 4 +BITMAP +008380 +01CFC0 +03DFE0 +079CE0 +0F1CE0 +1C39E0 +7FFFC0 +FFFF80 +7FFF00 +383800 +3C7000 +1E7000 +0F7000 +067000 +04E000 +ENDCHAR +STARTCHAR uni21AF +ENCODING 8623 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 15 23 1 0 +BITMAP +0380 +0700 +0700 +0E00 +0E00 +1C00 +1C1E +3BFC +3FFC +7FB8 +7038 +8070 +0070 +20E0 +70E0 +71C8 +39DC +3FBE +1FF8 +0FF0 +0FC0 +0780 +0200 +ENDCHAR +STARTCHAR carriagereturn +ENCODING 8629 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 20 18 0 4 +BITMAP +000070 +000070 +000070 +0000E0 +00C0E0 +01E0E0 +0780E0 +0F00E0 +1E01C0 +3FFFC0 +FFFFC0 +7FFFC0 +3C0000 +1E0000 +0E0000 +0F0000 +060000 +020000 +ENDCHAR STARTCHAR uni21B9 ENCODING 8633 SWIDTH 545 0 @@ -2960,6 +3103,70 @@ FFFD80 03C380 010000 ENDCHAR +STARTCHAR uni21DA +ENCODING 8666 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 18 14 1 5 +BITMAP +018000 +038000 +07FFC0 +0FFFC0 +1C0000 +780000 +FFFF80 +FFFF80 +780000 +380000 +3FFF00 +1FFF00 +0E0000 +040000 +ENDCHAR +STARTCHAR uni21DB +ENCODING 8667 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 19 14 -1 5 +BITMAP +000400 +000E00 +3FFF00 +3FFF00 +000780 +0003C0 +3FFFE0 +7FFFC0 +000780 +000F00 +7FFE00 +FFF800 +007000 +002000 +ENDCHAR +STARTCHAR uni21DC +ENCODING 8668 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 18 15 0 4 +BITMAP +008000 +018000 +03C000 +078000 +0E4900 +3CD980 +7FFF80 +FFFFC0 +7FFFC0 +386D80 +3C4800 +1E0000 +0F0000 +060000 +040000 +ENDCHAR STARTCHAR uni21E4 ENCODING 8676 SWIDTH 545 0 @@ -3004,50 +3211,217 @@ FFFDC0 030000 020000 ENDCHAR -STARTCHAR uni21E7 -ENCODING 8679 +STARTCHAR uni21FF +ENCODING 8703 SWIDTH 545 0 DWIDTH 17 0 -BBX 18 18 0 3 +BBX 21 17 -1 3 BITMAP -001000 -003000 -007800 -00FC00 -03FC00 -079E00 -0F0E00 -1E0F00 +002400 +004600 +00C700 +03C700 +07C780 +0FCFC0 +3F8FE0 +7BFEF0 +E3FE78 +73FCF0 +7B9DC0 3F1F80 -7E1F80 -FE1FC0 -0E1C00 -0E3800 -0E3800 -1C3800 -1FF800 -1FF000 -1FF000 +1F1F00 +0F1E00 +073800 +023000 +022000 ENDCHAR -STARTCHAR uni25A2 -ENCODING 9634 +STARTCHAR intersection +ENCODING 8745 SWIDTH 545 0 DWIDTH 17 0 -BBX 15 14 1 4 +BBX 16 18 0 1 BITMAP -1FF8 -7FFC -7FFE -F00E -E00E -E00E -E00E -E00E -E00E -E00E -F00E -7FFE -7FFC -1FF8 +00F8 +03FE +07FE +0F0F +0E07 +1C07 +1C07 +1C07 +380E +380E +380E +380E +380E +701C +701C +701C +701C +F038 +ENDCHAR +STARTCHAR weather-windy +ENCODING 58142 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 25 9 0 7 +BITMAP +1FFFE000 +1FFFE000 +00000000 +00000000 +FFFF7F80 +FFFF3F00 +00000000 +07FFF800 +07FFF800 +ENDCHAR +STARTCHAR cod-search +ENCODING 60013 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 30 32 0 -4 +BITMAP +0001FE00 +0007FF80 +000E01C0 +001C00E0 +00300070 +00700038 +00600018 +00E00018 +00C0000C +00C0000C +00C0000C +00C0000C +00C0000C +00C0001C +00600018 +00600018 +00300030 +00380070 +003C00E0 +007F87C0 +00E3FF00 +00C07800 +01800000 +03800000 +07000000 +0E000000 +1C000000 +38000000 +30000000 +60000000 +C0000000 +40000000 +ENDCHAR +STARTCHAR cod-copy +ENCODING 60364 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 24 28 0 -2 +BITMAP +7FFC00 +FFFE00 +C00000 +C00000 +C7FFC0 +CFFFE0 +CC0070 +CC0038 +CC001C +CC000E +CC0007 +CC0003 +CC0003 +CC0003 +CC0003 +CC0003 +CC0003 +CC0003 +CC0003 +CC0003 +CC0003 +CC0003 +4C0003 +4C0003 +0C0003 +0C0003 +07FFFE +03FFFC +ENDCHAR +STARTCHAR cod-layers +ENCODING 60370 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 25 28 0 -2 +BITMAP +001C0000 +007F0000 +00E78000 +03C1E000 +0700F000 +1E003C00 +3C001E00 +70000780 +E0000380 +F0000380 +78000F00 +1E003C00 +0F007800 +03C1E000 +81E3C080 +787F0F00 +1E3C3C00 +0F007800 +03C1E000 +81E38080 +787F0F00 +1E3C3C00 +0F007800 +03C1E000 +01E3C000 +007F0000 +003C0000 +00080000 +ENDCHAR +STARTCHAR linux-tux +ENCODING 62234 +SWIDTH 545 0 +DWIDTH 17 0 +BBX 28 32 0 -4 +BITMAP +001F0000 +003FC000 +003FC000 +007FE000 +005CE000 +006AE000 +007FE000 +0061E000 +0041E000 +006FE000 +00567000 +00487000 +00803800 +01803C00 +03803E00 +03001E00 +03001B00 +06000F00 +06000F00 +0E000B00 +0E000F00 +0A003F00 +71002F80 +80802E80 +80C02040 +80602020 +80404010 +8021C020 +801FC0C0 +7020C100 +0E204600 +01C03800 ENDCHAR ENDFONT diff --git a/fonts/VictorMonoNerdFont-SemiBoldItalic-32.pcf b/fonts/VictorMonoNerdFont-SemiBoldItalic-32.pcf index 693266faa031127a27a0da5cb8b1a534fe2d9782..4610d926bedd124357b09da66cac3dd1c2f7c65b 100644 GIT binary patch delta 2104 zcmai#-)~c87{|Zw>DU=K+F=Y%EN!R!4jUCr?6hGW;xZF1M1yicaJ8$fW9v%SWhE5P zJ2Bz~2|b)ek)VHoSC|@uUYJ8df-z0T9hjgVvP97fDKRlz%pJe)IfaSAc-qhV^ZE5Y z@6*%S8{*=RdNuyW9u4Sd1=;`v$--vf04K5LTz)CAe>;$B&aVsL`Yi$3obPV|F8szt zewF?(X}c{xKeR=JDrZMBIAR$(o4>*lg;R%4lNb+j%MrP}J& zYr-&1>!dWzb8_a4d8Ts0G(VCvCPy=;Ig*xXRc5McG;4lXF=oxPa)xWij5BN`n~L8k zIquFLmsQg;mYwp@Te2z5q5-c;hUvhO#lrZh8!OWmE0y^37fC zbP-qtLL_J{?@ESkKcEopD*_VeV{ee1)}2Q?_cEaS54DuGK1X4liX^Py9fTu5XNAi2 zU^swFB@R*MH7B?qc?XDcA=Ie-xn+xZ9w#KkoQ=Rw4)pU5LSYBtUI&J2!*wNl>Lq|= zfx09_T1kszMT2V$W{ZIBq<7swIjrS}G9zPaa`W^9Hp0Tv*irh?Zy zfbBpy3`a5?IEV-veO@@W7gmxQbgL?Eg_kTI4VtxfYsL`LPn}Nj5D9aqOw>sfYRm{} zj-e1$v@OJII8o~gFSdYk>u187^InWa+Pceq6>*G6);^)A64`>_%S_exl5r}Be!Pis zi6m=8#jNgDh1+5s-&!$PAQ&K5Xo2WgBtpE4zS9nlEjBQ}SjOZ+1IIq$T2vw$r2$&e zc?2y^V$@|cUM(=P5Ut;@1)a4()SdsE0@I=}?hP6=7sBxO~lL_)VOK_0L1hbc92s;^iggl8>hM@@J5fb9Bqz^~1O-k7#r5#Jj zp;%0&QXO&GWyfUHwhOUK2*w5=?1YzotnuC(e=yk(Jhk_`Pl;9>bX~kz+uM`gQ5))c zPH*ECrSTRr*500;2!?$XWS3O&c603zMN*v@K@Ou!+iHZv7~|%44dd)08uGQKgIAT8 zhc#bq&@e%%_(}~0_8(|L99go8BG-Oz*D%TcJF&vAEbxtAyD(A}mOYZPQlmQmeFjGj zv9HGJ{+e7Sb#jf|B)^h7{)`=_4@tp{$}44-~FOx zkFTB{7(gyx$`&WHnNn^dkLhf>G?FcLPv`Q(N0FHr?w-u1i%E~x z5Q4tB#wcDR!G!7kK?HHH?)_rWL^I;pi?CV=b*fs(P_b}Gif&W*gY=c1^7tdisn{ilR%w!! zHSIjJ?XsiBZKXxodHSF<#VBj(hFnFrU|Q0X2hvMq6KKnk1+ot8J4EgPi3D%_~#aycn)R?=x3p%FH=(9RMN}u<@cS?@Ky_=a3w>3MLF>w)>kjJR% z?imT-GSwLqS5WXgTy^8wm!SZzaq~%pMRX1Ro9gna%t&QnO$;ek7uUp+^lOf5iM%E6 z$w#t6evl2aU7c8$7g8DeDedP@9>u-eH!|IWSzq`1x^GAK4rFv6za3w}&T6JK$S$)7 F{sQ*um%#u4 diff --git a/fonts/flake.nix b/fonts/flake.nix index 0cfc97c..ea5572f 100644 --- a/fonts/flake.nix +++ b/fonts/flake.nix @@ -9,7 +9,7 @@ { devShell = pkgs.mkShell { buildInputs = with pkgs; [ - ( python3.withPackages ( ps: [ ps.fontforge ] ) ) + ( python3.withPackages ( ps: [ ps.fontforge ps.ipython ] ) ) ]; }; }