From 0bd09d4b04e34e2eef212c3930815ce743d65ab6 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Tue, 12 Mar 2024 15:41:38 -0700 Subject: [PATCH] Cleanup contracts --- .../Leds/Led.Animations.cs | 14 ++---- Source/Meadow.Foundation.Core/Leds/Led.cs | 4 +- .../Leds/PwmLed.Animations.cs | 49 ++++++++----------- Source/Meadow.Foundation.Core/Leds/PwmLed.cs | 13 ++--- Source/Meadow.Foundation.Core/Leds/RgbLed.cs | 4 +- 5 files changed, 28 insertions(+), 56 deletions(-) diff --git a/Source/Meadow.Foundation.Core/Leds/Led.Animations.cs b/Source/Meadow.Foundation.Core/Leds/Led.Animations.cs index 340db15f55..64df4cdd25 100644 --- a/Source/Meadow.Foundation.Core/Leds/Led.Animations.cs +++ b/Source/Meadow.Foundation.Core/Leds/Led.Animations.cs @@ -15,9 +15,7 @@ public partial class Led private CancellationTokenSource? cancellationTokenSource = null; - /// - /// Stops the current LED animation - /// + /// public async Task StopAnimation() { if (animationTask != null) @@ -29,19 +27,13 @@ public async Task StopAnimation() } } - /// - /// Start the Blink animation which sets turns the LED on and off on an interval of 1 second (500ms on, 500ms off) - /// + /// public Task StartBlink() { return StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500)); } - /// - /// Start the Blink animation which sets turns the LED on and off with the specified durations - /// - /// The duration the LED stays on - /// The duration the LED stays off + /// public async Task StartBlink(TimeSpan onDuration, TimeSpan offDuration) { await StopAnimation(); diff --git a/Source/Meadow.Foundation.Core/Leds/Led.cs b/Source/Meadow.Foundation.Core/Leds/Led.cs index cb9b212391..07e68cbd26 100644 --- a/Source/Meadow.Foundation.Core/Leds/Led.cs +++ b/Source/Meadow.Foundation.Core/Leds/Led.cs @@ -11,9 +11,7 @@ public partial class Led : ILed, IDisposable { readonly bool createdPort = false; - /// - /// Turns on LED with current color or turns it off - /// + /// public bool IsOn { get => isOn; diff --git a/Source/Meadow.Foundation.Core/Leds/PwmLed.Animations.cs b/Source/Meadow.Foundation.Core/Leds/PwmLed.Animations.cs index e62cd91118..78cf7a02b8 100644 --- a/Source/Meadow.Foundation.Core/Leds/PwmLed.Animations.cs +++ b/Source/Meadow.Foundation.Core/Leds/PwmLed.Animations.cs @@ -6,14 +6,12 @@ namespace Meadow.Foundation.Leds { public partial class PwmLed { - private readonly object syncRoot = new object(); + private readonly object syncRoot = new(); private Task? animationTask = null; private CancellationTokenSource? cancellationTokenSource = null; - /// - /// Stops any running animations. - /// + /// public async Task StopAnimation() { if (animationTask != null) @@ -25,12 +23,20 @@ public async Task StopAnimation() } } - /// - /// Start a Blink animation which sets the brightness of the LED alternating between a low and high brightness setting. - /// - /// The maximum brightness of the animation - /// The minimum brightness of the animation - public async Task StartBlink(float highBrightness = 1f, float lowBrightness = 0f) + /// + public Task StartBlink() + { + return StartBlink(1f, 0f); + } + + /// + public Task StartBlink(TimeSpan onDuration, TimeSpan offDuration) + { + return StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500)); + } + + /// + public async Task StartBlink(float highBrightness, float lowBrightness) { ValidateBrightness(highBrightness, lowBrightness); @@ -39,13 +45,7 @@ public async Task StartBlink(float highBrightness = 1f, float lowBrightness = 0f await StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500)); } - /// - /// Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness setting, using the durations provided. - /// - /// The duration the LED stays in high brightness - /// The duration the LED stays in low brightness - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// public async Task StartBlink( TimeSpan highBrightnessDuration, TimeSpan lowBrightnessDuration, @@ -76,11 +76,7 @@ public async Task StartBlink( } } - /// - /// Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting. - /// - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// public async Task StartPulse(float highBrightness = 1, float lowBrightness = 0.15F) { ValidateBrightness(highBrightness, lowBrightness); @@ -90,12 +86,7 @@ public async Task StartPulse(float highBrightness = 1, float lowBrightness = 0.1 await StartPulse(TimeSpan.FromMilliseconds(600), highBrightness, lowBrightness); } - /// - /// Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting, using the durations provided. - /// - /// The pulse animation duration - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// public async Task StartPulse( TimeSpan pulseDuration, float highBrightness = 1, @@ -113,7 +104,7 @@ public async Task StartPulse( { float brightness = lowBrightness; bool ascending = true; - var intervalTime = TimeSpan.FromMilliseconds(16); // aiming at 60fps to avoid visible steps in brightness changes + var intervalTime = TimeSpan.FromMilliseconds(16); float steps = (float)(pulseDuration.TotalMilliseconds / intervalTime.TotalMilliseconds); float delta = (highBrightness - lowBrightness) / steps; diff --git a/Source/Meadow.Foundation.Core/Leds/PwmLed.cs b/Source/Meadow.Foundation.Core/Leds/PwmLed.cs index ac794a7764..7800862ad6 100644 --- a/Source/Meadow.Foundation.Core/Leds/PwmLed.cs +++ b/Source/Meadow.Foundation.Core/Leds/PwmLed.cs @@ -25,9 +25,7 @@ public partial class PwmLed : IPwmLed, IDisposable /// public Voltage MIN_FORWARD_VOLTAGE => new Voltage(0); - /// - /// Turns on LED with current color or turns it off - /// + /// public bool IsOn { get => isOn; @@ -49,9 +47,7 @@ public bool IsOn /// public Voltage ForwardVoltage { get; protected set; } - /// - /// The brightness value assigned to the LED - /// + /// public float Brightness { get; protected set; } = 1f; /// @@ -115,10 +111,7 @@ protected void ValidateForwardVoltages(Voltage forwardVoltage) } } - /// - /// Sets the LED to a specific brightness. - /// - /// Valid values are from 0 to 1, inclusive + /// public void SetBrightness(float brightness) { if (brightness < 0 || brightness > 1) diff --git a/Source/Meadow.Foundation.Core/Leds/RgbLed.cs b/Source/Meadow.Foundation.Core/Leds/RgbLed.cs index 03f6fc2fae..9eda560357 100644 --- a/Source/Meadow.Foundation.Core/Leds/RgbLed.cs +++ b/Source/Meadow.Foundation.Core/Leds/RgbLed.cs @@ -36,9 +36,7 @@ public partial class RgbLed : IRgbLed, IDisposable /// public CommonType Common { get; protected set; } - /// - /// Turns on LED with current color or turns it off - /// + /// public bool IsOn { get => isOn;