Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #209 and #210 by adding additional progress effects #212

Merged
merged 8 commits into from
Jan 29, 2023
4 changes: 3 additions & 1 deletion octoprint_ws281x_led_status/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ class DeprecatedAtCommands:
}
PROGRESS_EFFECTS = {
"Progress Bar": progress.progress_bar,
"Reversed Progress Bar": progress.progress_bar_reversed,
"Gradient": progress.gradient,
"Single Pixel": progress.single_pixel,
"Both Ends": progress.both_ends,
"Both Ends": progress.progress_bar_from_both_ends,
"From Center": progress.progress_bar_from_center,
}
MODES = [
"startup",
Expand Down
106 changes: 64 additions & 42 deletions octoprint_ws281x_led_status/effects/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,49 @@ def progress_bar(
value,
progress_color,
base_color,
reverse,
*args,
**kwargs
):
brightness_manager.reset_brightness()
num_pixels = strip.numPixels()
upper_bar = (value / 100) * num_pixels
upper_remainder, upper_whole = math.modf(upper_bar)
pixels_remaining = num_pixels

for i in range(int(upper_whole)):
pixel = ((num_pixels - 1) - i) if reverse else i
strip.setPixelColorRGB(pixel, *progress_color)
pixels_remaining -= 1

if upper_remainder > 0.0:
tween_color = blend_two_colors(progress_color, base_color, upper_remainder)
pixel = ((num_pixels - int(upper_whole)) - 1) if reverse else int(upper_whole)
strip.setPixelColorRGB(pixel, *tween_color)
pixels_remaining -= 1

for i in range(pixels_remaining):
pixel = (
((pixels_remaining - 1) - i)
if reverse
else ((num_pixels - pixels_remaining) + i)
)
strip.setPixelColorRGB(pixel, *base_color)
progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, False, False)

strip.show()
if not q_poll_sleep(0.1, queue):
return

def progress_bar_from_both_ends(
strip,
queue,
brightness_manager,
value,
progress_color,
base_color,
*args,
**kwargs
):
progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, False, True)


def progress_bar_from_center(
strip,
queue,
brightness_manager,
value,
progress_color,
base_color,
*args,
**kwargs
):
progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, True, True)


def progress_bar_reversed(
strip,
queue,
brightness_manager,
value,
progress_color,
base_color,
*args,
**kwargs
):
progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, True, False)


def gradient(
Expand Down Expand Up @@ -84,47 +95,58 @@ def single_pixel(
return


def both_ends(
strip, queue, brightness_manager, value, progress_color, base_color, *args, **kwargs
def progress_bar_impl(
strip,
queue,
brightness_manager,
value,
progress_color,
base_color,
reverse,
half_strip,
*args,
**kwargs
):
brightness_manager.reset_brightness()
num_pixels = strip.numPixels()
odd_pixel = 0
if num_pixels % 2 != 0:
num_pixels -= 1
# Set the unused pixel to off
strip.setPixelColorRGB(num_pixels, 0, 0, 0)
odd_pixel = 1

def progress(min_pixel, max_pixel, val, reverse):
def progress(min_pixel, max_pixel, val, reverse_progress):
number_pixels = max_pixel - min_pixel
upper_bar = (val / 100) * number_pixels
upper_remainder, upper_whole = math.modf(upper_bar)
pixels_remaining = number_pixels

for i in range(int(upper_whole)):
pixel = ((max_pixel - 1) - i) if reverse else i
pixel = ((max_pixel - 1) - i) if reverse_progress else (min_pixel + i)
strip.setPixelColorRGB(pixel, *progress_color)
pixels_remaining -= 1

if upper_remainder > 0.0:
tween_color = blend_two_colors(progress_color, base_color, upper_remainder)
pixel = (
((max_pixel - int(upper_whole)) - 1) if reverse else int(upper_whole)
((max_pixel - int(upper_whole)) - 1) if reverse_progress else (int(upper_whole) + min_pixel)
)
strip.setPixelColorRGB(pixel, *tween_color)
pixels_remaining -= 1

for i in range(pixels_remaining):
pixel = (
((min_pixel + pixels_remaining - 1) - i)
if reverse
else ((number_pixels - pixels_remaining) + i)
if reverse_progress
else (min_pixel + (number_pixels - pixels_remaining) + i)
)
strip.setPixelColorRGB(pixel, *base_color)

# Set the progress to either end of the strip

progress(0, num_pixels // 2, value, False)
progress(num_pixels // 2, num_pixels, value, True)
if half_strip:
# Set the progress to either end of the strip
progress(0, math.floor(num_pixels / 2) + odd_pixel, value, True if reverse else False)
progress(math.ceil(num_pixels / 2) - odd_pixel, num_pixels, value, False if reverse else True)
else:
# Set the progress for the entire strip
progress(0, num_pixels, value, True if reverse else False)

strip.show()
if not q_poll_sleep(0.1, queue):
Expand Down
1 change: 0 additions & 1 deletion octoprint_ws281x_led_status/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ def progress_effect(self, mode, value):
"base_color": apply_color_correction(
self.color_correction, *hex_to_rgb(effect_settings["base"])
),
"reverse": self.strip_settings["reverse"],
},
name=mode,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

<h5>Progress effects {{ docs.help_icon("configuration/progress-effects") }}</h5>
<form class="form-horizontal">
{{ labelled_checkbox("strip.reverse", "Reverse progress bar direction") }}
<hr>
{{ labelled_checkbox("effects.progress_print.enabled", "Enable Printing Progress") }}
<div class="form-inline" data-bind="visible: {{ binding.effect_binding("progress_print.enabled") }}">
{{ effect_select("progress_print") }}
Expand Down