From 4b033857b17251f05ce4c418a3d142c8eef2a870 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 9 Feb 2019 13:12:04 -0800 Subject: [PATCH 01/32] Initial RGB with test animation running automatically --- kmk/firmware.py | 39 ++++++++++++++- kmk/rgb.py | 58 ++++++++++++++++++++++ user_keymaps/kdb424/nyquist_converter.py | 63 ++++++++++++++++++++---- 3 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 kmk/rgb.py diff --git a/kmk/firmware.py b/kmk/firmware.py index 907005b..af182ed 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -49,6 +49,16 @@ import kmk.internal_state # isort:skip # Thanks for sticking around. Now let's do real work, starting below from kmk.util import intify_coordinate as ic +import busio +import gc + +import supervisor +from kmk.consts import LeaderMode, UnicodeMode +from kmk.hid import USB_HID +from kmk.internal_state import InternalState +from kmk.keys import KC +from kmk.matrix import MatrixScanner +from kmk import rgb class Firmware: @@ -80,6 +90,10 @@ class Firmware: uart = None uart_flip = True uart_pin = None + pixel_pin = None + num_pixels = None + pixels = None + pixel_state = 0, 0 def __init__(self): # Attempt to sanely guess a coord_mapping if one is not provided @@ -174,6 +188,14 @@ class Firmware: else: return busio.UART(tx=pin, rx=None, timeout=timeout) + def init_pixels(self, pixel_pin, num_pixels=0): + try: + import neopixel + return neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False) + except ImportError as e: + print(e) + return None + def go(self): assert self.keymap, 'must define a keymap with at least one row' assert self.row_pins, 'no GPIO pins defined for matrix rows' @@ -194,7 +216,10 @@ class Firmware: if self.uart_pin is not None: self.uart = self.init_uart(self.uart_pin) - self.matrix = self.matrix_scanner( + if self.pixel_pin is not None: + self.pixels = self.init_pixels(self.pixel_pin, self.num_pixels) + + self.matrix = MatrixScanner( cols=self.col_pins, rows=self.row_pins, diode_orientation=self.diode_orientation, @@ -214,6 +239,7 @@ class Firmware: if self.debug_enabled: print("Firin' lazers. Keyboard is booted.") + while True: state_changed = False @@ -248,3 +274,14 @@ class Firmware: if self.debug_enabled and state_changed: print('New State: {}'.format(self._state._to_dict())) + + gc.collect() + test = rgb.color_chase(self.pixels, + self.num_pixels, + color=(255,0,0), + color2=(0,255,255), + animation_state=self.pixel_state[0]) + + if test is not None: + # Debugging some strange errors with NoneType + self.pixel_state = test diff --git a/kmk/rgb.py b/kmk/rgb.py new file mode 100644 index 0000000..c7bf5b1 --- /dev/null +++ b/kmk/rgb.py @@ -0,0 +1,58 @@ +OFF = (0, 0, 0) +RED = (255, 0, 0) +YELLOW = (255, 150, 0) +GREEN = (0, 255, 0) +CYAN = (0, 255, 255) +BLUE = (0, 0, 255, 0) +PURPLE = (180, 0, 255) + + +def wheel(pos): + # Input a value 0 to 255 to get a color value. + # The colours are a transition r - g - b - back to r. + if pos < 0 or pos > 255: + return (0, 0, 0) + if pos < 85: + return (255 - pos * 3, pos * 3, 0) + if pos < 170: + pos -= 85 + return (0, 255 - pos * 3, pos * 3) + pos -= 170 + return (pos * 3, 0, 255 - pos * 3) + + +def color_chase(pixels, num_pixels, color, color2=OFF, speed=100, animation_state=0): + if animation_state not in range(num_pixels): + color = color2 + pixels[int(animation_state - num_pixels)] = color + + else: + pixels[animation_state] = color + + pixels.show() + animation_state += 1 + + if animation_state >= num_pixels * 2: + animation_state = 0 + + return animation_state, 0 + + +def rainbow_cycle(pixels, num_pixels, speed=100, animation_state=0, color_state=0): + color_state += 1 + if color_state in range(255): + print(animation_state) + animation_state +=1 + if animation_state in range(num_pixels): + rc_index = (animation_state * 256 // num_pixels) + animation_state + print(pixels[animation_state]) + print(wheel(rc_index & 255)) + pixels[animation_state] = wheel(rc_index & 255) + else: + pixels.show() + return 0, color_state + else: + return animation_state, 0 + + + diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index ab77ffb..fcb9ffe 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -1,10 +1,11 @@ import board import busio +import neopixel from kmk.consts import DiodeOrientation, LeaderMode, UnicodeMode -from kmk.handlers.sequences import (compile_unicode_string_sequences, - simple_key_sequence) -from kmk.keys import KC +from kmk.handlers.layers import df_pressed +from kmk.handlers.sequences import (compile_unicode_string_sequences) +from kmk.keys import KC, layer_key_validator, make_argumented_key from kmk.mcus.circuitpython_samd51 import Firmware from kmk.pins import Pin as P @@ -27,6 +28,24 @@ keyboard.tap_time = 150 keyboard.leader_timeout = 2000 keyboard.debug_enabled = True +keyboard.pixel_pin = board.TX +keyboard.num_pixels = 12 +OFF = (0, 0, 0) +CYAN = (0, 255, 255) + +''' +pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False) + +RED = (255, 0, 0) +YELLOW = (255, 150, 0) +GREEN = (0, 255, 0) +BLUE = (0, 0, 255) +PURPLE = (180, 0, 255) + +pixels.fill(OFF) +pixels.show() +''' + emoticons = compile_unicode_string_sequences({ # Emoticons, but fancier 'ANGRY_TABLE_FLIP': r'(ノಠ痊ಠ)ノ彡┻━┻', @@ -49,7 +68,6 @@ keyboard.leader_dictionary = { 'f': emoticons.F, 'meh': emoticons.MEH, 'yay': emoticons.YAY, - 'gw': KC.DF(1), } _______ = KC.TRNS @@ -62,6 +80,33 @@ gw = 1 r1 = 2 r2 = 3 r3 = 4 + + +def base(*args, **kwargs): + keyboard.pixels.fill(OFF) + keyboard.pixels.show() + return df_pressed(*args, **kwargs) + + +def gaming(*args, **kwargs): + keyboard.pixels.fill(CYAN) + keyboard.pixels.show() + return df_pressed(*args, **kwargs) + +make_argumented_key( + validator=layer_key_validator, + names=('LAYER_GAMING',), + on_press=gaming, +) + +make_argumented_key( + validator=layer_key_validator, + names=('LAYER_BASE',), + on_press=base, +) +BASE = KC.LAYER_BASE(df) +GAMING = KC.LAYER_GAMING(gw) + # ---------------------- Keymap --------------------------------------------------------- keyboard.keymap = [ @@ -99,11 +144,11 @@ keyboard.keymap = [ ], [ # r3 - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.F10, KC.F11, KC.F12, KC.DEL], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], - [KC.DF(df), KC.DF(gw), _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], + [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.F10, KC.F11, KC.F12, KC.DEL], + [_______, _______, _______, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], + [_______, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], + [_______, _______, _______, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], + [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], ], ] From 7a58ac041ff3c23f0a74abc31678ea554ebe097a Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Tue, 19 Feb 2019 15:01:51 -0800 Subject: [PATCH 02/32] HSV functions added --- kmk/firmware.py | 2 + kmk/rgb.py | 117 ++++++++++++++++------- user_keymaps/kdb424/nyquist_converter.py | 115 ++++++++++++++++------ 3 files changed, 169 insertions(+), 65 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index af182ed..8bcdb82 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -276,6 +276,7 @@ class Firmware: print('New State: {}'.format(self._state._to_dict())) gc.collect() + ''' test = rgb.color_chase(self.pixels, self.num_pixels, color=(255,0,0), @@ -285,3 +286,4 @@ class Firmware: if test is not None: # Debugging some strange errors with NoneType self.pixel_state = test + ''' diff --git a/kmk/rgb.py b/kmk/rgb.py index c7bf5b1..3b719b8 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -1,27 +1,27 @@ -OFF = (0, 0, 0) -RED = (255, 0, 0) -YELLOW = (255, 150, 0) -GREEN = (0, 255, 0) -CYAN = (0, 255, 255) -BLUE = (0, 0, 255, 0) -PURPLE = (180, 0, 255) +COLORS = { + 'OFF': (0, 0, 0), + 'RED': (255, 0, 0), + 'GREEN': (0, 255, 0), + 'BLUE': (0, 0, 255, 0), + 'YELLOW': (255, 150, 0), + 'CYAN': (0, 255, 255), + 'PURPLE': (180, 0, 255), + 'WHITE': (255, 255, 255), +} -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) +def pixelinit(): + return { + 'h': 0, + 's': 255, + 'v': 255, + 'animation_mode': None, + 'speed': 0, + 'enable': True + } -def color_chase(pixels, num_pixels, color, color2=OFF, speed=100, animation_state=0): +def color_chase(pixels, num_pixels, color, color2=COLORS['OFF'], speed=100, animation_state=0): if animation_state not in range(num_pixels): color = color2 pixels[int(animation_state - num_pixels)] = color @@ -38,21 +38,70 @@ def color_chase(pixels, num_pixels, color, color2=OFF, speed=100, animation_stat return animation_state, 0 -def rainbow_cycle(pixels, num_pixels, speed=100, animation_state=0, color_state=0): - color_state += 1 - if color_state in range(255): - print(animation_state) - animation_state +=1 - if animation_state in range(num_pixels): - rc_index = (animation_state * 256 // num_pixels) + animation_state - print(pixels[animation_state]) - print(wheel(rc_index & 255)) - pixels[animation_state] = wheel(rc_index & 255) - else: - pixels.show() - return 0, color_state +def sethsv(hue, sat, val, pixels, index): + r = 0 + g = 0 + b = 0 + # TODO Actually pass this limit to allow overrides + RGBLIGHT_LIMIT_VAL = 255 + + if val > RGBLIGHT_LIMIT_VAL: + val=RGBLIGHT_LIMIT_VAL + + if sat == 0: + r = val + g = val + b = val + else: - return animation_state, 0 + base = ((255 - sat) * val) >> 8 + color = (val - base) * (hue % 60) / 60 + + x = hue / 60 + if x == 0: + r = val + g = base + color + b = base + elif x == 1: + r = val - color + g = val + b = base + elif x == 2: + r = base + g = val + b = base + color + elif x == 3: + r = base + g = val - color + b = val + elif x == 4: + r = base + color + g = base + b = val + elif x == 5: + r = val + g = base + b = val - color + + rgb = (r, g, b) + setrgb(rgb, pixels, index) +def setrgb(rgb, pixels, index): + pixels[index] = (rgb[0], rgb[1], rgb[2]) + + +def setrgbfill(rgb, pixels): + pixels.fill(rgb[0], rgb[1], rgb[2]) + + +def increasehue(hue, step): + return hue + step % 360 + + +def decreasehue(hue, step): + if hue - step < 0: + return (hue + 360 - step) % 360 + else: + return hue - step % 360 diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index fcb9ffe..5a39d31 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -1,9 +1,8 @@ import board import busio -import neopixel from kmk.consts import DiodeOrientation, LeaderMode, UnicodeMode -from kmk.handlers.layers import df_pressed +from kmk.handlers.layers import df_pressed, mo_pressed, mo_released, lt_pressed, lt_released from kmk.handlers.sequences import (compile_unicode_string_sequences) from kmk.keys import KC, layer_key_validator, make_argumented_key from kmk.mcus.circuitpython_samd51 import Firmware @@ -31,20 +30,11 @@ keyboard.debug_enabled = True keyboard.pixel_pin = board.TX keyboard.num_pixels = 12 OFF = (0, 0, 0) -CYAN = (0, 255, 255) - -''' -pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False) - -RED = (255, 0, 0) -YELLOW = (255, 150, 0) -GREEN = (0, 255, 0) -BLUE = (0, 0, 255) -PURPLE = (180, 0, 255) - -pixels.fill(OFF) -pixels.show() -''' +BLUE = (0, 0, 100) +CYAN = (0, 100, 100) +PURPLE = (71, 0, 100) +RED = (100, 0, 0) +WHITE = (100, 100, 100) emoticons = compile_unicode_string_sequences({ # Emoticons, but fancier @@ -70,10 +60,6 @@ keyboard.leader_dictionary = { 'yay': emoticons.YAY, } -_______ = KC.TRNS -XXXXXXX = KC.NO -LT3_SP = KC.LT(3, KC.SPC) -SHFT_INS = KC.LSHIFT(KC.INS) df = 0 gw = 1 @@ -88,23 +74,90 @@ def base(*args, **kwargs): return df_pressed(*args, **kwargs) +def layer1p(*args, **kwargs): + keyboard.pixels.fill(WHITE) + keyboard.pixels.show() + return mo_pressed(*args, **kwargs) + + +def layer1r(*args, **kwargs): + keyboard.pixels.fill(OFF) + keyboard.pixels.show() + return mo_released(*args, **kwargs) + + +def layer2p(*args, **kwargs): + keyboard.pixels.fill(BLUE) + keyboard.pixels.show() + return lt_pressed(*args, **kwargs) + + +def layer2r(*args, **kwargs): + keyboard.pixels.fill(OFF) + keyboard.pixels.show() + return lt_released(*args, **kwargs) + + +def layer3p(*args, **kwargs): + keyboard.pixels.fill(PURPLE) + keyboard.pixels.show() + return mo_pressed(*args, **kwargs) + + +def layer3r(*args, **kwargs): + keyboard.pixels.fill(OFF) + keyboard.pixels.show() + return mo_released(*args, **kwargs) + + def gaming(*args, **kwargs): keyboard.pixels.fill(CYAN) keyboard.pixels.show() return df_pressed(*args, **kwargs) + +make_argumented_key( + validator=layer_key_validator, + names=('LAYER_BASE',), + on_press=base, +) + +make_argumented_key( + validator=layer_key_validator, + names=('LAYER_1',), + on_press=layer1p, + on_release=layer1r, +) + +make_argumented_key( + validator=layer_key_validator, + names=('LAYER_2',), + on_press=layer2p, + on_release=layer2r, +) + +make_argumented_key( + validator=layer_key_validator, + names=('LAYER_3',), + on_press=layer3p, + on_release=layer3r, +) + + make_argumented_key( validator=layer_key_validator, names=('LAYER_GAMING',), on_press=gaming, ) -make_argumented_key( - validator=layer_key_validator, - names=('LAYER_BASE',), - on_press=base, -) +_______ = KC.TRNS +XXXXXXX = KC.NO +SHFT_INS = KC.LSHIFT(KC.INS) + BASE = KC.LAYER_BASE(df) +LAYER_1 = KC.LAYER_1(r1) +LT2_SP = KC.LAYER_2(r2, KC.SPC) +LAYER_3 = KC.LAYER_3(r3) GAMING = KC.LAYER_GAMING(gw) # ---------------------- Keymap --------------------------------------------------------- @@ -112,11 +165,11 @@ GAMING = KC.LAYER_GAMING(gw) keyboard.keymap = [ [ # df - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL], - [KC.GRV, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP], - [KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT], - [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH], - [KC.LCTRL, KC.LGUI, KC.LALT, KC.LEAD, KC.MO(r1), LT3_SP, LT3_SP, KC.MO(r3), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL], + [KC.GRV, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP], + [KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT], + [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH], + [KC.LCTRL, KC.LGUI, KC.LALT, KC.LEAD, LAYER_1, KC.LT(r2, KC.SPC), KC.LT(r2, KC.SPC), LAYER_3, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], ], [ # gw @@ -124,7 +177,7 @@ keyboard.keymap = [ [KC.TAB, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP], [KC.ESC, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT], [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH], - [KC.LCTRL, KC.LGUI, KC.LALT, KC.F1, KC.F2, KC.SPC, KC.SPC, KC.MO(r3), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + [KC.LCTRL, KC.LGUI, KC.LALT, KC.F1, KC.F2, KC.SPC, KC.LT(r2, KC.SPC), KC.MO(r3), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], ], [ # r1 From 0ba5911f8f6bbbf0ef4d4b71a66e19c4cb381e3b Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Tue, 19 Feb 2019 18:07:22 -0800 Subject: [PATCH 03/32] More animations, now based on time and intervals. Massively WIP --- kmk/firmware.py | 17 ++------ kmk/rgb.py | 100 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 80 insertions(+), 37 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index 8bcdb82..991c42f 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -93,7 +93,7 @@ class Firmware: pixel_pin = None num_pixels = None pixels = None - pixel_state = 0, 0 + pixel_state = rgb.pixelinit() def __init__(self): # Attempt to sanely guess a coord_mapping if one is not provided @@ -239,7 +239,6 @@ class Firmware: if self.debug_enabled: print("Firin' lazers. Keyboard is booted.") - while True: state_changed = False @@ -275,15 +274,7 @@ class Firmware: if self.debug_enabled and state_changed: print('New State: {}'.format(self._state._to_dict())) - gc.collect() - ''' - test = rgb.color_chase(self.pixels, - self.num_pixels, - color=(255,0,0), - color2=(0,255,255), - animation_state=self.pixel_state[0]) + if self.pixel_state['animation_mode'] is not None: + self.pixel_state = rgb.animate(self.pixel_state, self.pixels) - if test is not None: - # Debugging some strange errors with NoneType - self.pixel_state = test - ''' + gc.collect() diff --git a/kmk/rgb.py b/kmk/rgb.py index 3b719b8..29a5095 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -1,3 +1,6 @@ +from math import sin, exp, pi +import time + COLORS = { 'OFF': (0, 0, 0), 'RED': (255, 0, 0), @@ -16,29 +19,19 @@ def pixelinit(): 's': 255, 'v': 255, 'animation_mode': None, - 'speed': 0, + 'pos': 0, + 'timer': None, + 'intervals': (0, 0, 0, 0), + 'speed': 120, # Bigger is slower 'enable': True } -def color_chase(pixels, num_pixels, color, color2=COLORS['OFF'], speed=100, animation_state=0): - if animation_state not in range(num_pixels): - color = color2 - pixels[int(animation_state - num_pixels)] = color - - else: - pixels[animation_state] = color - - pixels.show() - animation_state += 1 - - if animation_state >= num_pixels * 2: - animation_state = 0 - - return animation_state, 0 +def time_ms(): + return time.monotonic_ns() / 10 -def sethsv(hue, sat, val, pixels, index): +def hsv_to_rgb(hue, sat, val): r = 0 g = 0 b = 0 @@ -46,7 +39,7 @@ def sethsv(hue, sat, val, pixels, index): RGBLIGHT_LIMIT_VAL = 255 if val > RGBLIGHT_LIMIT_VAL: - val=RGBLIGHT_LIMIT_VAL + val=RGBLIGHT_LIMIT_VAL if sat == 0: r = val @@ -83,25 +76,84 @@ def sethsv(hue, sat, val, pixels, index): g = base b = val - color - rgb = (r, g, b) - setrgb(rgb, pixels, index) + return r, g, b -def setrgb(rgb, pixels, index): +def set_hsv(hue, sat, val, pixels, index): + set_rgb(hsv_to_rgb(hue, sat, val), pixels, index) + + +def set_hsv_fill(hue, sat, val, pixels): + pixels.fill(hsv_to_rgb(hue, sat, val)) + pixels.show() + + +def set_rgb(rgb, pixels, index): pixels[index] = (rgb[0], rgb[1], rgb[2]) + pixels.show() -def setrgbfill(rgb, pixels): +def set_rgb_fill(rgb, pixels): pixels.fill(rgb[0], rgb[1], rgb[2]) + pixels.show() -def increasehue(hue, step): +def increase_hue(hue, step): return hue + step % 360 -def decreasehue(hue, step): +def decrease_hue(hue, step): if hue - step < 0: return (hue + 360 - step) % 360 else: return hue - step % 360 + +def animate(state, pixels): + if state['animation_mode'] == 'breathing': + return effect_breathing(state, pixels) + elif state['animation_mode'] == 'rainbow': + return effect_rainbow(state, pixels) + + return state + + +def animation_step(state): + interval = state['time'] - time_ms() + if interval in state['intervals']: + return interval + else: + return False + + +def effect_breathing(state, pixels): + if animation_step(state): + # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + state['v'] = (exp(sin(state['step'] / 2000.0 * pi)) - 0.36787944) * 108.0 + set_hsv_fill(state['h'], state['s'], state['v'], pixels) + + return state + + +def effect_rainbow(state, pixels): + if animation_step(state): + state['h'] = increase_hue(state['h'], 1) + set_hsv_fill(state['h'], state['s'], state['v'], pixels) + + return state + + +def effect_rainbow_swirl(state, pixels): + interval = animation_step(state) + if interval: + MAX_RGB_NUM = 12 # TODO Actually pass this + for i in range(0, MAX_RGB_NUM): + state['h'] = (360 / MAX_RGB_NUM * i + state['h']) % 360 + set_hsv_fill(state['h'], state['s'], state['v'], pixels) + + if interval % 2: + state['h'] = increase_hue(state['h'], 1) + else: + state['h'] = decrease_hue(state['h'], 1) + + return state From 31983a087330e193896a4a6ed51e44c7c851f1d7 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Wed, 20 Feb 2019 20:40:46 -0800 Subject: [PATCH 04/32] Breathing now finally working, a key to enable it, not sane defaults, and a toggle button --- kmk/firmware.py | 1 + kmk/handlers/stock.py | 11 +++ kmk/keys.py | 3 + kmk/rgb.py | 110 +++++++++++++---------- user_keymaps/kdb424/nyquist_converter.py | 2 +- 5 files changed, 78 insertions(+), 49 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index 991c42f..a5c37a6 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -277,4 +277,5 @@ class Firmware: if self.pixel_state['animation_mode'] is not None: self.pixel_state = rgb.animate(self.pixel_state, self.pixels) + gc.collect() diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index db37c66..e19aba5 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -118,3 +118,14 @@ def td_pressed(key, state, *args, **kwargs): def td_released(key, state, *args, **kwargs): return state._process_tap_dance(key, False) + + +def rgb_tog(key, state, *args, **kwargs): + state.config.pixel_state['enable'] = not state.config.pixel_state['enable'] + return state + + +def rgb_mode_breathe(key, state, *args, **kwargs): + state.config.pixel_state['animation_mode'] = 'breathing' + return state + diff --git a/kmk/keys.py b/kmk/keys.py index 2571b76..065d173 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -625,6 +625,9 @@ make_key(names=('DEBUG', 'DBG'), on_press=handlers.debug_pressed, on_release=han make_key(names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released) make_key(names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released) +make_key(names=('GESC', 'GRAVE_ESC'), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released) +make_key(names=('RGB_TOG',), on_press=handlers.rgb_tog) +make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe) make_key( names=('LEADER', 'LEAD'), on_press=handlers.leader_pressed, diff --git a/kmk/rgb.py b/kmk/rgb.py index 29a5095..0bc313b 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -1,4 +1,5 @@ -from math import sin, exp, pi +from math import sin, exp, pi, floor +from math import e as M_E import time COLORS = { @@ -15,31 +16,30 @@ COLORS = { def pixelinit(): return { - 'h': 0, - 's': 255, - 'v': 255, - 'animation_mode': None, + 'h': 180, + 's': 100, + 'v': 80, + 'animation_mode': 'Breathing', 'pos': 0, - 'timer': None, - 'intervals': (0, 0, 0, 0), + 'time': time_ms(), + 'intervals': (30, 20, 10, 5), 'speed': 120, # Bigger is slower 'enable': True } def time_ms(): - return time.monotonic_ns() / 10 + return floor(time.monotonic() * 10) def hsv_to_rgb(hue, sat, val): r = 0 g = 0 b = 0 - # TODO Actually pass this limit to allow overrides RGBLIGHT_LIMIT_VAL = 255 - if val > RGBLIGHT_LIMIT_VAL: - val=RGBLIGHT_LIMIT_VAL + if val > 255: + val = 255 if sat == 0: r = val @@ -50,33 +50,33 @@ def hsv_to_rgb(hue, sat, val): base = ((255 - sat) * val) >> 8 color = (val - base) * (hue % 60) / 60 - x = hue / 60 - if x == 0: - r = val - g = base + color - b = base - elif x == 1: - r = val - color - g = val - b = base - elif x == 2: - r = base - g = val - b = base + color - elif x == 3: - r = base - g = val - color - b = val - elif x == 4: - r = base + color - g = base - b = val - elif x == 5: - r = val - g = base - b = val - color + x = floor(hue / 60) + if x == 0: + r = val + g = base + color + b = base + elif x == 1: + r = val - color + g = val + b = base + elif x == 2: + r = base + g = val + b = base + color + elif x == 3: + r = base + g = val - color + b = val + elif x == 4: + r = base + color + g = base + b = val + elif x == 5: + r = val + g = base + b = val - color - return r, g, b + return floor(r), floor(g), floor(b) def set_hsv(hue, sat, val, pixels, index): @@ -99,27 +99,37 @@ def set_rgb_fill(rgb, pixels): def increase_hue(hue, step): - return hue + step % 360 + return (hue + step) % 360 def decrease_hue(hue, step): if hue - step < 0: return (hue + 360 - step) % 360 else: - return hue - step % 360 + return (hue - step) % 360 + + +def off(pixels): + set_hsv_fill(0, 0, 0, pixels) def animate(state, pixels): - if state['animation_mode'] == 'breathing': - return effect_breathing(state, pixels) - elif state['animation_mode'] == 'rainbow': - return effect_rainbow(state, pixels) + if state['enable']: + if state['animation_mode'] == 'breathing': + return effect_breathing(state, pixels) + elif state['animation_mode'] == 'rainbow': + return effect_rainbow(state, pixels) + else: + off(pixels) return state def animation_step(state): - interval = state['time'] - time_ms() + interval = time_ms() - state['time'] + if interval >= max(state['intervals']): + state['time'] = time_ms() + return max(state['intervals']) if interval in state['intervals']: return interval else: @@ -127,10 +137,14 @@ def animation_step(state): def effect_breathing(state, pixels): - if animation_step(state): - # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ - state['v'] = (exp(sin(state['step'] / 2000.0 * pi)) - 0.36787944) * 108.0 - set_hsv_fill(state['h'], state['s'], state['v'], pixels) + RGBLIGHT_EFFECT_BREATHE_CENTER = 1.5 # 1.0-2.7 + RGBLIGHT_EFFECT_BREATHE_MAX = 150 # 0-255 + interval = time_ms() - state['time'] + # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L787 + state['v'] = floor((exp(sin((state['pos']/255.0)*pi)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E))) + state['pos'] = (state['pos'] + 1) % 256; + set_hsv_fill(state['h'], state['s'], state['v'], pixels) return state diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index 5a39d31..a59a5b0 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -169,7 +169,7 @@ keyboard.keymap = [ [KC.GRV, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP], [KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT], [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH], - [KC.LCTRL, KC.LGUI, KC.LALT, KC.LEAD, LAYER_1, KC.LT(r2, KC.SPC), KC.LT(r2, KC.SPC), LAYER_3, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + [KC.LCTRL, KC.LGUI, KC.LALT, KC.RGB_TOG, LAYER_1, KC.LT(r2, KC.SPC), KC.LT(r2, KC.SPC), LAYER_3, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], ], [ # gw From 2ad1fe8a9c2f14861e7eddff24eeb35e52c31ab7 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Thu, 21 Feb 2019 18:27:35 -0800 Subject: [PATCH 05/32] Massively improved, still not complete. Much easier to use now --- kmk/firmware.py | 16 +- kmk/handlers/stock.py | 54 +++- kmk/keys.py | 10 + kmk/rgb.py | 393 +++++++++++++++-------- user_keymaps/kdb424/nyquist_converter.py | 8 + 5 files changed, 339 insertions(+), 142 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index a5c37a6..db34eb0 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -92,8 +92,8 @@ class Firmware: uart_pin = None pixel_pin = None num_pixels = None + rgb_order = (1, 0, 2) # GRB WS2812 pixels = None - pixel_state = rgb.pixelinit() def __init__(self): # Attempt to sanely guess a coord_mapping if one is not provided @@ -188,13 +188,6 @@ class Firmware: else: return busio.UART(tx=pin, rx=None, timeout=timeout) - def init_pixels(self, pixel_pin, num_pixels=0): - try: - import neopixel - return neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False) - except ImportError as e: - print(e) - return None def go(self): assert self.keymap, 'must define a keymap with at least one row' @@ -217,7 +210,8 @@ class Firmware: self.uart = self.init_uart(self.uart_pin) if self.pixel_pin is not None: - self.pixels = self.init_pixels(self.pixel_pin, self.num_pixels) + self.pixels = rgb.RGB(self.pixel_pin, self.rgb_order, self.num_pixels) + self.matrix = MatrixScanner( cols=self.col_pins, @@ -274,8 +268,8 @@ class Firmware: if self.debug_enabled and state_changed: print('New State: {}'.format(self._state._to_dict())) - if self.pixel_state['animation_mode'] is not None: - self.pixel_state = rgb.animate(self.pixel_state, self.pixels) + if self.pixels.animation_mode is not None: + self.pixels = self.pixels.animate() gc.collect() diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index e19aba5..2e135c4 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -121,11 +121,61 @@ def td_released(key, state, *args, **kwargs): def rgb_tog(key, state, *args, **kwargs): - state.config.pixel_state['enable'] = not state.config.pixel_state['enable'] + state.config.pixels.enabled = not state.config.pixels.enabled + return state + + +def rgb_forward(key, state, *args, **kwargs): + # TODO + return state + + +def rgb_reverse(key, state, *args, **kwargs): + # TODO + return state + + +def rgb_hui(key, state, *args, **kwargs): + state.config.pixels.increase_hue(state.config.pixels.hue_step) + return state + + +def rgb_hud(key, state, *args, **kwargs): + state.config.pixels.decrease_hue(state.config.pixels.hue_step) + return state + + +def rgb_sai(key, state, *args, **kwargs): + state.config.pixels.increase_sat(state.config.pixels.sat_step) + return state + + +def rgb_sad(key, state, *args, **kwargs): + state.config.pixels.decrease_sat(state.config.pixels.sat_step) + return state + + +def rgb_vai(key, state, *args, **kwargs): + state.config.pixels.increase_val(state.config.pixels.val_step) + return state + + +def rgb_vad(key, state, *args, **kwargs): + state.config.pixels.decrease_val(state.config.pixels.val_step) + return state + + +def rgb_mode_static(key, state, *args, **kwargs): + state.config.pixels.animation_mode = 'static' return state def rgb_mode_breathe(key, state, *args, **kwargs): - state.config.pixel_state['animation_mode'] = 'breathing' + state.config.pixels.animation_mode = 'breathing' + return state + + +def rgb_mode_rainbow(key, state, *args, **kwargs): + state.config.pixels.animation_mode = 'rainbow' return state diff --git a/kmk/keys.py b/kmk/keys.py index 065d173..5ab8849 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -627,7 +627,17 @@ make_key(names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.ge make_key(names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released) make_key(names=('GESC', 'GRAVE_ESC'), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released) make_key(names=('RGB_TOG',), on_press=handlers.rgb_tog) +make_key(names=('RGB_MODE_FORWARD', 'RGB_MOD'), on_press=handlers.rgb_forward) +make_key(names=('RGB_MODE_REVERSE', 'RGB_RMOD'), on_press=handlers.rgb_reverse) +make_key(names=('RGB_HUI',), on_press=handlers.rgb_hui) +make_key(names=('RGB_HUD',), on_press=handlers.rgb_hud) +make_key(names=('RGB_SAI',), on_press=handlers.rgb_sai) +make_key(names=('RGB_SAD',), on_press=handlers.rgb_sad) +make_key(names=('RGB_VAI',), on_press=handlers.rgb_vai) +make_key(names=('RGB_VAD',), on_press=handlers.rgb_vad) +make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static) make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe) +make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow) make_key( names=('LEADER', 'LEAD'), on_press=handlers.leader_pressed, diff --git a/kmk/rgb.py b/kmk/rgb.py index 0bc313b..bc0a12a 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -2,172 +2,307 @@ from math import sin, exp, pi, floor from math import e as M_E import time -COLORS = { - 'OFF': (0, 0, 0), - 'RED': (255, 0, 0), - 'GREEN': (0, 255, 0), - 'BLUE': (0, 0, 255, 0), - 'YELLOW': (255, 150, 0), - 'CYAN': (0, 255, 255), - 'PURPLE': (180, 0, 255), - 'WHITE': (255, 255, 255), -} +class RGB: + hue = 240 + sat = 100 + val = 80 + animation_mode = 'breathing' + pos = 0 + time = floor(time.monotonic() * 10) + intervals = (30, 20, 10, 5) + speed = 120 # Bigger is slower + enabled = True + neopixel = None + rgbw = False + num_pixels = 0 + disable_auto_write = False + hue_step = 5 + sat_step = 5 + val_step = 5 + limit_val = 255 -def pixelinit(): - return { - 'h': 180, - 's': 100, - 'v': 80, - 'animation_mode': 'Breathing', - 'pos': 0, - 'time': time_ms(), - 'intervals': (30, 20, 10, 5), - 'speed': 120, # Bigger is slower - 'enable': True - } + def __init__(self, pixel_pin, rgb_order, num_pixels=0): + try: + import neopixel + self.neopixel = neopixel.NeoPixel(pixel_pin, + num_pixels, + pixel_order=rgb_order, + auto_write=False) + if len(rgb_order) == 4: + self.rgbw = True + self.num_pixels = num_pixels + except ImportError as e: + print(e) -def time_ms(): - return floor(time.monotonic() * 10) + def __repr__(self): + return 'RGB({})'.format(self._to_dict()) + def _to_dict(self): + ret = { + 'hue': self.hue, + 'sat': self.sat, + 'val': self.val, + 'animation_mode': self.animation_mode, + 'time': self.time, + 'intervals': self.intervals, + 'speed': self.speed, + 'enabled': self.enabled, + 'neopixel': self.neopixel, + 'disable_auto_write': self.disable_auto_write, + } -def hsv_to_rgb(hue, sat, val): - r = 0 - g = 0 - b = 0 - RGBLIGHT_LIMIT_VAL = 255 + return ret - if val > 255: - val = 255 + def time_ms(self): + return floor(time.monotonic() * 10) - if sat == 0: - r = val - g = val - b = val + def hsv_to_rgb(self, hue, sat, val): + ''' + Converts HSV values, and returns a tuple of RGB values + :param hue: + :param sat: + :param val: + :return: (r, g, b) + ''' + r = 0 + g = 0 + b = 0 + self.limit_val = 255 - else: - base = ((255 - sat) * val) >> 8 - color = (val - base) * (hue % 60) / 60 + if val > 255: + val = 255 - x = floor(hue / 60) - if x == 0: + if sat == 0: r = val - g = base + color - b = base - elif x == 1: - r = val - color g = val - b = base - elif x == 2: - r = base - g = val - b = base + color - elif x == 3: - r = base - g = val - color b = val - elif x == 4: - r = base + color - g = base - b = val - elif x == 5: - r = val - g = base - b = val - color - return floor(r), floor(g), floor(b) + else: + base = ((255 - sat) * val) >> 8 + color = (val - base) * (hue % 60) / 60 + x = floor(hue / 60) + if x == 0: + r = val + g = base + color + b = base + elif x == 1: + r = val - color + g = val + b = base + elif x == 2: + r = base + g = val + b = base + color + elif x == 3: + r = base + g = val - color + b = val + elif x == 4: + r = base + color + g = base + b = val + elif x == 5: + r = val + g = base + b = val - color -def set_hsv(hue, sat, val, pixels, index): - set_rgb(hsv_to_rgb(hue, sat, val), pixels, index) + return floor(r), floor(g), floor(b) + def hsv_to_rgbw(self, hue, sat, val): + ''' + Converts HSV values, and returns a tuple of RGBW values + :param hue: + :param sat: + :param val: + :return: (r, g, b, w) + ''' + rgb = self.hsv_to_rgb(hue, sat, val) + return rgb[0], rgb[1], rgb[2], min(rgb) -def set_hsv_fill(hue, sat, val, pixels): - pixels.fill(hsv_to_rgb(hue, sat, val)) - pixels.show() + def set_hsv(self, hue, sat, val, index): + ''' + Takes HSV values and displays it on a single LED/Neopixel + :param hue: + :param sat: + :param val: + :param index: Index of LED/Pixel + ''' + if self.neopixel: + if self.rgbw: + self.set_rgb(self.hsv_to_rgbw(hue, sat, val), index) + else: + self.set_rgb(self.hsv_to_rgb(hue, sat, val), index) + def set_hsv_fill(self, hue, sat, val): + ''' + Takes HSV values and displays it on all LEDs/Neopixels + :param hue: + :param sat: + :param val: + :param index: Index of LED/Pixel + ''' + if self.neopixel: + if self.rgbw: + self.neopixel.fill(self.hsv_to_rgbw(hue, sat, val)) + else: + self.neopixel.fill(self.hsv_to_rgb(hue, sat, val)) + self.neopixel.show() -def set_rgb(rgb, pixels, index): - pixels[index] = (rgb[0], rgb[1], rgb[2]) - pixels.show() + def set_rgb(self, rgb, index): + ''' + Takes an RGB or RGBW and displays it on a single LED/Neopixel + :param rgb: RGB or RGBW + :param index: Index of LED/Pixel + ''' + if self.neopixel: + self.neopixel[index] = rgb + if not self.disable_auto_write: + self.neopixel.show() + def set_rgb_fill(self, rgb): + ''' + Takes an RGB or RGBW and displays it on all LEDs/Neopixels + :param rgb: RGB or RGBW + ''' + if self.neopixel: + self.neopixel.fill(rgb) + self.neopixel.show() -def set_rgb_fill(rgb, pixels): - pixels.fill(rgb[0], rgb[1], rgb[2]) - pixels.show() + def increase_hue(self, step): + ''' + Increases hue by step amount rolling at 360 and returning to 0 + :param step: + ''' + self.hue = (self.hue + step) % 360 + def decrease_hue(self, step): + ''' + Decreases hue by step amount rolling at 0 and returning to 360 + :param step: + ''' + if self.hue - step < 0: + self.hue = (self.hue + 360 - step) % 360 + else: + self.hue = (self.hue - step) % 360 -def increase_hue(hue, step): - return (hue + step) % 360 + def increase_sat(self, step): + ''' + Increases saturation by step amount stopping at 100 + :param step: + ''' + if self.sat + step >= 100: + self.sat = 100 + else: + self.sat += step + def decrease_sat(self, step): + ''' + Decreases saturation by step amount stopping at 0 + :param step: + ''' + if self.sat + step <= 0: + self.sat = 0 + else: + self.sat -= step -def decrease_hue(hue, step): - if hue - step < 0: - return (hue + 360 - step) % 360 - else: - return (hue - step) % 360 + def increase_val(self, step): + ''' + Increases value by step amount stopping at 100 + :param step: + ''' + if self.val + step >= 100: + self.val = 100 + else: + self.val += step + def decrease_val(self, step): + ''' + Decreases value by step amount stopping at 0 + :param step: + ''' + if self.val + step <= 0: + self.val = 0 + else: + self.val -= step -def off(pixels): - set_hsv_fill(0, 0, 0, pixels) + def off(self): + ''' + Turns off all LEDs/Neopixels without changing stored values + ''' + if self.neopixel: + if not self.disable_auto_write: + self.set_hsv_fill(0, 0, 0) + def show(self): + ''' + Turns on all LEDs/Neopixels without changing stored values + ''' + if self.neopixel: + self.neopixel.show() -def animate(state, pixels): - if state['enable']: - if state['animation_mode'] == 'breathing': - return effect_breathing(state, pixels) - elif state['animation_mode'] == 'rainbow': - return effect_rainbow(state, pixels) - else: - off(pixels) + def animate(self): + ''' + Activates a "step" in the animation based on the active mode + :return: Returns the new state in animation + ''' + if self.enabled: + if self.animation_mode == 'breathing': + return self.effect_breathing() + elif self.animation_mode == 'rainbow': + return self.effect_rainbow() + if self.animation_mode == 'static': + return self.effect_static() + else: + self.off() - return state + return self + def animation_step(self): + interval = self.time_ms() - self.time + if interval >= max(self.intervals): + self.time = self.time_ms() + return max(self.intervals) + if interval in self.intervals: + return interval + else: + return False -def animation_step(state): - interval = time_ms() - state['time'] - if interval >= max(state['intervals']): - state['time'] = time_ms() - return max(state['intervals']) - if interval in state['intervals']: - return interval - else: - return False + def effect_static(self): + self.set_hsv_fill(self.hue, self.sat, self.val) + return self + def effect_breathing(self): + RGBLIGHT_EFFECT_BREATHE_CENTER = 1.5 # 1.0-2.7 + RGBLIGHT_EFFECT_BREATHE_MAX = 100 # 0-255 + # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L787 + self.val = floor((exp(sin((self.pos/255.0)*pi)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)* + (RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E))) + self.pos = (self.pos + 1) % 256; + self.set_hsv_fill(self.hue, self.sat, self.val) -def effect_breathing(state, pixels): - RGBLIGHT_EFFECT_BREATHE_CENTER = 1.5 # 1.0-2.7 - RGBLIGHT_EFFECT_BREATHE_MAX = 150 # 0-255 - interval = time_ms() - state['time'] - # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ - # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L787 - state['v'] = floor((exp(sin((state['pos']/255.0)*pi)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E))) - state['pos'] = (state['pos'] + 1) % 256; - set_hsv_fill(state['h'], state['s'], state['v'], pixels) + return self - return state + def effect_rainbow(self): + if self.animation_step(self): + self.increase_hue(self.hue, 1) + self.set_hsv_fill(self.hue, self.sat, self.val) + return self -def effect_rainbow(state, pixels): - if animation_step(state): - state['h'] = increase_hue(state['h'], 1) - set_hsv_fill(state['h'], state['s'], state['v'], pixels) + def effect_rainbow_swirl(self): + interval = self.animation_step(self) + if interval: + for i in range(0, self.num_pixels): + self.hue = (360 / self.num_pixels * i + self.hue) % 360 + self.set_hsv_fill(self.hue, self.sat, self.val) - return state + if interval % 2: + self.increase_hue(self.hue, 1) + else: + self.decrease_hue(self.hue, 1) - -def effect_rainbow_swirl(state, pixels): - interval = animation_step(state) - if interval: - MAX_RGB_NUM = 12 # TODO Actually pass this - for i in range(0, MAX_RGB_NUM): - state['h'] = (360 / MAX_RGB_NUM * i + state['h']) % 360 - set_hsv_fill(state['h'], state['s'], state['v'], pixels) - - if interval % 2: - state['h'] = increase_hue(state['h'], 1) - else: - state['h'] = decrease_hue(state['h'], 1) - - return state + return self diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index a59a5b0..8979510 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -69,48 +69,56 @@ r3 = 4 def base(*args, **kwargs): + keyboard.pixel_state['animation_mode'] = 'breathing' keyboard.pixels.fill(OFF) keyboard.pixels.show() return df_pressed(*args, **kwargs) def layer1p(*args, **kwargs): + keyboard.pixel_state['animation_mode'] = 'User' keyboard.pixels.fill(WHITE) keyboard.pixels.show() return mo_pressed(*args, **kwargs) def layer1r(*args, **kwargs): + keyboard.pixel_state['animation_mode'] = 'breathing' keyboard.pixels.fill(OFF) keyboard.pixels.show() return mo_released(*args, **kwargs) def layer2p(*args, **kwargs): + keyboard.pixel_state['animation_mode'] = 'User' keyboard.pixels.fill(BLUE) keyboard.pixels.show() return lt_pressed(*args, **kwargs) def layer2r(*args, **kwargs): + keyboard.pixel_state['animation_mode'] = 'breathing' keyboard.pixels.fill(OFF) keyboard.pixels.show() return lt_released(*args, **kwargs) def layer3p(*args, **kwargs): + keyboard.pixel_state['animation_mode'] = 'User' keyboard.pixels.fill(PURPLE) keyboard.pixels.show() return mo_pressed(*args, **kwargs) def layer3r(*args, **kwargs): + keyboard.pixel_state['animation_mode'] = 'breathing' keyboard.pixels.fill(OFF) keyboard.pixels.show() return mo_released(*args, **kwargs) def gaming(*args, **kwargs): + keyboard.pixel_state['animation_mode'] = 'User' keyboard.pixels.fill(CYAN) keyboard.pixels.show() return df_pressed(*args, **kwargs) From 5334e7e0bee8a6475006359f4dfb8f2daa0e1f42 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Fri, 22 Feb 2019 19:50:56 -0800 Subject: [PATCH 06/32] Massive hsv math fix and configs can be passed now for most things --- kmk/firmware.py | 22 ++++++- kmk/handlers/stock.py | 5 ++ kmk/keys.py | 1 + kmk/rgb.py | 79 ++++++++++++++--------- user_keymaps/kdb424/nyquist_converter.py | 81 +++++++++++++++--------- 5 files changed, 129 insertions(+), 59 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index db34eb0..ae0806e 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -80,6 +80,7 @@ class Firmware: hid_helper = USB_HID + # Split config extra_data_pin = None split_offsets = () split_flip = False @@ -90,9 +91,21 @@ class Firmware: uart = None uart_flip = True uart_pin = None + + # RGB config pixel_pin = None num_pixels = None rgb_order = (1, 0, 2) # GRB WS2812 + val_limit = 255 + hue_default = 0 + sat_default = 100 + val_default = val_limit + hue_step = 1 + sat_step = 1 + val_step = 1 + animation_speed = 1 + breathe_center = 1.5 # 1.0-2.7 + animation_mode = 'static' pixels = None def __init__(self): @@ -210,7 +223,11 @@ class Firmware: self.uart = self.init_uart(self.uart_pin) if self.pixel_pin is not None: - self.pixels = rgb.RGB(self.pixel_pin, self.rgb_order, self.num_pixels) + self.pixels = rgb.RGB(self.pixel_pin, self.rgb_order, self.num_pixels, + self.hue_step, self.sat_step, self.val_step, + self.hue_default, self.sat_default, self.val_default, + self.breathe_center, self.val_limit, self.animation_mode + ) self.matrix = MatrixScanner( @@ -268,6 +285,9 @@ class Firmware: if self.debug_enabled and state_changed: print('New State: {}'.format(self._state._to_dict())) + if self.debug_enabled and state_changed and self.pixels.enabled: + print('New State: {}'.format(self.pixels)) + if self.pixels.animation_mode is not None: self.pixels = self.pixels.animate() diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index 2e135c4..b24ec10 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -175,6 +175,11 @@ def rgb_mode_breathe(key, state, *args, **kwargs): return state +def rgb_mode_breathe_rainbow(key, state, *args, **kwargs): + state.config.pixels.animation_mode = 'breathing_rainbow' + return state + + def rgb_mode_rainbow(key, state, *args, **kwargs): state.config.pixels.animation_mode = 'rainbow' return state diff --git a/kmk/keys.py b/kmk/keys.py index 5ab8849..d74b0b4 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -638,6 +638,7 @@ make_key(names=('RGB_VAD',), on_press=handlers.rgb_vad) make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static) make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe) make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow) +make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'), on_press=handlers.rgb_mode_breathe_rainbow) make_key( names=('LEADER', 'LEAD'), on_press=handlers.leader_pressed, diff --git a/kmk/rgb.py b/kmk/rgb.py index bc0a12a..7b942b4 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -4,25 +4,31 @@ import time class RGB: - hue = 240 + hue = 0 sat = 100 val = 80 - animation_mode = 'breathing' pos = 0 time = floor(time.monotonic() * 10) intervals = (30, 20, 10, 5) - speed = 120 # Bigger is slower + animation_speed = 1 enabled = True neopixel = None rgbw = False - num_pixels = 0 disable_auto_write = False - hue_step = 5 + + # Set by config + num_pixels = 0 + hue_step = 1 sat_step = 5 val_step = 5 - limit_val = 255 + breath_center = 1.5 # 1.0-2.7 + val_limit = 255 + animation_mode = 'static' - def __init__(self, pixel_pin, rgb_order, num_pixels=0): + def __init__(self, pixel_pin, rgb_order, num_pixels, + hue_step, sat_step, val_step, + hue_default, sat_default, val_default, + breath_center, val_limit, animation_mode): try: import neopixel self.neopixel = neopixel.NeoPixel(pixel_pin, @@ -32,6 +38,15 @@ class RGB: if len(rgb_order) == 4: self.rgbw = True self.num_pixels = num_pixels + self.hue_step = hue_step + self.sat_step = sat_step + self.val_step = val_step + self.hue = hue_default + self.sat = sat_default + self.val = val_default + self.breath_center = breath_center + self.val_limit = val_limit + self.animation_mode = animation_mode except ImportError as e: print(e) @@ -47,7 +62,7 @@ class RGB: 'animation_mode': self.animation_mode, 'time': self.time, 'intervals': self.intervals, - 'speed': self.speed, + 'animation_speed': self.animation_speed, 'enabled': self.enabled, 'neopixel': self.neopixel, 'disable_auto_write': self.disable_auto_write, @@ -69,10 +84,9 @@ class RGB: r = 0 g = 0 b = 0 - self.limit_val = 255 - if val > 255: - val = 255 + if val > self.val_limit: + val = self.val_limit if sat == 0: r = val @@ -80,8 +94,8 @@ class RGB: b = val else: - base = ((255 - sat) * val) >> 8 - color = (val - base) * (hue % 60) / 60 + base = ((100 - sat) * val) / 100 + color = floor((val - base) * ((hue % 60) / 60)) x = floor(hue / 60) if x == 0: @@ -183,7 +197,7 @@ class RGB: Decreases hue by step amount rolling at 0 and returning to 360 :param step: ''' - if self.hue - step < 0: + if (self.hue - step) <= 0: self.hue = (self.hue + 360 - step) % 360 else: self.hue = (self.hue - step) % 360 @@ -203,7 +217,7 @@ class RGB: Decreases saturation by step amount stopping at 0 :param step: ''' - if self.sat + step <= 0: + if (self.sat - step) <= 0: self.sat = 0 else: self.sat -= step @@ -213,7 +227,7 @@ class RGB: Increases value by step amount stopping at 100 :param step: ''' - if self.val + step >= 100: + if (self.val + step) >= 100: self.val = 100 else: self.val += step @@ -223,7 +237,7 @@ class RGB: Decreases value by step amount stopping at 0 :param step: ''' - if self.val + step <= 0: + if (self.val - step) <= 0: self.val = 0 else: self.val -= step @@ -253,7 +267,9 @@ class RGB: return self.effect_breathing() elif self.animation_mode == 'rainbow': return self.effect_rainbow() - if self.animation_mode == 'static': + elif self.animation_mode == 'breathing_rainbow': + return self.effect_breathing_rainbow() + elif self.animation_mode == 'static': return self.effect_static() else: self.off() @@ -275,34 +291,39 @@ class RGB: return self def effect_breathing(self): - RGBLIGHT_EFFECT_BREATHE_CENTER = 1.5 # 1.0-2.7 - RGBLIGHT_EFFECT_BREATHE_MAX = 100 # 0-255 # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ - # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L787 - self.val = floor((exp(sin((self.pos/255.0)*pi)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)* - (RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E))) - self.pos = (self.pos + 1) % 256; + # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L806 + self.val = floor((exp(sin((self.pos / 255.0) * pi)) - self.breath_center / M_E) * + (self.val_limit / (M_E - 1 / M_E))) + self.pos = (self.pos + self.animation_speed) % 256 self.set_hsv_fill(self.hue, self.sat, self.val) return self + def effect_breathing_rainbow(self): + if self.animation_step(): + self.increase_hue(self.animation_speed) + self.effect_breathing() + + return self + def effect_rainbow(self): - if self.animation_step(self): - self.increase_hue(self.hue, 1) + if self.animation_step(): + self.increase_hue(self.animation_speed) self.set_hsv_fill(self.hue, self.sat, self.val) return self def effect_rainbow_swirl(self): - interval = self.animation_step(self) + interval = self.animation_step() if interval: for i in range(0, self.num_pixels): self.hue = (360 / self.num_pixels * i + self.hue) % 360 self.set_hsv_fill(self.hue, self.sat, self.val) if interval % 2: - self.increase_hue(self.hue, 1) + self.increase_hue(self.animation_speed) else: - self.decrease_hue(self.hue, 1) + self.decrease_hue(self.animation_speed) return self diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index 8979510..b3f9915 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -29,6 +29,13 @@ keyboard.debug_enabled = True keyboard.pixel_pin = board.TX keyboard.num_pixels = 12 +keyboard.val_limit = 150 +keyboard.hue_step = 5 +keyboard.sat_step = 5 +keyboard.val_step = 5 +keyboard.hue_default = 260 +keyboard.animation_speed = 1 + OFF = (0, 0, 0) BLUE = (0, 0, 100) CYAN = (0, 100, 100) @@ -69,58 +76,74 @@ r3 = 4 def base(*args, **kwargs): - keyboard.pixel_state['animation_mode'] = 'breathing' - keyboard.pixels.fill(OFF) - keyboard.pixels.show() + ''' + keyboard.pixels.animation_mode = 'breathing' + keyboard.pixels.neopixel(OFF) + keyboard.pixels.neopixelshow() + ''' return df_pressed(*args, **kwargs) def layer1p(*args, **kwargs): - keyboard.pixel_state['animation_mode'] = 'User' - keyboard.pixels.fill(WHITE) - keyboard.pixels.show() + ''' + keyboard.pixels.animation_mode = 'User' + keyboard.pixels.neopixel.fill(WHITE) + keyboard.pixels.neopixel.show() + ''' return mo_pressed(*args, **kwargs) def layer1r(*args, **kwargs): - keyboard.pixel_state['animation_mode'] = 'breathing' - keyboard.pixels.fill(OFF) - keyboard.pixels.show() + ''' + keyboard.pixels.animation_mode = 'breathing' + keyboard.pixels.neopixel.fill(OFF) + keyboard.pixels.neopixel.show() + ''' return mo_released(*args, **kwargs) def layer2p(*args, **kwargs): - keyboard.pixel_state['animation_mode'] = 'User' - keyboard.pixels.fill(BLUE) - keyboard.pixels.show() + ''' + keyboard.pixels.animation_mode = 'User' + keyboard.pixels.neopixel.fill(BLUE) + keyboard.pixels.neopixel.show() + ''' return lt_pressed(*args, **kwargs) def layer2r(*args, **kwargs): - keyboard.pixel_state['animation_mode'] = 'breathing' - keyboard.pixels.fill(OFF) - keyboard.pixels.show() + ''' + keyboard.pixels.animation_mode = 'breathing' + keyboard.pixels.neopixel.fill(OFF) + keyboard.pixels.neopixel.show() + ''' return lt_released(*args, **kwargs) def layer3p(*args, **kwargs): - keyboard.pixel_state['animation_mode'] = 'User' - keyboard.pixels.fill(PURPLE) - keyboard.pixels.show() + ''' + keyboard.pixels.animation_mode = 'User' + keyboard.pixels.neopixel.fill(PURPLE) + keyboard.pixels.neopixel.show() + ''' return mo_pressed(*args, **kwargs) def layer3r(*args, **kwargs): - keyboard.pixel_state['animation_mode'] = 'breathing' - keyboard.pixels.fill(OFF) - keyboard.pixels.show() + ''' + keyboard.pixels.animation_mode = 'breathing' + keyboard.pixels.neopixel.fill(OFF) + keyboard.pixels.neopixel.show() + ''' return mo_released(*args, **kwargs) def gaming(*args, **kwargs): - keyboard.pixel_state['animation_mode'] = 'User' - keyboard.pixels.fill(CYAN) - keyboard.pixels.show() + ''' + keyboard.pixels.animation_mode = 'User' + keyboard.pixels.neopixel.fill(CYAN) + keyboard.pixels.neopixel.show() + ''' return df_pressed(*args, **kwargs) @@ -205,11 +228,11 @@ keyboard.keymap = [ ], [ # r3 - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.F10, KC.F11, KC.F12, KC.DEL], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], - [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], + [KC.GESC, KC.RGB_HUI, KC.RGB_HUD, KC.RGB_SAI, KC.RGB_SAD, KC.RGB_VAI, KC.RGB_VAD, _______, KC.F10, KC.F11, KC.F12, KC.DEL], + [KC.RGB_M_P, _______, _______, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], + [KC.RGB_M_B, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], + [KC.RGB_M_BR, _______, _______, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], + [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], ], ] From ad3430eeb636290d6c0439ec7b6e7e7b3fcb4d23 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 23 Feb 2019 14:03:13 -0800 Subject: [PATCH 07/32] Needs docs, but code is ready for review probably --- kmk/firmware.py | 5 +- kmk/handlers/stock.py | 9 ++++ kmk/keys.py | 1 + kmk/rgb.py | 65 +++++++++++++++++------- user_keymaps/kdb424/nyquist_converter.py | 6 ++- 5 files changed, 63 insertions(+), 23 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index ae0806e..1982156 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -105,6 +105,7 @@ class Firmware: val_step = 1 animation_speed = 1 breathe_center = 1.5 # 1.0-2.7 + knight_effect_length = 3 animation_mode = 'static' pixels = None @@ -226,10 +227,10 @@ class Firmware: self.pixels = rgb.RGB(self.pixel_pin, self.rgb_order, self.num_pixels, self.hue_step, self.sat_step, self.val_step, self.hue_default, self.sat_default, self.val_default, - self.breathe_center, self.val_limit, self.animation_mode + self.breathe_center, self.knight_effect_length, + self.val_limit, self.animation_mode, self.animation_speed ) - self.matrix = MatrixScanner( cols=self.col_pins, rows=self.row_pins, diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index b24ec10..f67a7ea 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -166,21 +166,30 @@ def rgb_vad(key, state, *args, **kwargs): def rgb_mode_static(key, state, *args, **kwargs): + state.config.pixels.effect_init = True state.config.pixels.animation_mode = 'static' return state def rgb_mode_breathe(key, state, *args, **kwargs): + state.config.pixels.effect_init = True state.config.pixels.animation_mode = 'breathing' return state def rgb_mode_breathe_rainbow(key, state, *args, **kwargs): + state.config.pixels.effect_init = True state.config.pixels.animation_mode = 'breathing_rainbow' return state def rgb_mode_rainbow(key, state, *args, **kwargs): + state.config.pixels.effect_init = True state.config.pixels.animation_mode = 'rainbow' return state + +def rgb_mode_knight(key, state, *args, **kwargs): + state.config.pixels.effect_init = True + state.config.pixels.animation_mode = 'knight' + return state diff --git a/kmk/keys.py b/kmk/keys.py index d74b0b4..40ed49a 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -639,6 +639,7 @@ make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static) make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe) make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow) make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'), on_press=handlers.rgb_mode_breathe_rainbow) +make_key(names=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight) make_key( names=('LEADER', 'LEAD'), on_press=handlers.leader_pressed, diff --git a/kmk/rgb.py b/kmk/rgb.py index 7b942b4..5514284 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -14,6 +14,7 @@ class RGB: enabled = True neopixel = None rgbw = False + reverse_animation = False disable_auto_write = False # Set by config @@ -22,13 +23,16 @@ class RGB: sat_step = 5 val_step = 5 breath_center = 1.5 # 1.0-2.7 + knight_effect_length = 4 val_limit = 255 animation_mode = 'static' + effect_init = False def __init__(self, pixel_pin, rgb_order, num_pixels, hue_step, sat_step, val_step, hue_default, sat_default, val_default, - breath_center, val_limit, animation_mode): + breath_center, knight_effect_length, + val_limit, animation_mode, animation_speed): try: import neopixel self.neopixel = neopixel.NeoPixel(pixel_pin, @@ -45,8 +49,10 @@ class RGB: self.sat = sat_default self.val = val_default self.breath_center = breath_center + self.knight_effect_length = knight_effect_length self.val_limit = val_limit self.animation_mode = animation_mode + self.animation_speed = animation_speed except ImportError as e: print(e) @@ -62,6 +68,7 @@ class RGB: 'animation_mode': self.animation_mode, 'time': self.time, 'intervals': self.intervals, + 'animation_mode': self.animation_mode, 'animation_speed': self.animation_speed, 'enabled': self.enabled, 'neopixel': self.neopixel, @@ -160,10 +167,9 @@ class RGB: ''' if self.neopixel: if self.rgbw: - self.neopixel.fill(self.hsv_to_rgbw(hue, sat, val)) + self.set_rgb_fill(self.hsv_to_rgbw(hue, sat, val)) else: - self.neopixel.fill(self.hsv_to_rgb(hue, sat, val)) - self.neopixel.show() + self.set_rgb_fill(self.hsv_to_rgb(hue, sat, val)) def set_rgb(self, rgb, index): ''' @@ -172,9 +178,10 @@ class RGB: :param index: Index of LED/Pixel ''' if self.neopixel: - self.neopixel[index] = rgb - if not self.disable_auto_write: - self.neopixel.show() + if index >=0 and index <= self.num_pixels - 1: + self.neopixel[index] = rgb + if not self.disable_auto_write: + self.neopixel.show() def set_rgb_fill(self, rgb): ''' @@ -183,7 +190,8 @@ class RGB: ''' if self.neopixel: self.neopixel.fill(rgb) - self.neopixel.show() + if not self.disable_auto_write: + self.neopixel.show() def increase_hue(self, step): ''' @@ -247,8 +255,7 @@ class RGB: Turns off all LEDs/Neopixels without changing stored values ''' if self.neopixel: - if not self.disable_auto_write: - self.set_hsv_fill(0, 0, 0) + self.set_hsv_fill(0, 0, 0) def show(self): ''' @@ -262,6 +269,8 @@ class RGB: Activates a "step" in the animation based on the active mode :return: Returns the new state in animation ''' + if self.effect_init: + self.init_effect() if self.enabled: if self.animation_mode == 'breathing': return self.effect_breathing() @@ -271,6 +280,8 @@ class RGB: return self.effect_breathing_rainbow() elif self.animation_mode == 'static': return self.effect_static() + elif self.animation_mode == 'knight': + return self.effect_knight() else: self.off() @@ -286,6 +297,11 @@ class RGB: else: return False + def init_effect(self): + self.pos = 0 + self.reverse_animation = False + self.effect_init = False + def effect_static(self): self.set_hsv_fill(self.hue, self.sat, self.val) return self @@ -314,16 +330,27 @@ class RGB: return self - def effect_rainbow_swirl(self): - interval = self.animation_step() - if interval: - for i in range(0, self.num_pixels): - self.hue = (360 / self.num_pixels * i + self.hue) % 360 - self.set_hsv_fill(self.hue, self.sat, self.val) + def effect_knight(self): + # Determine which LEDs should be lit up + self.disable_auto_write = True # Turn off instantly showing + self.off() # Fill all off + pos = floor(self.pos) - if interval % 2: - self.increase_hue(self.animation_speed) + # Set all pixels on in range of animation length offset by position + for i in range(pos, (pos + self.knight_effect_length)): + self.set_hsv(self.hue, self.sat, self.val, i) + + # Reverse animation when a boundary is hit + if pos >= self.num_pixels or pos - 1 < (self.knight_effect_length * -1): + self.reverse_animation = not self.reverse_animation + + if self.reverse_animation: + self.pos -= self.animation_speed / 5 else: - self.decrease_hue(self.animation_speed) + self.pos += self.animation_speed / 5 + + # Show final results + self.disable_auto_write = False # Resume showing changes + self.show() return self diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index b3f9915..754ffd4 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -34,7 +34,9 @@ keyboard.hue_step = 5 keyboard.sat_step = 5 keyboard.val_step = 5 keyboard.hue_default = 260 -keyboard.animation_speed = 1 +keyboard.knight_effect_length = 4 +keyboard.animation_mode = 'knight' +keyboard.animation_speed = 2 OFF = (0, 0, 0) BLUE = (0, 0, 100) @@ -230,7 +232,7 @@ keyboard.keymap = [ # r3 [KC.GESC, KC.RGB_HUI, KC.RGB_HUD, KC.RGB_SAI, KC.RGB_SAD, KC.RGB_VAI, KC.RGB_VAD, _______, KC.F10, KC.F11, KC.F12, KC.DEL], [KC.RGB_M_P, _______, _______, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], - [KC.RGB_M_B, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], + [KC.RGB_M_K, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], [KC.RGB_M_BR, _______, _______, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], ], From 1751cce29930d431693c38cc59bcb14bf88994a3 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Fri, 21 Jun 2019 16:41:58 -0700 Subject: [PATCH 08/32] code cleanup to pass lint and some for flake8 --- kmk/firmware.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index 1982156..389bde5 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -25,6 +25,7 @@ import kmk.util # isort:skip import busio # isort:skip import supervisor # isort:skip +from kmk import rgb # isort:skip from kmk.consts import LeaderMode, UnicodeMode # isort:skip from kmk.hid import USB_HID # isort:skip from kmk.internal_state import InternalState # isort:skip @@ -42,9 +43,7 @@ import kmk.matrix # isort:skip import kmk.hid # isort:skip import kmk.internal_state # isort:skip -# GC runs automatically after CircuitPython imports. If we ever go back to -# supporting MicroPython, we'll need a GC here (and probably after each -# chunk of the above) +# GC runs automatically after CircuitPython imports. # Thanks for sticking around. Now let's do real work, starting below @@ -142,10 +141,10 @@ class Firmware: self._send_hid() def _handle_matrix_report(self, update=None): - ''' + """ Bulk processing of update code for each cycle :param update: - ''' + """ if update is not None: self._state.matrix_changed( update[0], @@ -166,7 +165,6 @@ class Firmware: update = bytearray(self.uart.read(3)) # Built in debug mode switch if update == b'DEB': - # TODO Pretty up output print(self.uart.readline()) return None return update @@ -174,11 +172,11 @@ class Firmware: return None def _send_debug(self, message): - ''' + """ Prepends DEB and appends a newline to allow debug messages to be detected and handled differently than typical keypresses. :param message: Debug message - ''' + """ if self.uart is not None: self.uart.write('DEB') self.uart.write(message, '\n') @@ -202,7 +200,6 @@ class Firmware: else: return busio.UART(tx=pin, rx=None, timeout=timeout) - def go(self): assert self.keymap, 'must define a keymap with at least one row' assert self.row_pins, 'no GPIO pins defined for matrix rows' @@ -216,7 +213,7 @@ class Firmware: self.col_pins = list(reversed(self.col_pins)) if self.split_side == "Left": - self.split_master_left = self._master_half() + self.split_master_left = self._master_half() elif self.split_side == "Right": self.split_master_left = not self._master_half() @@ -228,8 +225,8 @@ class Firmware: self.hue_step, self.sat_step, self.val_step, self.hue_default, self.sat_default, self.val_default, self.breathe_center, self.knight_effect_length, - self.val_limit, self.animation_mode, self.animation_speed - ) + self.val_limit, self.animation_mode, self.animation_speed, + ) self.matrix = MatrixScanner( cols=self.col_pins, @@ -292,5 +289,4 @@ class Firmware: if self.pixels.animation_mode is not None: self.pixels = self.pixels.animate() - gc.collect() From 9fbad17ed4c8383543887b2e6f81a352e2c71325 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 23 Feb 2019 15:12:50 -0800 Subject: [PATCH 09/32] code cleanup to pass lint and some for flake8 --- kmk/internal_state.py | 6 +- kmk/keys.py | 3 +- kmk/rgb.py | 75 ++++++++++++------------ user_keymaps/kdb424/nyquist_converter.py | 5 +- 4 files changed, 43 insertions(+), 46 deletions(-) diff --git a/kmk/internal_state.py b/kmk/internal_state.py index d1edb9e..9ed6865 100644 --- a/kmk/internal_state.py +++ b/kmk/internal_state.py @@ -171,8 +171,7 @@ class InternalState: return self if ( - changed_key not in self.tap_dance_counts or - not self.tap_dance_counts[changed_key] + changed_key not in self.tap_dance_counts or not self.tap_dance_counts[changed_key] ): self.tap_dance_counts[changed_key] = 1 self.set_timeout(self.config.tap_time, lambda: self._end_tap_dance(changed_key)) @@ -257,8 +256,7 @@ class InternalState: for key in keys_pressed: if ( - self.config.leader_mode == LeaderMode.ENTER_ACTIVE and - key == KC.ENT + self.config.leader_mode == LeaderMode.ENTER_ACTIVE and key == KC.ENT ): self._handle_leader_sequence() break diff --git a/kmk/keys.py b/kmk/keys.py index 40ed49a..2f543fa 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -638,7 +638,8 @@ make_key(names=('RGB_VAD',), on_press=handlers.rgb_vad) make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static) make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe) make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow) -make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'), on_press=handlers.rgb_mode_breathe_rainbow) +make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'), + on_press=handlers.rgb_mode_breathe_rainbow) make_key(names=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight) make_key( names=('LEADER', 'LEAD'), diff --git a/kmk/rgb.py b/kmk/rgb.py index 5514284..85a0a0a 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -1,6 +1,6 @@ -from math import sin, exp, pi, floor -from math import e as M_E import time +from math import e as M_E +from math import exp, floor, pi, sin class RGB: @@ -65,7 +65,6 @@ class RGB: 'hue': self.hue, 'sat': self.sat, 'val': self.val, - 'animation_mode': self.animation_mode, 'time': self.time, 'intervals': self.intervals, 'animation_mode': self.animation_mode, @@ -81,13 +80,13 @@ class RGB: return floor(time.monotonic() * 10) def hsv_to_rgb(self, hue, sat, val): - ''' + """ Converts HSV values, and returns a tuple of RGB values :param hue: :param sat: :param val: :return: (r, g, b) - ''' + """ r = 0 g = 0 b = 0 @@ -133,24 +132,24 @@ class RGB: return floor(r), floor(g), floor(b) def hsv_to_rgbw(self, hue, sat, val): - ''' + """ Converts HSV values, and returns a tuple of RGBW values :param hue: :param sat: :param val: :return: (r, g, b, w) - ''' + """ rgb = self.hsv_to_rgb(hue, sat, val) return rgb[0], rgb[1], rgb[2], min(rgb) def set_hsv(self, hue, sat, val, index): - ''' + """ Takes HSV values and displays it on a single LED/Neopixel :param hue: :param sat: :param val: :param index: Index of LED/Pixel - ''' + """ if self.neopixel: if self.rgbw: self.set_rgb(self.hsv_to_rgbw(hue, sat, val), index) @@ -158,13 +157,12 @@ class RGB: self.set_rgb(self.hsv_to_rgb(hue, sat, val), index) def set_hsv_fill(self, hue, sat, val): - ''' + """ Takes HSV values and displays it on all LEDs/Neopixels :param hue: :param sat: :param val: - :param index: Index of LED/Pixel - ''' + """ if self.neopixel: if self.rgbw: self.set_rgb_fill(self.hsv_to_rgbw(hue, sat, val)) @@ -172,103 +170,102 @@ class RGB: self.set_rgb_fill(self.hsv_to_rgb(hue, sat, val)) def set_rgb(self, rgb, index): - ''' + """ Takes an RGB or RGBW and displays it on a single LED/Neopixel :param rgb: RGB or RGBW :param index: Index of LED/Pixel - ''' - if self.neopixel: - if index >=0 and index <= self.num_pixels - 1: - self.neopixel[index] = rgb - if not self.disable_auto_write: - self.neopixel.show() + """ + if self.neopixel and 0 <= index <= self.num_pixels - 1: + self.neopixel[index] = rgb + if not self.disable_auto_write: + self.neopixel.show() def set_rgb_fill(self, rgb): - ''' + """ Takes an RGB or RGBW and displays it on all LEDs/Neopixels :param rgb: RGB or RGBW - ''' + """ if self.neopixel: self.neopixel.fill(rgb) if not self.disable_auto_write: self.neopixel.show() def increase_hue(self, step): - ''' + """ Increases hue by step amount rolling at 360 and returning to 0 :param step: - ''' + """ self.hue = (self.hue + step) % 360 def decrease_hue(self, step): - ''' + """ Decreases hue by step amount rolling at 0 and returning to 360 :param step: - ''' + """ if (self.hue - step) <= 0: self.hue = (self.hue + 360 - step) % 360 else: self.hue = (self.hue - step) % 360 def increase_sat(self, step): - ''' + """ Increases saturation by step amount stopping at 100 :param step: - ''' + """ if self.sat + step >= 100: self.sat = 100 else: self.sat += step def decrease_sat(self, step): - ''' + """ Decreases saturation by step amount stopping at 0 :param step: - ''' + """ if (self.sat - step) <= 0: self.sat = 0 else: self.sat -= step def increase_val(self, step): - ''' + """ Increases value by step amount stopping at 100 :param step: - ''' + """ if (self.val + step) >= 100: self.val = 100 else: self.val += step def decrease_val(self, step): - ''' + """ Decreases value by step amount stopping at 0 :param step: - ''' + """ if (self.val - step) <= 0: self.val = 0 else: self.val -= step def off(self): - ''' + """ Turns off all LEDs/Neopixels without changing stored values - ''' + """ if self.neopixel: self.set_hsv_fill(0, 0, 0) def show(self): - ''' + """ Turns on all LEDs/Neopixels without changing stored values - ''' + """ if self.neopixel: self.neopixel.show() def animate(self): - ''' + """ Activates a "step" in the animation based on the active mode :return: Returns the new state in animation - ''' + """ if self.effect_init: self.init_effect() if self.enabled: diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index 754ffd4..3d4e760 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -2,8 +2,9 @@ import board import busio from kmk.consts import DiodeOrientation, LeaderMode, UnicodeMode -from kmk.handlers.layers import df_pressed, mo_pressed, mo_released, lt_pressed, lt_released -from kmk.handlers.sequences import (compile_unicode_string_sequences) +from kmk.handlers.layers import (df_pressed, lt_pressed, lt_released, + mo_pressed, mo_released) +from kmk.handlers.sequences import compile_unicode_string_sequences from kmk.keys import KC, layer_key_validator, make_argumented_key from kmk.mcus.circuitpython_samd51 import Firmware from kmk.pins import Pin as P From 3ae7432de09f7a9c19feae41e754b864f4f040e8 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 23 Feb 2019 19:35:00 -0800 Subject: [PATCH 10/32] Massive docs update --- docs/flashing.md | 41 ++++++++++++------ docs/hardware.md | 7 +--- docs/keycodes.md | 37 ++++++++++++++++ docs/rgb.md | 105 ++++++++++++++++++++++++++++++++++++++++++++++ docs/sequences.md | 2 +- docs/tapdance.md | 2 +- kmk/rgb.py | 6 +-- 7 files changed, 177 insertions(+), 23 deletions(-) create mode 100644 docs/rgb.md diff --git a/docs/flashing.md b/docs/flashing.md index 2b2d377..121f5f5 100644 --- a/docs/flashing.md +++ b/docs/flashing.md @@ -5,22 +5,39 @@ as appropriate (see [Adafruit's documentation](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython), though it doesn't cover all CircuitPython boards - you may need to glance around the CircuitPython source or ask on Discord). We primarily target CircuitPython -4.0-alpha1 and above, though many features should work on 3.x. You'll only need +4.0-alpha1 to 4.0-alpha3. You'll only need to flash CircuitPython once (unless we update our baseline supported version). After CircuitPython has been flashed, a `CIRCUITPY` drive should show up on your -computer (some Linux/BSD users without drive automounting will want to poke -around `dmesg` to find the drive identifier and mount this drive manually -somewhere - ex. `mkdir -p ~/mnt && sudo mount -o uid=1000,gid=1000 /dev/sdf1 -~/mnt`, where `uid` and `gid` are your user ID and primary group ID, as found in -`id -u` and `id -g`). Take note of the path that this is mounted to (for MacOS -users, this will probably look something like `/Volumes/CIRCUITPY`). +computer most likely. If not, check out the troubleshooting section below. -To "flash" all of KMK, your keymap, and a basic `main.py` that will start -everything up, run `make MOUNTPOINT=/path/to/wherever -USER_KEYMAP=path/to/keymap.py`. For example, if my `CIRCUITPY` volume is mounted -to `~/mnt`, I might flash my development breadboard with the following: +# Windows +Currently, we do not have an official "flasher" for windows. You can manually install it fairly easily and we recommend coming to the KMK discord/Matrix server if you have any questions. An actual tool is in development. Alternatively, you can flash from any linux like tool set (Cygwin, WSL, ect) using the Linux guide below. + +# Mac +Until an interactive installer is created, please follow the linux instructions replacing /mnt with /Volumes + +# Linux + +While in the directory for kmk, simply run this, changing the mount point and keymap name to whatever is appropriate. ```sh -make MOUNTPOINT=~/mnt USER_KEYMAP=user_keymaps/klardotsh/itsybitsy_m4_express/threethree.py +make MOUNTPOINT=/mnt/CIRCUITPY USER_KEYMAP=user_keymaps/nameofyourkeymap.py ``` + +# Troubleshooting +## Windows +Please join us on the Discord/Matrix server and we can help you out + +## Mac +Please join us on the Discord/Matrix server and we can help you out + +## Linux/BSD +Check to see if your drive may have mounted elsewhere with a gui tool. Most will give you the directory in the GUI. +If it's not mounted, you can read up on how to mount a drive manually here. https://wiki.archlinux.org/index.php/File_systems#Mount_a_file_system + +It would look something like this + +`sudo mount -o uid=1000,gid=1000 /dev/sdf1 ~/mnt` + +If you still are having issues, come say hi in the Discord/Matrix servers and we'll help you out. diff --git a/docs/hardware.md b/docs/hardware.md index d7e0c3c..4aed0b1 100644 --- a/docs/hardware.md +++ b/docs/hardware.md @@ -5,10 +5,6 @@ | [Adafruit Feather M4 Express](https://www.adafruit.com/product/3857) | Atmel SAMD51 (Cortex M4F) | CircuitPython | An economical solution for basic USB keyboards | | [Adafruit ItsyBitsy M4 Express](https://www.adafruit.com/product/3800) | Atmel SAMD51 (Cortex M4F) | CircuitPython | A smaller solution for basic USB keyboards | -## Community Supported -| Board | Chipset | Python Platform | Maintainer | Notes | -| ----- | ------- | --------------- | ----- | ----- | -| [pyboard v1.1](https://www.adafruit.com/product/2390) | STM32F405RG (Cortex M4F) | MicroPython | kdb424 | Very large and expensive, and has ram limitations. | ## Support Planned/WIP | Board | Chipset | Python Platform | Notes | @@ -20,7 +16,6 @@ ## Unsupported Devices - Here's a list of problematic, but possibly usable microcontrollers: | Board | Chipset | Python Platform | Notes | @@ -38,7 +33,7 @@ keyboards/microcontrollers. The base requirements for device support ## Secondary Support -In the future, secondary support for lesser contollers is planned. One of +In the future, secondary support for lesser controllers is planned. One of these cases is the pro micro being used for a slave half of a split keyboard while all actual work is being done by a supported board. This could also be used to convert boards that use USB or i2c that run lesser chips to a KMK diff --git a/docs/keycodes.md b/docs/keycodes.md index a8d4fa0..4d0a7f3 100644 --- a/docs/keycodes.md +++ b/docs/keycodes.md @@ -230,3 +230,40 @@ |`KC.RALT(kc)`|Hold Right Alt and press `kc` | |`KC.RGUI(kc)`|Hold Right GUI and press `kc` | +## [RGB/Underglow] + +|Key |Aliases |Description | +|-----------------------------|-------------------|----------------------------| +|`KC.RGB_TOG` | |Toggles RGB | +|`KC.RGB_HUI` | |Increase Hue | +|`KC.RGB_HUD` | |Decrease Hue | +|`KC.RGB_SAI` | |Increase Saturation | +|`KC.RGB_SAD` | |Decrease Saturation | +|`KC.RGB_VAI` | |Increase Value | +|`KC.RGB_VAD` | |Decrease Value | +|`KC.RGB_MODE_PLAIN` |`RGB_M_P` |Static RGB | +|`KC.RGB_MODE_BREATHE` |`RGB_M_B` |Breathing animation | +|`KC.RGB_MODE_RAINBOW` |`RGB_M_R` |Rainbow animation | +|`KC.RGB_MODE_BREATHE_RAINBOW`|`RGB_M_BR` |Breathing rainbow animation | +|`KC.RGB_MODE_KNIGHT` |`RGB_M_K` |Knightrider animation | + + +## [Mod-Tap Keys] NOT IMPLEMENTED AT THIS TIME + +|Key |Aliases |Description | +|------------|---------------------------------------|-------------------------------------------------------| +|`LCTL_T(kc)`|`CTL_T(kc)` |Left Control when held, `kc` when tapped | +|`RCTL_T(kc)`| |Right Control when held, `kc` when tapped | +|`LSFT_T(kc)`|`SFT_T(kc)` |Left Shift when held, `kc` when tapped | +|`RSFT_T(kc)`| |Right Shift when held, `kc` when tapped | +|`LALT_T(kc)`|`ALT_T(kc)` |Left Alt when held, `kc` when tapped | +|`RALT_T(kc)`|`ALGR_T(kc)` |Right Alt when held, `kc` when tapped | +|`LGUI_T(kc)`|`LCMD_T(kc)`, `RWIN_T(kc)`, `GUI_T(kc)`|Left GUI when held, `kc` when tapped | +|`RGUI_T(kc)`|`RCMD_T(kc)`, `RWIN_T(kc)` |Right GUI when held, `kc` when tapped | +|`C_S_T(kc)` | |Left Control and Shift when held, `kc` when tapped | +|`MEH_T(kc)` | |Left Control, Shift and Alt when held, `kc` when tapped| +|`LCAG_T(kc)`| |Left Control, Alt and GUI when held, `kc` when tapped | +|`RCAG_T(kc)`| |Right Control, Alt and GUI when held, `kc` when tapped | +|`ALL_T(kc)` | |Left Control, Shift, Alt and GUI when held, `kc` when tapped - more info [here](http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/)| +|`SGUI_T(kc)`|`SCMD_T(kc)`, `SWIN_T(kc)` |Left Shift and GUI when held, `kc` when tapped | +|`LCA_T(kc)` | |Left Control and Alt when held, `kc` when tapped | diff --git a/docs/rgb.md b/docs/rgb.md new file mode 100644 index 0000000..10dbcc3 --- /dev/null +++ b/docs/rgb.md @@ -0,0 +1,105 @@ +# RGB/Underglow/Neopixel +Want your keyboard to shine? Add some lights! +This does require the neopixel library from Adafruit. This can be downloaded here https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/master/neopixel.py + +Simply put this in the "root" of your circuitpython device. If unsure, it's the folder with main.py in it, and should be the first folder you see when you open the device. + +Currently we support the following addressable LEDs: + + * WS2811, WS2812, WS2812B, WS2812C, etc. + * SK6812, SK6812MINI, SK6805 + * All neopixels + +## Usage +At minimum you will need to make sure that these are set in either your keymap ip importing an MCU directly, or it should be included in the predefined boards if they support them. + +|Define |Description | +|---------------------|---------------------------------------------| +|`keyboard.pixel_pin` |The pin connected to the data pin of the LEDs| +|`keyboard.num_pixels`|The number of LEDs connected | + +Then you should be able to use the keycodes below to change the RGB lighting to your liking. + +### Color Selection + +KMK uses [Hue, Saturation, and Value](https://en.wikipedia.org/wiki/HSL_and_HSV) to select colors rather than RGB. The color wheel below demonstrates how this works. + +HSV Color Wheel + +Changing the **Hue** cycles around the circle. +Changing the **Saturation** moves between the inner and outer sections of the wheel, affecting the intensity of the color. +Changing the **Value** sets the overall brightness. + +## [Keycodes] + +|Key |Aliases |Description | +|-----------------------------|-------------------|----------------------------| +|`KC.RGB_TOG` | |Toggles RGB | +|`KC.RGB_HUI` | |Increase Hue | +|`KC.RGB_HUD` | |Decrease Hue | +|`KC.RGB_SAI` | |Increase Saturation | +|`KC.RGB_SAD` | |Decrease Saturation | +|`KC.RGB_VAI` | |Increase Value | +|`KC.RGB_VAD` | |Decrease Value | +|`KC.RGB_MODE_PLAIN` |`RGB_M_P` |Static RGB | +|`KC.RGB_MODE_BREATHE` |`RGB_M_B` |Breathing animation | +|`KC.RGB_MODE_RAINBOW` |`RGB_M_R` |Rainbow animation | +|`KC.RGB_MODE_BREATHE_RAINBOW`|`RGB_M_BR` |Breathing rainbow animation | +|`KC.RGB_MODE_KNIGHT` |`RGB_M_K` |Knightrider animation | + +## Configuration +|Define |Default |Description | +|---------------------|-------------|-----------------------------------------------------------------------------| +|`keyboard.hue_step` |`10` |The number of steps to cycle through the hue by | +|`keyboard.sat_step` |`17` |The number of steps to increment the saturation by | +|`keyboard.val_step` |`17` |The number of steps to increment the brightness by | +|`keyboard.val_limit` |`255` |The maximum brightness level | + +## Functions + +If you want to create your own animations, or for example, change the lighting in a macro, or a layer switch, here are some functions that are available. + +|Function |Description | +|--------------------------------------------------|--------------------------------------------------------------------------------------------| +|`keyboard.pixels.set_hsv_fill(hue, sat, val)` |Fills all LED's with HSV values | +|`keyboard.pixels.set_hsv(hue, sat, val, index)` |Sets a single LED with HSV value | +|`keyboard.pixels.set_rgb_fill((r, g, b))` |Fills all LED's with RGB(W) values | +|`keyboard.pixels.set_rgb((r, g, b), index)` |Set's a single LED with RGB(W) values | +|`keyboard.pixels.increase_hue(step)` |Increases hue by a given step | +|`keyboard.pixels.decrease_hue(step)` |Decreases hue by a given step | +|`keyboard.pixels.increase_sat(step)` |Increases saturation by a given step | +|`keyboard.pixels.decrease_sat(step)` |Decreases saturation by a given step | +|`keyboard.pixels.increase_val(step)` |Increases value (brightness) by a given step | +|`keyboard.pixels.decrease_val(step)` |Decreases value (brightness) by a given step | +|`keyboard.pixels.off()` |Turns all LED's off | +|`keyboard.pixels.show()` |Displays all stored configuration for LED's. Useful with disable_auto_write explained below | +|`keyboard.pixels.time_ms()` |Returns a time in ms since the board has booted. Useful for start/stop timers | + +Other settings that are useful that can be changed. +## Configuration +|Define |Default |Description | +|------------------------------|-------------|---------------------------------------------------------------------------------------------------------| +|`keyboard.hue` |`0` |Sets the hue from 0-360 | +|`keyboard.sat` |`100` |Sets the saturation from 0-100 | +|`keyboard.val` |`80` |Sets the brightness from 1-255 | +|`keyboard.disable_auto_write` |`False` |When True, disables showing changes. Good for setting multiple LED's before a visible update | +|`keyboard.reverse_animation` |`False` |If true, some animations will run in reverse. Can be safely used in user animations | +|`keyboard.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid | +|`keyboard.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5 | + +## Built-in Animation Configuration +|Define |Default |Description | +|-------------------------------|-------------|-------------------------------------------------------------------------------------| +|`keyboard.breath_center` |`1.5` |Used to calculate the curve for the breathing animation. Anywhere from 1.0 - 2.7 is valid| +|`keyboard.knight_effect_length`|`4` |The number of LEDs to light up for the "Knight" animation | + +## Hardware Modification + +To add LED's to boards that don't support them, you will have to add a 3 wires. The power wire will run on 3.3v or 5v (depending on the LED), ground, and data pins will need added to an unused pin on your microcontroller unless your keyboard has specific solder points for them. With those 3 wires connected, set the pixel_pin as described above, and you are ready to use your LED's/Neopixels. + +## ADVANCED USAGE +If you wish to interact with these as you would normal LED's and do not want help from KMK, you can disable all helper functions from working and access the neopixel object directly like this. +```python +keyboard.pixels.disabse_auto_write = True +keyboard.pixels.neopixel() # <-- This is the neopixel object +``` diff --git a/docs/sequences.md b/docs/sequences.md index 3a18523..30b80de 100644 --- a/docs/sequences.md +++ b/docs/sequences.md @@ -1,4 +1,4 @@ -# Sequences +# Sequences/Macros Sequences are used for sending multiple keystrokes in a single action, and can be used for things like unicode characters (even emojis! 🇨🇦), lorei epsum diff --git a/docs/tapdance.md b/docs/tapdance.md index 0f79078..bf73daf 100644 --- a/docs/tapdance.md +++ b/docs/tapdance.md @@ -1,6 +1,6 @@ # Tap Dance -Tap dance is a way to allow a single physical key to work as multple logical +Tap dance is a way to allow a single physical key to work as multiple logical keys / actions without using layers. With basic tap dance, you can trigger these "nested" keys or macros through a series of taps of the physical key within a given timeout. diff --git a/kmk/rgb.py b/kmk/rgb.py index 85a0a0a..4257fd7 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -19,9 +19,9 @@ class RGB: # Set by config num_pixels = 0 - hue_step = 1 - sat_step = 5 - val_step = 5 + hue_step = 10 + sat_step = 17 + val_step = 17 breath_center = 1.5 # 1.0-2.7 knight_effect_length = 4 val_limit = 255 From 5c8c2e97fd76b1b1f08ccd4c4cc5b7cd46ce272b Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 23 Feb 2019 20:03:42 -0800 Subject: [PATCH 11/32] Resolved many things --- docs/flashing.md | 4 ++-- docs/rgb.md | 2 -- user_keymaps/kdb424/nyquist_converter.py | 10 +++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/flashing.md b/docs/flashing.md index 121f5f5..4b9c971 100644 --- a/docs/flashing.md +++ b/docs/flashing.md @@ -5,7 +5,7 @@ as appropriate (see [Adafruit's documentation](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython), though it doesn't cover all CircuitPython boards - you may need to glance around the CircuitPython source or ask on Discord). We primarily target CircuitPython -4.0-alpha1 to 4.0-alpha3. You'll only need +4.0-alpha1 to 4.0-alpha2. You'll only need to flash CircuitPython once (unless we update our baseline supported version). After CircuitPython has been flashed, a `CIRCUITPY` drive should show up on your @@ -34,7 +34,7 @@ Please join us on the Discord/Matrix server and we can help you out ## Linux/BSD Check to see if your drive may have mounted elsewhere with a gui tool. Most will give you the directory in the GUI. -If it's not mounted, you can read up on how to mount a drive manually here. https://wiki.archlinux.org/index.php/File_systems#Mount_a_file_system +If it's not mounted, you can read up on how to mount a drive manually [here](https://wiki.archlinux.org/index.php/File_systems#Mount_a_file_system) It would look something like this diff --git a/docs/rgb.md b/docs/rgb.md index 10dbcc3..382b5c5 100644 --- a/docs/rgb.md +++ b/docs/rgb.md @@ -24,8 +24,6 @@ Then you should be able to use the keycodes below to change the RGB lighting to KMK uses [Hue, Saturation, and Value](https://en.wikipedia.org/wiki/HSL_and_HSV) to select colors rather than RGB. The color wheel below demonstrates how this works. -HSV Color Wheel - Changing the **Hue** cycles around the circle. Changing the **Saturation** moves between the inner and outer sections of the wheel, affecting the intensity of the color. Changing the **Value** sets the overall brightness. diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index 3d4e760..972942d 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -231,11 +231,11 @@ keyboard.keymap = [ ], [ # r3 - [KC.GESC, KC.RGB_HUI, KC.RGB_HUD, KC.RGB_SAI, KC.RGB_SAD, KC.RGB_VAI, KC.RGB_VAD, _______, KC.F10, KC.F11, KC.F12, KC.DEL], - [KC.RGB_M_P, _______, _______, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], - [KC.RGB_M_K, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], - [KC.RGB_M_BR, _______, _______, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], - [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], + [KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, _______, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL], + [_______, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], + [_______, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], + [_______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], + [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], ], ] From f65ea1e84192cee4e380bc8e2cf8f6a73176ae60 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sun, 24 Feb 2019 22:32:13 -0800 Subject: [PATCH 12/32] Added 2 more keys, stripped unused cruft, and added more docs. --- docs/examples.md | 33 ++++++++++++++++++++++++ docs/rgb.md | 17 ++++++++++-- kmk/handlers/stock.py | 20 +++++++------- kmk/keys.py | 4 +-- kmk/rgb.py | 22 +++++++++++++++- user_keymaps/kdb424/nyquist_converter.py | 10 +++---- 6 files changed, 86 insertions(+), 20 deletions(-) create mode 100644 docs/examples.md diff --git a/docs/examples.md b/docs/examples.md new file mode 100644 index 0000000..0d493bb --- /dev/null +++ b/docs/examples.md @@ -0,0 +1,33 @@ +# Examples +Here you can find some examples of what some users have created in their personal keyboard configs. These are here to +help you understand how some of the tools may be used. + +## Changing LED color based on layers +This allows you to create a layer key that also changes colors when pushing a layer key, and restore turn off the lights +when you release the layer key. The example uses the MO though any layer switch keys can be used if imported. Just use the +LAYER_1 key in your keymap, and it's ready to go! You can change animations, colors, or anything in there. + +```python +from kmk.handlers.layers import (mo_pressed, mo_released) +from kmk.keys import KC, layer_key_validator, make_argumented_key + + +def layer1p(*args, **kwargs): + keyboard.pixels.set_hsv_fill(100, 100, 100) + return mo_pressed(*args, **kwargs) + + +def layer1r(*args, **kwargs): + keyboard.pixels.set_hsv_fill.fill(0, 0, 0) + return mo_released(*args, **kwargs) + +make_argumented_key( + validator=layer_key_validator, + names=('LAYER_1',), + on_press=layer1p, + on_release=layer1r, +) + +LAYER_1 = KC.LAYER_1(1) + +``` \ No newline at end of file diff --git a/docs/rgb.md b/docs/rgb.md index 382b5c5..164e93c 100644 --- a/docs/rgb.md +++ b/docs/rgb.md @@ -1,6 +1,7 @@ # RGB/Underglow/Neopixel Want your keyboard to shine? Add some lights! -This does require the neopixel library from Adafruit. This can be downloaded here https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/master/neopixel.py +This does require the neopixel library from Adafruit. This can be downloaded [here](https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/6e35cd2b40575a20e2904b096508325cef4a71d3/neopixel.py). +It is part of the [Adafruit CircuitPython Bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle). Simply put this in the "root" of your circuitpython device. If unsure, it's the folder with main.py in it, and should be the first folder you see when you open the device. @@ -39,6 +40,8 @@ Changing the **Value** sets the overall brightness. |`KC.RGB_SAD` | |Decrease Saturation | |`KC.RGB_VAI` | |Increase Value | |`KC.RGB_VAD` | |Decrease Value | +|`KC.RGB_ANI` | |Increase animation speed | +|`KC.RGB_AND` | |Decrease animation speed | |`KC.RGB_MODE_PLAIN` |`RGB_M_P` |Static RGB | |`KC.RGB_MODE_BREATHE` |`RGB_M_B` |Breathing animation | |`KC.RGB_MODE_RAINBOW` |`RGB_M_R` |Rainbow animation | @@ -48,6 +51,7 @@ Changing the **Value** sets the overall brightness. ## Configuration |Define |Default |Description | |---------------------|-------------|-----------------------------------------------------------------------------| +|`keyboard.rgb_order` |`(1, 0, 2)` |The order of the pixels R G B, and optionally white. Example(1, 0, 2, 3) | |`keyboard.hue_step` |`10` |The number of steps to cycle through the hue by | |`keyboard.sat_step` |`17` |The number of steps to increment the saturation by | |`keyboard.val_step` |`17` |The number of steps to increment the brightness by | @@ -69,6 +73,8 @@ If you want to create your own animations, or for example, change the lighting i |`keyboard.pixels.decrease_sat(step)` |Decreases saturation by a given step | |`keyboard.pixels.increase_val(step)` |Increases value (brightness) by a given step | |`keyboard.pixels.decrease_val(step)` |Decreases value (brightness) by a given step | +|`keyboard.pixels.increase_ani()` |Increases animation speed by 1. Maximum 10 | +|`keyboard.pixels.decrease_ani()` |Decreases animation speed by 1. Minimum 10 | |`keyboard.pixels.off()` |Turns all LED's off | |`keyboard.pixels.show()` |Displays all stored configuration for LED's. Useful with disable_auto_write explained below | |`keyboard.pixels.time_ms()` |Returns a time in ms since the board has booted. Useful for start/stop timers | @@ -83,7 +89,7 @@ Other settings that are useful that can be changed. |`keyboard.disable_auto_write` |`False` |When True, disables showing changes. Good for setting multiple LED's before a visible update | |`keyboard.reverse_animation` |`False` |If true, some animations will run in reverse. Can be safely used in user animations | |`keyboard.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid | -|`keyboard.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5 | +|`keyboard.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. | ## Built-in Animation Configuration |Define |Default |Description | @@ -101,3 +107,10 @@ If you wish to interact with these as you would normal LED's and do not want hel keyboard.pixels.disabse_auto_write = True keyboard.pixels.neopixel() # <-- This is the neopixel object ``` + +## Troubleshooting +### Incorrect colors +If your colors are incorrect, check the pixel order of your specific LED's. Here are some common ones. + * WS2811, WS2812, WS2812B, WS2812C are all GRB (1, 0, 2) + * SK6812, SK6812MINI, SK6805 are all GRB (1, 0, 2) + * Neopixels will vary depending on which one you buy. It will be listed on the product page. diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index f67a7ea..3dc7d85 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -125,16 +125,6 @@ def rgb_tog(key, state, *args, **kwargs): return state -def rgb_forward(key, state, *args, **kwargs): - # TODO - return state - - -def rgb_reverse(key, state, *args, **kwargs): - # TODO - return state - - def rgb_hui(key, state, *args, **kwargs): state.config.pixels.increase_hue(state.config.pixels.hue_step) return state @@ -165,6 +155,16 @@ def rgb_vad(key, state, *args, **kwargs): return state +def rgb_ani(key, state, *args, **kwargs): + state.config.pixels.increase_ani() + return state + + +def rgb_and(key, state, *args, **kwargs): + state.config.pixels.decrease_ani() + return state + + def rgb_mode_static(key, state, *args, **kwargs): state.config.pixels.effect_init = True state.config.pixels.animation_mode = 'static' diff --git a/kmk/keys.py b/kmk/keys.py index 2f543fa..2e2b6ff 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -627,14 +627,14 @@ make_key(names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.ge make_key(names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released) make_key(names=('GESC', 'GRAVE_ESC'), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released) make_key(names=('RGB_TOG',), on_press=handlers.rgb_tog) -make_key(names=('RGB_MODE_FORWARD', 'RGB_MOD'), on_press=handlers.rgb_forward) -make_key(names=('RGB_MODE_REVERSE', 'RGB_RMOD'), on_press=handlers.rgb_reverse) make_key(names=('RGB_HUI',), on_press=handlers.rgb_hui) make_key(names=('RGB_HUD',), on_press=handlers.rgb_hud) make_key(names=('RGB_SAI',), on_press=handlers.rgb_sai) make_key(names=('RGB_SAD',), on_press=handlers.rgb_sad) make_key(names=('RGB_VAI',), on_press=handlers.rgb_vai) make_key(names=('RGB_VAD',), on_press=handlers.rgb_vad) +make_key(names=('RGB_ANI',), on_press=handlers.rgb_ani) +make_key(names=('RGB_AND',), on_press=handlers.rgb_and) make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static) make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe) make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow) diff --git a/kmk/rgb.py b/kmk/rgb.py index 4257fd7..b9a5eb1 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -77,7 +77,7 @@ class RGB: return ret def time_ms(self): - return floor(time.monotonic() * 10) + return floor(time.monotonic() * 1000) def hsv_to_rgb(self, hue, sat, val): """ @@ -247,6 +247,26 @@ class RGB: else: self.val -= step + def increase_ani(self): + """ + Increases animation speed by 1 amount stopping at 10 + :param step: + """ + if (self.animation_speed + 1) >= 10: + self.animation_speed = 10 + else: + self.val += 1 + + def decrease_ani(self): + """ + Decreases animation speed by 1 amount stopping at 0 + :param step: + """ + if (self.val - 1) <= 0: + self.val = 0 + else: + self.val -= 1 + def off(self): """ Turns off all LEDs/Neopixels without changing stored values diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index 972942d..6c7024d 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -231,11 +231,11 @@ keyboard.keymap = [ ], [ # r3 - [KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, _______, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL], - [_______, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], - [_______, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], - [_______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], - [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], + [KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, _______, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL], + [KC.RGB_ANI, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], + [KC.RGB_AND, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], + [_______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], + [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], ], ] From 7ebfaa3bf70d52aef56588250bc929b851130189 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Mon, 25 Feb 2019 14:10:09 -0800 Subject: [PATCH 13/32] cleaned up docs even more. I believe this fills all requirements for merge. --- docs/debugging.md | 2 +- docs/flashing.md | 10 ++++++---- docs/hardware.md | 19 +++++-------------- docs/keys.md | 6 +++--- docs/sequences.md | 6 ++++-- docs/split_keyboards.md | 17 ++++++++++------- docs/support.md | 13 +++++++++++++ docs/tapdance.md | 2 +- 8 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 docs/support.md diff --git a/docs/debugging.md b/docs/debugging.md index eb2ab9c..0b0ba0b 100644 --- a/docs/debugging.md +++ b/docs/debugging.md @@ -1,6 +1,6 @@ # Debugging Debug will output most of the useful state to the console. This can be enable in your firmware -by setting this in your keymap. NOTE that it will be MUCH slower, so only enable this when you +by setting this in your keymap. NOTE that it will be slower, so only enable this when you need debugging. ```python DEBUG_ENABLE = True diff --git a/docs/flashing.md b/docs/flashing.md index 4b9c971..cdd2918 100644 --- a/docs/flashing.md +++ b/docs/flashing.md @@ -12,7 +12,9 @@ After CircuitPython has been flashed, a `CIRCUITPY` drive should show up on your computer most likely. If not, check out the troubleshooting section below. # Windows -Currently, we do not have an official "flasher" for windows. You can manually install it fairly easily and we recommend coming to the KMK discord/Matrix server if you have any questions. An actual tool is in development. Alternatively, you can flash from any linux like tool set (Cygwin, WSL, ect) using the Linux guide below. +Currently, we do not have an official "flasher" for windows. You can manually install it fairly easily and we recommend +checking out the support page to join the community if you have any questions. An actual tool is in development. +Alternatively, you can flash from any linux like tool set (Cygwin, WSL, ect) using the Linux guide below. # Mac Until an interactive installer is created, please follow the linux instructions replacing /mnt with /Volumes @@ -27,10 +29,10 @@ make MOUNTPOINT=/mnt/CIRCUITPY USER_KEYMAP=user_keymaps/nameofyourkeymap.py # Troubleshooting ## Windows -Please join us on the Discord/Matrix server and we can help you out +Please check out our support page to get in contact with us and the community and we can gladly help you out. ## Mac -Please join us on the Discord/Matrix server and we can help you out +Please check out our support page to get in contact with us and the community and we can gladly help you out. ## Linux/BSD Check to see if your drive may have mounted elsewhere with a gui tool. Most will give you the directory in the GUI. @@ -40,4 +42,4 @@ It would look something like this `sudo mount -o uid=1000,gid=1000 /dev/sdf1 ~/mnt` -If you still are having issues, come say hi in the Discord/Matrix servers and we'll help you out. +If you still are having issues, check out our support page to see where you can come say hi and the community will gladly help you out. diff --git a/docs/hardware.md b/docs/hardware.md index 4aed0b1..6d30553 100644 --- a/docs/hardware.md +++ b/docs/hardware.md @@ -10,24 +10,15 @@ | Board | Chipset | Python Platform | Notes | | ----- | ------- | --------------- | ----- | | [Seeed nRF52840 Micro Dev Kit](https://www.seeedstudio.com/nRF52840-Micro-Development-Kit-p-3079.html) | nRF52840 | [CircuitPython](https://github.com/KMKfw/circuitpython/tree/topic-nrf52840-mdk) | This is basically as bleeding edge as it gets. Will support BLE HID to PC as well as BLE split boards | -| [Planck rev6 Keyboard](https://olkb.com/planck) | STM32 of some sort | MicroPython | Requires porting MicroPython to STM32F3, this work has begun but I'm pretty terrible at it. | -| [Proton C Controller?](https://www.reddit.com/r/MechanicalKeyboards/comments/87cw36/render_of_the_qmk_proton_c_qmkpowered_pro_micro/) | ??? | ??? | Does not exist yet, the controller from a Planck rev6 in a Pro Micro pin-compat controller chip | +| [Planck rev6 Keyboard](https://olkb.com/planck) | STM32F303 | CircuitPython | Requires porting CircuitPython to STM32F3. | +| [Proton C Controller?](https://olkb.com/parts/qmk-proton-c) | STM32F303CCT6 | CircuitPython | Requires porting CircuitPython to STM32F3. | -## Unsupported Devices - -Here's a list of problematic, but possibly usable microcontrollers: - -| Board | Chipset | Python Platform | Notes | -| ----- | ------- | --------------- | ------------------ | -| [Adafruit Feather Huzzah](https://www.adafruit.com/product/2821) | ESP8266 | CircuitPython | Suuuuuper limited on GPIO lanes, Lack USB HID (HW) | -| [Adafruit HUZZAH32](https://www.adafruit.com/product/3405) | ESP32 | MicroPython | This may work as a BLE HID device, or with a GPIO-based USB breakout. Lacks USB HID (HW) | -| [Adafruit Feather nRF52 BLE Controller](https://www.adafruit.com/product/3406) | nRF52832 | CircuitPython | Lacks USB HID (HW), but could be fixed with GPIO USB breakout. BLE HID should be possible, but it's considered somewhat unstable. This chip is considered "mostly unsupported" in CircuitPython at the time of writing. | ## Porting new devices Pull requests are welcome and encouraged to add support for new keyboards/microcontrollers. The base requirements for device support -- CircuitPython or MicroPython +- CircuitPython - 256KB of flash storage - HID over USB or Bluetooth. @@ -39,5 +30,5 @@ while all actual work is being done by a supported board. This could also be used to convert boards that use USB or i2c that run lesser chips to a KMK board, with a supported board acting as a translation layer. Support for a converter is planned with the inspiration coming from the [Hasu USB to -USB Controller Converter](https://www.1upkeyboards.com/shop/controllers/usb-to-usb-converter/) and would allow for conversion to KMK as -opposed to TMK or QMK with that board. \ No newline at end of file +USB Controller Converter](https://www.1upkeyboards.com/shop/controllers/usb-to-usb-converter/) +and would allow for conversion to KMK as opposed to TMK or QMK with that board. \ No newline at end of file diff --git a/docs/keys.md b/docs/keys.md index a1f2839..acb1511 100644 --- a/docs/keys.md +++ b/docs/keys.md @@ -1,10 +1,10 @@ # Keys > NOTE: This is not a lookup table of key objects provided by KMK. That listing -> can be found in `keycodes.md`, though that file is not always kept up to date. -> It's probably worth a look at the raw source if you're stumped: `kmk/keys.py`. +> can be found in `keycodes.md`. It's probably worth a look at the raw source if +> you're stumped: `kmk/keys.py`. -This is a bunch of documentation about how physical keypresses translate to +This is a bunch of documentation about how physical keypress translate to events (and the lifecycle of said events) in KMK. It's somewhat technical, but if you're looking to extend your keyboard's functionality with extra code, you'll need at least some of this technical knowledge. diff --git a/docs/sequences.md b/docs/sequences.md index 30b80de..8c4b08c 100644 --- a/docs/sequences.md +++ b/docs/sequences.md @@ -1,9 +1,11 @@ -# Sequences/Macros +# Sequences Sequences are used for sending multiple keystrokes in a single action, and can be used for things like unicode characters (even emojis! 🇨🇦), lorei epsum generators, triggering side effects (think lighting, speakers, -microcontroller-optimized cryptocurrency miners, whatever). +microcontroller-optimized cryptocurrency miners, whatever). If you are still +unsure of what this is, most other vendors call these "Macros", but can do much +more if you wish. ## Sending strings The most basic sequence is `send_string`. It can be used to send any standard diff --git a/docs/split_keyboards.md b/docs/split_keyboards.md index f949072..d0c4645 100644 --- a/docs/split_keyboards.md +++ b/docs/split_keyboards.md @@ -2,13 +2,22 @@ Split keyboards are mostly the same as unsplit and very easy to adapt a keymap for. Currently UART is supported, though other modes will come later such as Bluetooth and i2c. + +## UART +To enable uart it's as simple as adding this line, of course changing the pin +```python +keyboard.split_type = "UART" +keyboard.uart_pin = board.SCL +``` + +## Config Useful config options: ```python keyboard.split_flip = True # If your boards are identical but one is flipped, this option is for you keyboard.split_offsets = [6, 6, 6, 6] # This is the how many keys are on each column on the "Master" half ``` -## EE HANDS +### EE HANDS If you want to plug in on either side, it can be done fairly easily but requires setup. On each half of your keyboard make a file called kmk_side.py and add one of these lines to the file @@ -24,9 +33,3 @@ and then in your keymap, add the line from kmk_side import split_side ``` -# UART -To enable uart it's as simple as adding this line, of course changing the pin -```python -keyboard.split_type = "UART" -keyboard.uart_pin = board.SCL -``` diff --git a/docs/support.md b/docs/support.md new file mode 100644 index 0000000..d7a7fb1 --- /dev/null +++ b/docs/support.md @@ -0,0 +1,13 @@ +# Support +If you are having any issues in installing, configuring, or otherwise issues with KMK, please reach out to us and +our community here. We do have a bridge to allow communication between the platforms as well, though we recommend +using Matrix if possible. + +# Matrix +* [Software Support](https://matrix.to/#/#kmk-support:kmkfw.io) +* [Hardware Support](https://matrix.to/#/#kmk-hardware:kmkfw.io) +* [General discussion](https://matrix.to/#/#kmk-general:kmkfw.io) + + +# Discord +* [General support](https://discord.gg/NDUau62) \ No newline at end of file diff --git a/docs/tapdance.md b/docs/tapdance.md index bf73daf..6215acd 100644 --- a/docs/tapdance.md +++ b/docs/tapdance.md @@ -34,7 +34,7 @@ are planned to be worked around "eventually", but for now are noteworthy: - Super fancy stuff like sending a keypress only when the leader key is released (perhaps based on how long the leader key was held) is **unsupported** - an - example usecase might be "tap for Home, hold for Shift" + example use case might be "tap for Home, hold for Shift" Here's an example of all this in action: From f7a1d5475208e483deb2b6beab8bbc29e2d3aee2 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Tue, 26 Feb 2019 17:30:53 -0800 Subject: [PATCH 14/32] Added LED support, cleaned up RGB docs --- docs/led.md | 54 ++++++++++ docs/rgb.md | 57 ++++++----- kmk/firmware.py | 68 ++++++++---- kmk/handlers/stock.py | 49 +++++++-- kmk/keys.py | 11 ++ kmk/led.py | 125 +++++++++++++++++++++++ kmk/rgb.py | 53 ++++++---- user_keymaps/kdb424/nyquist_converter.py | 69 +++---------- 8 files changed, 356 insertions(+), 130 deletions(-) create mode 100644 docs/led.md create mode 100644 kmk/led.py diff --git a/docs/led.md b/docs/led.md new file mode 100644 index 0000000..1145c05 --- /dev/null +++ b/docs/led.md @@ -0,0 +1,54 @@ +# LED (Mono color backlight) +Want your keyboard to shine? Add some lights! + +## Usage +At minimum you will need to make sure that this set in either your keymap is importing an MCU directly, or it should be included in the predefined boards if they support them. + +|Define |Description | +|---------------------|---------------------------------------------| +|`keyboard.led_pin` |The pin connected to the data pin of the LEDs| + +Then you should be able to use the keycodes below to change the LED lighting to your liking. + +## [Keycodes] + +|Key |Aliases |Description | +|-----------------------------|-------------------|----------------------------| +|`KC.LED_TOG` | |Toggles LED's | +|`KC.LED_INC` | |Increase Brightness | +|`KC.LED_DEC` | |Decrease Brightness | +|`KC.LED_ANI` | |Increase animation speed | +|`KC.LED_AND` | |Decrease animation speed | +|`KC.LED_MODE_PLAIN` |`LED_M_P` |Static LED's | +|`KC.LED_MODE_BREATHE` |`LED_M_B` |Breathing animation | + +## Configuration +|Define |Default |Description | +|-------------------------------|-------------|------------------------------------------------| +|`keyboard.led_brightness_step` |`5` |The number of steps to change the brightness by | +|`keyboard.led_brightness_limit`|`100` |The maximum brightness level in percent | + +## Built-in Animation Configuration +|Define |Default |Description | +|-------------------------------|-------------|-------------------------------------------------------------------------------------| +|`keyboard.led_breath_center` |`1.5` |Used to calculate the curve for the breathing animation. Anywhere from 1.0 - 2.7 is valid| + +## Functions + +If you want to create your own animations, or for example, change the lighting in a macro, or a layer switch, here are some functions that are available. + +|Function |Description | +|--------------------------------------------|--------------------------------------------------------------------------------------------| +|`keyboard.pixels.increase_brightness(step)` |Increases hue by a given step | +|`keyboard.pixels.decrease_brightness(step)` |Decreases hue by a given step | +|`keyboard.pixels.set_brightness(percent)` |Increases saturation by a given step | + +## Direct variable access +|Define |Default |Description | +|-----------------------------------|-----------|--------------------------------------------------------------------------------------------------------| +|`keyboard.led.brightness` |`0` |Sets the brightness by percent 0-100 | +|`keyboard.led.brightness_limit` |`100` |Sets the limit of brightness | +|`keyboard.led.brightness_step` |`5` |Sets the step value to change brightness by | +|`keyboard.led.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid | +|`keyboard.led.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. | + diff --git a/docs/rgb.md b/docs/rgb.md index 164e93c..ec4c7e6 100644 --- a/docs/rgb.md +++ b/docs/rgb.md @@ -12,7 +12,7 @@ Currently we support the following addressable LEDs: * All neopixels ## Usage -At minimum you will need to make sure that these are set in either your keymap ip importing an MCU directly, or it should be included in the predefined boards if they support them. +At minimum you will need to make sure that these are set in either your keymap is importing an MCU directly, or it should be included in the predefined boards if they support them. |Define |Description | |---------------------|---------------------------------------------| @@ -49,13 +49,19 @@ Changing the **Value** sets the overall brightness. |`KC.RGB_MODE_KNIGHT` |`RGB_M_K` |Knightrider animation | ## Configuration -|Define |Default |Description | -|---------------------|-------------|-----------------------------------------------------------------------------| -|`keyboard.rgb_order` |`(1, 0, 2)` |The order of the pixels R G B, and optionally white. Example(1, 0, 2, 3) | -|`keyboard.hue_step` |`10` |The number of steps to cycle through the hue by | -|`keyboard.sat_step` |`17` |The number of steps to increment the saturation by | -|`keyboard.val_step` |`17` |The number of steps to increment the brightness by | -|`keyboard.val_limit` |`255` |The maximum brightness level | +|Define |Default |Description | +|-------------------------|-------------|-----------------------------------------------------------------------------| +|`keyboard.rgb_order` |`(1, 0, 2)` |The order of the pixels R G B, and optionally white. Example(1, 0, 2, 3) | +|`keyboard.rgb_hue_step` |`10` |The number of steps to cycle through the hue by | +|`keyboard.rgb_sat_step` |`17` |The number of steps to change the saturation by | +|`keyboard.rgb_val_step` |`17` |The number of steps to change the brightness by | +|`keyboard.rgb_val_limit` |`255` |The maximum brightness level | + +## Built-in Animation Configuration +|Define |Default |Description | +|-----------------------------------|-------------|-------------------------------------------------------------------------------------| +|`keyboard.rgb_breath_center` |`1.5` |Used to calculate the curve for the breathing animation. Anywhere from 1.0 - 2.7 is valid| +|`keyboard.rgb_knight_effect_length`|`4` |The number of LEDs to light up for the "Knight" animation | ## Functions @@ -67,6 +73,7 @@ If you want to create your own animations, or for example, change the lighting i |`keyboard.pixels.set_hsv(hue, sat, val, index)` |Sets a single LED with HSV value | |`keyboard.pixels.set_rgb_fill((r, g, b))` |Fills all LED's with RGB(W) values | |`keyboard.pixels.set_rgb((r, g, b), index)` |Set's a single LED with RGB(W) values | +|`keyboard.pixels.disable_auto_write(bool)` |When True, disables showing changes. Good for setting multiple LED's before a visible update| |`keyboard.pixels.increase_hue(step)` |Increases hue by a given step | |`keyboard.pixels.decrease_hue(step)` |Decreases hue by a given step | |`keyboard.pixels.increase_sat(step)` |Increases saturation by a given step | @@ -79,32 +86,28 @@ If you want to create your own animations, or for example, change the lighting i |`keyboard.pixels.show()` |Displays all stored configuration for LED's. Useful with disable_auto_write explained below | |`keyboard.pixels.time_ms()` |Returns a time in ms since the board has booted. Useful for start/stop timers | -Other settings that are useful that can be changed. -## Configuration -|Define |Default |Description | -|------------------------------|-------------|---------------------------------------------------------------------------------------------------------| -|`keyboard.hue` |`0` |Sets the hue from 0-360 | -|`keyboard.sat` |`100` |Sets the saturation from 0-100 | -|`keyboard.val` |`80` |Sets the brightness from 1-255 | -|`keyboard.disable_auto_write` |`False` |When True, disables showing changes. Good for setting multiple LED's before a visible update | -|`keyboard.reverse_animation` |`False` |If true, some animations will run in reverse. Can be safely used in user animations | -|`keyboard.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid | -|`keyboard.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. | +## Direct variable access +|Define |Default |Description | +|-----------------------------------|-----------|-----------------------------------------------------------------------------------------------------------| +|`keyboard.pixels.hue` |`0` |Sets the hue from 0-360 | +|`keyboard.pixels.sat` |`100` |Sets the saturation from 0-100 | +|`keyboard.pixels.val` |`80` |Sets the brightness from 1-255 | +|`keyboard.pixels.reverse_animation`|`False` |If true, some animations will run in reverse. Can be safely used in user animations | +|`keyboard.pixels.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid | +|`keyboard.pixels.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. | -## Built-in Animation Configuration -|Define |Default |Description | -|-------------------------------|-------------|-------------------------------------------------------------------------------------| -|`keyboard.breath_center` |`1.5` |Used to calculate the curve for the breathing animation. Anywhere from 1.0 - 2.7 is valid| -|`keyboard.knight_effect_length`|`4` |The number of LEDs to light up for the "Knight" animation | ## Hardware Modification -To add LED's to boards that don't support them, you will have to add a 3 wires. The power wire will run on 3.3v or 5v (depending on the LED), ground, and data pins will need added to an unused pin on your microcontroller unless your keyboard has specific solder points for them. With those 3 wires connected, set the pixel_pin as described above, and you are ready to use your LED's/Neopixels. +To add RGB LED's to boards that don't support them directly, you will have to add a 3 wires. The power wire will run on 3.3v or 5v (depending on the LED), +ground, and data pins will need added to an unused pin on your microcontroller unless your keyboard has specific solder points for them. With those 3 wires +connected, set the pixel_pin as described above, and you are ready to use your RGB LED's/Neopixels. ## ADVANCED USAGE -If you wish to interact with these as you would normal LED's and do not want help from KMK, you can disable all helper functions from working and access the neopixel object directly like this. +If you wish to interact with these as you would normal LED's and do not want help from KMK, you can disable all helper functions from working and access the +neopixel object directly like this. ```python -keyboard.pixels.disabse_auto_write = True +keyboard.pixels.disable_auto_write = True keyboard.pixels.neopixel() # <-- This is the neopixel object ``` diff --git a/kmk/firmware.py b/kmk/firmware.py index 389bde5..98e4fa3 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -92,21 +92,30 @@ class Firmware: uart_pin = None # RGB config - pixel_pin = None - num_pixels = None + rgb_pixel_pin = None + rgb_pixels = None + rgb_num_pixels = None rgb_order = (1, 0, 2) # GRB WS2812 - val_limit = 255 - hue_default = 0 - sat_default = 100 - val_default = val_limit - hue_step = 1 - sat_step = 1 - val_step = 1 - animation_speed = 1 - breathe_center = 1.5 # 1.0-2.7 - knight_effect_length = 3 - animation_mode = 'static' - pixels = None + rgb_val_limit = 255 + rgb_hue_default = 0 + rgb_sat_default = 100 + rgb_val_default = rgb_val_limit + rgb_hue_step = 1 + rgb_sat_step = 1 + rgb_val_step = 1 + rgb_animation_speed = 1 + rgb_breathe_center = 1.5 # 1.0-2.7 + rgb_knight_effect_length = 3 + rgb_animation_mode = 'static' + + # led config (mono color) + led = None + led_pin = None + led_brightness_step = 5 + led_brightness_limit = 100 + led_breathe_center = 1.5 + led_animation_mode = 'static' + led_animation_speed = 1 def __init__(self): # Attempt to sanely guess a coord_mapping if one is not provided @@ -220,14 +229,21 @@ class Firmware: if self.uart_pin is not None: self.uart = self.init_uart(self.uart_pin) - if self.pixel_pin is not None: - self.pixels = rgb.RGB(self.pixel_pin, self.rgb_order, self.num_pixels, - self.hue_step, self.sat_step, self.val_step, - self.hue_default, self.sat_default, self.val_default, - self.breathe_center, self.knight_effect_length, - self.val_limit, self.animation_mode, self.animation_speed, + if self.rgb_pixel_pin is not None: + self.pixels = rgb.RGB(self.rgb_pixel_pin, self.rgb_order, self.rgb_num_pixels, + self.rgb_hue_step, self.rgb_sat_step, self.rgb_val_step, + self.rgb_hue_default, self.rgb_sat_default, self.rgb_val_default, + self.rgb_breathe_center, self.rgb_knight_effect_length, + self.rgb_val_limit, self.rgb_animation_mode, + self.rgb_animation_speed, ) + if self.led_pin: + self.led = led.led(self.led_pin, self.led_brightness_step, self.led_brightness_limit, + self.led_animation_mode, self.led_animation_speed, + self.led_breathe_center, + ) + self.matrix = MatrixScanner( cols=self.col_pins, rows=self.row_pins, @@ -286,7 +302,15 @@ class Firmware: if self.debug_enabled and state_changed and self.pixels.enabled: print('New State: {}'.format(self.pixels)) - if self.pixels.animation_mode is not None: - self.pixels = self.pixels.animate() + if self.pixels: + # Only check animations if pixels is initialized + if self.pixels.animation_mode: + if self.pixels.animation_mode is not 'static_standby': + self.pixels = self.pixels.animate() + + if self.led: + # Only check animations if led is initialized + if self.led.animation_mode: + self.led = self.led.animate() gc.collect() diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index 3dc7d85..736cc61 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -126,32 +126,32 @@ def rgb_tog(key, state, *args, **kwargs): def rgb_hui(key, state, *args, **kwargs): - state.config.pixels.increase_hue(state.config.pixels.hue_step) + state.config.pixels.increase_hue() return state def rgb_hud(key, state, *args, **kwargs): - state.config.pixels.decrease_hue(state.config.pixels.hue_step) + state.config.pixels.decrease_hue() return state def rgb_sai(key, state, *args, **kwargs): - state.config.pixels.increase_sat(state.config.pixels.sat_step) + state.config.pixels.increase_sat() return state def rgb_sad(key, state, *args, **kwargs): - state.config.pixels.decrease_sat(state.config.pixels.sat_step) + state.config.pixels.decrease_sat() return state def rgb_vai(key, state, *args, **kwargs): - state.config.pixels.increase_val(state.config.pixels.val_step) + state.config.pixels.increase_val() return state def rgb_vad(key, state, *args, **kwargs): - state.config.pixels.decrease_val(state.config.pixels.val_step) + state.config.pixels.decrease_val() return state @@ -193,3 +193,40 @@ def rgb_mode_knight(key, state, *args, **kwargs): state.config.pixels.effect_init = True state.config.pixels.animation_mode = 'knight' return state + + +def led_tog(key, state, *args, **kwargs): + state.config.led.enabled = not state.config.led.enabled + return state + + +def led_inc(key, state, *args, **kwargs): + state.config.led.increase_brightness() + return state + + +def led_dec(key, state, *args, **kwargs): + state.config.led.decrease_brightness() + return state + + +def led_ani(key, state, *args, **kwargs): + state.config.led.increase_ani() + return state + + +def led_and(key, state, *args, **kwargs): + state.config.led.decrease_ani() + return state + + +def led_mode_static(key, state, *args, **kwargs): + state.config.led.effect_init = True + state.config.led.animation_mode = 'static' + return state + + +def led_mode_breathe(key, state, *args, **kwargs): + state.config.led.effect_init = True + state.config.led.animation_mode = 'breathing' + return state diff --git a/kmk/keys.py b/kmk/keys.py index 2e2b6ff..40ee7d5 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -641,6 +641,17 @@ make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainb make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'), on_press=handlers.rgb_mode_breathe_rainbow) make_key(names=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight) + + +make_key(names=('LED_TOG',), on_press=handlers.led_tog) +make_key(names=('LED_INC',), on_press=handlers.led_inc) +make_key(names=('LED_DEC',), on_press=handlers.led_dec) +make_key(names=('LED_ANI',), on_press=handlers.led_ani) +make_key(names=('LED_AND',), on_press=handlers.led_and) +make_key(names=('LED_MODE_PLAIN', 'LED_M_P'), on_press=handlers.led_mode_static) +make_key(names=('LED_MODE_BREATHE', 'LED_M_B'), on_press=handlers.led_mode_breathe) + + make_key( names=('LEADER', 'LEAD'), on_press=handlers.leader_pressed, diff --git a/kmk/led.py b/kmk/led.py new file mode 100644 index 0000000..eaaad7e --- /dev/null +++ b/kmk/led.py @@ -0,0 +1,125 @@ +import time +from math import e, exp, pi, sin + +import pulseio + + +class led: + brightness = 0 + time = int(time.monotonic() * 1000) + pos = 0 + effect_init = False + + led = None + brightness_step = 5 + brightness_limit = 100 + breath_center = 1.5 + animation_mode = 'static' + animation_speed = 1 + enabled = True + + def __init__(self, led_pin, brightness_step, brightness_limit, + animation_mode, animation_speed, breath_center): + self.led = pulseio.PWMOut(led_pin) + self.brightness_step = brightness_step + self.brightness_limit = brightness_limit + self.animation_mode = animation_mode + self.animation_speed = animation_speed + self.breath_center = breath_center + + def __repr__(self): + return 'LED({})'.format(self._to_dict()) + + def _to_dict(self): + return { + 'led': self.led, + 'brightness_step': self.brightness_step, + 'brightness_limit': self.brightness_limit, + 'animation_mode': self.animation_mode, + 'animation_speed': self.animation_speed, + 'breath_center': self.breath_center, + } + + def time_ms(self): + return int(time.monotonic() * 1000) + + def set_brightness(self, percent): + self.led.duty_cycle = int(percent / 100 * 65535) + + def increase_brightness(self, step=None): + if not step: + self.brightness += self.brightness_step + else: + self.brightness += step + + if self.brightness > 100: + self.brightness = 100 + + self.set_brightness(self.brightness) + + def decrease_brightness(self, step=None): + if not step: + self.brightness -= self.brightness_step + else: + self.brightness -= step + + if self.brightness < 0: + self.brightness = 0 + + self.set_brightness(self.brightness) + + def off(self): + self.set_brightness(0) + + def increase_ani(self): + """ + Increases animation speed by 1 amount stopping at 10 + :param step: + """ + if (self.animation_speed + 1) >= 10: + self.animation_speed = 10 + else: + self.val += 1 + + def decrease_ani(self): + """ + Decreases animation speed by 1 amount stopping at 0 + :param step: + """ + if (self.val - 1) <= 0: + self.val = 0 + else: + self.val -= 1 + + def effect_breathing(self): + # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L806 + self.brightness = int((exp(sin((self.pos / 255.0) * pi)) - self.breath_center / e) * + (self.brightness_limit / (e - 1 / e))) + self.pos = (self.pos + self.animation_speed) % 256 + self.set_brightness(self.brightness) + + return self + + def effect_static(self): + self.set_brightness(self.brightness) + # Set animation mode to none to prevent cycles from being wasted + self.animation_mode = None + return self + + def animate(self): + """ + Activates a "step" in the animation based on the active mode + :return: Returns the new state in animation + """ + if self.effect_init: + self.init_effect() + if self.enabled: + if self.animation_mode == 'breathing': + return self.effect_breathing() + elif self.animation_mode == 'static': + return self.effect_static() + else: + self.off() + + return self diff --git a/kmk/rgb.py b/kmk/rgb.py index b9a5eb1..037cb65 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -1,6 +1,5 @@ import time -from math import e as M_E -from math import exp, floor, pi, sin +from math import e, exp, pi, sin class RGB: @@ -8,7 +7,7 @@ class RGB: sat = 100 val = 80 pos = 0 - time = floor(time.monotonic() * 10) + time = int(time.monotonic() * 10) intervals = (30, 20, 10, 5) animation_speed = 1 enabled = True @@ -61,7 +60,7 @@ class RGB: return 'RGB({})'.format(self._to_dict()) def _to_dict(self): - ret = { + return { 'hue': self.hue, 'sat': self.sat, 'val': self.val, @@ -74,10 +73,8 @@ class RGB: 'disable_auto_write': self.disable_auto_write, } - return ret - def time_ms(self): - return floor(time.monotonic() * 1000) + return int(time.monotonic() * 1000) def hsv_to_rgb(self, hue, sat, val): """ @@ -101,9 +98,9 @@ class RGB: else: base = ((100 - sat) * val) / 100 - color = floor((val - base) * ((hue % 60) / 60)) + color = int((val - base) * ((hue % 60) / 60)) - x = floor(hue / 60) + x = int(hue / 60) if x == 0: r = val g = base + color @@ -129,7 +126,7 @@ class RGB: g = base b = val - color - return floor(r), floor(g), floor(b) + return int(r), int(g), int(b) def hsv_to_rgbw(self, hue, sat, val): """ @@ -190,58 +187,76 @@ class RGB: if not self.disable_auto_write: self.neopixel.show() - def increase_hue(self, step): + def increase_hue(self, step=None): """ Increases hue by step amount rolling at 360 and returning to 0 :param step: """ + if not step: + step = self.hue_step + self.hue = (self.hue + step) % 360 - def decrease_hue(self, step): + def decrease_hue(self, step=None): """ Decreases hue by step amount rolling at 0 and returning to 360 :param step: """ + if not step: + step = self.hue_step + if (self.hue - step) <= 0: self.hue = (self.hue + 360 - step) % 360 else: self.hue = (self.hue - step) % 360 - def increase_sat(self, step): + def increase_sat(self, step=None): """ Increases saturation by step amount stopping at 100 :param step: """ + if not step: + step = self.sat_step + if self.sat + step >= 100: self.sat = 100 else: self.sat += step - def decrease_sat(self, step): + def decrease_sat(self, step=None): """ Decreases saturation by step amount stopping at 0 :param step: """ + if not step: + step = self.sat_step + if (self.sat - step) <= 0: self.sat = 0 else: self.sat -= step - def increase_val(self, step): + def increase_val(self, step=None): """ Increases value by step amount stopping at 100 :param step: """ + if not step: + step = self.val_step + if (self.val + step) >= 100: self.val = 100 else: self.val += step - def decrease_val(self, step): + def decrease_val(self, step=None): """ Decreases value by step amount stopping at 0 :param step: """ + if not step: + step = self.val_step + if (self.val - step) <= 0: self.val = 0 else: @@ -326,8 +341,8 @@ class RGB: def effect_breathing(self): # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L806 - self.val = floor((exp(sin((self.pos / 255.0) * pi)) - self.breath_center / M_E) * - (self.val_limit / (M_E - 1 / M_E))) + self.val = int((exp(sin((self.pos / 255.0) * pi)) - self.breath_center / e) * + (self.val_limit / (e - 1 / e))) self.pos = (self.pos + self.animation_speed) % 256 self.set_hsv_fill(self.hue, self.sat, self.val) @@ -351,7 +366,7 @@ class RGB: # Determine which LEDs should be lit up self.disable_auto_write = True # Turn off instantly showing self.off() # Fill all off - pos = floor(self.pos) + pos = int(self.pos) # Set all pixels on in range of animation length offset by position for i in range(pos, (pos + self.knight_effect_length)): diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index 6c7024d..4b92c68 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -28,23 +28,20 @@ keyboard.tap_time = 150 keyboard.leader_timeout = 2000 keyboard.debug_enabled = True -keyboard.pixel_pin = board.TX -keyboard.num_pixels = 12 -keyboard.val_limit = 150 -keyboard.hue_step = 5 -keyboard.sat_step = 5 -keyboard.val_step = 5 -keyboard.hue_default = 260 -keyboard.knight_effect_length = 4 -keyboard.animation_mode = 'knight' -keyboard.animation_speed = 2 +# RGB Config (underglow) +keyboard.rgb_pixel_pin = board.TX +keyboard.rgb_num_pixels = 12 -OFF = (0, 0, 0) -BLUE = (0, 0, 100) -CYAN = (0, 100, 100) -PURPLE = (71, 0, 100) -RED = (100, 0, 0) -WHITE = (100, 100, 100) +keyboard.rgb_val_limit = 150 +keyboard.rgb_hue_step = 5 +keyboard.rgb_sat_step = 5 +keyboard.rgb_val_step = 5 +keyboard.rgb_hue_default = 260 +keyboard.rgb_sat_default = 100 +keyboard.rgb_val_default = 20 +keyboard.rgb_knight_effect_length = 4 +keyboard.rgb_animation_mode = 'static' +keyboard.rgb_animation_speed = 2 emoticons = compile_unicode_string_sequences({ # Emoticons, but fancier @@ -79,74 +76,34 @@ r3 = 4 def base(*args, **kwargs): - ''' - keyboard.pixels.animation_mode = 'breathing' - keyboard.pixels.neopixel(OFF) - keyboard.pixels.neopixelshow() - ''' return df_pressed(*args, **kwargs) def layer1p(*args, **kwargs): - ''' - keyboard.pixels.animation_mode = 'User' - keyboard.pixels.neopixel.fill(WHITE) - keyboard.pixels.neopixel.show() - ''' return mo_pressed(*args, **kwargs) def layer1r(*args, **kwargs): - ''' - keyboard.pixels.animation_mode = 'breathing' - keyboard.pixels.neopixel.fill(OFF) - keyboard.pixels.neopixel.show() - ''' return mo_released(*args, **kwargs) def layer2p(*args, **kwargs): - ''' - keyboard.pixels.animation_mode = 'User' - keyboard.pixels.neopixel.fill(BLUE) - keyboard.pixels.neopixel.show() - ''' return lt_pressed(*args, **kwargs) def layer2r(*args, **kwargs): - ''' - keyboard.pixels.animation_mode = 'breathing' - keyboard.pixels.neopixel.fill(OFF) - keyboard.pixels.neopixel.show() - ''' return lt_released(*args, **kwargs) def layer3p(*args, **kwargs): - ''' - keyboard.pixels.animation_mode = 'User' - keyboard.pixels.neopixel.fill(PURPLE) - keyboard.pixels.neopixel.show() - ''' return mo_pressed(*args, **kwargs) def layer3r(*args, **kwargs): - ''' - keyboard.pixels.animation_mode = 'breathing' - keyboard.pixels.neopixel.fill(OFF) - keyboard.pixels.neopixel.show() - ''' return mo_released(*args, **kwargs) def gaming(*args, **kwargs): - ''' - keyboard.pixels.animation_mode = 'User' - keyboard.pixels.neopixel.fill(CYAN) - keyboard.pixels.neopixel.show() - ''' return df_pressed(*args, **kwargs) From 54d63037bf72b6ec339a65131dcbba4cbd814559 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Thu, 28 Feb 2019 17:07:23 -0800 Subject: [PATCH 15/32] Added board definition for nyquist and add RGB and LED pins for nyquest and iris --- docs/examples.md | 25 +--- docs/hardware.md | 5 +- docs/keys.md | 2 +- docs/led.md | 16 +- docs/rgb.md | 21 ++- docs/support.md | 3 +- .../{kitsym4_iris.py => iris_converter.py} | 5 +- kmk/boards/levinson_converter.py | 19 +++ kmk/boards/nyquist_converter.py | 19 +++ kmk/firmware.py | 30 ++-- kmk/keys.py | 16 +- user_keymaps/Default/nyquist_converter.py | 137 ++++++++++++++++++ user_keymaps/kdb424/levinson_m4.py | 6 - user_keymaps/kdb424/nyquist_converter.py | 109 +------------- user_keymaps/klardotsh/kitsym4_iris.py | 2 +- 15 files changed, 240 insertions(+), 175 deletions(-) rename kmk/boards/{kitsym4_iris.py => iris_converter.py} (93%) create mode 100644 kmk/boards/levinson_converter.py create mode 100644 kmk/boards/nyquist_converter.py create mode 100644 user_keymaps/Default/nyquist_converter.py diff --git a/docs/examples.md b/docs/examples.md index 0d493bb..c8ea87d 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -8,26 +8,9 @@ when you release the layer key. The example uses the MO though any layer switch LAYER_1 key in your keymap, and it's ready to go! You can change animations, colors, or anything in there. ```python -from kmk.handlers.layers import (mo_pressed, mo_released) -from kmk.keys import KC, layer_key_validator, make_argumented_key - - -def layer1p(*args, **kwargs): - keyboard.pixels.set_hsv_fill(100, 100, 100) - return mo_pressed(*args, **kwargs) - - -def layer1r(*args, **kwargs): - keyboard.pixels.set_hsv_fill.fill(0, 0, 0) - return mo_released(*args, **kwargs) - -make_argumented_key( - validator=layer_key_validator, - names=('LAYER_1',), - on_press=layer1p, - on_release=layer1r, -) - -LAYER_1 = KC.LAYER_1(1) +LAYER_1 = KC.MO(1) +LAYER_1.after_press_handler(lambda *args, **kwargs: keyboard.pixels.set_hsv_fill(100, 100, 100)) +LAYER_1.after_release_handler(lambda *args, **kwargs: keyboard.pixels.set_hsv_fill(0, 0, 0)) +keyboard.keymap = [ ....... LAYER_1 ....... ] ``` \ No newline at end of file diff --git a/docs/hardware.md b/docs/hardware.md index 6d30553..799afa2 100644 --- a/docs/hardware.md +++ b/docs/hardware.md @@ -4,12 +4,13 @@ | ----- | ------- | --------------- | ----- | | [Adafruit Feather M4 Express](https://www.adafruit.com/product/3857) | Atmel SAMD51 (Cortex M4F) | CircuitPython | An economical solution for basic USB keyboards | | [Adafruit ItsyBitsy M4 Express](https://www.adafruit.com/product/3800) | Atmel SAMD51 (Cortex M4F) | CircuitPython | A smaller solution for basic USB keyboards | +| [Adafruit Feather NRF52840 Express](https://www.adafruit.com/product/4062) | Cortex M4F/nrf52840 | CircuitPython | Supports USB HID and soon BLE (Bluetooth) | +| [Seeed nRF52840 Micro Dev Kit](https://www.seeedstudio.com/nRF52840-Micro-Development-Kit-p-3079.html) | M4F/nrf52840 | CircuitPython | Supports USB HID and soon BLE (Bluetooth) | ## Support Planned/WIP | Board | Chipset | Python Platform | Notes | | ----- | ------- | --------------- | ----- | -| [Seeed nRF52840 Micro Dev Kit](https://www.seeedstudio.com/nRF52840-Micro-Development-Kit-p-3079.html) | nRF52840 | [CircuitPython](https://github.com/KMKfw/circuitpython/tree/topic-nrf52840-mdk) | This is basically as bleeding edge as it gets. Will support BLE HID to PC as well as BLE split boards | | [Planck rev6 Keyboard](https://olkb.com/planck) | STM32F303 | CircuitPython | Requires porting CircuitPython to STM32F3. | | [Proton C Controller?](https://olkb.com/parts/qmk-proton-c) | STM32F303CCT6 | CircuitPython | Requires porting CircuitPython to STM32F3. | @@ -20,7 +21,7 @@ Pull requests are welcome and encouraged to add support for new keyboards/microcontrollers. The base requirements for device support - CircuitPython - 256KB of flash storage -- HID over USB or Bluetooth. +- HID over USB and/or Bluetooth. ## Secondary Support diff --git a/docs/keys.md b/docs/keys.md index acb1511..46e8d29 100644 --- a/docs/keys.md +++ b/docs/keys.md @@ -4,7 +4,7 @@ > can be found in `keycodes.md`. It's probably worth a look at the raw source if > you're stumped: `kmk/keys.py`. -This is a bunch of documentation about how physical keypress translate to +This is a bunch of documentation about how a physical keypress translates to events (and the lifecycle of said events) in KMK. It's somewhat technical, but if you're looking to extend your keyboard's functionality with extra code, you'll need at least some of this technical knowledge. diff --git a/docs/led.md b/docs/led.md index 1145c05..cbadbb0 100644 --- a/docs/led.md +++ b/docs/led.md @@ -1,15 +1,6 @@ # LED (Mono color backlight) Want your keyboard to shine? Add some lights! -## Usage -At minimum you will need to make sure that this set in either your keymap is importing an MCU directly, or it should be included in the predefined boards if they support them. - -|Define |Description | -|---------------------|---------------------------------------------| -|`keyboard.led_pin` |The pin connected to the data pin of the LEDs| - -Then you should be able to use the keycodes below to change the LED lighting to your liking. - ## [Keycodes] |Key |Aliases |Description | @@ -52,3 +43,10 @@ If you want to create your own animations, or for example, change the lighting i |`keyboard.led.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid | |`keyboard.led.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. | +# Troubleshooting +Make sure that your board supports LED backlight by checking for a line with "LED_PIN". If it does not, you can add it to your keymap. + +|Define |Description | +|---------------------|---------------------------------------------| +|`keyboard.led_pin` |The pin connected to the data pin of the LEDs| + diff --git a/docs/rgb.md b/docs/rgb.md index ec4c7e6..e3f5266 100644 --- a/docs/rgb.md +++ b/docs/rgb.md @@ -11,16 +11,6 @@ Currently we support the following addressable LEDs: * SK6812, SK6812MINI, SK6805 * All neopixels -## Usage -At minimum you will need to make sure that these are set in either your keymap is importing an MCU directly, or it should be included in the predefined boards if they support them. - -|Define |Description | -|---------------------|---------------------------------------------| -|`keyboard.pixel_pin` |The pin connected to the data pin of the LEDs| -|`keyboard.num_pixels`|The number of LEDs connected | - -Then you should be able to use the keycodes below to change the RGB lighting to your liking. - ### Color Selection KMK uses [Hue, Saturation, and Value](https://en.wikipedia.org/wiki/HSL_and_HSV) to select colors rather than RGB. The color wheel below demonstrates how this works. @@ -116,4 +106,13 @@ keyboard.pixels.neopixel() # <-- This is the neopixel object If your colors are incorrect, check the pixel order of your specific LED's. Here are some common ones. * WS2811, WS2812, WS2812B, WS2812C are all GRB (1, 0, 2) * SK6812, SK6812MINI, SK6805 are all GRB (1, 0, 2) - * Neopixels will vary depending on which one you buy. It will be listed on the product page. + * Neopixels will vary depending on which one you buy. It will be listed on the product page.# Troubleshooting + +### Lights don't turn on +Make sure that your board supports LED backlight by checking for a line with "PIXEL_PIN". If it does not, you can add it to your keymap. +If you added the LED's yourself, you will also need to set num_pixels to the number of installed LED's in total. + +|Define |Description | +|---------------------|---------------------------------------------| +|`keyboard.pixel_pin` |The pin connected to the data pin of the LEDs| +|`keyboard.num_pixels`|The number of LEDs connected | diff --git a/docs/support.md b/docs/support.md index d7a7fb1..fba00e9 100644 --- a/docs/support.md +++ b/docs/support.md @@ -1,7 +1,6 @@ # Support If you are having any issues in installing, configuring, or otherwise issues with KMK, please reach out to us and -our community here. We do have a bridge to allow communication between the platforms as well, though we recommend -using Matrix if possible. +our community here. # Matrix * [Software Support](https://matrix.to/#/#kmk-support:kmkfw.io) diff --git a/kmk/boards/kitsym4_iris.py b/kmk/boards/iris_converter.py similarity index 93% rename from kmk/boards/kitsym4_iris.py rename to kmk/boards/iris_converter.py index e07a763..30bdce2 100644 --- a/kmk/boards/kitsym4_iris.py +++ b/kmk/boards/iris_converter.py @@ -16,8 +16,11 @@ class Firmware(_Firmware): split_flip = True split_offsets = (6, 6, 6, 6, 6) - split_type = "UART" + split_type = 'UART' uart_pin = board.SCL + extra_data_pin = board.SDA + rgb_pixel_pin = board.TX + led_pin = board.D7 coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(12)) diff --git a/kmk/boards/levinson_converter.py b/kmk/boards/levinson_converter.py new file mode 100644 index 0000000..965cfc6 --- /dev/null +++ b/kmk/boards/levinson_converter.py @@ -0,0 +1,19 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.D13, P.D11, P.D10, P.D9) + diode_orientation = DiodeOrientation.COLUMNS + + split_type = 'UART' + split_flip = True + split_offsets = [6, 6, 6, 6, 6] + uart_pin = board.SCL + extra_data_pin = board.SDA + rgb_pixel_pin = board.TX + #led_pin = board.D7 diff --git a/kmk/boards/nyquist_converter.py b/kmk/boards/nyquist_converter.py new file mode 100644 index 0000000..cd0c1f2 --- /dev/null +++ b/kmk/boards/nyquist_converter.py @@ -0,0 +1,19 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.RX, P.A1, P.A2, P.A3, P.A4, P.A5) + row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7) + diode_orientation = DiodeOrientation.COLUMNS + + split_type = 'UART' + split_flip = True + split_offsets = [6, 6, 6, 6, 6] + uart_pin = board.SCL + rgb_pixel_pin = board.TX + extra_data_pin = board.SDA + diff --git a/kmk/firmware.py b/kmk/firmware.py index 98e4fa3..685be68 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -150,16 +150,22 @@ class Firmware: self._send_hid() def _handle_matrix_report(self, update=None): - """ + ''' Bulk processing of update code for each cycle :param update: - """ + ''' if update is not None: - self._state.matrix_changed( - update[0], - update[1], - update[2], - ) + # TODO Sort why this is needed when mashing keys on split half + # This is a dirty hack to prevent crashes in unrealistic cases + try: + self._state.matrix_changed( + update[0], + update[1], + update[2], + ) + except Exception as e: + print(e) + print(update) def _send_to_master(self, update): if self.split_master_left: @@ -181,11 +187,11 @@ class Firmware: return None def _send_debug(self, message): - """ + ''' Prepends DEB and appends a newline to allow debug messages to be detected and handled differently than typical keypresses. :param message: Debug message - """ + ''' if self.uart is not None: self.uart.write('DEB') self.uart.write(message, '\n') @@ -221,9 +227,9 @@ class Firmware: if self.split_flip and not self._master_half(): self.col_pins = list(reversed(self.col_pins)) - if self.split_side == "Left": + if self.split_side == 'Left': self.split_master_left = self._master_half() - elif self.split_side == "Right": + elif self.split_side == 'Right': self.split_master_left = not self._master_half() if self.uart_pin is not None: @@ -262,7 +268,7 @@ class Firmware: del self.leader_dictionary[k] if self.debug_enabled: - print("Firin' lazers. Keyboard is booted.") + print('Firin\' lazers. Keyboard is booted.') while True: state_changed = False diff --git a/kmk/keys.py b/kmk/keys.py index 40ee7d5..1a0a608 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -432,18 +432,18 @@ make_key(code=39, names=('0', 'N0')) gc.collect() # More ASCII standard keys -make_key(code=40, names=('ENTER', 'ENT', "\n")) +make_key(code=40, names=('ENTER', 'ENT', '\n')) make_key(code=41, names=('ESCAPE', 'ESC')) make_key(code=42, names=('BACKSPACE', 'BSPC', 'BKSP')) -make_key(code=43, names=('TAB', "\t")) +make_key(code=43, names=('TAB', '\t')) make_key(code=44, names=('SPACE', 'SPC', ' ')) make_key(code=45, names=('MINUS', 'MINS', '-')) make_key(code=46, names=('EQUAL', 'EQL', '=')) make_key(code=47, names=('LBRACKET', 'LBRC', '[')) make_key(code=48, names=('RBRACKET', 'RBRC', ']')) -make_key(code=49, names=('BACKSLASH', 'BSLASH', 'BSLS', "\\")) +make_key(code=49, names=('BACKSLASH', 'BSLASH', 'BSLS', '\\')) make_key(code=51, names=('SEMICOLON', 'SCOLON', 'SCLN', ';')) -make_key(code=52, names=('QUOTE', 'QUOT', "'")) +make_key(code=52, names=('QUOTE', 'QUOT', '\'')) make_key(code=53, names=('GRAVE', 'GRV', 'ZKHK', '`')) make_key(code=54, names=('COMMA', 'COMM', ',')) make_key(code=55, names=('DOT', '.')) @@ -531,7 +531,7 @@ make_key(code=134, names=('KP_EQUAL_AS400', 'NUMPAD_EQUAL_AS400')) gc.collect() # Making life better for folks on tiny keyboards especially: exposes -# the "shifted" keys as raw keys. Under the hood we're still +# the 'shifted' keys as raw keys. Under the hood we're still # sending Shift+(whatever key is normally pressed) to get these, so # for example `KC_AT` will hold shift and press 2. make_shifted_key('GRAVE', names=('TILDE', 'TILD', '~')) @@ -551,7 +551,7 @@ make_shifted_key('LBRACKET', names=('LEFT_CURLY_BRACE', 'LCBR', '{')) make_shifted_key('RBRACKET', names=('RIGHT_CURLY_BRACE', 'RCBR', '}')) make_shifted_key('BACKSLASH', names=('PIPE', '|')) make_shifted_key('SEMICOLON', names=('COLON', 'COLN', ':')) -make_shifted_key('QUOTE', names=('DOUBLE_QUOTE', 'DQUO', 'DQT', '"')) +make_shifted_key('QUOTE', names=('DOUBLE_QUOTE', 'DQUO', 'DQT', '\'')) make_shifted_key('COMMA', names=('LEFT_ANGLE_BRACKET', 'LABK', '<')) make_shifted_key('DOT', names=('RIGHT_ANGLE_BRACKET', 'RABK', '>')) make_shifted_key('SLSH', names=('QUESTION', 'QUES', '?')) @@ -584,9 +584,9 @@ make_key(code=152, names=('LANG9',)) gc.collect() -# Consumer ("media") keys. Most known keys aren't supported here. A much +# Consumer ('media') keys. Most known keys aren't supported here. A much # longer list used to exist in this file, but the codes were almost certainly -# incorrect, conflicting with each other, or otherwise "weird". We'll add them +# incorrect, conflicting with each other, or otherwise 'weird'. We'll add them # back in piecemeal as needed. PRs welcome. # # A super useful reference for these is http://www.freebsddiary.org/APC/usb_hid_usages.php diff --git a/user_keymaps/Default/nyquist_converter.py b/user_keymaps/Default/nyquist_converter.py new file mode 100644 index 0000000..391ed7c --- /dev/null +++ b/user_keymaps/Default/nyquist_converter.py @@ -0,0 +1,137 @@ +from kmk.boards.nyquist_converter import Firmware +from kmk.keys import KC + +keyboard = Firmware() + +_______ = KC.TRNS +XXXXXXX = KC.NO + +LOWER = KC.MO(3) +RAISE = KC.MO(4) +ADJUST = KC.MO(5) + +keyboard.keymap = [ + # Qwerty + # ,-----------------------------------------------------------------------------------. + # | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # | Tab | Q | W | E | R | T | Y | U | I | O | P | Del | + # |------+------+------+------+------+-------------+------+------+------+------+------| + # | Esc | A | S | D | F | G | H | J | K | L | ; | " | + # |------+------+------+------+------+------|------+------+------+------+------+------| + # | Shift| Z | X | C | V | B | N | M | , | . | / |Enter | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right | + # `-----------------------------------------------------------------------------------' + [ + [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC], + [KC.TAB, KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.P, KC.DEL], + [KC.ESC, KC.A, KC.S, KC.D, KC.F, KC.G, KC.H, KC.J, KC.K, KC.L, KC.SCLN, KC.QUOT], + [KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.N, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.ENT], + [ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT], + ], + + # Colemak + # ,-----------------------------------------------------------------------------------. + # | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # | Tab | Q | W | F | P | G | J | L | U | Y | ; | Del | + # |------+------+------+------+------+-------------+------+------+------+------+------| + # | Esc | A | R | S | T | D | H | N | E | I | O | " | + # |------+------+------+------+------+------|------+------+------+------+------+------| + # | Shift| Z | X | C | V | B | K | M | , | . | / |Enter | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right | + # `-----------------------------------------------------------------------------------' + [ + [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC], + [KC.TAB, KC.Q, KC.W, KC.F, KC.P, KC.G, KC.J, KC.L, KC.U, KC.Y, KC.SCLN, KC.DEL], + [KC.ESC, KC.A, KC.R, KC.S, KC.T, KC.D, KC.H, KC.N, KC.E, KC.I, KC.O, KC.QUOT], + [KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.K, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.ENT], + [ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT], + ], + + # Dvorak + # ,-----------------------------------------------------------------------------------. + # | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # | Tab | " | , | . | P | Y | F | G | C | R | L | Del | + # |------+------+------+------+------+-------------+------+------+------+------+------| + # | Esc | A | O | E | U | I | D | H | T | N | S | / | + # |------+------+------+------+------+------|------+------+------+------+------+------| + # | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right | + # `-----------------------------------------------------------------------------------' + [ + [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC], + [KC.TAB, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.DEL], + [KC.ESC, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.SLSH], + [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.ENT], + [ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT], + ], + + # Lower + # ,-----------------------------------------------------------------------------------. + # | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp | + # |------+------+------+------+------+-------------+------+------+------+------+------| + # | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Del | + # |------+------+------+------+------+-------------+------+------+------+------+------| + # | Del | F1 | F2 | F3 | F4 | F5 | F6 | . | + | | \ | | | + # |------+------+------+------+------+------|------+------+------+------+------+------| + # | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | |Enter | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # | | | | | | | | Next | Vol- | Vol+ | Play | + # `-----------------------------------------------------------------------------------' + [ + [KC.TILD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.BSPC], + [KC.TILD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.DEL], + [KC.DEL, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.UNDS, KC.PLUS, KC.LCBR, KC.RCBR, KC.PIPE], + [_______, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.NUHS, KC.NUBS, _______, _______, _______], + [_______, _______, _______, _______, _______, _______, _______, _______, KC.MNXT, KC.VOLD, KC.VOLU, KC.MPLY], + ], + + # Raise + # ,-----------------------------------------------------------------------------------. + # | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + # |------+------+------+------+------+-------------+------+------+------+------+------| + # | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Del | + # |------+------+------+------+------+-------------+------+------+------+------+------| + # | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | + # |------+------+------+------+------+------|------+------+------+------+------+------| + # | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | |Enter | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # | | | | | | | | Next | Vol- | Vol+ | Play | + # `-----------------------------------------------------------------------------------' + [ + [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC], + [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL], + [KC.DEL, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.MINS, KC.EQL, KC.LBRC, KC.RBRC, KC.BSLS], + [_______, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.NUHS, KC.NUBS, _______, _______, _______], + [_______, _______, _______, _______, _______, _______, _______, _______, KC.MNXT, KC.VOLD, KC.VOLU, KC.MPLY], + ], + + # Adjust + # ,-----------------------------------------------------------------------------------. + # | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # | | Reset|RGB Tg|RGB Md|Hue Up|Hue Dn|Sat Up|Sat Dn|Val Up|Val Dn| | Del | + # |------+------+------+------+------+-------------+------+------+------+------+------| + # | | | | | | | |Qwerty|Colemk|Dvorak| | | + # |------+------+------+------+------+------|------+------+------+------+------+------| + # | | | | | | | | | | | | | + # |------+------+------+------+------+------+------+------+------+------+------+------| + # | | | | | | | | | | | | + # `-----------------------------------------------------------------------------------' + [ + [KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12], + [_______, _______, KC.RGB.TOG, KC.RGB.MOD, KC.RGB.HUD, KC.RGB.HUI, KC.RGB.SAD, KC.RGB.SAI, KC.RGB.VAD, KC.RGB.VAI, _______, KC.DEL], + [_______, _______, _______, _______, _______, _______, _______, KC.DF(0), KC.DF(1), KC.DF(2), _______, _______], + [_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______], + [_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______], + ], + +] + +if __name__ == '__main__': + keyboard.go() diff --git a/user_keymaps/kdb424/levinson_m4.py b/user_keymaps/kdb424/levinson_m4.py index 5dc16a6..5313e6c 100644 --- a/user_keymaps/kdb424/levinson_m4.py +++ b/user_keymaps/kdb424/levinson_m4.py @@ -13,12 +13,6 @@ keyboard.col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) keyboard.row_pins = (P.D13, P.D11, P.D10, P.D9) keyboard.diode_orientation = DiodeOrientation.COLUMNS -keyboard.split_type = "UART" -keyboard.split_flip = True -keyboard.split_offsets = [6, 6, 6, 6] -keyboard.uart_pin = board.SCL -keyboard.extra_data_pin = board.SDA - # ------------------User level config variables --------------------------------------- keyboard.leader_mode = LeaderMode.TIMEOUT keyboard.unicode_mode = UnicodeMode.LINUX diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index 4b92c68..ca579d9 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -1,26 +1,10 @@ -import board -import busio - -from kmk.consts import DiodeOrientation, LeaderMode, UnicodeMode -from kmk.handlers.layers import (df_pressed, lt_pressed, lt_released, - mo_pressed, mo_released) +from kmk.boards.nyquist_converter import Firmware +from kmk.consts import LeaderMode, UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences -from kmk.keys import KC, layer_key_validator, make_argumented_key -from kmk.mcus.circuitpython_samd51 import Firmware -from kmk.pins import Pin as P +from kmk.keys import KC keyboard = Firmware() -keyboard.col_pins = (P.RX, P.A1, P.A2, P.A3, P.A4, P.A5) -keyboard.row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7) -keyboard.diode_orientation = DiodeOrientation.COLUMNS - -keyboard.split_type = "UART" -keyboard.split_flip = True -keyboard.split_offsets = [6, 6, 6, 6, 6] -keyboard.uart_pin = board.SCL -keyboard.extra_data_pin = board.SDA - # ------------------User level config variables --------------------------------------- keyboard.leader_mode = LeaderMode.TIMEOUT keyboard.unicode_mode = UnicodeMode.LINUX @@ -29,7 +13,6 @@ keyboard.leader_timeout = 2000 keyboard.debug_enabled = True # RGB Config (underglow) -keyboard.rgb_pixel_pin = board.TX keyboard.rgb_num_pixels = 12 keyboard.rgb_val_limit = 150 @@ -67,89 +50,13 @@ keyboard.leader_dictionary = { 'yay': emoticons.YAY, } - -df = 0 -gw = 1 -r1 = 2 -r2 = 3 -r3 = 4 - - -def base(*args, **kwargs): - return df_pressed(*args, **kwargs) - - -def layer1p(*args, **kwargs): - return mo_pressed(*args, **kwargs) - - -def layer1r(*args, **kwargs): - return mo_released(*args, **kwargs) - - -def layer2p(*args, **kwargs): - return lt_pressed(*args, **kwargs) - - -def layer2r(*args, **kwargs): - return lt_released(*args, **kwargs) - - -def layer3p(*args, **kwargs): - return mo_pressed(*args, **kwargs) - - -def layer3r(*args, **kwargs): - return mo_released(*args, **kwargs) - - -def gaming(*args, **kwargs): - return df_pressed(*args, **kwargs) - - -make_argumented_key( - validator=layer_key_validator, - names=('LAYER_BASE',), - on_press=base, -) - -make_argumented_key( - validator=layer_key_validator, - names=('LAYER_1',), - on_press=layer1p, - on_release=layer1r, -) - -make_argumented_key( - validator=layer_key_validator, - names=('LAYER_2',), - on_press=layer2p, - on_release=layer2r, -) - -make_argumented_key( - validator=layer_key_validator, - names=('LAYER_3',), - on_press=layer3p, - on_release=layer3r, -) - - -make_argumented_key( - validator=layer_key_validator, - names=('LAYER_GAMING',), - on_press=gaming, -) - _______ = KC.TRNS XXXXXXX = KC.NO SHFT_INS = KC.LSHIFT(KC.INS) -BASE = KC.LAYER_BASE(df) -LAYER_1 = KC.LAYER_1(r1) -LT2_SP = KC.LAYER_2(r2, KC.SPC) -LAYER_3 = KC.LAYER_3(r3) -GAMING = KC.LAYER_GAMING(gw) +BASE = KC.DF(0) +LT2_SP = KC.LT(3, KC.SPC) +GAMING = KC.DF(1) # ---------------------- Keymap --------------------------------------------------------- @@ -160,7 +67,7 @@ keyboard.keymap = [ [KC.GRV, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP], [KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT], [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH], - [KC.LCTRL, KC.LGUI, KC.LALT, KC.RGB_TOG, LAYER_1, KC.LT(r2, KC.SPC), KC.LT(r2, KC.SPC), LAYER_3, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + [KC.LCTRL, KC.LGUI, KC.LALT, KC.RGB_TOG, KC.MO(2), LT2_SP, LT2_SP, KC.MO(4), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], ], [ # gw @@ -168,7 +75,7 @@ keyboard.keymap = [ [KC.TAB, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP], [KC.ESC, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT], [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH], - [KC.LCTRL, KC.LGUI, KC.LALT, KC.F1, KC.F2, KC.SPC, KC.LT(r2, KC.SPC), KC.MO(r3), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + [KC.LCTRL, KC.LGUI, KC.LALT, KC.F1, KC.F2, KC.SPC, LT2_SP, KC.MO(4), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], ], [ # r1 diff --git a/user_keymaps/klardotsh/kitsym4_iris.py b/user_keymaps/klardotsh/kitsym4_iris.py index 9b7f425..a46f872 100644 --- a/user_keymaps/klardotsh/kitsym4_iris.py +++ b/user_keymaps/klardotsh/kitsym4_iris.py @@ -1,4 +1,4 @@ -from kmk.boards.kitsym4_iris import Firmware +from kmk.boards.iris_converter import Firmware from kmk.consts import LeaderMode, UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences as cuss from kmk.handlers.sequences import send_string, simple_key_sequence From 373ca8355e8554ec015543380f91cfb5ac00aa4b Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 2 Mar 2019 13:19:03 -0800 Subject: [PATCH 16/32] Added MANY boards to supported list, and organized supported boards --- kmk/boards/converter/40percentclub/__init__.py | 0 kmk/boards/converter/40percentclub/gherkin.py | 9 +++++++++ kmk/boards/converter/40percentclub/luddite.py | 12 ++++++++++++ kmk/boards/converter/__init__.py | 0 kmk/boards/converter/keebio/__init__.py | 0 kmk/boards/converter/keebio/bdn9.py | 11 +++++++++++ kmk/boards/converter/keebio/fourier.py | 16 ++++++++++++++++ kmk/boards/converter/keebio/iris_r1.py | 16 ++++++++++++++++ .../keebio/iris_r2.py} | 0 kmk/boards/converter/keebio/lapace.py | 12 ++++++++++++ kmk/boards/converter/keebio/levinson_r1.py | 16 ++++++++++++++++ .../keebio/levinson_r2.py} | 2 +- kmk/boards/converter/keebio/nyquist_r1.py | 16 ++++++++++++++++ .../keebio/nyquist_r2.py} | 1 - kmk/boards/converter/keebio/quefrency.py | 17 +++++++++++++++++ kmk/boards/converter/keebio/rorschach.py | 16 ++++++++++++++++ kmk/boards/converter/keebio/tragicforce68.py | 9 +++++++++ kmk/boards/converter/keebio/viterbi_r1.py | 16 ++++++++++++++++ kmk/boards/converter/keebio/viterbi_r2.py | 16 ++++++++++++++++ kmk/boards/converter/lets-split/__init__.py | 0 .../converter/lets-split/lets-split_r1.py | 16 ++++++++++++++++ .../converter/lets-split/lets-split_r2.py | 16 ++++++++++++++++ user_keymaps/Default/nyquist_converter.py | 2 +- user_keymaps/kdb424/nyquist_converter.py | 2 +- user_keymaps/klardotsh/kitsym4_iris.py | 4 ++-- 25 files changed, 219 insertions(+), 6 deletions(-) create mode 100644 kmk/boards/converter/40percentclub/__init__.py create mode 100644 kmk/boards/converter/40percentclub/gherkin.py create mode 100644 kmk/boards/converter/40percentclub/luddite.py create mode 100644 kmk/boards/converter/__init__.py create mode 100644 kmk/boards/converter/keebio/__init__.py create mode 100644 kmk/boards/converter/keebio/bdn9.py create mode 100644 kmk/boards/converter/keebio/fourier.py create mode 100644 kmk/boards/converter/keebio/iris_r1.py rename kmk/boards/{iris_converter.py => converter/keebio/iris_r2.py} (100%) create mode 100644 kmk/boards/converter/keebio/lapace.py create mode 100644 kmk/boards/converter/keebio/levinson_r1.py rename kmk/boards/{levinson_converter.py => converter/keebio/levinson_r2.py} (95%) create mode 100644 kmk/boards/converter/keebio/nyquist_r1.py rename kmk/boards/{nyquist_converter.py => converter/keebio/nyquist_r2.py} (99%) create mode 100644 kmk/boards/converter/keebio/quefrency.py create mode 100644 kmk/boards/converter/keebio/rorschach.py create mode 100644 kmk/boards/converter/keebio/tragicforce68.py create mode 100644 kmk/boards/converter/keebio/viterbi_r1.py create mode 100644 kmk/boards/converter/keebio/viterbi_r2.py create mode 100644 kmk/boards/converter/lets-split/__init__.py create mode 100644 kmk/boards/converter/lets-split/lets-split_r1.py create mode 100644 kmk/boards/converter/lets-split/lets-split_r2.py diff --git a/kmk/boards/converter/40percentclub/__init__.py b/kmk/boards/converter/40percentclub/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kmk/boards/converter/40percentclub/gherkin.py b/kmk/boards/converter/40percentclub/gherkin.py new file mode 100644 index 0000000..83ab43c --- /dev/null +++ b/kmk/boards/converter/40percentclub/gherkin.py @@ -0,0 +1,9 @@ +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.D9, P.D10, P.D11, P.D12, P.D13, P.SCL) + row_pins = (P.A3, P.A4, P.A5, P.SCK, P.MOSI) + diode_orientation = DiodeOrientation.COLUMNS diff --git a/kmk/boards/converter/40percentclub/luddite.py b/kmk/boards/converter/40percentclub/luddite.py new file mode 100644 index 0000000..46a2024 --- /dev/null +++ b/kmk/boards/converter/40percentclub/luddite.py @@ -0,0 +1,12 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A0, P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.TX, P.RX, P.SDA, P.SCL, P.D13, P.D12, P.D11, P.D10) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.D9 diff --git a/kmk/boards/converter/__init__.py b/kmk/boards/converter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kmk/boards/converter/keebio/__init__.py b/kmk/boards/converter/keebio/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kmk/boards/converter/keebio/bdn9.py b/kmk/boards/converter/keebio/bdn9.py new file mode 100644 index 0000000..1c75906 --- /dev/null +++ b/kmk/boards/converter/keebio/bdn9.py @@ -0,0 +1,11 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.RX, P.D13, P.A0, P.D11, P.A4, P.A5, P.D10, P.D9, P.SCK) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX diff --git a/kmk/boards/converter/keebio/fourier.py b/kmk/boards/converter/keebio/fourier.py new file mode 100644 index 0000000..e86a459 --- /dev/null +++ b/kmk/boards/converter/keebio/fourier.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.A0, P.D11, P.D10, P.D9) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [7, 7, 7, 7] diff --git a/kmk/boards/converter/keebio/iris_r1.py b/kmk/boards/converter/keebio/iris_r1.py new file mode 100644 index 0000000..f687a8e --- /dev/null +++ b/kmk/boards/converter/keebio/iris_r1.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.D11, P.D10, P.D9, P.D7, P.D13) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [6, 6, 6, 6, 6] diff --git a/kmk/boards/iris_converter.py b/kmk/boards/converter/keebio/iris_r2.py similarity index 100% rename from kmk/boards/iris_converter.py rename to kmk/boards/converter/keebio/iris_r2.py diff --git a/kmk/boards/converter/keebio/lapace.py b/kmk/boards/converter/keebio/lapace.py new file mode 100644 index 0000000..7629fe6 --- /dev/null +++ b/kmk/boards/converter/keebio/lapace.py @@ -0,0 +1,12 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.SDA, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.TX, P.A0, P.RX, P.A1, P.D11, P.D9, P.D12, P.D10) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.D13 diff --git a/kmk/boards/converter/keebio/levinson_r1.py b/kmk/boards/converter/keebio/levinson_r1.py new file mode 100644 index 0000000..9d622a8 --- /dev/null +++ b/kmk/boards/converter/keebio/levinson_r1.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.A0) + row_pins = (P.D11, P.D10, P.D9, P.D7) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [6, 6, 6, 6] diff --git a/kmk/boards/levinson_converter.py b/kmk/boards/converter/keebio/levinson_r2.py similarity index 95% rename from kmk/boards/levinson_converter.py rename to kmk/boards/converter/keebio/levinson_r2.py index 965cfc6..c30b9b6 100644 --- a/kmk/boards/levinson_converter.py +++ b/kmk/boards/converter/keebio/levinson_r2.py @@ -16,4 +16,4 @@ class Firmware(_Firmware): uart_pin = board.SCL extra_data_pin = board.SDA rgb_pixel_pin = board.TX - #led_pin = board.D7 + # led_pin = board.D7 diff --git a/kmk/boards/converter/keebio/nyquist_r1.py b/kmk/boards/converter/keebio/nyquist_r1.py new file mode 100644 index 0000000..a7b2c51 --- /dev/null +++ b/kmk/boards/converter/keebio/nyquist_r1.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [6, 6, 6, 6, 6] diff --git a/kmk/boards/nyquist_converter.py b/kmk/boards/converter/keebio/nyquist_r2.py similarity index 99% rename from kmk/boards/nyquist_converter.py rename to kmk/boards/converter/keebio/nyquist_r2.py index cd0c1f2..b0a9699 100644 --- a/kmk/boards/nyquist_converter.py +++ b/kmk/boards/converter/keebio/nyquist_r2.py @@ -16,4 +16,3 @@ class Firmware(_Firmware): uart_pin = board.SCL rgb_pixel_pin = board.TX extra_data_pin = board.SDA - diff --git a/kmk/boards/converter/keebio/quefrency.py b/kmk/boards/converter/keebio/quefrency.py new file mode 100644 index 0000000..a2e7cdc --- /dev/null +++ b/kmk/boards/converter/keebio/quefrency.py @@ -0,0 +1,17 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + # Will need additional work and testing + col_pins = (P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI, P.D12) + row_pins = (P.A0, P.D13, P.D11, P.D10, P.D9, P.D7) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = False + split_offsets = [8, 8, 8, 8, 8, 8] diff --git a/kmk/boards/converter/keebio/rorschach.py b/kmk/boards/converter/keebio/rorschach.py new file mode 100644 index 0000000..942c19d --- /dev/null +++ b/kmk/boards/converter/keebio/rorschach.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.D11, P.D10, P.D9, P.RX, P.D13) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [6, 6, 6, 6, 6] diff --git a/kmk/boards/converter/keebio/tragicforce68.py b/kmk/boards/converter/keebio/tragicforce68.py new file mode 100644 index 0000000..17d6841 --- /dev/null +++ b/kmk/boards/converter/keebio/tragicforce68.py @@ -0,0 +1,9 @@ +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A0, P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.TX, P.RX, P.SDA, P.SCL, P.D9, P.D10, P.D12, P.D11, P.D13) + diode_orientation = DiodeOrientation.COLUMNS diff --git a/kmk/boards/converter/keebio/viterbi_r1.py b/kmk/boards/converter/keebio/viterbi_r1.py new file mode 100644 index 0000000..6f5d161 --- /dev/null +++ b/kmk/boards/converter/keebio/viterbi_r1.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) + row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [7, 7, 7, 7, 7] diff --git a/kmk/boards/converter/keebio/viterbi_r2.py b/kmk/boards/converter/keebio/viterbi_r2.py new file mode 100644 index 0000000..d273669 --- /dev/null +++ b/kmk/boards/converter/keebio/viterbi_r2.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A0, P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK) + row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [7, 7, 7, 7, 7] diff --git a/kmk/boards/converter/lets-split/__init__.py b/kmk/boards/converter/lets-split/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kmk/boards/converter/lets-split/lets-split_r1.py b/kmk/boards/converter/lets-split/lets-split_r1.py new file mode 100644 index 0000000..c304f44 --- /dev/null +++ b/kmk/boards/converter/lets-split/lets-split_r1.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.A5, P.A4, P.A3, P.A2, P.A1, P.A0) + row_pins = (P.D7, P.D9, P.D10, P.D11) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [6, 6, 6, 6] diff --git a/kmk/boards/converter/lets-split/lets-split_r2.py b/kmk/boards/converter/lets-split/lets-split_r2.py new file mode 100644 index 0000000..6520bf9 --- /dev/null +++ b/kmk/boards/converter/lets-split/lets-split_r2.py @@ -0,0 +1,16 @@ +import board + +from kmk.consts import DiodeOrientation +from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware +from kmk.pins import Pin as P + + +class Firmware(_Firmware): + col_pins = (P.MOSI, P.SCK, P.A5, P.A4, P.A3, P.A2) + row_pins = (P.D11, P.D10, P.D9, P.D7) + diode_orientation = DiodeOrientation.COLUMNS + rgb_pixel_pin = board.TX + uart_pin = board.SCL + split_type = 'UART' + split_flip = True + split_offsets = [6, 6, 6, 6] diff --git a/user_keymaps/Default/nyquist_converter.py b/user_keymaps/Default/nyquist_converter.py index 391ed7c..f13f0a8 100644 --- a/user_keymaps/Default/nyquist_converter.py +++ b/user_keymaps/Default/nyquist_converter.py @@ -1,4 +1,4 @@ -from kmk.boards.nyquist_converter import Firmware +from kmk.boards.converter.keebio.nyquist_r2 import Firmware from kmk.keys import KC keyboard = Firmware() diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_converter.py index ca579d9..3bc36fd 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_converter.py @@ -1,4 +1,4 @@ -from kmk.boards.nyquist_converter import Firmware +from kmk.boards.converter.keebio.nyquist_r2 import Firmware from kmk.consts import LeaderMode, UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences from kmk.keys import KC diff --git a/user_keymaps/klardotsh/kitsym4_iris.py b/user_keymaps/klardotsh/kitsym4_iris.py index a46f872..8964c65 100644 --- a/user_keymaps/klardotsh/kitsym4_iris.py +++ b/user_keymaps/klardotsh/kitsym4_iris.py @@ -1,7 +1,7 @@ -from kmk.boards.iris_converter import Firmware +from kmk.boards.converter.keebio.iris_r2 import Firmware from kmk.consts import LeaderMode, UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences as cuss -from kmk.handlers.sequences import send_string, simple_key_sequence +from kmk.handlers.sequences import send_string from kmk.keys import KC keyboard = Firmware() From a882ef2c3896588fc807acf3bf8bf51b258ccf96 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 2 Mar 2019 13:49:25 -0800 Subject: [PATCH 17/32] Quick patch unrealistic face roll keyboard corruption --- kmk/firmware.py | 11 ++++++++--- .../Default/{nyquist_converter.py => nyquist_r2.py} | 0 .../kdb424/{levinson_m4.py => levinson_r2.py} | 0 .../kdb424/{nyquist_converter.py => nyquist_r2.py} | 2 +- .../klardotsh/{kitsym4_iris.py => iris_r2.py} | 0 5 files changed, 9 insertions(+), 4 deletions(-) rename user_keymaps/Default/{nyquist_converter.py => nyquist_r2.py} (100%) rename user_keymaps/kdb424/{levinson_m4.py => levinson_r2.py} (100%) rename user_keymaps/kdb424/{nyquist_converter.py => nyquist_r2.py} (99%) rename user_keymaps/klardotsh/{kitsym4_iris.py => iris_r2.py} (100%) diff --git a/kmk/firmware.py b/kmk/firmware.py index 685be68..390fbba 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -163,9 +163,14 @@ class Firmware: update[1], update[2], ) - except Exception as e: - print(e) - print(update) + except IndexError: + # If buffer get's corrupted, reset the master half. + # Alternative would be flush the contents and release all keys + import microcontroller + microcontroller.reset() + + def _flush_buffer(self): + self.uart.read() def _send_to_master(self, update): if self.split_master_left: diff --git a/user_keymaps/Default/nyquist_converter.py b/user_keymaps/Default/nyquist_r2.py similarity index 100% rename from user_keymaps/Default/nyquist_converter.py rename to user_keymaps/Default/nyquist_r2.py diff --git a/user_keymaps/kdb424/levinson_m4.py b/user_keymaps/kdb424/levinson_r2.py similarity index 100% rename from user_keymaps/kdb424/levinson_m4.py rename to user_keymaps/kdb424/levinson_r2.py diff --git a/user_keymaps/kdb424/nyquist_converter.py b/user_keymaps/kdb424/nyquist_r2.py similarity index 99% rename from user_keymaps/kdb424/nyquist_converter.py rename to user_keymaps/kdb424/nyquist_r2.py index 3bc36fd..d05aabd 100644 --- a/user_keymaps/kdb424/nyquist_converter.py +++ b/user_keymaps/kdb424/nyquist_r2.py @@ -10,7 +10,7 @@ keyboard.leader_mode = LeaderMode.TIMEOUT keyboard.unicode_mode = UnicodeMode.LINUX keyboard.tap_time = 150 keyboard.leader_timeout = 2000 -keyboard.debug_enabled = True +keyboard.debug_enabled = False # RGB Config (underglow) keyboard.rgb_num_pixels = 12 diff --git a/user_keymaps/klardotsh/kitsym4_iris.py b/user_keymaps/klardotsh/iris_r2.py similarity index 100% rename from user_keymaps/klardotsh/kitsym4_iris.py rename to user_keymaps/klardotsh/iris_r2.py From e2413a3c25f376806b07bddf9afa28e993ffafd6 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 2 Mar 2019 15:14:11 -0800 Subject: [PATCH 18/32] Still dirty, but moved the problem to a better place. Still unrealistic to hit --- kmk/firmware.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index 390fbba..20a057e 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -155,22 +155,12 @@ class Firmware: :param update: ''' if update is not None: - # TODO Sort why this is needed when mashing keys on split half - # This is a dirty hack to prevent crashes in unrealistic cases - try: - self._state.matrix_changed( - update[0], - update[1], - update[2], - ) - except IndexError: - # If buffer get's corrupted, reset the master half. - # Alternative would be flush the contents and release all keys - import microcontroller - microcontroller.reset() - def _flush_buffer(self): - self.uart.read() + self._state.matrix_changed( + update[0], + update[1], + update[2], + ) def _send_to_master(self, update): if self.split_master_left: @@ -182,7 +172,13 @@ class Firmware: def _receive_from_slave(self): if self.uart is not None and self.uart.in_waiting > 0: + if self.uart.in_waiting >= 60: + # This is a dirty hack to prevent crashes in unrealistic cases + import microcontroller + microcontroller.reset() + update = bytearray(self.uart.read(3)) + # Built in debug mode switch if update == b'DEB': print(self.uart.readline()) @@ -216,7 +212,7 @@ class Firmware: def init_uart(self, pin, timeout=20): if self._master_half(): - return busio.UART(tx=None, rx=pin, timeout=timeout) + return busio.UART(tx=None, rx=pin, timeout=timeout,) else: return busio.UART(tx=pin, rx=None, timeout=timeout) From 0a06e733d200ed2c6956f398c26182f3fa4cb354 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 2 Mar 2019 15:44:04 -0800 Subject: [PATCH 19/32] Solved. Added uart buffer on the master to free up the uart bus buffer --- kmk/firmware.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index 20a057e..ab653b0 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -70,6 +70,7 @@ class Firmware: col_pins = None diode_orientation = None matrix_scanner = MatrixScanner + uart_buffer = [] unicode_mode = UnicodeMode.NOOP tap_time = 300 @@ -171,19 +172,22 @@ class Firmware: self.uart.write(update) def _receive_from_slave(self): - if self.uart is not None and self.uart.in_waiting > 0: + if self.uart is not None and self.uart.in_waiting > 0 or self.uart_buffer: if self.uart.in_waiting >= 60: # This is a dirty hack to prevent crashes in unrealistic cases import microcontroller microcontroller.reset() - update = bytearray(self.uart.read(3)) + while self.uart.in_waiting >=3: + self.uart_buffer.append(self.uart.read(3)) + if self.uart_buffer: + update = bytearray(self.uart_buffer.pop(0)) - # Built in debug mode switch - if update == b'DEB': - print(self.uart.readline()) - return None - return update + # Built in debug mode switch + if update == b'DEB': + print(self.uart.readline()) + return None + return update return None From ec1a62e52defafe96cf7758292b561abd477a56d Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sun, 3 Mar 2019 10:27:24 -0800 Subject: [PATCH 20/32] Added static standby mode for performance. --- kmk/firmware.py | 6 ++--- kmk/rgb.py | 66 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index ab653b0..ed7c47c 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -178,7 +178,7 @@ class Firmware: import microcontroller microcontroller.reset() - while self.uart.in_waiting >=3: + while self.uart.in_waiting >= 3: self.uart_buffer.append(self.uart.read(3)) if self.uart_buffer: update = bytearray(self.uart_buffer.pop(0)) @@ -216,7 +216,7 @@ class Firmware: def init_uart(self, pin, timeout=20): if self._master_half(): - return busio.UART(tx=None, rx=pin, timeout=timeout,) + return busio.UART(tx=None, rx=pin, timeout=timeout) else: return busio.UART(tx=pin, rx=None, timeout=timeout) @@ -316,7 +316,7 @@ class Firmware: if self.pixels: # Only check animations if pixels is initialized if self.pixels.animation_mode: - if self.pixels.animation_mode is not 'static_standby': + if self.pixels.animation_mode: self.pixels = self.pixels.animate() if self.led: diff --git a/kmk/rgb.py b/kmk/rgb.py index 037cb65..d405165 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -153,6 +153,8 @@ class RGB: else: self.set_rgb(self.hsv_to_rgb(hue, sat, val), index) + return self + def set_hsv_fill(self, hue, sat, val): """ Takes HSV values and displays it on all LEDs/Neopixels @@ -165,6 +167,7 @@ class RGB: self.set_rgb_fill(self.hsv_to_rgbw(hue, sat, val)) else: self.set_rgb_fill(self.hsv_to_rgb(hue, sat, val)) + return self def set_rgb(self, rgb, index): """ @@ -177,6 +180,8 @@ class RGB: if not self.disable_auto_write: self.neopixel.show() + return self + def set_rgb_fill(self, rgb): """ Takes an RGB or RGBW and displays it on all LEDs/Neopixels @@ -187,6 +192,8 @@ class RGB: if not self.disable_auto_write: self.neopixel.show() + return self + def increase_hue(self, step=None): """ Increases hue by step amount rolling at 360 and returning to 0 @@ -197,6 +204,11 @@ class RGB: self.hue = (self.hue + step) % 360 + if self._check_update(): + self._do_update() + + return self + def decrease_hue(self, step=None): """ Decreases hue by step amount rolling at 0 and returning to 360 @@ -210,6 +222,11 @@ class RGB: else: self.hue = (self.hue - step) % 360 + if self._check_update(): + self._do_update() + + return self + def increase_sat(self, step=None): """ Increases saturation by step amount stopping at 100 @@ -223,6 +240,11 @@ class RGB: else: self.sat += step + if self._check_update(): + self._do_update() + + return self + def decrease_sat(self, step=None): """ Decreases saturation by step amount stopping at 0 @@ -236,6 +258,11 @@ class RGB: else: self.sat -= step + if self._check_update(): + self._do_update() + + return self + def increase_val(self, step=None): """ Increases value by step amount stopping at 100 @@ -249,6 +276,11 @@ class RGB: else: self.val += step + if self._check_update(): + self._do_update() + + return self + def decrease_val(self, step=None): """ Decreases value by step amount stopping at 0 @@ -262,6 +294,11 @@ class RGB: else: self.val -= step + if self._check_update(): + self._do_update() + + return self + def increase_ani(self): """ Increases animation speed by 1 amount stopping at 10 @@ -282,6 +319,8 @@ class RGB: else: self.val -= 1 + return self + def off(self): """ Turns off all LEDs/Neopixels without changing stored values @@ -289,6 +328,8 @@ class RGB: if self.neopixel: self.set_hsv_fill(0, 0, 0) + return self + def show(self): """ Turns on all LEDs/Neopixels without changing stored values @@ -296,13 +337,16 @@ class RGB: if self.neopixel: self.neopixel.show() + return self + def animate(self): """ Activates a "step" in the animation based on the active mode :return: Returns the new state in animation """ if self.effect_init: - self.init_effect() + self._init_effect() + if self.enabled: if self.animation_mode == 'breathing': return self.effect_breathing() @@ -314,12 +358,14 @@ class RGB: return self.effect_static() elif self.animation_mode == 'knight': return self.effect_knight() + elif self.animation_mode == 'static_standby': + pass else: self.off() return self - def animation_step(self): + def _animation_step(self): interval = self.time_ms() - self.time if interval >= max(self.intervals): self.time = self.time_ms() @@ -329,13 +375,23 @@ class RGB: else: return False - def init_effect(self): + def _init_effect(self): self.pos = 0 self.reverse_animation = False self.effect_init = False + return self + + def _check_update(self): + if self.animation_mode == 'static_standby': + return True + + def _do_update(self): + if self.animation_mode == 'static_standby': + self.animation_mode = 'static' def effect_static(self): self.set_hsv_fill(self.hue, self.sat, self.val) + self.animation_mode = 'static_standby' return self def effect_breathing(self): @@ -349,14 +405,14 @@ class RGB: return self def effect_breathing_rainbow(self): - if self.animation_step(): + if self._animation_step(): self.increase_hue(self.animation_speed) self.effect_breathing() return self def effect_rainbow(self): - if self.animation_step(): + if self._animation_step(): self.increase_hue(self.animation_speed) self.set_hsv_fill(self.hue, self.sat, self.val) From 7ebf8d623f141ebdbd81edb483e5b06858dcb217 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Mon, 4 Mar 2019 23:23:15 -0800 Subject: [PATCH 21/32] Fix toggle --- kmk/handlers/stock.py | 4 ++++ user_keymaps/kdb424/nyquist_r2.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index 736cc61..1c58565 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -121,6 +121,8 @@ def td_released(key, state, *args, **kwargs): def rgb_tog(key, state, *args, **kwargs): + if state.config.pixels.animation_mode == 'static_standby': + state.config.pixels.animation_mode = 'static' state.config.pixels.enabled = not state.config.pixels.enabled return state @@ -196,6 +198,8 @@ def rgb_mode_knight(key, state, *args, **kwargs): def led_tog(key, state, *args, **kwargs): + if state.config.led.animation_mode == 'static_standby': + state.config.led.animation_mode = 'static' state.config.led.enabled = not state.config.led.enabled return state diff --git a/user_keymaps/kdb424/nyquist_r2.py b/user_keymaps/kdb424/nyquist_r2.py index d05aabd..2fe1e1a 100644 --- a/user_keymaps/kdb424/nyquist_r2.py +++ b/user_keymaps/kdb424/nyquist_r2.py @@ -24,7 +24,7 @@ keyboard.rgb_sat_default = 100 keyboard.rgb_val_default = 20 keyboard.rgb_knight_effect_length = 4 keyboard.rgb_animation_mode = 'static' -keyboard.rgb_animation_speed = 2 +keyboard.rgb_animation_speed = 1 emoticons = compile_unicode_string_sequences({ # Emoticons, but fancier From 1a06e0ed72cdd8ed033205b15097c6d24f0a24b4 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Thu, 7 Mar 2019 17:41:57 -0800 Subject: [PATCH 22/32] Renamed some things and added luddite layout for kdb424 and default --- .../__init__.py | 0 .../gherkin.py | 0 .../luddite.py | 0 user_keymaps/Default/__init__.py | 0 user_keymaps/Default/converter/__init__.py | 0 .../converter/fourtypercentclub/__init__.py | 0 .../converter/fourtypercentclub/luddite.py | 28 ++++++++ .../Default/converter/keebio/__init__.py | 0 .../{ => converter/keebio}/nyquist_r2.py | 0 user_keymaps/kdb424/luddite.py | 65 +++++++++++++++++++ 10 files changed, 93 insertions(+) rename kmk/boards/converter/{40percentclub => fourtypercentclub}/__init__.py (100%) rename kmk/boards/converter/{40percentclub => fourtypercentclub}/gherkin.py (100%) rename kmk/boards/converter/{40percentclub => fourtypercentclub}/luddite.py (100%) create mode 100644 user_keymaps/Default/__init__.py create mode 100644 user_keymaps/Default/converter/__init__.py create mode 100644 user_keymaps/Default/converter/fourtypercentclub/__init__.py create mode 100644 user_keymaps/Default/converter/fourtypercentclub/luddite.py create mode 100644 user_keymaps/Default/converter/keebio/__init__.py rename user_keymaps/Default/{ => converter/keebio}/nyquist_r2.py (100%) create mode 100644 user_keymaps/kdb424/luddite.py diff --git a/kmk/boards/converter/40percentclub/__init__.py b/kmk/boards/converter/fourtypercentclub/__init__.py similarity index 100% rename from kmk/boards/converter/40percentclub/__init__.py rename to kmk/boards/converter/fourtypercentclub/__init__.py diff --git a/kmk/boards/converter/40percentclub/gherkin.py b/kmk/boards/converter/fourtypercentclub/gherkin.py similarity index 100% rename from kmk/boards/converter/40percentclub/gherkin.py rename to kmk/boards/converter/fourtypercentclub/gherkin.py diff --git a/kmk/boards/converter/40percentclub/luddite.py b/kmk/boards/converter/fourtypercentclub/luddite.py similarity index 100% rename from kmk/boards/converter/40percentclub/luddite.py rename to kmk/boards/converter/fourtypercentclub/luddite.py diff --git a/user_keymaps/Default/__init__.py b/user_keymaps/Default/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user_keymaps/Default/converter/__init__.py b/user_keymaps/Default/converter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user_keymaps/Default/converter/fourtypercentclub/__init__.py b/user_keymaps/Default/converter/fourtypercentclub/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user_keymaps/Default/converter/fourtypercentclub/luddite.py b/user_keymaps/Default/converter/fourtypercentclub/luddite.py new file mode 100644 index 0000000..7be1533 --- /dev/null +++ b/user_keymaps/Default/converter/fourtypercentclub/luddite.py @@ -0,0 +1,28 @@ +from kmk.boards.converter.fourtypercentclub.luddite import Firmware +from kmk.keys import KC + +keyboard = Firmware() + +_______ = KC.TRNS +XXXXXXX = KC.NO + +BASE = 0 +FN1 = 1 + +keyboard.keymap = [ + [ + [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.MINS, KC.EQL, KC.BSPC], + [KC.TAB, KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.P, KC.LBRC, KC.RBRC, KC.BSLS], + [KC.CAPS, KC.A, KC.S, KC.D, KC.F, KC.G, KC.H, KC.J, KC.K, KC.L, KC.SCLN, KC.QUOT, KC.ENT], + [KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.N, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.RSFT], + [KC.LCTL, KC.LGUI, KC.LALT, KC.SPC, KC.RALT, KC.RGUI, KC.MO(FN1), KC.RCTL], + ], + + [ + [KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.BSPC], + [KC.RGB_TOG, _______, KC.UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______], + [_______, KC.LEFT, KC.DOWN, KC.RGHT, _______, _______, _______, _______, _______, _______, _______, _______, _______], + [KC.LED_INC, KC.LED_DEC, KC.LED_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______], + [KC.GRV, _______, _______, _______, _______, _______, _______, _______], + ], +] diff --git a/user_keymaps/Default/converter/keebio/__init__.py b/user_keymaps/Default/converter/keebio/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user_keymaps/Default/nyquist_r2.py b/user_keymaps/Default/converter/keebio/nyquist_r2.py similarity index 100% rename from user_keymaps/Default/nyquist_r2.py rename to user_keymaps/Default/converter/keebio/nyquist_r2.py diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py new file mode 100644 index 0000000..2918197 --- /dev/null +++ b/user_keymaps/kdb424/luddite.py @@ -0,0 +1,65 @@ +from kmk.boards.converter.fourtypercentclub.luddite import Firmware +from kmk.consts import LeaderMode, UnicodeMode +from kmk.handlers.sequences import compile_unicode_string_sequences +from kmk.keys import KC + +keyboard = Firmware() + +# ---------------------------------- Config -------------------------------------------- + +keyboard.leader_mode = LeaderMode.TIMEOUT +keyboard.unicode_mode = UnicodeMode.LINUX +keyboard.tap_time = 150 +keyboard.leader_timeout = 2000 + +# ---------------------- Leader Key Macros -------------------------------------------- + +emoticons = compile_unicode_string_sequences({ + # Emoticons, but fancier + 'ANGRY_TABLE_FLIP': r'(ノಠ痊ಠ)ノ彡┻━┻', + 'CHEER': r'+。:.゚ヽ(´∀。)ノ゚.:。+゚゚+。:.゚ヽ(*´∀)ノ゚.:。+゚', + 'TABLE_FLIP': r'(╯°□°)╯︵ ┻━┻', + 'WAT': r'⊙.☉', + 'FF': r'凸(゚Д゚#)', + 'F': r'( ̄^ ̄)凸', + 'MEH': r'╮( ̄_ ̄)╭', + 'YAY': r'o(^▽^)o', +}) + + +keyboard.leader_dictionary = { + 'flip': emoticons.ANGRY_TABLE_FLIP, + 'cheer': emoticons.CHEER, + 'wat': emoticons.WAT, + 'ff': emoticons.FF, + 'f': emoticons.F, + 'meh': emoticons.MEH, + 'yay': emoticons.YAY, +} + +# ---------------------- Keymap --------------------------------------------------------- + + +_______ = KC.TRNS +XXXXXXX = KC.NO + +BASE = 0 +FN1 = 1 + +keyboard.keymap = [ + [ + [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.LBRC, KC.RBRC, KC.BSPC], + [KC.LEAD, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.SLSH, KC.EQL, KC.BSLS], + [KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.MINS, KC.ENT], + [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.RSFT], + [KC.LCTL, KC.LGUI, KC.MO(FN1), KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + ], + + [ + [KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.DEL], + [KC.RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC.VOLU, _______], + [_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC.VOLD, _______], + [_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______], + [KC.GRV, _______, _______, _______, KC.LALT, _______, _______, _______], + ], +] From efb642c3741734ed09b44864842cb62b58f87806 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 9 Mar 2019 11:29:45 -0800 Subject: [PATCH 23/32] Fix some issues if you don't define some things --- kmk/boards/converter/fourtypercentclub/luddite.py | 1 + kmk/firmware.py | 8 ++++++-- kmk/rgb.py | 4 ++-- .../Default/converter/fourtypercentclub/luddite.py | 3 +++ user_keymaps/kdb424/luddite.py | 3 +++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kmk/boards/converter/fourtypercentclub/luddite.py b/kmk/boards/converter/fourtypercentclub/luddite.py index 46a2024..99e5ca5 100644 --- a/kmk/boards/converter/fourtypercentclub/luddite.py +++ b/kmk/boards/converter/fourtypercentclub/luddite.py @@ -10,3 +10,4 @@ class Firmware(_Firmware): row_pins = (P.TX, P.RX, P.SDA, P.SCL, P.D13, P.D12, P.D11, P.D10) diode_orientation = DiodeOrientation.COLUMNS rgb_pixel_pin = board.D9 + rgb_num_pixels = 12 diff --git a/kmk/firmware.py b/kmk/firmware.py index ed7c47c..b5de854 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -95,7 +95,7 @@ class Firmware: # RGB config rgb_pixel_pin = None rgb_pixels = None - rgb_num_pixels = None + rgb_num_pixels = 0 rgb_order = (1, 0, 2) # GRB WS2812 rgb_val_limit = 255 rgb_hue_default = 0 @@ -240,7 +240,7 @@ class Firmware: if self.uart_pin is not None: self.uart = self.init_uart(self.uart_pin) - if self.rgb_pixel_pin is not None: + if self.rgb_pixel_pin: self.pixels = rgb.RGB(self.rgb_pixel_pin, self.rgb_order, self.rgb_num_pixels, self.rgb_hue_step, self.rgb_sat_step, self.rgb_val_step, self.rgb_hue_default, self.rgb_sat_default, self.rgb_val_default, @@ -248,12 +248,16 @@ class Firmware: self.rgb_val_limit, self.rgb_animation_mode, self.rgb_animation_speed, ) + else: + self.pixels = None if self.led_pin: self.led = led.led(self.led_pin, self.led_brightness_step, self.led_brightness_limit, self.led_animation_mode, self.led_animation_speed, self.led_breathe_center, ) + else: + self.led = None self.matrix = MatrixScanner( cols=self.col_pins, diff --git a/kmk/rgb.py b/kmk/rgb.py index d405165..0d29b40 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -50,8 +50,8 @@ class RGB: self.breath_center = breath_center self.knight_effect_length = knight_effect_length self.val_limit = val_limit - self.animation_mode = animation_mode - self.animation_speed = animation_speed + self.rgb_animation_mode = animation_mode + self.rgb_animation_speed = animation_speed except ImportError as e: print(e) diff --git a/user_keymaps/Default/converter/fourtypercentclub/luddite.py b/user_keymaps/Default/converter/fourtypercentclub/luddite.py index 7be1533..8085ae0 100644 --- a/user_keymaps/Default/converter/fourtypercentclub/luddite.py +++ b/user_keymaps/Default/converter/fourtypercentclub/luddite.py @@ -26,3 +26,6 @@ keyboard.keymap = [ [KC.GRV, _______, _______, _______, _______, _______, _______, _______], ], ] + +if __name__ == '__main__': + keyboard.go() diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py index 2918197..dd18e82 100644 --- a/user_keymaps/kdb424/luddite.py +++ b/user_keymaps/kdb424/luddite.py @@ -63,3 +63,6 @@ keyboard.keymap = [ [KC.GRV, _______, _______, _______, KC.LALT, _______, _______, _______], ], ] + +if __name__ == '__main__': + keyboard.go() From fa28b3afba8085fce5ac0bf2d6cff57cb23cb0c4 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 9 Mar 2019 18:28:10 -0800 Subject: [PATCH 24/32] Luddite "fixes" for personal layout. Exposes a KMK limitation --- user_keymaps/kdb424/luddite.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py index dd18e82..38a96c0 100644 --- a/user_keymaps/kdb424/luddite.py +++ b/user_keymaps/kdb424/luddite.py @@ -48,19 +48,25 @@ FN1 = 1 keyboard.keymap = [ [ - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.LBRC, KC.RBRC, KC.BSPC], - [KC.LEAD, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.SLSH, KC.EQL, KC.BSLS], - [KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.MINS, KC.ENT], - [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.RSFT], - [KC.LCTL, KC.LGUI, KC.MO(FN1), KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7], + [KC.N8, KC.N9, KC.N0, KC.LBRC, KC.RBRC, KC.BSPC, KC.LEAD, KC.QUOT], + [KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R], + [KC.L, KC.SLSH, KC.EQL, KC.BSLS, KC.TAB, KC.A, KC.O, KC.E], + [KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.MINS], + [KC.ENT, KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B], + [KC.M, KC.W, KC.V, KC.Z, KC.RSFT, KC.LCTL, KC.LGUI, KC.MO(FN1)], + [KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], ], [ - [KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.DEL], - [KC.RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC.VOLU, _______], - [_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC.VOLD, _______], - [_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______], - [KC.GRV, _______, _______, _______, KC.LALT, _______, _______, _______], + [KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7], + [KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.DEL, KC.RGB_TOG, _______], + [_______, _______, _______, _______, _______, _______, _______, _______], + [_______, _______, KC.VOLU, _______, _______, _______, _______, _______], + [_______, _______, _______, _______, _______, _______, _______, KC.VOLD], + [_______, _______, _______, _______, _______, _______, _______, _______], + [_______, _______, _______, _______, _______, KC.GRV, _______, _______], + [_______, KC.LALT, _______, _______, _______], ], ] From bb198709f29f1a1446c9d1ac6aef223f3c2fc846 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Tue, 12 Mar 2019 00:34:22 -0700 Subject: [PATCH 25/32] fix incorrect merge --- kmk/firmware.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index b5de854..e7ef9e5 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -25,7 +25,6 @@ import kmk.util # isort:skip import busio # isort:skip import supervisor # isort:skip -from kmk import rgb # isort:skip from kmk.consts import LeaderMode, UnicodeMode # isort:skip from kmk.hid import USB_HID # isort:skip from kmk.internal_state import InternalState # isort:skip @@ -57,7 +56,7 @@ from kmk.hid import USB_HID from kmk.internal_state import InternalState from kmk.keys import KC from kmk.matrix import MatrixScanner -from kmk import rgb +from kmk import led, rgb # isort:skip class Firmware: From 86b8c4ffb0b5757dc5370801577f92277f6b4148 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Fri, 15 Mar 2019 17:37:25 -0700 Subject: [PATCH 26/32] New animation --- kmk/handlers/stock.py | 8 +++- kmk/keys.py | 1 + kmk/rgb.py | 20 +++++++++- user_keymaps/kdb424/luddite.py | 64 ++++++++++++++++++++++++------- user_keymaps/kdb424/nyquist_r2.py | 10 ++--- 5 files changed, 82 insertions(+), 21 deletions(-) diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index 1c58565..feea67c 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -52,8 +52,6 @@ def gesc_pressed(key, state, KC, *args, **kwargs): if GESC_TRIGGERS.intersection(state.keys_pressed): # First, release GUI if already pressed - state.keys_pressed.discard(KC.LGUI) - state.keys_pressed.discard(KC.RGUI) state.config._send_hid() # if Shift is held, KC_GRAVE will become KC_TILDE on OS level state.keys_pressed.add(KC.GRAVE) @@ -191,6 +189,12 @@ def rgb_mode_rainbow(key, state, *args, **kwargs): return state +def rgb_mode_swirl(key, state, *args, **kwargs): + state.config.pixels.effect_init = True + state.config.pixels.animation_mode = 'swirl' + return state + + def rgb_mode_knight(key, state, *args, **kwargs): state.config.pixels.effect_init = True state.config.pixels.animation_mode = 'knight' diff --git a/kmk/keys.py b/kmk/keys.py index 1a0a608..b98c272 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -640,6 +640,7 @@ make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breat make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow) make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'), on_press=handlers.rgb_mode_breathe_rainbow) +make_key(names=('RGB_MODE_SWIRL', 'RGB_M_S'), on_press=handlers.rgb_mode_swirl) make_key(names=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight) diff --git a/kmk/rgb.py b/kmk/rgb.py index 0d29b40..15473f9 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -51,7 +51,7 @@ class RGB: self.knight_effect_length = knight_effect_length self.val_limit = val_limit self.rgb_animation_mode = animation_mode - self.rgb_animation_speed = animation_speed + self.animation_speed = animation_speed except ImportError as e: print(e) @@ -358,6 +358,8 @@ class RGB: return self.effect_static() elif self.animation_mode == 'knight': return self.effect_knight() + elif self.animation_mode == 'swirl': + return self.effect_swirl() elif self.animation_mode == 'static_standby': pass else: @@ -418,6 +420,22 @@ class RGB: return self + def effect_swirl(self): + if self._animation_step(): + self.increase_hue(self.animation_speed) + self.disable_auto_write = True # Turn off instantly showing + for i in range(0, self.num_pixels): + self.set_hsv( + (self.hue - (i * self.num_pixels)) % 360, + self.sat, + self.val, + i) + + # Show final results + self.disable_auto_write = False # Resume showing changes + self.show() + return self + def effect_knight(self): # Determine which LEDs should be lit up self.disable_auto_write = True # Turn off instantly showing diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py index 38a96c0..81cbdd3 100644 --- a/user_keymaps/kdb424/luddite.py +++ b/user_keymaps/kdb424/luddite.py @@ -1,16 +1,58 @@ from kmk.boards.converter.fourtypercentclub.luddite import Firmware from kmk.consts import LeaderMode, UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences -from kmk.keys import KC +from kmk.keys import KC, make_key keyboard = Firmware() # ---------------------------------- Config -------------------------------------------- -keyboard.leader_mode = LeaderMode.TIMEOUT +keyboard.leader_mode = LeaderMode.ENTER keyboard.unicode_mode = UnicodeMode.LINUX keyboard.tap_time = 150 -keyboard.leader_timeout = 2000 +keyboard.leader_timeout = 999999999999 +keyboard.rgb_num_pixels = 16 +keyboard.rgb_hue_default = 260 +keyboard.rgb_sat_default = 100 +keyboard.rgb_val_default = 20 +keyboard.rgb_knight_effect_length = 6 +keyboard.rgb_animation_mode = 'static' +keyboard.rgb_animation_speed = 3 +keyboard.debug_enabled = True + + +# ---------------------- Custom Functions -------------------------------------------- + + +def portal_lights(*args, **kwargs): + keyboard.pixels.disable_auto_write = True + keyboard.pixels.rgb_animation_mode = 'User' + for i in range(0, 9): + keyboard.pixels.set_hsv(21, 100, 100, i) + for i in range(10, 16): + keyboard.pixels.set_hsv(220, 100, 100, i) + keyboard.pixels.show() + + +def portal_off(*args, **kwargs): + keyboard.pixels.disable_auto_write = False + keyboard.pixels.off() + keyboard.pixels.rgb_animation_mode = 'static' + +# ---------------------- Custom Keys -------------------------------------------- + + +LON = make_key(on_press=portal_lights) +LOFF = make_key(on_press=portal_off) + +_______ = KC.TRNS +XXXXXXX = KC.NO +HOME = KC.MT(KC.HOME, KC.LSFT) +END = KC.MT(KC.END, KC.RSFT) + + +BASE = 0 +FN1 = 1 # ---------------------- Leader Key Macros -------------------------------------------- @@ -35,17 +77,13 @@ keyboard.leader_dictionary = { 'f': emoticons.F, 'meh': emoticons.MEH, 'yay': emoticons.YAY, -} + 'p': LON, + 'po': LOFF, +} # ---------------------- Keymap --------------------------------------------------------- -_______ = KC.TRNS -XXXXXXX = KC.NO - -BASE = 0 -FN1 = 1 - keyboard.keymap = [ [ [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7], @@ -55,7 +93,7 @@ keyboard.keymap = [ [KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.MINS], [KC.ENT, KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B], [KC.M, KC.W, KC.V, KC.Z, KC.RSFT, KC.LCTL, KC.LGUI, KC.MO(FN1)], - [KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + [KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], ], [ @@ -65,8 +103,8 @@ keyboard.keymap = [ [_______, _______, KC.VOLU, _______, _______, _______, _______, _______], [_______, _______, _______, _______, _______, _______, _______, KC.VOLD], [_______, _______, _______, _______, _______, _______, _______, _______], - [_______, _______, _______, _______, _______, KC.GRV, _______, _______], - [_______, KC.LALT, _______, _______, _______], + [_______, _______, _______, _______, _______, KC.RGB_M_K, _______, _______], + [_______, KC.LALT, KC.RGB_M_S, LON, LOFF], ], ] diff --git a/user_keymaps/kdb424/nyquist_r2.py b/user_keymaps/kdb424/nyquist_r2.py index 2fe1e1a..0658717 100644 --- a/user_keymaps/kdb424/nyquist_r2.py +++ b/user_keymaps/kdb424/nyquist_r2.py @@ -95,11 +95,11 @@ keyboard.keymap = [ ], [ # r3 - [KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, _______, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL], - [KC.RGB_ANI, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], - [KC.RGB_AND, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], - [_______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], - [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], + [KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, KC.RGB_M_S, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL], + [KC.RGB_ANI, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], + [KC.RGB_AND, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], + [_______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], + [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], ], ] From 9d8682c866dc4a2f7029b6648fa4648485c183aa Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 16 Mar 2019 12:29:16 -0700 Subject: [PATCH 27/32] Config changes and uses consts to save ram --- docs/led.md | 14 +++---- docs/rgb.md | 29 ++++++++------ kmk/firmware.py | 37 +++-------------- kmk/led.py | 34 ++++++++++------ kmk/rgb.py | 72 ++++++++++++++++++++-------------- user_keymaps/kdb424/luddite.py | 49 ++++++++++++----------- 6 files changed, 121 insertions(+), 114 deletions(-) diff --git a/docs/led.md b/docs/led.md index cbadbb0..ba2b5a6 100644 --- a/docs/led.md +++ b/docs/led.md @@ -14,15 +14,15 @@ Want your keyboard to shine? Add some lights! |`KC.LED_MODE_BREATHE` |`LED_M_B` |Breathing animation | ## Configuration -|Define |Default |Description | -|-------------------------------|-------------|------------------------------------------------| -|`keyboard.led_brightness_step` |`5` |The number of steps to change the brightness by | -|`keyboard.led_brightness_limit`|`100` |The maximum brightness level in percent | +|Define |Default |Description | +|-----------------------------------------|-------------|------------------------------------------------| +|`keyboard.led_config['brightness_step']` |`5` |The number of steps to change the brightness by | +|`keyboard.led_config['brightness_limit']`|`100` |The maximum brightness level in percent | ## Built-in Animation Configuration -|Define |Default |Description | -|-------------------------------|-------------|-------------------------------------------------------------------------------------| -|`keyboard.led_breath_center` |`1.5` |Used to calculate the curve for the breathing animation. Anywhere from 1.0 - 2.7 is valid| +|Define |Default |Description | +|-----------------------------------------|-------------|-------------------------------------------------------------------------------------| +|`keyboard.led_config['breath_center']` |`1.5` |Used to calculate the curve for the breathing animation. Anywhere from 1.0 - 2.7 is valid| ## Functions diff --git a/docs/rgb.md b/docs/rgb.md index e3f5266..454d226 100644 --- a/docs/rgb.md +++ b/docs/rgb.md @@ -15,8 +15,8 @@ Currently we support the following addressable LEDs: KMK uses [Hue, Saturation, and Value](https://en.wikipedia.org/wiki/HSL_and_HSV) to select colors rather than RGB. The color wheel below demonstrates how this works. -Changing the **Hue** cycles around the circle. -Changing the **Saturation** moves between the inner and outer sections of the wheel, affecting the intensity of the color. +Changing the **Hue** cycles around the circle. +Changing the **Saturation** moves between the inner and outer sections of the wheel, affecting the intensity of the color. Changing the **Value** sets the overall brightness. ## [Keycodes] @@ -39,19 +39,22 @@ Changing the **Value** sets the overall brightness. |`KC.RGB_MODE_KNIGHT` |`RGB_M_K` |Knightrider animation | ## Configuration -|Define |Default |Description | -|-------------------------|-------------|-----------------------------------------------------------------------------| -|`keyboard.rgb_order` |`(1, 0, 2)` |The order of the pixels R G B, and optionally white. Example(1, 0, 2, 3) | -|`keyboard.rgb_hue_step` |`10` |The number of steps to cycle through the hue by | -|`keyboard.rgb_sat_step` |`17` |The number of steps to change the saturation by | -|`keyboard.rgb_val_step` |`17` |The number of steps to change the brightness by | -|`keyboard.rgb_val_limit` |`255` |The maximum brightness level | +|Define |Default |Description | +|-------------------------------------|-------------|-----------------------------------------------------------------------------| +|`keyboard.rgb_config['rgb_order']` |`(1, 0, 2)` |The order of the pixels R G B, and optionally white. Example(1, 0, 2, 3) | +|`keyboard.rgb_config['hue_step']` |`10` |The number of steps to cycle through the hue by | +|`keyboard.rgb_config['sat_step']` |`17` |The number of steps to change the saturation by | +|`keyboard.rgb_config['val_step']` |`17` |The number of steps to change the brightness by | +|`keyboard.rgb_config['hue_default']` |`0` |The default hue when the keyboard boots | +|`keyboard.rgb_config['sat_default']` |`100` |The default saturation when the keyboard boots | +|`keyboard.rgb_config['val_default']` |`100` |The default value (brightness) when the keyboard boots | +|`keyboard.rgb_config['val_limit']` |`255` |The maximum brightness level | ## Built-in Animation Configuration -|Define |Default |Description | -|-----------------------------------|-------------|-------------------------------------------------------------------------------------| -|`keyboard.rgb_breath_center` |`1.5` |Used to calculate the curve for the breathing animation. Anywhere from 1.0 - 2.7 is valid| -|`keyboard.rgb_knight_effect_length`|`4` |The number of LEDs to light up for the "Knight" animation | +|Define |Default |Description | +|----------------------------------------------|-------------|-------------------------------------------------------------------------------------| +|`keyboard.rgb_config['breathe_center']` |`1.5` |Used to calculate the curve for the breathing animation. Anywhere from 1.0 - 2.7 is valid| +|`keyboard.rgb_config['knight_effect_length']` |`4` |The number of LEDs to light up for the "Knight" animation | ## Functions diff --git a/kmk/firmware.py b/kmk/firmware.py index e7ef9e5..db07ff4 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -93,29 +93,11 @@ class Firmware: # RGB config rgb_pixel_pin = None - rgb_pixels = None - rgb_num_pixels = 0 - rgb_order = (1, 0, 2) # GRB WS2812 - rgb_val_limit = 255 - rgb_hue_default = 0 - rgb_sat_default = 100 - rgb_val_default = rgb_val_limit - rgb_hue_step = 1 - rgb_sat_step = 1 - rgb_val_step = 1 - rgb_animation_speed = 1 - rgb_breathe_center = 1.5 # 1.0-2.7 - rgb_knight_effect_length = 3 - rgb_animation_mode = 'static' + rgb_config = rgb.rgb_config # led config (mono color) - led = None led_pin = None - led_brightness_step = 5 - led_brightness_limit = 100 - led_breathe_center = 1.5 - led_animation_mode = 'static' - led_animation_speed = 1 + led_config = led.led_config def __init__(self): # Attempt to sanely guess a coord_mapping if one is not provided @@ -240,21 +222,14 @@ class Firmware: self.uart = self.init_uart(self.uart_pin) if self.rgb_pixel_pin: - self.pixels = rgb.RGB(self.rgb_pixel_pin, self.rgb_order, self.rgb_num_pixels, - self.rgb_hue_step, self.rgb_sat_step, self.rgb_val_step, - self.rgb_hue_default, self.rgb_sat_default, self.rgb_val_default, - self.rgb_breathe_center, self.rgb_knight_effect_length, - self.rgb_val_limit, self.rgb_animation_mode, - self.rgb_animation_speed, - ) + self.pixels = rgb.RGB(self.rgb_config, self.rgb_pixel_pin) + self.rgb_config = None # No longer needed else: self.pixels = None if self.led_pin: - self.led = led.led(self.led_pin, self.led_brightness_step, self.led_brightness_limit, - self.led_animation_mode, self.led_animation_speed, - self.led_breathe_center, - ) + self.led = led.led(self.led_pin, self.led_config) + self.led_config = None # No longer needed else: self.led = None diff --git a/kmk/led.py b/kmk/led.py index eaaad7e..b0f5f4c 100644 --- a/kmk/led.py +++ b/kmk/led.py @@ -1,8 +1,16 @@ import time from math import e, exp, pi, sin +from micropython import const import pulseio +led_config = { + 'brightness_step': 5, + 'brightness_limit': 100, + 'breathe_center': 1.5, + 'animation_mode': 'static', + 'animation_speed': 1, +} class led: brightness = 0 @@ -13,19 +21,18 @@ class led: led = None brightness_step = 5 brightness_limit = 100 - breath_center = 1.5 + breathe_center = 1.5 animation_mode = 'static' animation_speed = 1 enabled = True - def __init__(self, led_pin, brightness_step, brightness_limit, - animation_mode, animation_speed, breath_center): + def __init__(self, led_pin, config): self.led = pulseio.PWMOut(led_pin) - self.brightness_step = brightness_step - self.brightness_limit = brightness_limit - self.animation_mode = animation_mode - self.animation_speed = animation_speed - self.breath_center = breath_center + self.brightness_step = const(config['brightness_step']) + self.brightness_limit = const(config['brightness_limit']) + self.animation_mode = const(config['animation_mode']) + self.animation_speed = const(config['animation_speed']) + self.breathe_center = const(config['breathe_center']) def __repr__(self): return 'LED({})'.format(self._to_dict()) @@ -37,9 +44,14 @@ class led: 'brightness_limit': self.brightness_limit, 'animation_mode': self.animation_mode, 'animation_speed': self.animation_speed, - 'breath_center': self.breath_center, + 'breathe_center': self.breathe_center, } + def _init_effect(self): + self.pos = 0 + self.effect_init = False + return self + def time_ms(self): return int(time.monotonic() * 1000) @@ -94,7 +106,7 @@ class led: def effect_breathing(self): # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L806 - self.brightness = int((exp(sin((self.pos / 255.0) * pi)) - self.breath_center / e) * + self.brightness = int((exp(sin((self.pos / 255.0) * pi)) - self.breathe_center / e) * (self.brightness_limit / (e - 1 / e))) self.pos = (self.pos + self.animation_speed) % 256 self.set_brightness(self.brightness) @@ -113,7 +125,7 @@ class led: :return: Returns the new state in animation """ if self.effect_init: - self.init_effect() + self._init_effect() if self.enabled: if self.animation_mode == 'breathing': return self.effect_breathing() diff --git a/kmk/rgb.py b/kmk/rgb.py index 15473f9..dc3e595 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -1,6 +1,24 @@ import time from math import e, exp, pi, sin +from micropython import const +rgb_config = { + 'pixels': None, + 'num_pixels': 0, + 'pixel_pin': None, + 'val_limit': 255, + 'hue_default' : 0, + 'sat_default': 100, + 'rgb_order': (1, 0, 2), # GRB WS2812 + 'val_default': 100, + 'hue_step': 1, + 'sat_step': 1, + 'val_step': 1, + 'animation_speed': 1, + 'breathe_center': 1.5, # 1.0-2.7 + 'knight_effect_length': 3, + 'animation_mode': 'static' +} class RGB: hue = 0 @@ -15,43 +33,39 @@ class RGB: rgbw = False reverse_animation = False disable_auto_write = False + animation_mode = 'static' # Set by config - num_pixels = 0 - hue_step = 10 - sat_step = 17 - val_step = 17 - breath_center = 1.5 # 1.0-2.7 - knight_effect_length = 4 - val_limit = 255 - animation_mode = 'static' + num_pixels = None + hue_step = None + sat_step = None + val_step = None + breathe_center = None # 1.0-2.7 + knight_effect_length = None + val_limit = None effect_init = False - def __init__(self, pixel_pin, rgb_order, num_pixels, - hue_step, sat_step, val_step, - hue_default, sat_default, val_default, - breath_center, knight_effect_length, - val_limit, animation_mode, animation_speed): + def __init__(self, config, pixel_pin): try: import neopixel self.neopixel = neopixel.NeoPixel(pixel_pin, - num_pixels, - pixel_order=rgb_order, + config['num_pixels'], + pixel_order=config['rgb_order'], auto_write=False) - if len(rgb_order) == 4: + if len(config['rgb_order']) == 4: self.rgbw = True - self.num_pixels = num_pixels - self.hue_step = hue_step - self.sat_step = sat_step - self.val_step = val_step - self.hue = hue_default - self.sat = sat_default - self.val = val_default - self.breath_center = breath_center - self.knight_effect_length = knight_effect_length - self.val_limit = val_limit - self.rgb_animation_mode = animation_mode - self.animation_speed = animation_speed + self.num_pixels = const(config['num_pixels']) + self.hue_step = const(config['hue_step']) + self.sat_step = const(config['sat_step']) + self.val_step = const(config['val_step']) + self.hue = const(config['hue_default']) + self.sat = const(config['sat_default']) + self.val = const(config['val_default']) + self.breathe_center = const(config['breathe_center']) + self.knight_effect_length = const(config['knight_effect_length']) + self.val_limit = const(config['val_limit']) + self.rgb_animation_mode = const(config['animation_mode']) + self.animation_speed = const(config['animation_speed']) except ImportError as e: print(e) @@ -399,7 +413,7 @@ class RGB: def effect_breathing(self): # http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ # https://github.com/qmk/qmk_firmware/blob/9f1d781fcb7129a07e671a46461e501e3f1ae59d/quantum/rgblight.c#L806 - self.val = int((exp(sin((self.pos / 255.0) * pi)) - self.breath_center / e) * + self.val = int((exp(sin((self.pos / 255.0) * pi)) - self.breathe_center / e) * (self.val_limit / (e - 1 / e))) self.pos = (self.pos + self.animation_speed) % 256 self.set_hsv_fill(self.hue, self.sat, self.val) diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py index 81cbdd3..62f384f 100644 --- a/user_keymaps/kdb424/luddite.py +++ b/user_keymaps/kdb424/luddite.py @@ -10,25 +10,29 @@ keyboard = Firmware() keyboard.leader_mode = LeaderMode.ENTER keyboard.unicode_mode = UnicodeMode.LINUX keyboard.tap_time = 150 -keyboard.leader_timeout = 999999999999 -keyboard.rgb_num_pixels = 16 -keyboard.rgb_hue_default = 260 -keyboard.rgb_sat_default = 100 -keyboard.rgb_val_default = 20 -keyboard.rgb_knight_effect_length = 6 -keyboard.rgb_animation_mode = 'static' -keyboard.rgb_animation_speed = 3 -keyboard.debug_enabled = True +keyboard.leader_timeout = 999999 + +keyboard.rgb_config['num_pixels'] = 16 +keyboard.rgb_config['val_limit'] = 150 +keyboard.rgb_config['hue_step'] = 10 +keyboard.rgb_config['sat_step'] = 5 +keyboard.rgb_config['val_step'] = 5 +keyboard.rgb_config['hue_default'] = 260 +keyboard.rgb_config['sat_default'] = 100 +keyboard.rgb_config['val_default'] = 20 +keyboard.rgb_config['knight_effect_length'] = 6 +keyboard.rgb_config['animation_mode'] = 'static' +keyboard.rgb_config['animation_speed'] = 2 +keyboard.debug_enabled = False # ---------------------- Custom Functions -------------------------------------------- - def portal_lights(*args, **kwargs): keyboard.pixels.disable_auto_write = True keyboard.pixels.rgb_animation_mode = 'User' for i in range(0, 9): - keyboard.pixels.set_hsv(21, 100, 100, i) + keyboard.pixels.set_hsv(10, 100, 100, i) for i in range(10, 16): keyboard.pixels.set_hsv(220, 100, 100, i) keyboard.pixels.show() @@ -44,7 +48,6 @@ def portal_off(*args, **kwargs): LON = make_key(on_press=portal_lights) LOFF = make_key(on_press=portal_off) - _______ = KC.TRNS XXXXXXX = KC.NO HOME = KC.MT(KC.HOME, KC.LSFT) @@ -73,12 +76,12 @@ keyboard.leader_dictionary = { 'flip': emoticons.ANGRY_TABLE_FLIP, 'cheer': emoticons.CHEER, 'wat': emoticons.WAT, - 'ff': emoticons.FF, - 'f': emoticons.F, + 'f': emoticons.FF, + 'fu': emoticons.F, 'meh': emoticons.MEH, 'yay': emoticons.YAY, - 'p': LON, - 'po': LOFF, + 'p': LON, + 'po': LOFF, } # ---------------------- Keymap --------------------------------------------------------- @@ -91,20 +94,20 @@ keyboard.keymap = [ [KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R], [KC.L, KC.SLSH, KC.EQL, KC.BSLS, KC.TAB, KC.A, KC.O, KC.E], [KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.MINS], - [KC.ENT, KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B], - [KC.M, KC.W, KC.V, KC.Z, KC.RSFT, KC.LCTL, KC.LGUI, KC.MO(FN1)], + [KC.ENT, HOME, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B], + [KC.M, KC.W, KC.V, KC.Z, END, KC.LCTL, KC.LGUI, KC.MO(FN1)], [KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], ], [ [KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7], - [KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.DEL, KC.RGB_TOG, _______], - [_______, _______, _______, _______, _______, _______, _______, _______], - [_______, _______, KC.VOLU, _______, _______, _______, _______, _______], + [KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.DEL, KC.RGB_TOG, KC.RGB_HUD], + [KC.RGB_HUI, _______, _______, _______, _______, _______, _______, _______], + [_______, _______, KC.VOLU, _______, _______, KC.RGB_SAD, KC.RGB_SAI, _______], [_______, _______, _______, _______, _______, _______, _______, KC.VOLD], - [_______, _______, _______, _______, _______, _______, _______, _______], + [_______, _______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______], [_______, _______, _______, _______, _______, KC.RGB_M_K, _______, _______], - [_______, KC.LALT, KC.RGB_M_S, LON, LOFF], + [_______, KC.LALT, KC.RGB_M_S, _______, _______], ], ] From 3f8c6e764881abff2c4cf94162d8670d19853fc7 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 16 Mar 2019 14:26:19 -0700 Subject: [PATCH 28/32] Added support for user animations with docs --- docs/led.md | 40 +++++++++++++++++++++++++++++----- docs/rgb.md | 27 +++++++++++++++++++++++ kmk/led.py | 8 ++++++- kmk/rgb.py | 11 ++++++++-- user_keymaps/kdb424/luddite.py | 23 ++++++++++++++----- 5 files changed, 96 insertions(+), 13 deletions(-) diff --git a/docs/led.md b/docs/led.md index ba2b5a6..1fd495f 100644 --- a/docs/led.md +++ b/docs/led.md @@ -37,11 +37,41 @@ If you want to create your own animations, or for example, change the lighting i ## Direct variable access |Define |Default |Description | |-----------------------------------|-----------|--------------------------------------------------------------------------------------------------------| -|`keyboard.led.brightness` |`0` |Sets the brightness by percent 0-100 | -|`keyboard.led.brightness_limit` |`100` |Sets the limit of brightness | -|`keyboard.led.brightness_step` |`5` |Sets the step value to change brightness by | -|`keyboard.led.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid | -|`keyboard.led.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. | +|`keyboard.led.brightness` |`0` |Sets the brightness by percent 0-100 | +|`keyboard.led.brightness_limit` |`100` |Sets the limit of brightness | +|`keyboard.led.brightness_step` |`5` |Sets the step value to change brightness by | +|`keyboard.led.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid | +|`keyboard.led.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. | + +## User animations +User animations can be created as well. An example of a light show would look like this +```python +from kmk.keys import make_key + +def start_flicker(*args, **kwargs): + # Setting mode to user will use the user animation + keyboard.led.animation_mode = 'user' + + +def flicker(self): + # This is the code that is run every cycle that can serve as an animation + # Refer to the kmk/rgb.py for actual examples of what has been done + if self.brightness == 0: + self.brightness = 100 + else: + self.brightness = 0 + keyboard.led.set_brightness(self.brightness) + return self + + +# This is what "gives" your function to KMK so it knows what your animation code is +keyboard.led_config['user_animation'] = flicker + +# Makes a key that would start your animation +LS = make_key(on_press=start_flicker()) + +keymap = [...LS,...] +``` # Troubleshooting Make sure that your board supports LED backlight by checking for a line with "LED_PIN". If it does not, you can add it to your keymap. diff --git a/docs/rgb.md b/docs/rgb.md index 454d226..2705973 100644 --- a/docs/rgb.md +++ b/docs/rgb.md @@ -104,6 +104,33 @@ keyboard.pixels.disable_auto_write = True keyboard.pixels.neopixel() # <-- This is the neopixel object ``` +## User animations +User animations can be created as well. An example of a light show would look like this +```python +from kmk.keys import make_key + +def start_light_show(*args, **kwargs): + # Setting mode to user will use the user animation + keyboard.pixels.animation_mode = 'user' + + +def light_show(self): + # This is the code that is run every cycle that can serve as an animation + # Refer to the kmk/rgb.py for actual examples of what has been done + self.hue = (self.hue + 35) % 360 + keyboard.pixels.set_hsv_fill(self.hue, self.sat, self.val) + return self + + +# This is what "gives" your function to KMK so it knows what your animation code is +keyboard.rgb_config['user_animation'] = light_show + +# Makes a key that would start your animation +LS = make_key(on_press=start_light_show()) + +keymap = [...LS,...] +``` + ## Troubleshooting ### Incorrect colors If your colors are incorrect, check the pixel order of your specific LED's. Here are some common ones. diff --git a/kmk/led.py b/kmk/led.py index b0f5f4c..7aa6f31 100644 --- a/kmk/led.py +++ b/kmk/led.py @@ -1,8 +1,8 @@ import time from math import e, exp, pi, sin -from micropython import const import pulseio +from micropython import const led_config = { 'brightness_step': 5, @@ -12,6 +12,7 @@ led_config = { 'animation_speed': 1, } + class led: brightness = 0 time = int(time.monotonic() * 1000) @@ -25,6 +26,7 @@ class led: animation_mode = 'static' animation_speed = 1 enabled = True + user_animation = None def __init__(self, led_pin, config): self.led = pulseio.PWMOut(led_pin) @@ -33,6 +35,8 @@ class led: self.animation_mode = const(config['animation_mode']) self.animation_speed = const(config['animation_speed']) self.breathe_center = const(config['breathe_center']) + if config['user_animation']: + self.user_animation = config['user_animation'] def __repr__(self): return 'LED({})'.format(self._to_dict()) @@ -131,6 +135,8 @@ class led: return self.effect_breathing() elif self.animation_mode == 'static': return self.effect_static() + elif self.animation_mode == 'user': + return self.user_animation(self) else: self.off() diff --git a/kmk/rgb.py b/kmk/rgb.py index dc3e595..8916b97 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -1,5 +1,6 @@ import time from math import e, exp, pi, sin + from micropython import const rgb_config = { @@ -7,7 +8,7 @@ rgb_config = { 'num_pixels': 0, 'pixel_pin': None, 'val_limit': 255, - 'hue_default' : 0, + 'hue_default': 0, 'sat_default': 100, 'rgb_order': (1, 0, 2), # GRB WS2812 'val_default': 100, @@ -17,9 +18,10 @@ rgb_config = { 'animation_speed': 1, 'breathe_center': 1.5, # 1.0-2.7 'knight_effect_length': 3, - 'animation_mode': 'static' + 'animation_mode': 'static', } + class RGB: hue = 0 sat = 100 @@ -44,6 +46,7 @@ class RGB: knight_effect_length = None val_limit = None effect_init = False + user_animation = None def __init__(self, config, pixel_pin): try: @@ -66,6 +69,8 @@ class RGB: self.val_limit = const(config['val_limit']) self.rgb_animation_mode = const(config['animation_mode']) self.animation_speed = const(config['animation_speed']) + if config['user_animation']: + self.user_animation = config['user_animation'] except ImportError as e: print(e) @@ -374,6 +379,8 @@ class RGB: return self.effect_knight() elif self.animation_mode == 'swirl': return self.effect_swirl() + elif self.animation_mode == 'user': + return self.user_animation(self) elif self.animation_mode == 'static_standby': pass else: diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py index 62f384f..65cec58 100644 --- a/user_keymaps/kdb424/luddite.py +++ b/user_keymaps/kdb424/luddite.py @@ -23,14 +23,14 @@ keyboard.rgb_config['val_default'] = 20 keyboard.rgb_config['knight_effect_length'] = 6 keyboard.rgb_config['animation_mode'] = 'static' keyboard.rgb_config['animation_speed'] = 2 -keyboard.debug_enabled = False +keyboard.debug_enabled = True # ---------------------- Custom Functions -------------------------------------------- def portal_lights(*args, **kwargs): + keyboard.pixels.animation_mode = 'static_standby' keyboard.pixels.disable_auto_write = True - keyboard.pixels.rgb_animation_mode = 'User' for i in range(0, 9): keyboard.pixels.set_hsv(10, 100, 100, i) for i in range(10, 16): @@ -41,8 +41,21 @@ def portal_lights(*args, **kwargs): def portal_off(*args, **kwargs): keyboard.pixels.disable_auto_write = False keyboard.pixels.off() - keyboard.pixels.rgb_animation_mode = 'static' + keyboard.pixels.animation_mode = 'static' + +def start_light_show(*args, **kwargs): + keyboard.pixels.animation_mode = 'user' + + +def light_show(self): + self.hue = (self.hue + 35) % 360 + keyboard.pixels.set_hsv_fill(self.hue, self.sat, self.val) + return self + + +keyboard.rgb_config['user_animation'] = light_show +LS = make_key(on_press=start_light_show()) # ---------------------- Custom Keys -------------------------------------------- @@ -80,8 +93,8 @@ keyboard.leader_dictionary = { 'fu': emoticons.F, 'meh': emoticons.MEH, 'yay': emoticons.YAY, - 'p': LON, - 'po': LOFF, + 'p': LON, + 'po': LOFF, } # ---------------------- Keymap --------------------------------------------------------- From 51580945499a95da8755d47522232f1ad1c11b8a Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Tue, 9 Apr 2019 16:47:20 -0700 Subject: [PATCH 29/32] Small changes --- docs/rgb.md | 2 +- kmk/rgb.py | 5 +++++ user_keymaps/kdb424/levinson_r2.py | 11 ++--------- user_keymaps/kdb424/luddite.py | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/rgb.md b/docs/rgb.md index 2705973..c595f89 100644 --- a/docs/rgb.md +++ b/docs/rgb.md @@ -126,7 +126,7 @@ def light_show(self): keyboard.rgb_config['user_animation'] = light_show # Makes a key that would start your animation -LS = make_key(on_press=start_light_show()) +LS = make_key(on_press=start_light_show) keymap = [...LS,...] ``` diff --git a/kmk/rgb.py b/kmk/rgb.py index 8916b97..ca80b50 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -399,6 +399,11 @@ class RGB: return False def _init_effect(self): + if self.animation_mode == 'breathing' or self.animation_mode == 'breathing_rainbow': + self.intervals = (30, 20, 10, 5) + elif self.animation_mode == 'swirl': + self.intervals = (50, 50) + self.pos = 0 self.reverse_animation = False self.effect_init = False diff --git a/user_keymaps/kdb424/levinson_r2.py b/user_keymaps/kdb424/levinson_r2.py index 5313e6c..98e8e40 100644 --- a/user_keymaps/kdb424/levinson_r2.py +++ b/user_keymaps/kdb424/levinson_r2.py @@ -1,18 +1,11 @@ -import board -import busio +from kmk.boards.converter.keebio.levinson_r2 import Firmware -from kmk.consts import DiodeOrientation, LeaderMode, UnicodeMode +from kmk.consts import LeaderMode, UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences from kmk.keys import KC -from kmk.mcus.circuitpython_samd51 import Firmware -from kmk.pins import Pin as P keyboard = Firmware() -keyboard.col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI) -keyboard.row_pins = (P.D13, P.D11, P.D10, P.D9) -keyboard.diode_orientation = DiodeOrientation.COLUMNS - # ------------------User level config variables --------------------------------------- keyboard.leader_mode = LeaderMode.TIMEOUT keyboard.unicode_mode = UnicodeMode.LINUX diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py index 65cec58..9265512 100644 --- a/user_keymaps/kdb424/luddite.py +++ b/user_keymaps/kdb424/luddite.py @@ -23,7 +23,7 @@ keyboard.rgb_config['val_default'] = 20 keyboard.rgb_config['knight_effect_length'] = 6 keyboard.rgb_config['animation_mode'] = 'static' keyboard.rgb_config['animation_speed'] = 2 -keyboard.debug_enabled = True +keyboard.debug_enabled = False # ---------------------- Custom Functions -------------------------------------------- @@ -55,7 +55,7 @@ def light_show(self): keyboard.rgb_config['user_animation'] = light_show -LS = make_key(on_press=start_light_show()) +LS = make_key(on_press=start_light_show) # ---------------------- Custom Keys -------------------------------------------- From 39b0b1e7f2fcd047f757213de36514180204cfea Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Fri, 21 Jun 2019 16:31:20 -0700 Subject: [PATCH 30/32] final commit before rebase --- kmk/firmware.py | 3 +- kmk/rgb.py | 15 +++---- user_keymaps/kdb424/levinson_r2.py | 16 ++++++- user_keymaps/kdb424/luddite.py | 69 +----------------------------- 4 files changed, 22 insertions(+), 81 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index db07ff4..c058390 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -294,8 +294,7 @@ class Firmware: if self.pixels: # Only check animations if pixels is initialized if self.pixels.animation_mode: - if self.pixels.animation_mode: - self.pixels = self.pixels.animate() + self.pixels = self.pixels.animate() if self.led: # Only check animations if led is initialized diff --git a/kmk/rgb.py b/kmk/rgb.py index ca80b50..126e261 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -67,9 +67,10 @@ class RGB: self.breathe_center = const(config['breathe_center']) self.knight_effect_length = const(config['knight_effect_length']) self.val_limit = const(config['val_limit']) - self.rgb_animation_mode = const(config['animation_mode']) + self.animation_mode = config['animation_mode'] self.animation_speed = const(config['animation_speed']) - if config['user_animation']: + if 'user_animation' in config: + print(config['user_animation']) self.user_animation = config['user_animation'] except ImportError as e: @@ -282,14 +283,11 @@ class RGB: return self - def increase_val(self, step=None): + def increase_val(self, step=0): """ Increases value by step amount stopping at 100 :param step: """ - if not step: - step = self.val_step - if (self.val + step) >= 100: self.val = 100 else: @@ -300,14 +298,11 @@ class RGB: return self - def decrease_val(self, step=None): + def decrease_val(self, step=0): """ Decreases value by step amount stopping at 0 :param step: """ - if not step: - step = self.val_step - if (self.val - step) <= 0: self.val = 0 else: diff --git a/user_keymaps/kdb424/levinson_r2.py b/user_keymaps/kdb424/levinson_r2.py index 98e8e40..6c9d1de 100644 --- a/user_keymaps/kdb424/levinson_r2.py +++ b/user_keymaps/kdb424/levinson_r2.py @@ -1,5 +1,4 @@ from kmk.boards.converter.keebio.levinson_r2 import Firmware - from kmk.consts import LeaderMode, UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences from kmk.keys import KC @@ -13,6 +12,19 @@ keyboard.tap_time = 150 keyboard.leader_timeout = 2000 keyboard.debug_enabled = True +keyboard.rgb_config['num_pixels'] = 16 +keyboard.rgb_config['val_limit'] = 150 +keyboard.rgb_config['hue_step'] = 10 +keyboard.rgb_config['sat_step'] = 5 +keyboard.rgb_config['val_step'] = 5 +keyboard.rgb_config['hue_default'] = 260 +keyboard.rgb_config['sat_default'] = 100 +keyboard.rgb_config['val_default'] = 20 +keyboard.rgb_config['knight_effect_length'] = 6 +keyboard.rgb_config['animation_mode'] = 'swirl' +keyboard.rgb_config['animation_speed'] = 2 +keyboard.debug_enabled = False + emoticons = compile_unicode_string_sequences({ # Emoticons, but fancier 'ANGRY_TABLE_FLIP': r'(ノಠ痊ಠ)ノ彡┻━┻', @@ -45,7 +57,7 @@ keyboard.keymap = [ KC.GESC, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP, KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT, KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH, - KC.LCTRL, KC.LGUI, KC.LALT, KC.LEAD, KC.MO(2), KC.LT(3, KC.SPC), KC.LT(3, KC.SPC), KC.MO(4), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT, + KC.LCTRL, KC.LGUI, KC.LALT, KC.RGB_TOG, KC.MO(2), KC.LT(3, KC.SPC), KC.LT(3, KC.SPC), KC.MO(4), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT, ], [ # Gaming diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py index 9265512..430e797 100644 --- a/user_keymaps/kdb424/luddite.py +++ b/user_keymaps/kdb424/luddite.py @@ -1,16 +1,11 @@ from kmk.boards.converter.fourtypercentclub.luddite import Firmware -from kmk.consts import LeaderMode, UnicodeMode -from kmk.handlers.sequences import compile_unicode_string_sequences -from kmk.keys import KC, make_key +from kmk.keys import KC keyboard = Firmware() # ---------------------------------- Config -------------------------------------------- -keyboard.leader_mode = LeaderMode.ENTER -keyboard.unicode_mode = UnicodeMode.LINUX keyboard.tap_time = 150 -keyboard.leader_timeout = 999999 keyboard.rgb_config['num_pixels'] = 16 keyboard.rgb_config['val_limit'] = 150 @@ -19,7 +14,7 @@ keyboard.rgb_config['sat_step'] = 5 keyboard.rgb_config['val_step'] = 5 keyboard.rgb_config['hue_default'] = 260 keyboard.rgb_config['sat_default'] = 100 -keyboard.rgb_config['val_default'] = 20 +keyboard.rgb_config['val_default'] = 0 keyboard.rgb_config['knight_effect_length'] = 6 keyboard.rgb_config['animation_mode'] = 'static' keyboard.rgb_config['animation_speed'] = 2 @@ -28,39 +23,6 @@ keyboard.debug_enabled = False # ---------------------- Custom Functions -------------------------------------------- -def portal_lights(*args, **kwargs): - keyboard.pixels.animation_mode = 'static_standby' - keyboard.pixels.disable_auto_write = True - for i in range(0, 9): - keyboard.pixels.set_hsv(10, 100, 100, i) - for i in range(10, 16): - keyboard.pixels.set_hsv(220, 100, 100, i) - keyboard.pixels.show() - - -def portal_off(*args, **kwargs): - keyboard.pixels.disable_auto_write = False - keyboard.pixels.off() - keyboard.pixels.animation_mode = 'static' - - -def start_light_show(*args, **kwargs): - keyboard.pixels.animation_mode = 'user' - - -def light_show(self): - self.hue = (self.hue + 35) % 360 - keyboard.pixels.set_hsv_fill(self.hue, self.sat, self.val) - return self - - -keyboard.rgb_config['user_animation'] = light_show -LS = make_key(on_press=start_light_show) -# ---------------------- Custom Keys -------------------------------------------- - - -LON = make_key(on_press=portal_lights) -LOFF = make_key(on_press=portal_off) _______ = KC.TRNS XXXXXXX = KC.NO HOME = KC.MT(KC.HOME, KC.LSFT) @@ -70,33 +32,6 @@ END = KC.MT(KC.END, KC.RSFT) BASE = 0 FN1 = 1 -# ---------------------- Leader Key Macros -------------------------------------------- - -emoticons = compile_unicode_string_sequences({ - # Emoticons, but fancier - 'ANGRY_TABLE_FLIP': r'(ノಠ痊ಠ)ノ彡┻━┻', - 'CHEER': r'+。:.゚ヽ(´∀。)ノ゚.:。+゚゚+。:.゚ヽ(*´∀)ノ゚.:。+゚', - 'TABLE_FLIP': r'(╯°□°)╯︵ ┻━┻', - 'WAT': r'⊙.☉', - 'FF': r'凸(゚Д゚#)', - 'F': r'( ̄^ ̄)凸', - 'MEH': r'╮( ̄_ ̄)╭', - 'YAY': r'o(^▽^)o', -}) - - -keyboard.leader_dictionary = { - 'flip': emoticons.ANGRY_TABLE_FLIP, - 'cheer': emoticons.CHEER, - 'wat': emoticons.WAT, - 'f': emoticons.FF, - 'fu': emoticons.F, - 'meh': emoticons.MEH, - 'yay': emoticons.YAY, - 'p': LON, - 'po': LOFF, - -} # ---------------------- Keymap --------------------------------------------------------- From 5532ffdcbf8021b0c1a4dfdda1661798a4e14522 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Fri, 21 Jun 2019 17:24:32 -0700 Subject: [PATCH 31/32] Ready for merging --- kmk/firmware.py | 11 -- kmk/keys.py | 3 +- kmk/rgb.py | 8 +- .../converter/fourtypercentclub/luddite.py | 20 ++-- .../Default/converter/keebio/nyquist_r2.py | 60 +++++------ user_keymaps/kdb424/luddite.py | 40 ++++--- user_keymaps/kdb424/nyquist_r2.py | 101 +++++++----------- 7 files changed, 108 insertions(+), 135 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index c058390..97c5afd 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -47,15 +47,6 @@ import kmk.internal_state # isort:skip # Thanks for sticking around. Now let's do real work, starting below from kmk.util import intify_coordinate as ic -import busio -import gc - -import supervisor -from kmk.consts import LeaderMode, UnicodeMode -from kmk.hid import USB_HID -from kmk.internal_state import InternalState -from kmk.keys import KC -from kmk.matrix import MatrixScanner from kmk import led, rgb # isort:skip @@ -300,5 +291,3 @@ class Firmware: # Only check animations if led is initialized if self.led.animation_mode: self.led = self.led.animate() - - gc.collect() diff --git a/kmk/keys.py b/kmk/keys.py index b98c272..790a37e 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -625,7 +625,8 @@ make_key(names=('DEBUG', 'DBG'), on_press=handlers.debug_pressed, on_release=han make_key(names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released) make_key(names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released) -make_key(names=('GESC', 'GRAVE_ESC'), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released) +make_key(names=('GESC', 'GRAVE_ESC'), on_press=handlers.gesc_pressed, + on_release=handlers.gesc_released) make_key(names=('RGB_TOG',), on_press=handlers.rgb_tog) make_key(names=('RGB_HUI',), on_press=handlers.rgb_hui) make_key(names=('RGB_HUD',), on_press=handlers.rgb_hud) diff --git a/kmk/rgb.py b/kmk/rgb.py index 126e261..b6afbb1 100644 --- a/kmk/rgb.py +++ b/kmk/rgb.py @@ -283,11 +283,13 @@ class RGB: return self - def increase_val(self, step=0): + def increase_val(self, step=None): """ Increases value by step amount stopping at 100 :param step: """ + if not step: + step = self.val_step if (self.val + step) >= 100: self.val = 100 else: @@ -298,11 +300,13 @@ class RGB: return self - def decrease_val(self, step=0): + def decrease_val(self, step=None): """ Decreases value by step amount stopping at 0 :param step: """ + if not step: + step = self.val_step if (self.val - step) <= 0: self.val = 0 else: diff --git a/user_keymaps/Default/converter/fourtypercentclub/luddite.py b/user_keymaps/Default/converter/fourtypercentclub/luddite.py index 8085ae0..51d5f69 100644 --- a/user_keymaps/Default/converter/fourtypercentclub/luddite.py +++ b/user_keymaps/Default/converter/fourtypercentclub/luddite.py @@ -11,19 +11,19 @@ FN1 = 1 keyboard.keymap = [ [ - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.MINS, KC.EQL, KC.BSPC], - [KC.TAB, KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.P, KC.LBRC, KC.RBRC, KC.BSLS], - [KC.CAPS, KC.A, KC.S, KC.D, KC.F, KC.G, KC.H, KC.J, KC.K, KC.L, KC.SCLN, KC.QUOT, KC.ENT], - [KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.N, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.RSFT], - [KC.LCTL, KC.LGUI, KC.LALT, KC.SPC, KC.RALT, KC.RGUI, KC.MO(FN1), KC.RCTL], + KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.MINS, KC.EQL, KC.BSPC, + KC.TAB, KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.P, KC.LBRC, KC.RBRC, KC.BSLS, + KC.CAPS, KC.A, KC.S, KC.D, KC.F, KC.G, KC.H, KC.J, KC.K, KC.L, KC.SCLN, KC.QUOT, KC.ENT, + KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.N, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.RSFT, + KC.LCTL, KC.LGUI, KC.LALT, KC.SPC, KC.RALT, KC.RGUI, KC.MO(FN1), KC.RCTL, ], [ - [KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.BSPC], - [KC.RGB_TOG, _______, KC.UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______], - [_______, KC.LEFT, KC.DOWN, KC.RGHT, _______, _______, _______, _______, _______, _______, _______, _______, _______], - [KC.LED_INC, KC.LED_DEC, KC.LED_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______], - [KC.GRV, _______, _______, _______, _______, _______, _______, _______], + KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.BSPC, + KC.RGB_TOG, _______, KC.UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, KC.LEFT, KC.DOWN, KC.RGHT, _______, _______, _______, _______, _______, _______, _______, _______, _______, + KC.LED_INC, KC.LED_DEC, KC.LED_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + KC.GRV, _______, _______, _______, _______, _______, _______, _______, ], ] diff --git a/user_keymaps/Default/converter/keebio/nyquist_r2.py b/user_keymaps/Default/converter/keebio/nyquist_r2.py index f13f0a8..9a604e5 100644 --- a/user_keymaps/Default/converter/keebio/nyquist_r2.py +++ b/user_keymaps/Default/converter/keebio/nyquist_r2.py @@ -24,11 +24,11 @@ keyboard.keymap = [ # |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right | # `-----------------------------------------------------------------------------------' [ - [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC], - [KC.TAB, KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.P, KC.DEL], - [KC.ESC, KC.A, KC.S, KC.D, KC.F, KC.G, KC.H, KC.J, KC.K, KC.L, KC.SCLN, KC.QUOT], - [KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.N, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.ENT], - [ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT], + KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC, + KC.TAB, KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.P, KC.DEL, + KC.ESC, KC.A, KC.S, KC.D, KC.F, KC.G, KC.H, KC.J, KC.K, KC.L, KC.SCLN, KC.QUOT, + KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.N, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.ENT, + ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT, ], # Colemak @@ -44,11 +44,11 @@ keyboard.keymap = [ # |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right | # `-----------------------------------------------------------------------------------' [ - [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC], - [KC.TAB, KC.Q, KC.W, KC.F, KC.P, KC.G, KC.J, KC.L, KC.U, KC.Y, KC.SCLN, KC.DEL], - [KC.ESC, KC.A, KC.R, KC.S, KC.T, KC.D, KC.H, KC.N, KC.E, KC.I, KC.O, KC.QUOT], - [KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.K, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.ENT], - [ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT], + KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC, + KC.TAB, KC.Q, KC.W, KC.F, KC.P, KC.G, KC.J, KC.L, KC.U, KC.Y, KC.SCLN, KC.DEL, + KC.ESC, KC.A, KC.R, KC.S, KC.T, KC.D, KC.H, KC.N, KC.E, KC.I, KC.O, KC.QUOT, + KC.LSFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.K, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.ENT, + ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT, ], # Dvorak @@ -64,11 +64,11 @@ keyboard.keymap = [ # |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right | # `-----------------------------------------------------------------------------------' [ - [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC], - [KC.TAB, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.DEL], - [KC.ESC, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.SLSH], - [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.ENT], - [ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT], + KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC, + KC.TAB, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.DEL, + KC.ESC, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.SLSH, + KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.ENT, + ADJUST, KC.LCTL, KC.LALT, KC.LGUI, LOWER, KC.SPC, KC.SPC, RAISE, KC.LEFT, KC.DOWN, KC.UP, KC.RGHT, ], # Lower @@ -84,11 +84,11 @@ keyboard.keymap = [ # | | | | | | | | Next | Vol- | Vol+ | Play | # `-----------------------------------------------------------------------------------' [ - [KC.TILD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.BSPC], - [KC.TILD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.DEL], - [KC.DEL, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.UNDS, KC.PLUS, KC.LCBR, KC.RCBR, KC.PIPE], - [_______, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.NUHS, KC.NUBS, _______, _______, _______], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.MNXT, KC.VOLD, KC.VOLU, KC.MPLY], + KC.TILD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.BSPC, + KC.TILD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.DEL, + KC.DEL, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.UNDS, KC.PLUS, KC.LCBR, KC.RCBR, KC.PIPE, + _______, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.NUHS, KC.NUBS, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, KC.MNXT, KC.VOLD, KC.VOLU, KC.MPLY, ], # Raise @@ -104,11 +104,11 @@ keyboard.keymap = [ # | | | | | | | | Next | Vol- | Vol+ | Play | # `-----------------------------------------------------------------------------------' [ - [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC], - [KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL], - [KC.DEL, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.MINS, KC.EQL, KC.LBRC, KC.RBRC, KC.BSLS], - [_______, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.NUHS, KC.NUBS, _______, _______, _______], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.MNXT, KC.VOLD, KC.VOLU, KC.MPLY], + KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.BSPC, + KC.GRV, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL, + KC.DEL, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.MINS, KC.EQL, KC.LBRC, KC.RBRC, KC.BSLS, + _______, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.NUHS, KC.NUBS, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, KC.MNXT, KC.VOLD, KC.VOLU, KC.MPLY, ], # Adjust @@ -124,11 +124,11 @@ keyboard.keymap = [ # | | | | | | | | | | | | # `-----------------------------------------------------------------------------------' [ - [KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12], - [_______, _______, KC.RGB.TOG, KC.RGB.MOD, KC.RGB.HUD, KC.RGB.HUI, KC.RGB.SAD, KC.RGB.SAI, KC.RGB.VAD, KC.RGB.VAI, _______, KC.DEL], - [_______, _______, _______, _______, _______, _______, _______, KC.DF(0), KC.DF(1), KC.DF(2), _______, _______], - [_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______], - [_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______], + KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, + _______, _______, KC.RGB.TOG, KC.RGB.MOD, KC.RGB.HUD, KC.RGB.HUI, KC.RGB.SAD, KC.RGB.SAI, KC.RGB.VAD, KC.RGB.VAI, _______, KC.DEL, + _______, _______, _______, _______, _______, _______, _______, KC.DF(0), KC.DF(1), KC.DF(2), _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ], ] diff --git a/user_keymaps/kdb424/luddite.py b/user_keymaps/kdb424/luddite.py index 430e797..116c4eb 100644 --- a/user_keymaps/kdb424/luddite.py +++ b/user_keymaps/kdb424/luddite.py @@ -30,32 +30,38 @@ END = KC.MT(KC.END, KC.RSFT) BASE = 0 -FN1 = 1 +GAMING = 1 +FN1 = 2 # ---------------------- Keymap --------------------------------------------------------- keyboard.keymap = [ + # df [ - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7], - [KC.N8, KC.N9, KC.N0, KC.LBRC, KC.RBRC, KC.BSPC, KC.LEAD, KC.QUOT], - [KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R], - [KC.L, KC.SLSH, KC.EQL, KC.BSLS, KC.TAB, KC.A, KC.O, KC.E], - [KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.MINS], - [KC.ENT, HOME, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B], - [KC.M, KC.W, KC.V, KC.Z, END, KC.LCTL, KC.LGUI, KC.MO(FN1)], - [KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.LBRC, KC.RBRC, KC.BSPC, + KC.LEAD, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.SLSH, KC.EQL, KC.BSLS, + KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.MINS, KC.ENT, + HOME, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, END, + KC.LCTL, KC.LGUI, KC.MO(FN1), KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT, ], + # df [ - [KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7], - [KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.DEL, KC.RGB_TOG, KC.RGB_HUD], - [KC.RGB_HUI, _______, _______, _______, _______, _______, _______, _______], - [_______, _______, KC.VOLU, _______, _______, KC.RGB_SAD, KC.RGB_SAI, _______], - [_______, _______, _______, _______, _______, _______, _______, KC.VOLD], - [_______, _______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______], - [_______, _______, _______, _______, _______, KC.RGB_M_K, _______, _______], - [_______, KC.LALT, KC.RGB_M_S, _______, _______], + KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.LBRC, KC.RBRC, KC.BSPC, + KC.LEAD, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.SLSH, KC.EQL, KC.BSLS, + KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.MINS, KC.ENT, + KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.RSFT, + KC.LCTL, KC.LGUI, KC.MO(FN1), KC.SPC, KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT, + ], + + # fn + [ + KC.GESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12, KC.DEL, + KC.RGB_TOG, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC.VOLU, _______, + _______, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, _______, _______, _______, KC.VOLD, _______, + _______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, _______, _______, _______, _______, + KC.RGB_M_K, _______, _______, _______, KC.LALT, KC.RGB_M_S, KC.DF(0), KC.DF(1), ], ] diff --git a/user_keymaps/kdb424/nyquist_r2.py b/user_keymaps/kdb424/nyquist_r2.py index 0658717..e17f2a6 100644 --- a/user_keymaps/kdb424/nyquist_r2.py +++ b/user_keymaps/kdb424/nyquist_r2.py @@ -1,54 +1,27 @@ from kmk.boards.converter.keebio.nyquist_r2 import Firmware -from kmk.consts import LeaderMode, UnicodeMode -from kmk.handlers.sequences import compile_unicode_string_sequences from kmk.keys import KC keyboard = Firmware() # ------------------User level config variables --------------------------------------- -keyboard.leader_mode = LeaderMode.TIMEOUT -keyboard.unicode_mode = UnicodeMode.LINUX keyboard.tap_time = 150 keyboard.leader_timeout = 2000 keyboard.debug_enabled = False # RGB Config (underglow) -keyboard.rgb_num_pixels = 12 +keyboard.rgb_config['num_pixels'] = 12 +keyboard.rgb_config['val_limit'] = 150 +keyboard.rgb_config['hue_step'] = 10 +keyboard.rgb_config['sat_step'] = 5 +keyboard.rgb_config['val_step'] = 5 +keyboard.rgb_config['hue_default'] = 260 +keyboard.rgb_config['sat_default'] = 100 +keyboard.rgb_config['val_default'] = 20 +keyboard.rgb_config['knight_effect_length'] = 4 +keyboard.rgb_config['animation_mode'] = 'static' +keyboard.rgb_config['animation_speed'] = 1 +keyboard.debug_enabled = False -keyboard.rgb_val_limit = 150 -keyboard.rgb_hue_step = 5 -keyboard.rgb_sat_step = 5 -keyboard.rgb_val_step = 5 -keyboard.rgb_hue_default = 260 -keyboard.rgb_sat_default = 100 -keyboard.rgb_val_default = 20 -keyboard.rgb_knight_effect_length = 4 -keyboard.rgb_animation_mode = 'static' -keyboard.rgb_animation_speed = 1 - -emoticons = compile_unicode_string_sequences({ - # Emoticons, but fancier - 'ANGRY_TABLE_FLIP': r'(ノಠ痊ಠ)ノ彡┻━┻', - 'CHEER': r'+。:.゚ヽ(´∀。)ノ゚.:。+゚゚+。:.゚ヽ(*´∀)ノ゚.:。+゚', - 'TABLE_FLIP': r'(╯°□°)╯︵ ┻━┻', - 'WAT': r'⊙.☉', - 'FF': r'凸(゚Д゚#)', - 'F': r'( ̄^ ̄)凸', - 'MEH': r'╮( ̄_ ̄)╭', - 'YAY': r'o(^▽^)o', -}) - -# ---------------------- Leader Key Macros -------------------------------------------- - -keyboard.leader_dictionary = { - 'flip': emoticons.ANGRY_TABLE_FLIP, - 'cheer': emoticons.CHEER, - 'wat': emoticons.WAT, - 'ff': emoticons.FF, - 'f': emoticons.F, - 'meh': emoticons.MEH, - 'yay': emoticons.YAY, -} _______ = KC.TRNS XXXXXXX = KC.NO @@ -63,43 +36,43 @@ GAMING = KC.DF(1) keyboard.keymap = [ [ # df - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL], - [KC.GRV, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP], - [KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT], - [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH], - [KC.LCTRL, KC.LGUI, KC.LALT, KC.RGB_TOG, KC.MO(2), LT2_SP, LT2_SP, KC.MO(4), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL, + KC.GRV, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP, + KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT, + KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH, + KC.LCTRL, KC.LGUI, KC.LALT, KC.RGB_TOG, KC.MO(2), LT2_SP, LT2_SP, KC.MO(4), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT, ], [ # gw - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL], - [KC.TAB, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP], - [KC.ESC, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT], - [KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH], - [KC.LCTRL, KC.LGUI, KC.LALT, KC.F1, KC.F2, KC.SPC, LT2_SP, KC.MO(4), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT], + KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL, + KC.TAB, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP, + KC.ESC, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT, + KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH, + KC.LCTRL, KC.LGUI, KC.LALT, KC.F1, KC.F2, KC.SPC, LT2_SP, KC.MO(4), KC.LEFT, KC.DOWN, KC.UP, KC.RIGHT, ], [ # r1 - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL], - [KC.TILD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.DEL], - [_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC.LBRC, KC.RBRC, KC.BSLS], - [_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC.INS, _______, _______, KC.MINS], - [KC.RESET, _______, _______, _______, _______, XXXXXXX, XXXXXXX, KC.EQL, KC.HOME, KC.PGDN, KC.PGUP, KC.END], + KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL, + KC.TILD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.DEL, + _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC.LBRC, KC.RBRC, KC.BSLS, + _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC.INS, _______, _______, KC.MINS, + KC.RESET, _______, _______, _______, _______, XXXXXXX, XXXXXXX, KC.EQL, KC.HOME, KC.PGDN, KC.PGUP, KC.END, ], [ # r2 - [KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.N7, KC.N8, KC.N9, KC.BKSP], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.N4, KC.N5, KC.N6, XXXXXXX], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.N1, KC.N2, KC.N3, XXXXXXX], - [_______, _______, _______, _______, _______, _______, _______, _______, KC.N0, KC.N0, KC.PDOT, KC.ENT], + KC.GESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.DEL, + _______, _______, _______, _______, _______, _______, _______, _______, KC.N7, KC.N8, KC.N9, KC.BKSP, + _______, _______, _______, _______, _______, _______, _______, _______, KC.N4, KC.N5, KC.N6, XXXXXXX, + _______, _______, _______, _______, _______, _______, _______, _______, KC.N1, KC.N2, KC.N3, XXXXXXX, + _______, _______, _______, _______, _______, _______, _______, _______, KC.N0, KC.N0, KC.PDOT, KC.ENT, ], [ # r3 - [KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, KC.RGB_M_S, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL], - [KC.RGB_ANI, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS], - [KC.RGB_AND, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU], - [_______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD], - [BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX], + KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, KC.RGB_M_S, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL, + KC.RGB_ANI, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS, + KC.RGB_AND, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU, + _______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD, + BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX, ], ] From c16e2c51aa5845f5eebcb1d22901c70887c33fc5 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Mon, 24 Jun 2019 17:09:52 -0700 Subject: [PATCH 32/32] addressing PR feedback --- user_keymaps/{Default => default}/__init__.py | 0 user_keymaps/{Default => default}/converter/__init__.py | 0 .../converter/fourtypercentclub/__init__.py | 0 .../{Default => default}/converter/fourtypercentclub/luddite.py | 0 user_keymaps/{Default => default}/converter/keebio/__init__.py | 0 .../{Default => default}/converter/keebio/nyquist_r2.py | 0 user_keymaps/kdb424/klanck.py | 2 +- user_keymaps/kdb424/levinson_r2.py | 2 +- 8 files changed, 2 insertions(+), 2 deletions(-) rename user_keymaps/{Default => default}/__init__.py (100%) rename user_keymaps/{Default => default}/converter/__init__.py (100%) rename user_keymaps/{Default => default}/converter/fourtypercentclub/__init__.py (100%) rename user_keymaps/{Default => default}/converter/fourtypercentclub/luddite.py (100%) rename user_keymaps/{Default => default}/converter/keebio/__init__.py (100%) rename user_keymaps/{Default => default}/converter/keebio/nyquist_r2.py (100%) diff --git a/user_keymaps/Default/__init__.py b/user_keymaps/default/__init__.py similarity index 100% rename from user_keymaps/Default/__init__.py rename to user_keymaps/default/__init__.py diff --git a/user_keymaps/Default/converter/__init__.py b/user_keymaps/default/converter/__init__.py similarity index 100% rename from user_keymaps/Default/converter/__init__.py rename to user_keymaps/default/converter/__init__.py diff --git a/user_keymaps/Default/converter/fourtypercentclub/__init__.py b/user_keymaps/default/converter/fourtypercentclub/__init__.py similarity index 100% rename from user_keymaps/Default/converter/fourtypercentclub/__init__.py rename to user_keymaps/default/converter/fourtypercentclub/__init__.py diff --git a/user_keymaps/Default/converter/fourtypercentclub/luddite.py b/user_keymaps/default/converter/fourtypercentclub/luddite.py similarity index 100% rename from user_keymaps/Default/converter/fourtypercentclub/luddite.py rename to user_keymaps/default/converter/fourtypercentclub/luddite.py diff --git a/user_keymaps/Default/converter/keebio/__init__.py b/user_keymaps/default/converter/keebio/__init__.py similarity index 100% rename from user_keymaps/Default/converter/keebio/__init__.py rename to user_keymaps/default/converter/keebio/__init__.py diff --git a/user_keymaps/Default/converter/keebio/nyquist_r2.py b/user_keymaps/default/converter/keebio/nyquist_r2.py similarity index 100% rename from user_keymaps/Default/converter/keebio/nyquist_r2.py rename to user_keymaps/default/converter/keebio/nyquist_r2.py diff --git a/user_keymaps/kdb424/klanck.py b/user_keymaps/kdb424/klanck.py index 3149293..465cd9b 100644 --- a/user_keymaps/kdb424/klanck.py +++ b/user_keymaps/kdb424/klanck.py @@ -49,7 +49,7 @@ WPM = send_string("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed keyboard.keymap = [ [ - # Default + # default KC.GESC, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP, KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT, KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH, diff --git a/user_keymaps/kdb424/levinson_r2.py b/user_keymaps/kdb424/levinson_r2.py index 6c9d1de..fae4891 100644 --- a/user_keymaps/kdb424/levinson_r2.py +++ b/user_keymaps/kdb424/levinson_r2.py @@ -53,7 +53,7 @@ keyboard.leader_dictionary = { keyboard.keymap = [ [ - # Default + # default KC.GESC, KC.QUOTE, KC.COMMA, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BKSP, KC.TAB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT, KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH,