code cleanup to pass lint and some for flake8

This commit is contained in:
Kyle Brown 2019-02-23 15:12:50 -08:00
parent 1751cce299
commit 9fbad17ed4
4 changed files with 43 additions and 46 deletions

View File

@ -171,8 +171,7 @@ class InternalState:
return self return self
if ( if (
changed_key not in self.tap_dance_counts or changed_key not in self.tap_dance_counts or not self.tap_dance_counts[changed_key]
not self.tap_dance_counts[changed_key]
): ):
self.tap_dance_counts[changed_key] = 1 self.tap_dance_counts[changed_key] = 1
self.set_timeout(self.config.tap_time, lambda: self._end_tap_dance(changed_key)) 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: for key in keys_pressed:
if ( if (
self.config.leader_mode == LeaderMode.ENTER_ACTIVE and self.config.leader_mode == LeaderMode.ENTER_ACTIVE and key == KC.ENT
key == KC.ENT
): ):
self._handle_leader_sequence() self._handle_leader_sequence()
break break

View File

@ -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_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_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_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=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight)
make_key( make_key(
names=('LEADER', 'LEAD'), names=('LEADER', 'LEAD'),

View File

@ -1,6 +1,6 @@
from math import sin, exp, pi, floor
from math import e as M_E
import time import time
from math import e as M_E
from math import exp, floor, pi, sin
class RGB: class RGB:
@ -65,7 +65,6 @@ class RGB:
'hue': self.hue, 'hue': self.hue,
'sat': self.sat, 'sat': self.sat,
'val': self.val, 'val': self.val,
'animation_mode': self.animation_mode,
'time': self.time, 'time': self.time,
'intervals': self.intervals, 'intervals': self.intervals,
'animation_mode': self.animation_mode, 'animation_mode': self.animation_mode,
@ -81,13 +80,13 @@ class RGB:
return floor(time.monotonic() * 10) return floor(time.monotonic() * 10)
def hsv_to_rgb(self, hue, sat, val): def hsv_to_rgb(self, hue, sat, val):
''' """
Converts HSV values, and returns a tuple of RGB values Converts HSV values, and returns a tuple of RGB values
:param hue: :param hue:
:param sat: :param sat:
:param val: :param val:
:return: (r, g, b) :return: (r, g, b)
''' """
r = 0 r = 0
g = 0 g = 0
b = 0 b = 0
@ -133,24 +132,24 @@ class RGB:
return floor(r), floor(g), floor(b) return floor(r), floor(g), floor(b)
def hsv_to_rgbw(self, hue, sat, val): def hsv_to_rgbw(self, hue, sat, val):
''' """
Converts HSV values, and returns a tuple of RGBW values Converts HSV values, and returns a tuple of RGBW values
:param hue: :param hue:
:param sat: :param sat:
:param val: :param val:
:return: (r, g, b, w) :return: (r, g, b, w)
''' """
rgb = self.hsv_to_rgb(hue, sat, val) rgb = self.hsv_to_rgb(hue, sat, val)
return rgb[0], rgb[1], rgb[2], min(rgb) return rgb[0], rgb[1], rgb[2], min(rgb)
def set_hsv(self, hue, sat, val, index): def set_hsv(self, hue, sat, val, index):
''' """
Takes HSV values and displays it on a single LED/Neopixel Takes HSV values and displays it on a single LED/Neopixel
:param hue: :param hue:
:param sat: :param sat:
:param val: :param val:
:param index: Index of LED/Pixel :param index: Index of LED/Pixel
''' """
if self.neopixel: if self.neopixel:
if self.rgbw: if self.rgbw:
self.set_rgb(self.hsv_to_rgbw(hue, sat, val), index) 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) self.set_rgb(self.hsv_to_rgb(hue, sat, val), index)
def set_hsv_fill(self, hue, sat, val): def set_hsv_fill(self, hue, sat, val):
''' """
Takes HSV values and displays it on all LEDs/Neopixels Takes HSV values and displays it on all LEDs/Neopixels
:param hue: :param hue:
:param sat: :param sat:
:param val: :param val:
:param index: Index of LED/Pixel """
'''
if self.neopixel: if self.neopixel:
if self.rgbw: if self.rgbw:
self.set_rgb_fill(self.hsv_to_rgbw(hue, sat, val)) 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)) self.set_rgb_fill(self.hsv_to_rgb(hue, sat, val))
def set_rgb(self, rgb, index): def set_rgb(self, rgb, index):
''' """
Takes an RGB or RGBW and displays it on a single LED/Neopixel Takes an RGB or RGBW and displays it on a single LED/Neopixel
:param rgb: RGB or RGBW :param rgb: RGB or RGBW
:param index: Index of LED/Pixel :param index: Index of LED/Pixel
''' """
if self.neopixel: if self.neopixel and 0 <= index <= self.num_pixels - 1:
if index >=0 and index <= self.num_pixels - 1: self.neopixel[index] = rgb
self.neopixel[index] = rgb if not self.disable_auto_write:
if not self.disable_auto_write: self.neopixel.show()
self.neopixel.show()
def set_rgb_fill(self, rgb): def set_rgb_fill(self, rgb):
''' """
Takes an RGB or RGBW and displays it on all LEDs/Neopixels Takes an RGB or RGBW and displays it on all LEDs/Neopixels
:param rgb: RGB or RGBW :param rgb: RGB or RGBW
''' """
if self.neopixel: if self.neopixel:
self.neopixel.fill(rgb) self.neopixel.fill(rgb)
if not self.disable_auto_write: if not self.disable_auto_write:
self.neopixel.show() self.neopixel.show()
def increase_hue(self, step): def increase_hue(self, step):
''' """
Increases hue by step amount rolling at 360 and returning to 0 Increases hue by step amount rolling at 360 and returning to 0
:param step: :param step:
''' """
self.hue = (self.hue + step) % 360 self.hue = (self.hue + step) % 360
def decrease_hue(self, step): def decrease_hue(self, step):
''' """
Decreases hue by step amount rolling at 0 and returning to 360 Decreases hue by step amount rolling at 0 and returning to 360
:param step: :param step:
''' """
if (self.hue - step) <= 0: if (self.hue - step) <= 0:
self.hue = (self.hue + 360 - step) % 360 self.hue = (self.hue + 360 - step) % 360
else: else:
self.hue = (self.hue - step) % 360 self.hue = (self.hue - step) % 360
def increase_sat(self, step): def increase_sat(self, step):
''' """
Increases saturation by step amount stopping at 100 Increases saturation by step amount stopping at 100
:param step: :param step:
''' """
if self.sat + step >= 100: if self.sat + step >= 100:
self.sat = 100 self.sat = 100
else: else:
self.sat += step self.sat += step
def decrease_sat(self, step): def decrease_sat(self, step):
''' """
Decreases saturation by step amount stopping at 0 Decreases saturation by step amount stopping at 0
:param step: :param step:
''' """
if (self.sat - step) <= 0: if (self.sat - step) <= 0:
self.sat = 0 self.sat = 0
else: else:
self.sat -= step self.sat -= step
def increase_val(self, step): def increase_val(self, step):
''' """
Increases value by step amount stopping at 100 Increases value by step amount stopping at 100
:param step: :param step:
''' """
if (self.val + step) >= 100: if (self.val + step) >= 100:
self.val = 100 self.val = 100
else: else:
self.val += step self.val += step
def decrease_val(self, step): def decrease_val(self, step):
''' """
Decreases value by step amount stopping at 0 Decreases value by step amount stopping at 0
:param step: :param step:
''' """
if (self.val - step) <= 0: if (self.val - step) <= 0:
self.val = 0 self.val = 0
else: else:
self.val -= step self.val -= step
def off(self): def off(self):
''' """
Turns off all LEDs/Neopixels without changing stored values Turns off all LEDs/Neopixels without changing stored values
''' """
if self.neopixel: if self.neopixel:
self.set_hsv_fill(0, 0, 0) self.set_hsv_fill(0, 0, 0)
def show(self): def show(self):
''' """
Turns on all LEDs/Neopixels without changing stored values Turns on all LEDs/Neopixels without changing stored values
''' """
if self.neopixel: if self.neopixel:
self.neopixel.show() self.neopixel.show()
def animate(self): def animate(self):
''' """
Activates a "step" in the animation based on the active mode Activates a "step" in the animation based on the active mode
:return: Returns the new state in animation :return: Returns the new state in animation
''' """
if self.effect_init: if self.effect_init:
self.init_effect() self.init_effect()
if self.enabled: if self.enabled:

View File

@ -2,8 +2,9 @@ import board
import busio import busio
from kmk.consts import DiodeOrientation, LeaderMode, UnicodeMode 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.layers import (df_pressed, lt_pressed, lt_released,
from kmk.handlers.sequences import (compile_unicode_string_sequences) 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.keys import KC, layer_key_validator, make_argumented_key
from kmk.mcus.circuitpython_samd51 import Firmware from kmk.mcus.circuitpython_samd51 import Firmware
from kmk.pins import Pin as P from kmk.pins import Pin as P