forked from julianschill/klipper-led_effect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "chore(all): Remove all new features"
This reverts commit aadb235.
- Loading branch information
Showing
16 changed files
with
8,454 additions
and
258 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
led_effect/layer_parser_lark.py: led_effect/layer_parser.lark | ||
poetry run python -m lark.tools.standalone -s line -o $@ $< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
def rgb_to_hsl(rgb): | ||
r, g, b = rgb | ||
r, g, b = r / 255.0, g / 255.0, b / 255.0 | ||
|
||
max_val = max(r, g, b) | ||
min_val = min(r, g, b) | ||
diff = max_val-min_val | ||
|
||
if max_val == min_val: | ||
h = 0 | ||
elif max_val == r: | ||
h = (60 * ((g-b)/diff) + 360) % 360 | ||
elif max_val == g: | ||
h = (60 * ((b-r)/diff) + 120) % 360 | ||
elif max_val == b: | ||
h = (60 * ((r-g)/diff) + 240) % 360 | ||
|
||
l = (max_val + min_val) / 2 | ||
|
||
if max_val == min_val: | ||
s = 0 | ||
elif l <= 0.5: | ||
s = diff / (max_val + min_val) | ||
else: | ||
s = diff / (2 - max_val - min_val) | ||
|
||
return h, s, l | ||
|
||
|
||
def hsl_to_rgb(hsl): | ||
h, s, l = hsl | ||
|
||
c = (1 - abs(2*l - 1)) * s | ||
x = c * (1 - abs((h / 60) % 2 - 1)) | ||
m = l - c/2 | ||
|
||
if h < 60: | ||
r, g, b = c, x, 0 | ||
elif h < 120: | ||
r, g, b = x, c, 0 | ||
elif h < 180: | ||
r, g, b = 0, c, x | ||
elif h < 240: | ||
r, g, b = 0, x, c | ||
elif h < 300: | ||
r, g, b = x, 0, c | ||
else: | ||
r, g, b = c, 0, x | ||
|
||
r, g, b = (r + m) * 255, (g + m) * 255, (b + m) * 255 | ||
|
||
return round(r), round(g), round(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
line: legacy_line | parameterized_line | ||
|
||
legacy_line: LAYER_NAME RATE CUTOFF BLEND palette | ||
LAYER_NAME: CNAME | ||
RATE: NUMBER | ||
CUTOFF: NUMBER | ||
BLEND: CNAME | ||
|
||
parameterized_line: LAYER_NAME "(" parameters ")" BLEND palette | ||
parameters: (parameter ("," parameter)*)? | ||
parameter: CNAME "=" (NUMBER | string) | ||
NUMBER: (FLOAT | INT) | ||
|
||
palette: palette_entry ("," palette_entry)* | ||
palette_entry: float_triplet | hex | rgb | rgbw | ||
float_triplet: "(" (NUMBER) "," (NUMBER) "," (NUMBER) ["," (NUMBER)] ")" | ||
rgb: "rgb" "(" (NUMBER) "," (NUMBER) "," (NUMBER) ")" | ||
rgbw: "rgbw" "(" (NUMBER) "," (NUMBER) "," (NUMBER) "," (NUMBER) ")" | ||
|
||
hex: ("#" | "$" | "0x") HEX_OCTET HEX_OCTET HEX_OCTET HEX_OCTET? | ||
HEX_OCTET: HEX_DIGIT HEX_DIGIT | ||
HEX_DIGIT: /[0-9a-fA-F]/ | ||
|
||
?string: CNAME | ESCAPED_STRING | ||
|
||
%import common.CNAME | ||
%import common.WORD | ||
%import common.FLOAT | ||
%import common.INT | ||
%import common.WS | ||
%import common.ESCAPED_STRING | ||
|
||
%ignore WS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from . import layer_parser_lark | ||
|
||
|
||
class TermTransformer(layer_parser_lark.Transformer): | ||
NUMBER = float | ||
RATE = float | ||
CUTOFF = float | ||
BLEND = str | ||
LAYER_NAME = str | ||
WORD = str | ||
CNAME = str | ||
palette = list | ||
|
||
@layer_parser_lark.v_args(inline=True) | ||
def ESCAPED_STRING(self, s): | ||
return s[1:-1].replace('\\"', '"') | ||
|
||
def float_triplet(self, triplet): | ||
return tuple(triplet) | ||
|
||
def palette_entry(self, children): | ||
return children[0] | ||
|
||
def hex(self, hex): | ||
return tuple([int(hexVal,16)/255.0 for hexVal in hex]) | ||
|
||
def rgb(self, rgb): | ||
return tuple([int(rgbVal)/255.0 for rgbVal in rgb]) | ||
|
||
def rgbw(self, rgbw): | ||
return self.rgb(rgbw) | ||
|
||
def legacy_line(self, children): | ||
effect, rate, cutoff, blend, palette = children | ||
return { | ||
"effect": effect, "parameters": {"effectRate": rate, "effectCutoff": cutoff}, | ||
"blend": blend, "palette": palette | ||
} | ||
|
||
def parameterized_line(self, children): | ||
effect, parameters, blend, palette = children | ||
|
||
params = {k: v for k, v in [ | ||
(param.children[0], param.children[1]) for param in parameters.children]} | ||
|
||
return { | ||
"effect": effect, "blend": blend, "palette": palette, "parameters": params | ||
} | ||
|
||
|
||
layer_line_parser = layer_parser_lark.Lark_StandAlone() | ||
|
||
|
||
|
||
|
||
def parse(line): | ||
tree = TermTransformer().transform(layer_line_parser.parse(line)) | ||
return tree.children[0] | ||
|
Oops, something went wrong.