Skip to content

Commit

Permalink
Release 0.0.10 (#131)
Browse files Browse the repository at this point in the history
* Update for new klipper paths
* Synax Errors Fixed
* limit effect rate to frame rate in strobe effect
* reworked installation script
* installation script: fix for moonraker restart
* Added uninstaller
* Improve Commands for stopping effects (#118)
* Better stopping of effects by defining LED
* Added Replace Parameter to SET_LED_EFFECTS command
* Improved STOP_LED_EFFECTS command for certain LEDs
* Updated documentation for new STOP possibilities
* Use constructor instead of copy() (#121)
Fixes #120
* Updated simulator, fix coordinates
* Add Homing effect (#129)
* Added homing effect
* Add endstop to simulator
* homing: cycle through palette
* Added documentation for homing effect
* Updated docs for homing effect

---------

Co-authored-by: Michael <89716126+mlee12382@users.noreply.github.com>
  • Loading branch information
julianschill and mlee12382 authored Feb 4, 2023
1 parent 785a398 commit 35cf587
Show file tree
Hide file tree
Showing 8 changed files with 611 additions and 357 deletions.
34 changes: 25 additions & 9 deletions docs/LED_Effect.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ chain_count: 16
pin: ar15
chain_count: 6
[neopixel bed_lights]
[dotstar bed_lights]
data_pin: ar21
clock_pin ar22
chain_count: 5
Expand All @@ -109,19 +109,20 @@ This has defined an effect called `panel_idle`.

### Controlling the effects
Effects can be active or inactive. Inactive effects don't output any color
data, while active effects return color data, that is added up for each LED
data, while active effects return color data, that is summed up for each LED
they run on.

#### Activating and deactivating effects
Our example effect can be activated by running the GCode command
`SET_LED_EFFECT EFFECT=panel_idle`.
`SET_LED_EFFECT EFFECT=panel_idle`. To stop all effects which are currently
running on the LEDs the new effect is using, set the `REPLACE` parameter to 1:
`SET_LED_EFFECT EFFECT=panel_idle REPLACE=1`
Running the command `SET_LED_EFFECT EFFECT=panel_idle STOP=1` deactivates this
particular effect again.
particular effect again.
To deactivate all effects we can use the GCode command `STOP_LED_EFFECTS`.
To only deactivate effects for certain LEDs we can specify the LEDS parameter:
`STOP_LED_EFFECTS LEDS="neopixel:panel_ring"` The parameter has match exactly
the line defined in the "leds" section of the effect, including the indices
(see below): `STOP_LED_EFFECTS LEDS="neopixel:panel_ring (1-7)"`. Only one
`STOP_LED_EFFECTS LEDS="neopixel:panel_ring"` You can also specify indeces (see
below): `STOP_LED_EFFECTS LEDS="neopixel:panel_ring (1-7)"`. Only one
LED parameter can be specified at a time. To stop the effects for multiple LEDs
we have to run the command multiple times.

Expand All @@ -131,7 +132,8 @@ Effects can be faded in and out by specifying the `FADETIME` parameter:
second. Running `SET_LED_EFFECT EFFECT=panel_idle STOP=1 FADETIME=1.0` fades it
out in one second. We can also fade out all effects by running
`STOP_LED_EFFECTS FADETIME=1.0`. It is also possible to crossfade effects by
running a fade in command and a fade out command successively.
using the `REPLACE` parameter with `SET_LED_EFFECT` (see above):
`SET_LED_EFFECT EFFECT=panel_idle REPLACE=1 FADETIME=1.0`

### Additional effect level parameters

Expand All @@ -154,9 +156,14 @@ analog_pin:
Specifies the pin to use for effects using an analog signal.

stepper:
Specifies the stepper motor to use for the stepper effect. Possible values are:
Specifies the axis to use for the stepper effect. Possible values are:
`x`, `y` and `z`. Example: `stepper: x`

endstops:
Specifies the endstops the homing effect triggers on. Multiple endstops can be
specified as a comma seprated list. Possible values are: `x`, `y`, `z` and `probe`.
Example: `endstops: x, y`

## Defining LEDs

The `leds:` section is a list of Neopixel or Dotstar strips that will
Expand Down Expand Up @@ -405,6 +412,15 @@ palette, that is calculated as a gradient over the specified color values.
Exact same configuration as Stepper but instead of reporting stepper position, this
layer reports print progress.

#### Homing
Effect Rate: 1 Determines decay rate. A higher number yields slower decay
Cutoff: 0 Not used, but must be provided
Palette: Colors are cycled in order

LEDs turn on during homing when the endstop is triggered and fade out again. The
effect rate determines the time for the fade out. If a palette of multiple colors
is provided, it will cycle through those colors in order.

## Effect Layer Blending
If you have ever used image editing software you may be familiar with
color blending between image layers. Several common color blending
Expand Down
147 changes: 109 additions & 38 deletions install-led_effect.sh
Original file line number Diff line number Diff line change
@@ -1,74 +1,145 @@
#!/bin/bash
# Force script to exit if an error occurs
set -e

KLIPPER_PATH="${HOME}/klipper"
SYSTEMDDIR="/etc/systemd/system"
MOONRAKER_CONFIG_DIR="${HOME}/printer_data/config"

# Fall back to old directory for configuration as default
if [ ! -d "${MOONRAKER_CONFIG_DIR}" ]; then
echo "\"$MOONRAKER_CONFIG_DIR\" does not exist. Falling back to "${HOME}/klipper_config" as default."
MOONRAKER_CONFIG_DIR="${HOME}/klipper_config"
fi

usage(){ echo "Usage: $0 [-k <klipper path>] [-c <configuration path>]" 1>&2; exit 1; }
# Parse command line arguments
while getopts "k:c:uh" arg; do
case $arg in
k) KLIPPER_PATH=$OPTARG;;
c) MOONRAKER_CONFIG_DIR=$OPTARG;;
u) UNINSTALL=1;;
h) usage;;
esac
done

# Find SRCDIR from the pathname of this script
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/src/ && pwd )"

# Step 1: Verify Klipper has been installed
# Verify Klipper has been installed
check_klipper()
{
if [ "$(sudo systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
echo "Klipper service found!"
echo "Klipper service found."
else
echo "Klipper service not found, please install Klipper first"
echo "[ERROR] Klipper service not found, please install Klipper first"
exit -1
fi
}

check_folders()
{
if [ ! -d "$KLIPPER_PATH/klippy/extras/" ]; then
echo "[ERROR] Klipper installation not found in directory \"$KLIPPER_PATH\". Exiting"
exit -1
fi
echo "Klipper installation found at $KLIPPER_PATH"

if [ ! -f "${MOONRAKER_CONFIG_DIR}/moonraker.conf" ]; then
echo "[ERROR] Moonraker configuration not found in directory \"$MOONRAKER_CONFIG_DIR\". Exiting"
exit -1
fi
echo "Moonraker configuration found at $MOONRAKER_CONFIG_DIR"
}

# Step 2: link extension to Klipper
# Link extension to Klipper
link_extension()
{
echo "Linking extension to Klipper..."
echo -n "Linking extension to Klipper... "
ln -sf "${SRCDIR}/led_effect.py" "${KLIPPER_PATH}/klippy/extras/led_effect.py"
echo "[OK]"
}

# Step 3: Add updater
# webcamd to moonraker.conf
echo -e "Adding update manager to moonraker.conf"

update_section=$(grep -c '\[update_manager led_effect\]' \
${HOME}/klipper_config/moonraker.conf || true)
if [ "${update_section}" -eq 0 ]; then
echo -e "\n" >> ${HOME}/klipper_config/moonraker.conf
while read -r line; do
echo -e "${line}" >> ${HOME}/klipper_config/moonraker.conf
done < "$PWD/file_templates/moonraker_update.txt"
echo -e "\n" >> ${HOME}/klipper_config/moonraker.conf
else
echo -e "[update_manager led_effect] already exist in moonraker.conf [SKIPPED]"
fi
# Restart moonraker
restart_moonraker()
{
echo -n "Restarting Moonraker... "
sudo systemctl restart moonraker
echo "[OK]"
}

# Add updater for led_effect to moonraker.conf
add_updater()
{
echo -e -n "Adding update manager to moonraker.conf... "

update_section=$(grep -c '\[update_manager led_effect\]' ${MOONRAKER_CONFIG_DIR}/moonraker.conf || true)
if [ "${update_section}" -eq 0 ]; then
echo -e "\n" >> ${MOONRAKER_CONFIG_DIR}/moonraker.conf
while read -r line; do
echo -e "${line}" >> ${MOONRAKER_CONFIG_DIR}/moonraker.conf
done < "$PWD/file_templates/moonraker_update.txt"
echo -e "\n" >> ${MOONRAKER_CONFIG_DIR}/moonraker.conf
echo "[OK]"
restart_moonraker
else
echo -e "[update_manager led_effect] already exists in moonraker.conf [SKIPPED]"
fi
}

# Step 4: restarting Klipper
restart_klipper()
{
echo "Restarting Klipper..."
echo -n "Restarting Klipper... "
sudo systemctl restart klipper
echo "[OK]"
}

start_klipper()
{
echo -n "Starting Klipper... "
sudo systemctl start klipper
echo "[OK]"
}

stop_klipper()
{
echo -n "Stopping Klipper... "
sudo systemctl start klipper
echo "[OK]"
}

uninstall()
{
if [ -f "${KLIPPER_PATH}/klippy/extras/led_effect.py" ]; then
echo -n "Uninstalling... "
rm -f "${KLIPPER_PATH}/klippy/extras/led_effect.py"
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 "[FAILED]"
fi
}

# Helper functions
verify_ready()
{
if [ "$EUID" -eq 0 ]; then
echo "This script must not run as root"
echo "[ERROR] This script must not run as root. Exiting."
exit -1
fi
}

# Force script to exit if an error occurs
set -e

# Find SRCDIR from the pathname of this script
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/src/ && pwd )"

# Parse command line arguments
while getopts "k:" arg; do
case $arg in
k) KLIPPER_PATH=$OPTARG;;
esac
done

# Run steps
verify_ready
link_extension
restart_klipper
check_klipper
check_folders
stop_klipper
if [ ! $UNINSTALL ]; then
link_extension
add_updater
else
uninstall
fi
start_klipper

Loading

0 comments on commit 35cf587

Please sign in to comment.