From 66f0574e4ddce3ec18cc60e28a9c467184854d33 Mon Sep 17 00:00:00 2001 From: Lilith Silver <84940819+LilithSilver@users.noreply.github.com> Date: Fri, 19 Apr 2024 00:54:46 -0700 Subject: [PATCH 1/7] Add customizable max transition duration for settings changes --- .../TimeSpanToSecondsDoubleConverter.cs | 20 ++++++ .../TimeSpanToSecondsStringConverter.cs | 30 +++++++++ LightBulb/Services/SettingsService.cs | 3 + .../Components/DashboardViewModel.cs | 62 +++++++++++++++++-- .../Settings/GeneralSettingsTabViewModel.cs | 9 +++ .../Settings/GeneralSettingsTabView.axaml | 20 ++++++ 6 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 LightBulb/Converters/TimeSpanToSecondsDoubleConverter.cs create mode 100644 LightBulb/Converters/TimeSpanToSecondsStringConverter.cs diff --git a/LightBulb/Converters/TimeSpanToSecondsDoubleConverter.cs b/LightBulb/Converters/TimeSpanToSecondsDoubleConverter.cs new file mode 100644 index 00000000..60455c95 --- /dev/null +++ b/LightBulb/Converters/TimeSpanToSecondsDoubleConverter.cs @@ -0,0 +1,20 @@ +using System; +using System.Globalization; +using Avalonia.Data.Converters; + +namespace LightBulb.Converters; + +public class TimeSpanToSecondsDoubleConverter : IValueConverter +{ + public static TimeSpanToSecondsDoubleConverter Instance { get; } = new(); + + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => + value is TimeSpan timeSpanValue ? timeSpanValue.TotalSeconds : default; + + public object ConvertBack( + object? value, + Type targetType, + object? parameter, + CultureInfo culture + ) => value is double doubleValue ? TimeSpan.FromSeconds(doubleValue) : default; +} diff --git a/LightBulb/Converters/TimeSpanToSecondsStringConverter.cs b/LightBulb/Converters/TimeSpanToSecondsStringConverter.cs new file mode 100644 index 00000000..8089c2d3 --- /dev/null +++ b/LightBulb/Converters/TimeSpanToSecondsStringConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Globalization; +using Avalonia.Data.Converters; + +namespace LightBulb.Converters; + +public class TimeSpanToSecondsStringConverter : IValueConverter +{ + public static TimeSpanToSecondsStringConverter Instance { get; } = new(); + + public object? Convert( + object? value, + Type targetType, + object? parameter, + CultureInfo culture + ) => + value is TimeSpan timeSpanValue + ? timeSpanValue.TotalSeconds.ToString("0.#", culture) + : default; + + public object ConvertBack( + object? value, + Type targetType, + object? parameter, + CultureInfo culture + ) => + value is string stringValue && double.TryParse(stringValue, culture, out var result) + ? TimeSpan.FromSeconds(result) + : default; +} diff --git a/LightBulb/Services/SettingsService.cs b/LightBulb/Services/SettingsService.cs index 33e40d99..d19bb8c3 100644 --- a/LightBulb/Services/SettingsService.cs +++ b/LightBulb/Services/SettingsService.cs @@ -63,6 +63,9 @@ public partial class SettingsService() : SettingsBase(GetFilePath()) [ObservableProperty] private double _configurationTransitionOffset; + [ObservableProperty] + private TimeSpan _maxSettingsTransitionDuration = TimeSpan.FromSeconds(1); + // Location [ObservableProperty] diff --git a/LightBulb/ViewModels/Components/DashboardViewModel.cs b/LightBulb/ViewModels/Components/DashboardViewModel.cs index 45d088c1..d3735314 100644 --- a/LightBulb/ViewModels/Components/DashboardViewModel.cs +++ b/LightBulb/ViewModels/Components/DashboardViewModel.cs @@ -108,7 +108,10 @@ ExternalApplicationService externalApplicationService ) ); - _updateConfigurationTimer = new Timer(TimeSpan.FromMilliseconds(50), UpdateConfiguration); + _updateConfigurationTimer = new Timer( + TimeSpan.FromMilliseconds(50), + () => UpdateConfiguration(1000 / (double)50) + ); _updateInstantTimer = new Timer(TimeSpan.FromMilliseconds(50), UpdateInstant); _updateIsPausedTimer = new Timer(TimeSpan.FromSeconds(1), UpdateIsPaused); } @@ -285,12 +288,63 @@ private void UpdateInstant() } } - private void UpdateConfiguration() + private const double _brightnessDefaultStep = 0.08; + private const double _temperatureDefaultStep = 30; + + private double _brightnessMaxStep = _brightnessDefaultStep; + private double _temperatureMaxStep = _temperatureDefaultStep; + + private ColorConfiguration _lastTarget; + + private void UpdateConfiguration(double stepsPerSecond) { - var isSmooth = _settingsService.IsConfigurationSmoothingEnabled && !IsCyclePreviewEnabled; + if (CurrentConfiguration == TargetConfiguration) + return; + + var isSmooth = + _settingsService.IsConfigurationSmoothingEnabled + && !IsCyclePreviewEnabled + && _settingsService.MaxSettingsTransitionDuration.TotalSeconds >= 0.1; + + // If we've changed targets, restart with default settings. + if (_lastTarget != TargetConfiguration && isSmooth) + { + _brightnessMaxStep = _brightnessDefaultStep; + _temperatureMaxStep = _temperatureDefaultStep; + _lastTarget = TargetConfiguration; + + var tempDelta = Math.Abs( + TargetConfiguration.Temperature - CurrentConfiguration.Temperature + ); + var brightnessDelta = Math.Abs( + TargetConfiguration.Brightness - CurrentConfiguration.Brightness + ); + var expectedTemperatureDuration = tempDelta / (_temperatureMaxStep * stepsPerSecond); + var expectedBrightnessDuration = + brightnessDelta / (_brightnessMaxStep * stepsPerSecond); + + // If the expected durations are longer than our duration limit, we adjust the step amount to stay at the max duration. + var goalDuration = Math.Max(expectedTemperatureDuration, expectedBrightnessDuration); + goalDuration = Math.Min( + goalDuration, + _settingsService.MaxSettingsTransitionDuration.TotalSeconds + ); + + // Calculate the step-rate needed to reach the goal. + _brightnessMaxStep = brightnessDelta / (goalDuration * stepsPerSecond); + _temperatureMaxStep = tempDelta / (goalDuration * stepsPerSecond); + + // If we ended up slower on either of the durations, speed us up. + _brightnessMaxStep = Math.Max(_brightnessMaxStep, _brightnessDefaultStep); + _temperatureMaxStep = Math.Max(_temperatureMaxStep, _temperatureDefaultStep); + } CurrentConfiguration = isSmooth - ? CurrentConfiguration.StepTo(TargetConfiguration, 30, 0.008) + ? CurrentConfiguration.StepTo( + TargetConfiguration, + _temperatureMaxStep, + _brightnessMaxStep + ) : TargetConfiguration; _gammaService.SetGamma(CurrentConfiguration); diff --git a/LightBulb/ViewModels/Components/Settings/GeneralSettingsTabViewModel.cs b/LightBulb/ViewModels/Components/Settings/GeneralSettingsTabViewModel.cs index 3df5e2c6..844a1ebf 100644 --- a/LightBulb/ViewModels/Components/Settings/GeneralSettingsTabViewModel.cs +++ b/LightBulb/ViewModels/Components/Settings/GeneralSettingsTabViewModel.cs @@ -92,6 +92,15 @@ public TimeSpan ConfigurationTransitionDuration ); } + public TimeSpan MaxSettingsTransitionDuration + { + get => SettingsService.MaxSettingsTransitionDuration; + set => + SettingsService.MaxSettingsTransitionDuration = TimeSpan.FromSeconds( + Math.Clamp(value.TotalSeconds, 0, 15) + ); + } + public double ConfigurationTransitionOffset { get => SettingsService.ConfigurationTransitionOffset; diff --git a/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml b/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml index 19bebf9a..f2c7254e 100644 --- a/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml +++ b/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml @@ -163,5 +163,25 @@ Minimum="0" SmallChange="0.01" Value="{Binding ConfigurationTransitionOffset}" /> + + + + + + + + + + + \ No newline at end of file From 72857e8f1e4c29436ef9581f36444609c28e9559 Mon Sep 17 00:00:00 2001 From: Lilith Silver <84940819+LilithSilver@users.noreply.github.com> Date: Sun, 21 Apr 2024 17:10:06 -0700 Subject: [PATCH 2/7] remove max duration setting from UI, keeping it in SettingsService --- .../TimeSpanToSecondsDoubleConverter.cs | 20 -- .../TimeSpanToSecondsStringConverter.cs | 30 --- LightBulb/Services/SettingsService.cs | 2 +- .../Settings/GeneralSettingsTabViewModel.cs | 9 - .../Settings/GeneralSettingsTabView.axaml | 200 ++++++++---------- 5 files changed, 91 insertions(+), 170 deletions(-) delete mode 100644 LightBulb/Converters/TimeSpanToSecondsDoubleConverter.cs delete mode 100644 LightBulb/Converters/TimeSpanToSecondsStringConverter.cs diff --git a/LightBulb/Converters/TimeSpanToSecondsDoubleConverter.cs b/LightBulb/Converters/TimeSpanToSecondsDoubleConverter.cs deleted file mode 100644 index 60455c95..00000000 --- a/LightBulb/Converters/TimeSpanToSecondsDoubleConverter.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Globalization; -using Avalonia.Data.Converters; - -namespace LightBulb.Converters; - -public class TimeSpanToSecondsDoubleConverter : IValueConverter -{ - public static TimeSpanToSecondsDoubleConverter Instance { get; } = new(); - - public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => - value is TimeSpan timeSpanValue ? timeSpanValue.TotalSeconds : default; - - public object ConvertBack( - object? value, - Type targetType, - object? parameter, - CultureInfo culture - ) => value is double doubleValue ? TimeSpan.FromSeconds(doubleValue) : default; -} diff --git a/LightBulb/Converters/TimeSpanToSecondsStringConverter.cs b/LightBulb/Converters/TimeSpanToSecondsStringConverter.cs deleted file mode 100644 index 8089c2d3..00000000 --- a/LightBulb/Converters/TimeSpanToSecondsStringConverter.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Globalization; -using Avalonia.Data.Converters; - -namespace LightBulb.Converters; - -public class TimeSpanToSecondsStringConverter : IValueConverter -{ - public static TimeSpanToSecondsStringConverter Instance { get; } = new(); - - public object? Convert( - object? value, - Type targetType, - object? parameter, - CultureInfo culture - ) => - value is TimeSpan timeSpanValue - ? timeSpanValue.TotalSeconds.ToString("0.#", culture) - : default; - - public object ConvertBack( - object? value, - Type targetType, - object? parameter, - CultureInfo culture - ) => - value is string stringValue && double.TryParse(stringValue, culture, out var result) - ? TimeSpan.FromSeconds(result) - : default; -} diff --git a/LightBulb/Services/SettingsService.cs b/LightBulb/Services/SettingsService.cs index d19bb8c3..708758a7 100644 --- a/LightBulb/Services/SettingsService.cs +++ b/LightBulb/Services/SettingsService.cs @@ -64,7 +64,7 @@ public partial class SettingsService() : SettingsBase(GetFilePath()) private double _configurationTransitionOffset; [ObservableProperty] - private TimeSpan _maxSettingsTransitionDuration = TimeSpan.FromSeconds(1); + private TimeSpan _maxSettingsTransitionDuration = TimeSpan.FromSeconds(15); // Location diff --git a/LightBulb/ViewModels/Components/Settings/GeneralSettingsTabViewModel.cs b/LightBulb/ViewModels/Components/Settings/GeneralSettingsTabViewModel.cs index 844a1ebf..3df5e2c6 100644 --- a/LightBulb/ViewModels/Components/Settings/GeneralSettingsTabViewModel.cs +++ b/LightBulb/ViewModels/Components/Settings/GeneralSettingsTabViewModel.cs @@ -92,15 +92,6 @@ public TimeSpan ConfigurationTransitionDuration ); } - public TimeSpan MaxSettingsTransitionDuration - { - get => SettingsService.MaxSettingsTransitionDuration; - set => - SettingsService.MaxSettingsTransitionDuration = TimeSpan.FromSeconds( - Math.Clamp(value.TotalSeconds, 0, 15) - ); - } - public double ConfigurationTransitionOffset { get => SettingsService.ConfigurationTransitionOffset; diff --git a/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml b/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml index f2c7254e..95c607fb 100644 --- a/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml +++ b/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml @@ -5,24 +5,24 @@ xmlns:behaviors="clr-namespace:LightBulb.Behaviors" xmlns:converters="clr-namespace:LightBulb.Converters" xmlns:settings="clr-namespace:LightBulb.ViewModels.Components.Settings"> - - - + + + - - - - - + + + + - - - - - - + + + + + - - - - + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - + + + + + - - - - + + + - - - - - - + + + + + - - - - - - - - - - - - - - + + + - + - + SmallChange="0.01" + Value="{Binding ConfigurationTransitionOffset}" /> + \ No newline at end of file From 8f7b304106c10d42f70623f1a834f0d4cbc5a83d Mon Sep 17 00:00:00 2001 From: Lilith Silver <84940819+LilithSilver@users.noreply.github.com> Date: Sun, 21 Apr 2024 17:12:11 -0700 Subject: [PATCH 3/7] fix accidental spaces-to-tabs --- .../Settings/GeneralSettingsTabView.axaml | 182 +++++++++--------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml b/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml index 95c607fb..19bebf9a 100644 --- a/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml +++ b/LightBulb/Views/Components/Settings/GeneralSettingsTabView.axaml @@ -5,24 +5,24 @@ xmlns:behaviors="clr-namespace:LightBulb.Behaviors" xmlns:converters="clr-namespace:LightBulb.Converters" xmlns:settings="clr-namespace:LightBulb.ViewModels.Components.Settings"> - - - + + + - - - - - + + + + - - - - - - + + + + + - - - - + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - + + + + + - - - - + + + - - - - - - + + + + + - - - - + + + - - - - - - + + + + + - + \ No newline at end of file From e33ef7ad1fa6af9f1385562edc710c37285826f7 Mon Sep 17 00:00:00 2001 From: Lilith Silver <84940819+LilithSilver@users.noreply.github.com> Date: Mon, 22 Apr 2024 09:51:31 -0700 Subject: [PATCH 4/7] make Interval public and use that instead of parameter to smoothing method --- LightBulb.PlatformInterop/Timer.cs | 2 ++ LightBulb/ViewModels/Components/DashboardViewModel.cs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/LightBulb.PlatformInterop/Timer.cs b/LightBulb.PlatformInterop/Timer.cs index 096a71f9..34a25a2e 100644 --- a/LightBulb.PlatformInterop/Timer.cs +++ b/LightBulb.PlatformInterop/Timer.cs @@ -33,6 +33,8 @@ public Timer(TimeSpan firstTickDelay, TimeSpan interval, Action tick) public Timer(TimeSpan interval, Action callback) : this(TimeSpan.Zero, interval, callback) { } + public TimeSpan Interval => _interval; + private void Tick() { // Prevent multiple reentry diff --git a/LightBulb/ViewModels/Components/DashboardViewModel.cs b/LightBulb/ViewModels/Components/DashboardViewModel.cs index d3735314..2acf9b1a 100644 --- a/LightBulb/ViewModels/Components/DashboardViewModel.cs +++ b/LightBulb/ViewModels/Components/DashboardViewModel.cs @@ -110,7 +110,7 @@ ExternalApplicationService externalApplicationService _updateConfigurationTimer = new Timer( TimeSpan.FromMilliseconds(50), - () => UpdateConfiguration(1000 / (double)50) + UpdateConfiguration ); _updateInstantTimer = new Timer(TimeSpan.FromMilliseconds(50), UpdateInstant); _updateIsPausedTimer = new Timer(TimeSpan.FromSeconds(1), UpdateIsPaused); @@ -296,11 +296,13 @@ private void UpdateInstant() private ColorConfiguration _lastTarget; - private void UpdateConfiguration(double stepsPerSecond) + private void UpdateConfiguration() { if (CurrentConfiguration == TargetConfiguration) return; + double stepsPerSecond = 1000 / _updateConfigurationTimer.Interval.TotalMilliseconds; + var isSmooth = _settingsService.IsConfigurationSmoothingEnabled && !IsCyclePreviewEnabled From a856938993c0555f220271cc975c42e0597d1d57 Mon Sep 17 00:00:00 2001 From: Lilith Silver <84940819+LilithSilver@users.noreply.github.com> Date: Mon, 22 Apr 2024 10:01:03 -0700 Subject: [PATCH 5/7] rename transition smoothing property --- LightBulb/Services/SettingsService.cs | 2 +- LightBulb/ViewModels/Components/DashboardViewModel.cs | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/LightBulb/Services/SettingsService.cs b/LightBulb/Services/SettingsService.cs index 708758a7..e3af3eb5 100644 --- a/LightBulb/Services/SettingsService.cs +++ b/LightBulb/Services/SettingsService.cs @@ -64,7 +64,7 @@ public partial class SettingsService() : SettingsBase(GetFilePath()) private double _configurationTransitionOffset; [ObservableProperty] - private TimeSpan _maxSettingsTransitionDuration = TimeSpan.FromSeconds(15); + private TimeSpan _configurationSmoothingDuration = TimeSpan.FromSeconds(15); // Location diff --git a/LightBulb/ViewModels/Components/DashboardViewModel.cs b/LightBulb/ViewModels/Components/DashboardViewModel.cs index 2acf9b1a..5b5055c1 100644 --- a/LightBulb/ViewModels/Components/DashboardViewModel.cs +++ b/LightBulb/ViewModels/Components/DashboardViewModel.cs @@ -108,10 +108,7 @@ ExternalApplicationService externalApplicationService ) ); - _updateConfigurationTimer = new Timer( - TimeSpan.FromMilliseconds(50), - UpdateConfiguration - ); + _updateConfigurationTimer = new Timer(TimeSpan.FromMilliseconds(50), UpdateConfiguration); _updateInstantTimer = new Timer(TimeSpan.FromMilliseconds(50), UpdateInstant); _updateIsPausedTimer = new Timer(TimeSpan.FromSeconds(1), UpdateIsPaused); } @@ -306,7 +303,7 @@ private void UpdateConfiguration() var isSmooth = _settingsService.IsConfigurationSmoothingEnabled && !IsCyclePreviewEnabled - && _settingsService.MaxSettingsTransitionDuration.TotalSeconds >= 0.1; + && _settingsService.ConfigurationSmoothingDuration.TotalSeconds >= 0.1; // If we've changed targets, restart with default settings. if (_lastTarget != TargetConfiguration && isSmooth) @@ -329,7 +326,7 @@ private void UpdateConfiguration() var goalDuration = Math.Max(expectedTemperatureDuration, expectedBrightnessDuration); goalDuration = Math.Min( goalDuration, - _settingsService.MaxSettingsTransitionDuration.TotalSeconds + _settingsService.ConfigurationSmoothingDuration.TotalSeconds ); // Calculate the step-rate needed to reach the goal. From d57f747480bc9c1b5ac4d448f26b931899b57d68 Mon Sep 17 00:00:00 2001 From: Lilith Silver <84940819+LilithSilver@users.noreply.github.com> Date: Sun, 5 May 2024 15:35:16 -0700 Subject: [PATCH 6/7] recalculate state per target --- .../Components/DashboardViewModel.cs | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/LightBulb/ViewModels/Components/DashboardViewModel.cs b/LightBulb/ViewModels/Components/DashboardViewModel.cs index 5b5055c1..6caf00ff 100644 --- a/LightBulb/ViewModels/Components/DashboardViewModel.cs +++ b/LightBulb/ViewModels/Components/DashboardViewModel.cs @@ -288,15 +288,15 @@ private void UpdateInstant() private const double _brightnessDefaultStep = 0.08; private const double _temperatureDefaultStep = 30; - private double _brightnessMaxStep = _brightnessDefaultStep; - private double _temperatureMaxStep = _temperatureDefaultStep; - private ColorConfiguration _lastTarget; private void UpdateConfiguration() { if (CurrentConfiguration == TargetConfiguration) + { + _gammaService.SetGamma(CurrentConfiguration); return; + } double stepsPerSecond = 1000 / _updateConfigurationTimer.Interval.TotalMilliseconds; @@ -308,41 +308,42 @@ private void UpdateConfiguration() // If we've changed targets, restart with default settings. if (_lastTarget != TargetConfiguration && isSmooth) { - _brightnessMaxStep = _brightnessDefaultStep; - _temperatureMaxStep = _temperatureDefaultStep; _lastTarget = TargetConfiguration; + } - var tempDelta = Math.Abs( - TargetConfiguration.Temperature - CurrentConfiguration.Temperature - ); - var brightnessDelta = Math.Abs( - TargetConfiguration.Brightness - CurrentConfiguration.Brightness - ); - var expectedTemperatureDuration = tempDelta / (_temperatureMaxStep * stepsPerSecond); - var expectedBrightnessDuration = - brightnessDelta / (_brightnessMaxStep * stepsPerSecond); - - // If the expected durations are longer than our duration limit, we adjust the step amount to stay at the max duration. - var goalDuration = Math.Max(expectedTemperatureDuration, expectedBrightnessDuration); - goalDuration = Math.Min( - goalDuration, - _settingsService.ConfigurationSmoothingDuration.TotalSeconds - ); + double brightnessMaxStep = _brightnessDefaultStep; + double temperatureMaxStep = _temperatureDefaultStep; + + // Calculate the step size... + var tempDelta = Math.Abs( + TargetConfiguration.Temperature - CurrentConfiguration.Temperature + ); + var brightnessDelta = Math.Abs( + TargetConfiguration.Brightness - CurrentConfiguration.Brightness + ); + var expectedTemperatureDuration = tempDelta / (temperatureMaxStep * stepsPerSecond); + var expectedBrightnessDuration = brightnessDelta / (brightnessMaxStep * stepsPerSecond); + + // If the expected durations are longer than our duration limit, we adjust the step amount to stay at the max duration. + var goalDuration = Math.Max(expectedTemperatureDuration, expectedBrightnessDuration); + goalDuration = Math.Min( + goalDuration, + _settingsService.ConfigurationSmoothingDuration.TotalSeconds + ); - // Calculate the step-rate needed to reach the goal. - _brightnessMaxStep = brightnessDelta / (goalDuration * stepsPerSecond); - _temperatureMaxStep = tempDelta / (goalDuration * stepsPerSecond); + // Calculate the step-rate needed to reach the goal. + brightnessMaxStep = brightnessDelta / (goalDuration * stepsPerSecond); + temperatureMaxStep = tempDelta / (goalDuration * stepsPerSecond); - // If we ended up slower on either of the durations, speed us up. - _brightnessMaxStep = Math.Max(_brightnessMaxStep, _brightnessDefaultStep); - _temperatureMaxStep = Math.Max(_temperatureMaxStep, _temperatureDefaultStep); - } + // If we ended up slower on either of the durations, speed us up. + brightnessMaxStep = Math.Max(brightnessMaxStep, _brightnessDefaultStep); + temperatureMaxStep = Math.Max(temperatureMaxStep, _temperatureDefaultStep); CurrentConfiguration = isSmooth ? CurrentConfiguration.StepTo( TargetConfiguration, - _temperatureMaxStep, - _brightnessMaxStep + temperatureMaxStep, + brightnessMaxStep ) : TargetConfiguration; From 427a280d65ed340a741078731e8642c88105dfe0 Mon Sep 17 00:00:00 2001 From: Lilith Silver <84940819+LilithSilver@users.noreply.github.com> Date: Mon, 6 May 2024 12:30:54 -0700 Subject: [PATCH 7/7] rename max duration --- LightBulb/Services/SettingsService.cs | 2 +- LightBulb/ViewModels/Components/DashboardViewModel.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LightBulb/Services/SettingsService.cs b/LightBulb/Services/SettingsService.cs index e3af3eb5..fb197c6b 100644 --- a/LightBulb/Services/SettingsService.cs +++ b/LightBulb/Services/SettingsService.cs @@ -64,7 +64,7 @@ public partial class SettingsService() : SettingsBase(GetFilePath()) private double _configurationTransitionOffset; [ObservableProperty] - private TimeSpan _configurationSmoothingDuration = TimeSpan.FromSeconds(15); + private TimeSpan _configurationSmoothingMaxDuration = TimeSpan.FromSeconds(15); // Location diff --git a/LightBulb/ViewModels/Components/DashboardViewModel.cs b/LightBulb/ViewModels/Components/DashboardViewModel.cs index 6caf00ff..0b3c9f38 100644 --- a/LightBulb/ViewModels/Components/DashboardViewModel.cs +++ b/LightBulb/ViewModels/Components/DashboardViewModel.cs @@ -303,7 +303,7 @@ private void UpdateConfiguration() var isSmooth = _settingsService.IsConfigurationSmoothingEnabled && !IsCyclePreviewEnabled - && _settingsService.ConfigurationSmoothingDuration.TotalSeconds >= 0.1; + && _settingsService.ConfigurationSmoothingMaxDuration.TotalSeconds >= 0.1; // If we've changed targets, restart with default settings. if (_lastTarget != TargetConfiguration && isSmooth) @@ -328,7 +328,7 @@ private void UpdateConfiguration() var goalDuration = Math.Max(expectedTemperatureDuration, expectedBrightnessDuration); goalDuration = Math.Min( goalDuration, - _settingsService.ConfigurationSmoothingDuration.TotalSeconds + _settingsService.ConfigurationSmoothingMaxDuration.TotalSeconds ); // Calculate the step-rate needed to reach the goal.