From 2bce10e2093e3174b27c871e05eacd640dd3ce56 Mon Sep 17 00:00:00 2001 From: CoryCharlton Date: Fri, 27 Jan 2023 11:40:50 -0800 Subject: [PATCH 1/8] Fixes issue #210 by adding the `reverse` parameter and setting the left/right `reverse_progress` parameter based on that --- .../effects/progress.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/octoprint_ws281x_led_status/effects/progress.py b/octoprint_ws281x_led_status/effects/progress.py index 425fa30..a00d3b4 100644 --- a/octoprint_ws281x_led_status/effects/progress.py +++ b/octoprint_ws281x_led_status/effects/progress.py @@ -85,7 +85,15 @@ def single_pixel( def both_ends( - strip, queue, brightness_manager, value, progress_color, base_color, *args, **kwargs + strip, + queue, + brightness_manager, + value, + progress_color, + base_color, + reverse, + *args, + **kwargs ): brightness_manager.reset_brightness() num_pixels = strip.numPixels() @@ -94,21 +102,21 @@ def both_ends( # Set the unused pixel to off strip.setPixelColorRGB(num_pixels, 0, 0, 0) - 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 @@ -116,15 +124,15 @@ def progress(min_pixel, max_pixel, val, reverse): 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) + progress(0, num_pixels // 2, value, True if reverse else False) + progress(num_pixels // 2, num_pixels, value, False if reverse else True) strip.show() if not q_poll_sleep(0.1, queue): From 3e46ed75f9d5de35b27a8e8db8bf55302becd681 Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Sun, 29 Jan 2023 11:34:23 -0800 Subject: [PATCH 2/8] Refactored progress bar effect into a shared method --- .../effects/progress.py | 87 +++++++++++++------ 1 file changed, 59 insertions(+), 28 deletions(-) diff --git a/octoprint_ws281x_led_status/effects/progress.py b/octoprint_ws281x_led_status/effects/progress.py index a00d3b4..34d00e5 100644 --- a/octoprint_ws281x_led_status/effects/progress.py +++ b/octoprint_ws281x_led_status/effects/progress.py @@ -21,34 +21,7 @@ def progress_bar( *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) - - strip.show() - if not q_poll_sleep(0.1, queue): - return + progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, reverse, False) def gradient( @@ -84,6 +57,64 @@ def single_pixel( return +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: + odd_pixel = 1 + + 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_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_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_progress + else (min_pixel + (number_pixels - pixels_remaining) + i) + ) + strip.setPixelColorRGB(pixel, *base_color) + + 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): + return + + def both_ends( strip, queue, From 4d39f533625abd0e05ee2e1f458a634d5c6c76ce Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Sun, 29 Jan 2023 11:44:01 -0800 Subject: [PATCH 3/8] Refactored both ends effect to use the shared progress_bar_impl method --- octoprint_ws281x_led_status/constants.py | 2 +- .../effects/progress.py | 69 ++++--------------- 2 files changed, 15 insertions(+), 56 deletions(-) diff --git a/octoprint_ws281x_led_status/constants.py b/octoprint_ws281x_led_status/constants.py index df3f813..c219371 100644 --- a/octoprint_ws281x_led_status/constants.py +++ b/octoprint_ws281x_led_status/constants.py @@ -111,7 +111,7 @@ class DeprecatedAtCommands: "Progress Bar": progress.progress_bar, "Gradient": progress.gradient, "Single Pixel": progress.single_pixel, - "Both Ends": progress.both_ends, + "Both Ends": progress.progress_bar_from_both_ends(), } MODES = [ "startup", diff --git a/octoprint_ws281x_led_status/effects/progress.py b/octoprint_ws281x_led_status/effects/progress.py index 34d00e5..d2fd021 100644 --- a/octoprint_ws281x_led_status/effects/progress.py +++ b/octoprint_ws281x_led_status/effects/progress.py @@ -24,6 +24,20 @@ def progress_bar( progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, reverse, False) +def progress_bar_from_both_ends( + strip, + queue, + brightness_manager, + value, + progress_color, + base_color, + reverse, + *args, + **kwargs +): + progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, reverse, True) + + def gradient( strip, queue, value, brightness_manager, progress_color, base_color, *args, **kwargs ): @@ -113,58 +127,3 @@ def progress(min_pixel, max_pixel, val, reverse_progress): strip.show() if not q_poll_sleep(0.1, queue): return - - -def both_ends( - strip, - queue, - brightness_manager, - value, - progress_color, - base_color, - reverse, - *args, - **kwargs -): - brightness_manager.reset_brightness() - num_pixels = strip.numPixels() - if num_pixels % 2 != 0: - num_pixels -= 1 - # Set the unused pixel to off - strip.setPixelColorRGB(num_pixels, 0, 0, 0) - - 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_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_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_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, True if reverse else False) - progress(num_pixels // 2, num_pixels, value, False if reverse else True) - - strip.show() - if not q_poll_sleep(0.1, queue): - return From c2a478d561a7b8bd078bde60c21899ba18b093a1 Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Sun, 29 Jan 2023 11:48:09 -0800 Subject: [PATCH 4/8] Added the "From Center" progress effect --- octoprint_ws281x_led_status/constants.py | 3 ++- octoprint_ws281x_led_status/effects/progress.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/octoprint_ws281x_led_status/constants.py b/octoprint_ws281x_led_status/constants.py index c219371..f839bef 100644 --- a/octoprint_ws281x_led_status/constants.py +++ b/octoprint_ws281x_led_status/constants.py @@ -111,7 +111,8 @@ class DeprecatedAtCommands: "Progress Bar": progress.progress_bar, "Gradient": progress.gradient, "Single Pixel": progress.single_pixel, - "Both Ends": progress.progress_bar_from_both_ends(), + "Both Ends": progress.progress_bar_from_both_ends, + "From Center": progress.progress_bar_from_center, } MODES = [ "startup", diff --git a/octoprint_ws281x_led_status/effects/progress.py b/octoprint_ws281x_led_status/effects/progress.py index d2fd021..884b13a 100644 --- a/octoprint_ws281x_led_status/effects/progress.py +++ b/octoprint_ws281x_led_status/effects/progress.py @@ -38,6 +38,19 @@ def progress_bar_from_both_ends( progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, reverse, 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 gradient( strip, queue, value, brightness_manager, progress_color, base_color, *args, **kwargs ): From 4ad273cb86eca69252175e0ba7a92a61dab6bc53 Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Sun, 29 Jan 2023 11:52:11 -0800 Subject: [PATCH 5/8] Added the "Reversed Progress Bar" progress effect --- octoprint_ws281x_led_status/constants.py | 1 + .../effects/progress.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/octoprint_ws281x_led_status/constants.py b/octoprint_ws281x_led_status/constants.py index f839bef..0e88099 100644 --- a/octoprint_ws281x_led_status/constants.py +++ b/octoprint_ws281x_led_status/constants.py @@ -109,6 +109,7 @@ 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.progress_bar_from_both_ends, diff --git a/octoprint_ws281x_led_status/effects/progress.py b/octoprint_ws281x_led_status/effects/progress.py index 884b13a..6581c96 100644 --- a/octoprint_ws281x_led_status/effects/progress.py +++ b/octoprint_ws281x_led_status/effects/progress.py @@ -17,11 +17,10 @@ def progress_bar( value, progress_color, base_color, - reverse, *args, **kwargs ): - progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, reverse, False) + progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, False, False) def progress_bar_from_both_ends( @@ -31,11 +30,10 @@ def progress_bar_from_both_ends( value, progress_color, base_color, - reverse, *args, **kwargs ): - progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, reverse, True) + progress_bar_impl(strip, queue, brightness_manager, value, progress_color, base_color, False, True) def progress_bar_from_center( @@ -51,6 +49,19 @@ def progress_bar_from_center( 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( strip, queue, value, brightness_manager, progress_color, base_color, *args, **kwargs ): From 4e8d9b262c54f7560bc5442d802df055c87dc9fa Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Sun, 29 Jan 2023 12:21:53 -0800 Subject: [PATCH 6/8] Remove `Reverse progress bar direction` from the UI and from being passed into the `EffectRunner` --- octoprint_ws281x_led_status/runner/__init__.py | 1 - .../templates/settings/progress_effects.jinja2 | 2 -- 2 files changed, 3 deletions(-) diff --git a/octoprint_ws281x_led_status/runner/__init__.py b/octoprint_ws281x_led_status/runner/__init__.py index 2b8bd7b..012af41 100644 --- a/octoprint_ws281x_led_status/runner/__init__.py +++ b/octoprint_ws281x_led_status/runner/__init__.py @@ -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, ) diff --git a/octoprint_ws281x_led_status/templates/settings/progress_effects.jinja2 b/octoprint_ws281x_led_status/templates/settings/progress_effects.jinja2 index d605808..4a64723 100644 --- a/octoprint_ws281x_led_status/templates/settings/progress_effects.jinja2 +++ b/octoprint_ws281x_led_status/templates/settings/progress_effects.jinja2 @@ -27,8 +27,6 @@
Progress effects {{ docs.help_icon("configuration/progress-effects") }}
- {{ labelled_checkbox("strip.reverse", "Reverse progress bar direction") }} -
{{ labelled_checkbox("effects.progress_print.enabled", "Enable Printing Progress") }}
{{ effect_select("progress_print") }} From c5c27857a14e70184cf4abd9f8f78f7150b9d671 Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Sun, 29 Jan 2023 22:28:58 +0000 Subject: [PATCH 7/8] :left_right_arrow: Add settings migration --- octoprint_ws281x_led_status/settings.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/octoprint_ws281x_led_status/settings.py b/octoprint_ws281x_led_status/settings.py index b8e75c5..12e2d5a 100644 --- a/octoprint_ws281x_led_status/settings.py +++ b/octoprint_ws281x_led_status/settings.py @@ -18,7 +18,6 @@ "dma": 10, "invert": False, "channel": 0, - "reverse": False, "type": "WS2811_STRIP_GRB", "brightness": 50, "adjustment": {"R": 100, "G": 100, "B": 100}, @@ -142,6 +141,10 @@ def migrate_settings(target, current, settings): # 1 => 2 migrate_one_to_two(settings) + if (current is None or current <= 2) and target == 3: + # 2 => 3 + migrate_two_to_three(settings) + def migrate_none_to_one(settings): new_settings = { @@ -264,6 +267,22 @@ def migrate_one_to_two(settings): settings.settings.remove(["plugins", "ws281x_led_status", "debug_logging"]) +def migrate_two_to_three(settings): + # See PR #212 for changes + reverse = settings.get(["strip", "reverse"]) + + if reverse and settings.get(["effects", "progress_print", "effect"]) == "Progress Bar": + settings.set(["effects", "progress_print", "effect"], "Progress Bar Reversed") + + if reverse and settings.get(["effects", "progress_heatup", "effect"]) == "Progress Bar": + settings.set(["effects", "progress_heatup", "effect"], "Progress Bar Reversed") + + if reverse and settings.get(["effects", "progress_cooling", "effect"]) == "Progress Bar": + settings.set(["effects", "progress_cooling", "effect"], "Progress Bar Reversed") + + settings.settings.remove(["plugins", "ws281x_led_status", "strip", "reverse"]) + + def filter_none(target): """ Recursively remove any key/value pairs where the value is None From 3118a510192088083432d06b7cfe2e2944a9bf78 Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Sun, 29 Jan 2023 22:29:39 +0000 Subject: [PATCH 8/8] :art: reverse is already a bool --- octoprint_ws281x_led_status/effects/progress.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/octoprint_ws281x_led_status/effects/progress.py b/octoprint_ws281x_led_status/effects/progress.py index 6581c96..5d4b5e8 100644 --- a/octoprint_ws281x_led_status/effects/progress.py +++ b/octoprint_ws281x_led_status/effects/progress.py @@ -142,11 +142,11 @@ def progress(min_pixel, max_pixel, val, reverse_progress): 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) + progress(0, math.floor(num_pixels / 2) + odd_pixel, value, reverse) + progress(math.ceil(num_pixels / 2) - odd_pixel, num_pixels, value, not reverse) else: # Set the progress for the entire strip - progress(0, num_pixels, value, True if reverse else False) + progress(0, num_pixels, value, reverse) strip.show() if not q_poll_sleep(0.1, queue):