Skip to content

Commit

Permalink
Merge pull request #372 from WildernessLabs/adrian-led-cleanup
Browse files Browse the repository at this point in the history
Led namespace cleanup + other minor fixes/cleanup
  • Loading branch information
adrianstevens authored Jul 14, 2022
2 parents a2840f6 + a1d6e7c commit 18c16d0
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Leds;
using Meadow.Peripherals.Leds;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -20,7 +21,7 @@ public override Task Initialize()
redPin: Device.Pins.OnboardLedRed,
greenPin: Device.Pins.OnboardLedGreen,
bluePin: Device.Pins.OnboardLedBlue);
onRgbLed.SetColor(RgbLed.Colors.Red);
onRgbLed.SetColor(RgbLedColors.Red);

leds = new List<Led>
{
Expand All @@ -42,7 +43,7 @@ public override Task Initialize()
new Led(Device.CreateDigitalOutputPort(Device.Pins.D15, false))
};

onRgbLed.SetColor(RgbLed.Colors.Green);
onRgbLed.SetColor(RgbLedColors.Green);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Leds;
using Meadow.Peripherals.Leds;
using Meadow.Units;
using System;
using System.Collections.Generic;
Expand All @@ -23,7 +24,7 @@ public override Task Initialize()
redPin: Device.Pins.OnboardLedRed,
greenPin: Device.Pins.OnboardLedGreen,
bluePin: Device.Pins.OnboardLedBlue);
onRgbLed.SetColor(RgbLed.Colors.Red);
onRgbLed.SetColor(RgbLedColors.Red);

pwmLeds = new List<PwmLed>
{
Expand All @@ -41,7 +42,7 @@ public override Task Initialize()
new PwmLed(Device.CreatePwmPort(Device.Pins.D13, new Frequency(100, Frequency.UnitType.Hertz)), TypicalForwardVoltage.Blue)
};

onRgbLed.SetColor(RgbLed.Colors.Green);
onRgbLed.SetColor(RgbLedColors.Green);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Leds;
using Meadow.Peripherals.Leds;

namespace Leds.RgbLed_Sample
{
Expand All @@ -23,7 +23,7 @@ public override Task Initialize()
redPin: Device.Pins.OnboardLedRed,
greenPin: Device.Pins.OnboardLedGreen,
bluePin: Device.Pins.OnboardLedBlue);
onRgbLed.SetColor(RgbLed.Colors.Red);
onRgbLed.SetColor(RgbLedColors.Red);

rgbLeds = new List<RgbLed>
{
Expand All @@ -45,7 +45,7 @@ public override Task Initialize()
Device.CreateDigitalOutputPort(Device.Pins.D13))
};

onRgbLed.SetColor(RgbLed.Colors.Green);
onRgbLed.SetColor(RgbLedColors.Green);

return Task.CompletedTask;
}
Expand All @@ -59,9 +59,9 @@ public override async Task Run()
Console.WriteLine("Going through each color on each RGB LED...");
foreach (var rgbLed in rgbLeds)
{
for (int i = 0; i < (int)RgbLed.Colors.count; i++)
for (int i = 0; i < (int)RgbLedColors.count; i++)
{
rgbLed.SetColor((RgbLed.Colors)i);
rgbLed.SetColor((RgbLedColors)i);
await Task.Delay(500);
}
}
Expand All @@ -71,9 +71,9 @@ public override async Task Run()
Console.WriteLine("Blinking through each color on each RGB LED...");
foreach (var rgbLed in rgbLeds)
{
for (int i = 0; i < (int)RgbLed.Colors.count; i++)
for (int i = 0; i < (int)RgbLedColors.count; i++)
{
rgbLed.StartBlink((RgbLed.Colors)i);
rgbLed.StartBlink((RgbLedColors)i);
await Task.Delay(3000);
}
}
Expand All @@ -83,9 +83,9 @@ public override async Task Run()
Console.WriteLine("Blinking through each color on each RGB LED...");
foreach (var rgbLed in rgbLeds)
{
for (int i = 0; i < (int)RgbLed.Colors.count; i++)
for (int i = 0; i < (int)RgbLedColors.count; i++)
{
rgbLed.StartBlink((RgbLed.Colors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
await Task.Delay(3000);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Meadow.Devices;
using Meadow.Foundation;
using Meadow.Foundation.Leds;
using Meadow.Peripherals.Leds;
using System;
using System.Threading;
using System.Threading.Tasks;
using static Meadow.Peripherals.Leds.IRgbLed;

namespace Leds.RgbPwmLed_Onboard_Sample
{
Expand All @@ -28,11 +28,13 @@ public override Task Initialize()
return Task.CompletedTask;
}

public override async Task Run()
public override Task Run()
{
TestColors();

RunColors();

return Task.CompletedTask;
}

public void TestColors()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Meadow.Devices;
using Meadow.Foundation;
using Meadow.Foundation.Leds;
using Meadow.Peripherals.Leds;
using System;
using System.Collections.Generic;
using System.Threading;
Expand All @@ -24,7 +25,7 @@ public override Task Initialize()
redPin: Device.Pins.OnboardLedRed,
greenPin: Device.Pins.OnboardLedGreen,
bluePin: Device.Pins.OnboardLedBlue);
onRgbLed.SetColor(RgbLed.Colors.Red);
onRgbLed.SetColor(RgbLedColors.Red);

rgbPwmLeds = new List<RgbPwmLed>()
{
Expand All @@ -50,7 +51,7 @@ public override Task Initialize()
Device.Pins.D13)
};

onRgbLed.SetColor(RgbLed.Colors.Green);
onRgbLed.SetColor(RgbLedColors.Green);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Meadow.Foundation;
using Meadow.Foundation.Leds;
using Meadow.Foundation.Sensors.Buttons;
using Meadow.Peripherals.Leds;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -28,7 +29,7 @@ public override Task Initialize()
redPwmPin: Device.Pins.OnboardLedRed,
greenPwmPin: Device.Pins.OnboardLedGreen,
bluePwmPin: Device.Pins.OnboardLedBlue,
Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode);
CommonType.CommonAnode);

//===== Push Button
// intialize the push button
Expand Down
51 changes: 0 additions & 51 deletions Source/Meadow.Foundation.Core/Leds/RgbLed.Enums.cs

This file was deleted.

31 changes: 15 additions & 16 deletions Source/Meadow.Foundation.Core/Leds/RgbLed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using Meadow.Peripherals.Leds;
using static Meadow.Peripherals.Leds.IRgbLed;
using System;

namespace Meadow.Foundation.Leds
Expand All @@ -18,7 +17,7 @@ public partial class RgbLed : IRgbLed
/// <summary>
/// Get the color the LED has been set to.
/// </summary>
public Colors Color { get; protected set; } = Colors.White;
public RgbLedColors Color { get; protected set; } = RgbLedColors.White;

/// <summary>
/// Get the red LED port
Expand Down Expand Up @@ -48,7 +47,7 @@ public bool IsOn
get => isOn;
set
{
SetColor(value? Color : Colors.Black);
SetColor(value? Color : RgbLedColors.Black);
isOn = value;
}
}
Expand Down Expand Up @@ -106,50 +105,50 @@ public void Stop()
/// Sets the current color of the LED.
/// </summary>
/// <param name="color"></param>
public void SetColor(Colors color)
public void SetColor(RgbLedColors color)
{
Color = color;

bool onState = (Common == CommonType.CommonCathode);

switch (color)
{
case Colors.Red:
case RgbLedColors.Red:
RedPort.State = onState;
GreenPort.State = !onState;
BluePort.State = !onState;
break;
case Colors.Green:
case RgbLedColors.Green:
RedPort.State = !onState;
GreenPort.State = onState;
BluePort.State = !onState;
break;
case Colors.Blue:
case RgbLedColors.Blue:
RedPort.State = !onState;
GreenPort.State = !onState;
BluePort.State = onState;
break;
case Colors.Yellow:
case RgbLedColors.Yellow:
RedPort.State = onState;
GreenPort.State = onState;
BluePort.State = !onState;
break;
case Colors.Magenta:
case RgbLedColors.Magenta:
RedPort.State = onState;
GreenPort.State = !onState;
BluePort.State = onState;
break;
case Colors.Cyan:
case RgbLedColors.Cyan:
RedPort.State = !onState;
GreenPort.State = onState;
BluePort.State = onState;
break;
case Colors.White:
case RgbLedColors.White:
RedPort.State = onState;
GreenPort.State = onState;
BluePort.State = onState;
break;
case Colors.Black:
case RgbLedColors.Black:
RedPort.State = !onState;
GreenPort.State = !onState;
BluePort.State = !onState;
Expand All @@ -161,7 +160,7 @@ public void SetColor(Colors color)
/// Starts the blink animation LED turning it on (500) and off (500)
/// </summary>
/// <param name="color"></param>
public void StartBlink(Colors color)
public void StartBlink(RgbLedColors color)
{
var onDuration = TimeSpan.FromMilliseconds(500);
var offDuration = TimeSpan.FromMilliseconds(500);
Expand All @@ -182,7 +181,7 @@ public void StartBlink(Colors color)
/// <param name="color"></param>
/// <param name="onDuration"></param>
/// <param name="offDuration"></param>
public void StartBlink(Colors color, TimeSpan onDuration, TimeSpan offDuration)
public void StartBlink(RgbLedColors color, TimeSpan onDuration, TimeSpan offDuration)
{
Stop();

Expand All @@ -202,7 +201,7 @@ public void StartBlink(Colors color, TimeSpan onDuration, TimeSpan offDuration)
/// <param name="offDuration"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
protected async Task StartBlinkAsync(Colors color, TimeSpan onDuration, TimeSpan offDuration, CancellationToken cancellationToken)
protected async Task StartBlinkAsync(RgbLedColors color, TimeSpan onDuration, TimeSpan offDuration, CancellationToken cancellationToken)
{
while (true)
{
Expand All @@ -213,7 +212,7 @@ protected async Task StartBlinkAsync(Colors color, TimeSpan onDuration, TimeSpan

SetColor(color);
await Task.Delay(onDuration);
SetColor(Colors.Black);
SetColor(RgbLedColors.Black);
await Task.Delay(offDuration);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Meadow.Foundation.Core/Leds/RgbPwmLed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using static Meadow.Peripherals.Leds.IRgbLed;
using Meadow.Peripherals.Leds;

namespace Meadow.Foundation.Leds
{
Expand Down
Loading

0 comments on commit 18c16d0

Please sign in to comment.