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

Cleanup contracts #921

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions Source/Meadow.Foundation.Core/Leds/Led.Animations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public partial class Led
private CancellationTokenSource? cancellationTokenSource = null;


/// <summary>
/// Stops the current LED animation
/// </summary>
/// <inheritdoc/>
public async Task StopAnimation()
{
if (animationTask != null)
Expand All @@ -29,19 +27,13 @@ public async Task StopAnimation()
}
}

/// <summary>
/// Start the Blink animation which sets turns the LED on and off on an interval of 1 second (500ms on, 500ms off)
/// </summary>
/// <inheritdoc/>
public Task StartBlink()
{
return StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));
}

/// <summary>
/// Start the Blink animation which sets turns the LED on and off with the specified durations
/// </summary>
/// <param name="onDuration">The duration the LED stays on</param>
/// <param name="offDuration">The duration the LED stays off</param>
/// <inheritdoc/>
public async Task StartBlink(TimeSpan onDuration, TimeSpan offDuration)
{
await StopAnimation();
Expand Down
4 changes: 1 addition & 3 deletions Source/Meadow.Foundation.Core/Leds/Led.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public partial class Led : ILed, IDisposable
{
readonly bool createdPort = false;

/// <summary>
/// Turns on LED with current color or turns it off
/// </summary>
/// <inheritdoc/>
public bool IsOn
{
get => isOn;
Expand Down
49 changes: 20 additions & 29 deletions Source/Meadow.Foundation.Core/Leds/PwmLed.Animations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Stops any running animations.
/// </summary>
/// <inheritdoc/>
public async Task StopAnimation()
{
if (animationTask != null)
Expand All @@ -25,12 +23,20 @@ public async Task StopAnimation()
}
}

/// <summary>
/// Start a Blink animation which sets the brightness of the LED alternating between a low and high brightness setting.
/// </summary>
/// <param name="highBrightness">The maximum brightness of the animation</param>
/// <param name="lowBrightness">The minimum brightness of the animation</param>
public async Task StartBlink(float highBrightness = 1f, float lowBrightness = 0f)
/// <inheritdoc/>
public Task StartBlink()
{
return StartBlink(1f, 0f);
}

/// <inheritdoc/>
public Task StartBlink(TimeSpan onDuration, TimeSpan offDuration)
{
return StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));
}

/// <inheritdoc/>
public async Task StartBlink(float highBrightness, float lowBrightness)
{
ValidateBrightness(highBrightness, lowBrightness);

Expand All @@ -39,13 +45,7 @@ public async Task StartBlink(float highBrightness = 1f, float lowBrightness = 0f
await StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));
}

/// <summary>
/// Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness setting, using the durations provided.
/// </summary>
/// <param name="highBrightnessDuration">The duration the LED stays in high brightness</param>
/// <param name="lowBrightnessDuration">The duration the LED stays in low brightness</param>
/// <param name="highBrightness">The maximum brightness of the animation</param>
/// <param name="lowBrightness">The minimum brightness of the animation</param>
/// <inheritdoc/>
public async Task StartBlink(
TimeSpan highBrightnessDuration,
TimeSpan lowBrightnessDuration,
Expand Down Expand Up @@ -76,11 +76,7 @@ public async Task StartBlink(
}
}

/// <summary>
/// Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting.
/// </summary>
/// <param name="highBrightness">The maximum brightness of the animation</param>
/// <param name="lowBrightness">The minimum brightness of the animation</param>
/// <inheritdoc/>
public async Task StartPulse(float highBrightness = 1, float lowBrightness = 0.15F)
{
ValidateBrightness(highBrightness, lowBrightness);
Expand All @@ -90,12 +86,7 @@ public async Task StartPulse(float highBrightness = 1, float lowBrightness = 0.1
await StartPulse(TimeSpan.FromMilliseconds(600), highBrightness, lowBrightness);
}

/// <summary>
/// Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting, using the durations provided.
/// </summary>
/// <param name="pulseDuration">The pulse animation duration</param>
/// <param name="highBrightness">The maximum brightness of the animation</param>
/// <param name="lowBrightness">The minimum brightness of the animation</param>
/// <inheritdoc/>
public async Task StartPulse(
TimeSpan pulseDuration,
float highBrightness = 1,
Expand All @@ -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;

Expand Down
13 changes: 3 additions & 10 deletions Source/Meadow.Foundation.Core/Leds/PwmLed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public partial class PwmLed : IPwmLed, IDisposable
/// </summary>
public Voltage MIN_FORWARD_VOLTAGE => new Voltage(0);

/// <summary>
/// Turns on LED with current color or turns it off
/// </summary>
/// <inheritdoc/>
public bool IsOn
{
get => isOn;
Expand All @@ -49,9 +47,7 @@ public bool IsOn
/// </summary>
public Voltage ForwardVoltage { get; protected set; }

/// <summary>
/// The brightness value assigned to the LED
/// </summary>
/// <inheritdoc/>
public float Brightness { get; protected set; } = 1f;

/// <summary>
Expand Down Expand Up @@ -115,10 +111,7 @@ protected void ValidateForwardVoltages(Voltage forwardVoltage)
}
}

/// <summary>
/// Sets the LED to a specific brightness.
/// </summary>
/// <param name="brightness">Valid values are from 0 to 1, inclusive</param>
/// <inheritdoc/>
public void SetBrightness(float brightness)
{
if (brightness < 0 || brightness > 1)
Expand Down
4 changes: 1 addition & 3 deletions Source/Meadow.Foundation.Core/Leds/RgbLed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public partial class RgbLed : IRgbLed, IDisposable
/// </summary>
public CommonType Common { get; protected set; }

/// <summary>
/// Turns on LED with current color or turns it off
/// </summary>
/// <inheritdoc/>
public bool IsOn
{
get => isOn;
Expand Down
Loading