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.
- Loading branch information
Showing
24 changed files
with
29,936 additions
and
7 deletions.
There are no files selected for viewing
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/src/layer_parser_lark.py: src/layer_parser.lark | ||
poetry run python -m lark.tools.standalone -s line -o $@ $< |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[tool.poetry] | ||
package-mode = false | ||
name = "layer_parser" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Julian Schill <[email protected]>", "reemo3dp <[email protected]>"] | ||
license = "GPL3" | ||
readme = "README.md" | ||
|
||
[tool.poetry.dependencies] | ||
python = ">=3.8,<3.12" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
lark = "^1.1.9" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
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,25 @@ | ||
line: legacy_line | parameterized_line | ||
|
||
legacy_line: LAYER_NAME RATE CUTOFF BLEND palette | ||
LAYER_NAME: WORD | ||
RATE: NUMBER | ||
CUTOFF: NUMBER | ||
BLEND: WORD | ||
|
||
parameterized_line: LAYER_NAME "(" parameters ")" BLEND palette | ||
parameters: (parameter ("," parameter)*)? | ||
parameter: CNAME "=" (NUMBER | string) | ||
NUMBER: (FLOAT | INT) | ||
|
||
palette: palette_entry ("," palette_entry)* | ||
palette_entry: "(" (NUMBER) "," (NUMBER) "," (NUMBER) ["," (NUMBER)] ")" | ||
?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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[tool.poetry] | ||
name = "led-effect" | ||
name = "led_effect" | ||
version = "0.1.0" | ||
authors = ["Julian Schill <[email protected]>"] | ||
description = "" | ||
|
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,44 @@ | ||
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 | ||
|
||
@layer_parser_lark.v_args(inline=True) | ||
def ESCAPED_STRING(self, s): | ||
return s[1:-1].replace('\\"', '"') | ||
|
||
|
||
layer_line_parser = layer_parser_lark.Lark_StandAlone() | ||
|
||
|
||
def parse(line): | ||
tree = TermTransformer().transform(layer_line_parser.parse(line)) | ||
|
||
if tree.children[0].data == "legacy_line": | ||
effect, rate, cutoff, blend, palette = tree.children[0].children | ||
palette = [tuple([color for color in entry.children if color != None]) | ||
for entry in palette.children] | ||
return { | ||
"effect": effect, "parameters": {"effectRate": rate, "effectCutoff": cutoff}, | ||
"blend": blend, "palette": palette | ||
} | ||
elif tree.children[0].data == "parameterized_line": | ||
effect, parameters, blend, palette = tree.children[0].children | ||
|
||
params = {k: v for k, v in [ | ||
(param.children[0], param.children[1]) for param in parameters.children]} | ||
|
||
palette = [tuple([color for color in entry.children if color != None]) | ||
for entry in palette.children] | ||
return { | ||
"effect": effect, "blend": blend, "palette": palette, "parameters": params | ||
} | ||
return None |
Oops, something went wrong.