From 8cf2d15ed1c09645cc1c33fca9a6376ed4b635f0 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 30 Nov 2019 17:53:49 +0100 Subject: [PATCH] Fix light scheme 4 speed Fix light scheme 4 speed (#7072) --- tasmota/CHANGELOG.md | 1 + tasmota/xdrv_04_light.ino | 30 +++++++++++------------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index c5aa2355d..e9949c4f5 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix slider for devices with one or two channels like only white or white/yellow - Fix TasmotaSlave buffer overrun on Tele +- Fix light scheme 4 speed (#7072) - Add support for TasmotaSlave executing commands on Tasmota ## Released diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 695815d71..b50d8e4df 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -242,6 +242,7 @@ struct LIGHT { uint8_t color_remap[LST_MAX]; uint8_t wheel = 0; + uint8_t random = 0; uint8_t subtype = 0; // LST_ subtype uint8_t device = 0; uint8_t old_power = 1; @@ -1541,28 +1542,19 @@ void LightCycleColor(int8_t direction) if (Light.strip_timer_counter % (Settings.light_speed * 2)) { return; } - Light.wheel += direction; + + if (0 == direction) { + if (Light.random == Light.wheel) { + Light.random = random(255); + } + Light.wheel += (Light.random < Light.wheel) ? -1 : 1; + } else { + Light.wheel += direction; + } LightWheel(Light.wheel); memcpy(Light.new_color, Light.entry_color, sizeof(Light.new_color)); } -void LightRandomColor(void) -{ - bool update = false; - for (uint32_t i = 0; i < LST_RGB; i++) { - if (Light.new_color[i] != Light.current_color[i]) { - update = true; - } - } - if (!update) { - Light.wheel = random(255); - LightWheel(Light.wheel); - memcpy(Light.current_color, Light.entry_color, sizeof(Light.current_color)); - } - - memcpy(Light.new_color, Light.current_color, sizeof(Light.new_color)); -} - void LightSetPower(void) { // Light.power = XdrvMailbox.index; @@ -1652,7 +1644,7 @@ void LightAnimate(void) LightCycleColor(-1); break; case LS_RANDOM: - LightRandomColor(); + LightCycleColor(0); break; default: XlgtCall(FUNC_SET_SCHEME);