Skip to content

Commit

Permalink
Merge pull request #920 from WildernessLabs/feature/control-additions
Browse files Browse the repository at this point in the history
Feature/control additions
  • Loading branch information
adrianstevens authored Mar 9, 2024
2 parents 9e6114f + ea8c599 commit e18bc1f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 15 deletions.
27 changes: 26 additions & 1 deletion Source/Meadow.Foundation.Core/Leds/RgbPwmLed.Animations.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Meadow.Peripherals.Leds;
using System;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -26,6 +27,30 @@ public async Task StopAnimation()
}
}

///<inheritdoc/>
public Task StartBlink()
{
return StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500), 1f, 0f);
}

///<inheritdoc/>
public Task StartBlink(RgbLedColors color)
{
return StartBlink(color.AsColor(), TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500), 1f, 0f);
}

///<inheritdoc/>
public Task StartBlink(TimeSpan onDuration, TimeSpan offDuration)
{
return StartBlink(onDuration, offDuration, 1f, 0f);
}

///<inheritdoc/>
public Task StartBlink(RgbLedColors color, TimeSpan onDuration, TimeSpan offDuration)
{
return StartBlink(color.AsColor(), onDuration, offDuration, 1f, 0f);
}

///<inheritdoc/>
public Task StartBlink(float highBrightness = 1f, float lowBrightness = 0f)
{
Expand Down
25 changes: 14 additions & 11 deletions Source/Meadow.Foundation.Core/Leds/RgbPwmLed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ namespace Meadow.Foundation.Leds
/// </summary>
public partial class RgbPwmLed : IRgbPwmLed, IDisposable
{
readonly bool createdPorts = false;

static readonly Frequency DefaultFrequency = new Frequency(200, Frequency.UnitType.Hertz);

readonly float DEFAULT_DUTY_CYCLE = 0f;

readonly double maxRedDutyCycle = 1;
readonly double maxGreenDutyCycle = 1;
readonly double maxBlueDutyCycle = 1;
private readonly bool createdPorts = false;
private static readonly Frequency DefaultFrequency = new Frequency(200, Frequency.UnitType.Hertz);
private readonly float DEFAULT_DUTY_CYCLE = 0f;
private readonly double maxRedDutyCycle = 1;
private readonly double maxGreenDutyCycle = 1;
private readonly double maxBlueDutyCycle = 1;

/// <summary>
/// Maximum forward voltage (3.3 Volts)
Expand All @@ -40,7 +37,8 @@ public bool IsOn
isOn = value;
}
}
bool isOn;

private bool isOn;

/// <summary>
/// The current LED color
Expand Down Expand Up @@ -265,7 +263,6 @@ public void SetBrightness(float brightness)
SetColor(Color, brightness);
}

///<inheritdoc/>
public void SetColor(Color color, float brightness = 1)

Check warning on line 266 in Source/Meadow.Foundation.Core/Leds/RgbPwmLed.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'RgbPwmLed.SetColor(Color, float)'
{
if (color == Color && brightness == Brightness)
Expand All @@ -281,6 +278,12 @@ public void SetColor(Color color, float brightness = 1)
BluePwm.DutyCycle = (float)(Color.B / 255.0 * maxBlueDutyCycle * brightness);
}

///<inheritdoc/>
public new void SetColor(RgbLedColors color)

Check warning on line 282 in Source/Meadow.Foundation.Core/Leds/RgbPwmLed.cs

View workflow job for this annotation

GitHub Actions / build

The member 'RgbPwmLed.SetColor(RgbLedColors)' does not hide an accessible member. The new keyword is not required.
{
SetColor(color.AsColor());
}

///<inheritdoc/>
public void Dispose()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ public static Image LoadFromResource(string name)
throw new ArgumentException("Requested resource not found");
}

/// <summary>
/// Load an image from a Stream
/// </summary>
/// <param name="stream">The resource stream</param>
public static Image LoadFromStream(Stream stream)
{
return new Image(stream);
}

private Image(Stream source)
{ // determine type
var buffer = new byte[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public Color ForeColor
set => SetInvalidatingProperty(ref foreColor, value);
}

/// <summary>
/// Gets or sets the foreground color of the Circle.
/// </summary>
public Point Center
{
get => center;
set => SetInvalidatingProperty(ref center, value);
}

/// <summary>
/// Gets or sets the foreground color of the Circle.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Meadow.Hardware;
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;

Expand All @@ -12,7 +12,7 @@ namespace Meadow.Foundation.Sensors.Hid;
public partial class Keyboard : IDigitalInterruptController, IDigitalOutputController, IDisposable
{
private static Thread? _thread = null;
private static Dictionary<char, KeyboardKey> _keys = new Dictionary<char, KeyboardKey>();
private static ConcurrentDictionary<char, KeyboardKey> _keys = new();

private bool _keepScanning = false;
private bool _isDisposed = false;
Expand Down Expand Up @@ -94,7 +94,7 @@ public IDigitalInterruptPort CreateDigitalInterruptPort(IPin pin, InterruptMode
var ci = kp.SupportedChannels?.First() as IDigitalChannelInfo ?? throw new ArgumentException("Pin is not a Digital channel");

var kbk = new KeyboardKey(kp, ci, interruptMode);
_keys.Add(key, kbk);
_keys[key] = kbk;
return kbk;
}

Expand Down

0 comments on commit e18bc1f

Please sign in to comment.