Revert "Monocolor LED backlight added"
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
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
|
@@ -1,13 +0,0 @@
|
||||
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
|
||||
rgb_num_pixels = 12
|
@@ -1,11 +0,0 @@
|
||||
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
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -1,12 +0,0 @@
|
||||
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
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -1,19 +0,0 @@
|
||||
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
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -1,18 +0,0 @@
|
||||
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
|
@@ -1,17 +0,0 @@
|
||||
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]
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -1,9 +0,0 @@
|
||||
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
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -1,16 +0,0 @@
|
||||
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]
|
@@ -16,11 +16,8 @@ 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))
|
@@ -42,12 +42,13 @@ import kmk.matrix # isort:skip
|
||||
import kmk.hid # isort:skip
|
||||
import kmk.internal_state # isort:skip
|
||||
|
||||
# GC runs automatically after CircuitPython imports.
|
||||
# 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)
|
||||
|
||||
# Thanks for sticking around. Now let's do real work, starting below
|
||||
|
||||
from kmk.util import intify_coordinate as ic
|
||||
from kmk import led, rgb # isort:skip
|
||||
|
||||
|
||||
class Firmware:
|
||||
@@ -60,7 +61,6 @@ class Firmware:
|
||||
col_pins = None
|
||||
diode_orientation = None
|
||||
matrix_scanner = MatrixScanner
|
||||
uart_buffer = []
|
||||
|
||||
unicode_mode = UnicodeMode.NOOP
|
||||
tap_time = 300
|
||||
@@ -70,7 +70,6 @@ class Firmware:
|
||||
|
||||
hid_helper = USB_HID
|
||||
|
||||
# Split config
|
||||
extra_data_pin = None
|
||||
split_offsets = ()
|
||||
split_flip = False
|
||||
@@ -82,14 +81,6 @@ class Firmware:
|
||||
uart_flip = True
|
||||
uart_pin = None
|
||||
|
||||
# RGB config
|
||||
rgb_pixel_pin = None
|
||||
rgb_config = rgb.rgb_config
|
||||
|
||||
# led config (mono color)
|
||||
led_pin = None
|
||||
led_config = led.led_config
|
||||
|
||||
def __init__(self):
|
||||
# Attempt to sanely guess a coord_mapping if one is not provided
|
||||
|
||||
@@ -128,7 +119,6 @@ class Firmware:
|
||||
:param update:
|
||||
'''
|
||||
if update is not None:
|
||||
|
||||
self._state.matrix_changed(
|
||||
update[0],
|
||||
update[1],
|
||||
@@ -144,22 +134,14 @@ class Firmware:
|
||||
self.uart.write(update)
|
||||
|
||||
def _receive_from_slave(self):
|
||||
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()
|
||||
|
||||
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
|
||||
if self.uart is not None and self.uart.in_waiting > 0:
|
||||
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
|
||||
|
||||
return None
|
||||
|
||||
@@ -204,27 +186,15 @@ class Firmware:
|
||||
if self.split_flip and not self._master_half():
|
||||
self.col_pins = list(reversed(self.col_pins))
|
||||
|
||||
if self.split_side == 'Left':
|
||||
self.split_master_left = self._master_half()
|
||||
elif self.split_side == 'Right':
|
||||
if self.split_side == "Left":
|
||||
self.split_master_left = self._master_half()
|
||||
elif self.split_side == "Right":
|
||||
self.split_master_left = not self._master_half()
|
||||
|
||||
if self.uart_pin is not None:
|
||||
self.uart = self.init_uart(self.uart_pin)
|
||||
|
||||
if self.rgb_pixel_pin:
|
||||
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_config)
|
||||
self.led_config = None # No longer needed
|
||||
else:
|
||||
self.led = None
|
||||
|
||||
self.matrix = MatrixScanner(
|
||||
self.matrix = self.matrix_scanner(
|
||||
cols=self.col_pins,
|
||||
rows=self.row_pins,
|
||||
diode_orientation=self.diode_orientation,
|
||||
@@ -242,7 +212,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
|
||||
@@ -278,16 +248,3 @@ 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:
|
||||
# Only check animations if pixels is initialized
|
||||
if self.pixels.animation_mode:
|
||||
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()
|
||||
|
@@ -52,6 +52,8 @@ 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)
|
||||
@@ -116,125 +118,3 @@ 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):
|
||||
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
|
||||
|
||||
|
||||
def rgb_hui(key, state, *args, **kwargs):
|
||||
state.config.pixels.increase_hue()
|
||||
return state
|
||||
|
||||
|
||||
def rgb_hud(key, state, *args, **kwargs):
|
||||
state.config.pixels.decrease_hue()
|
||||
return state
|
||||
|
||||
|
||||
def rgb_sai(key, state, *args, **kwargs):
|
||||
state.config.pixels.increase_sat()
|
||||
return state
|
||||
|
||||
|
||||
def rgb_sad(key, state, *args, **kwargs):
|
||||
state.config.pixels.decrease_sat()
|
||||
return state
|
||||
|
||||
|
||||
def rgb_vai(key, state, *args, **kwargs):
|
||||
state.config.pixels.increase_val()
|
||||
return state
|
||||
|
||||
|
||||
def rgb_vad(key, state, *args, **kwargs):
|
||||
state.config.pixels.decrease_val()
|
||||
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'
|
||||
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_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'
|
||||
return state
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
@@ -171,7 +171,8 @@ 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))
|
||||
@@ -256,7 +257,8 @@ 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
|
||||
|
45
kmk/keys.py
45
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
|
||||
@@ -625,35 +625,6 @@ 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_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)
|
||||
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)
|
||||
|
||||
|
||||
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,
|
||||
|
143
kmk/led.py
143
kmk/led.py
@@ -1,143 +0,0 @@
|
||||
import time
|
||||
from math import e, exp, pi, sin
|
||||
|
||||
import pulseio
|
||||
from micropython import const
|
||||
|
||||
led_config = {
|
||||
'brightness_step': 5,
|
||||
'brightness_limit': 100,
|
||||
'breathe_center': 1.5,
|
||||
'animation_mode': 'static',
|
||||
'animation_speed': 1,
|
||||
}
|
||||
|
||||
|
||||
class led:
|
||||
brightness = 0
|
||||
time = int(time.monotonic() * 1000)
|
||||
pos = 0
|
||||
effect_init = False
|
||||
|
||||
led = None
|
||||
brightness_step = 5
|
||||
brightness_limit = 100
|
||||
breathe_center = 1.5
|
||||
animation_mode = 'static'
|
||||
animation_speed = 1
|
||||
enabled = True
|
||||
user_animation = None
|
||||
|
||||
def __init__(self, led_pin, config):
|
||||
self.led = pulseio.PWMOut(led_pin)
|
||||
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'])
|
||||
if config['user_animation']:
|
||||
self.user_animation = config['user_animation']
|
||||
|
||||
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,
|
||||
'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)
|
||||
|
||||
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.breathe_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()
|
||||
elif self.animation_mode == 'user':
|
||||
return self.user_animation(self)
|
||||
else:
|
||||
self.off()
|
||||
|
||||
return self
|
487
kmk/rgb.py
487
kmk/rgb.py
@@ -1,487 +0,0 @@
|
||||
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
|
||||
sat = 100
|
||||
val = 80
|
||||
pos = 0
|
||||
time = int(time.monotonic() * 10)
|
||||
intervals = (30, 20, 10, 5)
|
||||
animation_speed = 1
|
||||
enabled = True
|
||||
neopixel = None
|
||||
rgbw = False
|
||||
reverse_animation = False
|
||||
disable_auto_write = False
|
||||
animation_mode = 'static'
|
||||
|
||||
# Set by config
|
||||
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
|
||||
user_animation = None
|
||||
|
||||
def __init__(self, config, pixel_pin):
|
||||
try:
|
||||
import neopixel
|
||||
self.neopixel = neopixel.NeoPixel(pixel_pin,
|
||||
config['num_pixels'],
|
||||
pixel_order=config['rgb_order'],
|
||||
auto_write=False)
|
||||
if len(config['rgb_order']) == 4:
|
||||
self.rgbw = True
|
||||
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.animation_mode = config['animation_mode']
|
||||
self.animation_speed = const(config['animation_speed'])
|
||||
if 'user_animation' in config:
|
||||
print(config['user_animation'])
|
||||
self.user_animation = config['user_animation']
|
||||
|
||||
except ImportError as e:
|
||||
print(e)
|
||||
|
||||
def __repr__(self):
|
||||
return 'RGB({})'.format(self._to_dict())
|
||||
|
||||
def _to_dict(self):
|
||||
return {
|
||||
'hue': self.hue,
|
||||
'sat': self.sat,
|
||||
'val': self.val,
|
||||
'time': self.time,
|
||||
'intervals': self.intervals,
|
||||
'animation_mode': self.animation_mode,
|
||||
'animation_speed': self.animation_speed,
|
||||
'enabled': self.enabled,
|
||||
'neopixel': self.neopixel,
|
||||
'disable_auto_write': self.disable_auto_write,
|
||||
}
|
||||
|
||||
def time_ms(self):
|
||||
return int(time.monotonic() * 1000)
|
||||
|
||||
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
|
||||
|
||||
if val > self.val_limit:
|
||||
val = self.val_limit
|
||||
|
||||
if sat == 0:
|
||||
r = val
|
||||
g = val
|
||||
b = val
|
||||
|
||||
else:
|
||||
base = ((100 - sat) * val) / 100
|
||||
color = int((val - base) * ((hue % 60) / 60))
|
||||
|
||||
x = int(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 int(r), int(g), int(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)
|
||||
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
|
||||
:param hue:
|
||||
:param sat:
|
||||
:param val:
|
||||
"""
|
||||
if self.neopixel:
|
||||
if self.rgbw:
|
||||
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):
|
||||
"""
|
||||
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 and 0 <= index <= self.num_pixels - 1:
|
||||
self.neopixel[index] = 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
|
||||
:param rgb: RGB or RGBW
|
||||
"""
|
||||
if self.neopixel:
|
||||
self.neopixel.fill(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
|
||||
:param step:
|
||||
"""
|
||||
if not step:
|
||||
step = self.hue_step
|
||||
|
||||
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
|
||||
: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
|
||||
|
||||
if self._check_update():
|
||||
self._do_update()
|
||||
|
||||
return self
|
||||
|
||||
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
|
||||
|
||||
if self._check_update():
|
||||
self._do_update()
|
||||
|
||||
return self
|
||||
|
||||
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
|
||||
|
||||
if self._check_update():
|
||||
self._do_update()
|
||||
|
||||
return self
|
||||
|
||||
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
|
||||
|
||||
if self._check_update():
|
||||
self._do_update()
|
||||
|
||||
return self
|
||||
|
||||
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:
|
||||
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
|
||||
: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
|
||||
|
||||
return self
|
||||
|
||||
def off(self):
|
||||
"""
|
||||
Turns off all LEDs/Neopixels without changing stored values
|
||||
"""
|
||||
if self.neopixel:
|
||||
self.set_hsv_fill(0, 0, 0)
|
||||
|
||||
return self
|
||||
|
||||
def show(self):
|
||||
"""
|
||||
Turns on all LEDs/Neopixels without changing stored values
|
||||
"""
|
||||
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()
|
||||
|
||||
if self.enabled:
|
||||
if self.animation_mode == 'breathing':
|
||||
return self.effect_breathing()
|
||||
elif self.animation_mode == 'rainbow':
|
||||
return self.effect_rainbow()
|
||||
elif self.animation_mode == 'breathing_rainbow':
|
||||
return self.effect_breathing_rainbow()
|
||||
elif self.animation_mode == 'static':
|
||||
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 == 'user':
|
||||
return self.user_animation(self)
|
||||
elif self.animation_mode == 'static_standby':
|
||||
pass
|
||||
else:
|
||||
self.off()
|
||||
|
||||
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 _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
|
||||
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):
|
||||
# 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.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)
|
||||
|
||||
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.increase_hue(self.animation_speed)
|
||||
self.set_hsv_fill(self.hue, self.sat, self.val)
|
||||
|
||||
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
|
||||
self.off() # Fill all off
|
||||
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)):
|
||||
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.pos += self.animation_speed / 5
|
||||
|
||||
# Show final results
|
||||
self.disable_auto_write = False # Resume showing changes
|
||||
self.show()
|
||||
|
||||
return self
|
Reference in New Issue
Block a user