Skip to content

Commit

Permalink
Revert "chore(all): Remove all new features"
Browse files Browse the repository at this point in the history
This reverts commit aadb235.
  • Loading branch information
reemo3dp committed Apr 7, 2024
1 parent a19ed6c commit 82035a9
Show file tree
Hide file tree
Showing 16 changed files with 8,454 additions and 258 deletions.
149 changes: 92 additions & 57 deletions docs/LED_Effect.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions install-led_effect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ check_folders()
link_extension()
{
echo -n "Linking extension to Klipper... "
ln -sf "${SRCDIR}/packages/led_effect/led_effect/led_effect_plugin.py" "${KLIPPER_PATH}/klippy/extras/led_effect.py"
ln -sf "${SRCDIR}/packages/led_effect/led_effect/" "${KLIPPER_PATH}/klippy/extras/led_effect"
echo "[OK]"
}

Expand Down Expand Up @@ -162,13 +162,13 @@ stop_klipper()

uninstall()
{
if [ -f "${KLIPPER_PATH}/klippy/extras/led_effect.py" ]; then
if [ -d "${KLIPPER_PATH}/klippy/extras/led_effect" ]; then
echo -n "Uninstalling... "
rm -f "${KLIPPER_PATH}/klippy/extras/led_effect.py"
rm -f "${KLIPPER_PATH}/klippy/extras/led_effect"
echo "[OK]"
echo "You can now remove the [update_manager led_effect] section in your moonraker.conf and delete this directory. Also remove all led_effect configurations from your Klipper configuration."
else
echo "led_effect.py not found in \"${KLIPPER_PATH}/klippy/extras/\". Is it installed?"
echo "led_effect not found in \"${KLIPPER_PATH}/klippy/extras/\". Is it installed?"
echo "[FAILED]"
fi
}
Expand Down
2 changes: 2 additions & 0 deletions packages/led_effect/Makefile
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 $@ $<
52 changes: 52 additions & 0 deletions packages/led_effect/led_effect/color_conversions.py
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)
33 changes: 33 additions & 0 deletions packages/led_effect/led_effect/layer_parser.lark
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
59 changes: 59 additions & 0 deletions packages/led_effect/led_effect/layer_parser.py
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]

Loading

0 comments on commit 82035a9

Please sign in to comment.