Skip to content

Commit

Permalink
chore: Merge main and develop
Browse files Browse the repository at this point in the history
  • Loading branch information
reemo3dp committed Mar 2, 2024
1 parent 44b03c3 commit ab06c07
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_pages.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: pages
on:
push:
branches:
- main

env:
PYTHON_VERSION: 3.x
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install dependencies
working-directory: ./packages/led_effect_tests
working-directory: ./packages/led_effect
run: poetry install
- name: Run tests
working-directory: ./packages/led_effect_tests
working-directory: ./packages/led_effect
run: poetry run pytest -s -v

klipper-test:
Expand Down
2 changes: 1 addition & 1 deletion 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/src/" "${KLIPPER_PATH}/klippy/extras/led_effect"
ln -sf "${SRCDIR}/packages/led_effect/led_effect/" "${KLIPPER_PATH}/klippy/extras/led_effect"
echo "[OK]"
}

Expand Down
12 changes: 7 additions & 5 deletions packages/klippermock/src/klippermock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from led_effect import ledEffect, ledFrameHandler
from led_effect.led_effect_plugin import ledEffect, ledFrameHandler

class mockPrinter:
NOW = 0
Expand Down Expand Up @@ -57,17 +57,19 @@ def register_adc(self, name, mcu):
pass
def lookup_heater(self, name):
return self
def set_heater(self, min, max, temp):
self.led_effect.handler.heaterLast["bed"] = self.led_effect.handler.heaterCurrent["bed"]
self.led_effect.handler.heaterCurrent["bed"] = temp
self.led_effect.handler.heaterTarget["bed"] = max
def set_heater(self, min, max, temp, heater = "bed"):
self.led_effect.handler.heaterLast[heater] = self.led_effect.handler.heaterCurrent[heater]
self.led_effect.handler.heaterCurrent[heater] = temp
self.led_effect.handler.heaterTarget[heater] = max
def set_progress (self, progress):
self.led_effect.handler.printProgress=progress
def set_analog(self, value):
self.led_effect.analogValue=value
def load_template(self, config, name):
self.template = config.get(name)
return self
def config_error(self, msg):
raise Exception(msg)
def render(self, context=None):
return self.template
def create_template_context(self):
Expand Down
2 changes: 1 addition & 1 deletion packages/led_effect/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
src/layer_parser_lark.py: src/layer_parser.lark
led_effect/layer_parser_lark.py: led_effect/layer_parser.lark
poetry run python -m lark.tools.standalone -s line -o $@ $<
7 changes: 7 additions & 0 deletions packages/led_effect/led_effect/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from . import led_effect_plugin

def load_config(config):
return led_effect_plugin.load_config(config)

def load_config_prefix(config):
return led_effect_plugin.load_config_prefix(config)
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions packages/led_effect/src/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion packages/led_effect/tests/layer_parser_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import layer_parser
from led_effect import layer_parser

legacy_format_data = [
("breathing .5 0 screen (0,.1,1), (0,1,.5), (0, 1,1), (0,.1,.5)", "breathing",
Expand Down
139 changes: 139 additions & 0 deletions packages/led_effect/tests/led_effect_plugin_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import pytest
from klippermock import *


def test_legacy_works():
config = mockConfig()
config.setint("ledcount", 10)
config.set(
"layers", "gradient 2 3 top (1.0,0.0,0.0),(0.0,1.0,0.0),(0.0,0.0,1.0) ")
printer = mockPrinter(config)
printer._handle_ready()
layer = printer.led_effect.handler.effects[0].layers[0]

assert layer.speed == 2
assert layer.count == 3
assert layer.blendingMode == "top"
assert layer.paletteColors == [1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]


def test_new_params_work():
config = mockConfig()
config.setint("ledcount", 10)
config.set(
"layers", "gradient(speed=2, count=3) top (1.0,0.0,0.0),(0.0,1.0,0.0),(0.0,0,1.0) ")
printer = mockPrinter(config)
printer._handle_ready()
layer = printer.led_effect.handler.effects[0].layers[0]

assert layer.speed == 2
assert layer.count == 3
assert layer.blendingMode == "top"
assert layer.paletteColors == [1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]


def test_missing_param_throws():
config = mockConfig()
config.setint("ledcount", 10)
config.set(
"layers", "gradient(count=3) top (1.0,0.0,0.0),(0.0,1.0,0.0),(0.0,0,1.0) ")
with pytest.raises(Exception):
printer = mockPrinter(config)
printer._handle_ready()


def test_allow_layer_specific_heater():
config = mockConfig()
config.setint("ledcount", 1)
config.set(
"layers", """
heater(minTemp=10,disableOnceReached=0,heater=heater_bed) add (1.0,0.0,0.0)
heater(minTemp=10,disableOnceReached=0,heater=hotend) add (0,0.0,1.0)
""")
printer = mockPrinter(config)
printer._handle_ready()
printer.set_heater(None, 200, 100, "heater_bed")
assert printer.led_effect.getFrame(0) == ([1.0, 0.0, 0.0, 0.0], True)
printer.set_heater(None, 200, 100, "hotend")
assert printer.led_effect.getFrame(1) == ([1.0, 0.0, 1.0, 0.0], True)


def test_color_blending_colorspace_rgb_default():
config = mockConfig()
config.setint("ledcount", 3)
config.set(
"layers", """
static() top (1, 0, 0), (0, 0, 1)
""")
printer = mockPrinter(config)
printer._handle_ready()
assert printer.led_effect.getFrame(0) == ([
1.0, 0.0, 0.0, 0.0,
0.5, 0.0, 0.5, 0.0,
0.0, 0.0, 1.0, 0.0
], True)


def test_color_blending_colorspace_lab():
config = mockConfig()
config.setint("ledcount", 3)
config.set(
"layers", """
static(colorSpace=lab) top (1, 0, 0), (0, 0, 1)
""")
printer = mockPrinter(config)
printer._handle_ready()
assert printer.led_effect.getFrame(0) == ([
1.0, 0.0, 0.0, 0.0,
0.7923588275927302, 0.0, 0.5387489625917922, 0.0,
0.0, 0.0, 1.0, 0.0
], True)


def test_color_blending_colorspace_none():
config = mockConfig()
config.setint("ledcount", 4)
config.set(
"layers", """
static(colorSpace=none) top (1, 0, 0), (0, 0, 1)
""")
printer = mockPrinter(config)
printer._handle_ready()
assert printer.led_effect.getFrame(0) == ([
1.0, 0.0, 0.0, 0.0,
1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 1.0, 0.0
], True)


def test_default_heater_gradient_length():
config = mockConfig()
config.setint("ledcount", 1)
config.set(
"layers", """
heater(heater=heater_bed,minTemp=0,disableOnceReached=0) top (1, 0, 0), (0, 0, 1), (0, 0, 1)
""")
printer = mockPrinter(config)
printer._handle_ready()
printer.set_heater(None, 100, 50, "heater_bed")
assert printer.led_effect.getFrame(0) == ([
0.4974874371859297, 0.0, 0.5025125628140703, 0.0
], True)


def test_changing_heater_gradient_length():
config = mockConfig()
config.setint("ledcount", 1)
config.set(
"layers", """
heater(heater=heater_bed,minTemp=0,disableOnceReached=0,gradientSteps=3) top (1, 0, 0), (0, 0, 1), (0, 0, 1)
""")
printer = mockPrinter(config)
printer._handle_ready()
printer.set_heater(None, 100, 50, "heater_bed")
assert printer.led_effect.getFrame(0) == ([
0.5, 0.0, 0.5, 0.0
], True)
6 changes: 3 additions & 3 deletions packages/web_simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"build:vite": "vite build",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"build:whl": "rm src/*.whl || true; run-p build:whl:*",
"build:whl:klippermock": "cd ../klippermock; poetry build -f wheel -o ../web_simulator/src",
"build:whl:led_effect": "cd ../led_effect; poetry build -f wheel -o ../web_simulator/src"
"build:whl": "run-p build:whl:*",
"build:whl:klippermock": "rm src/klippermock*.whl || true; cd ../klippermock; poetry build -f wheel -o ../web_simulator/src",
"build:whl:led_effect": "rm src/led_effect*.whl || true; cd ../led_effect; poetry build -f wheel -o ../web_simulator/src"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/web_simulator/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
import colormath from "./colormath-3.0.0-py3-none-any.whl?url";
import led_effect from "./led_effect-0.1.0-py3-none-any.whl?url";
import klippermock from "./klippermock-0.1.0-py3-none-any.whl?url";
Expand All @@ -9,7 +10,7 @@
const pyodide = await (window as any).loadPyodide();
await pyodide.loadPackage("micropip");
const micropip = pyodide.pyimport("micropip");
await micropip.install([led_effect, klippermock]);
await micropip.install([colormath, led_effect, klippermock]);
kmock = pyodide.pyimport("klippermock");
};
Expand Down

0 comments on commit ab06c07

Please sign in to comment.