From b9c3039f0787c9ede5abf0da750615e4eced8f60 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 27 Jul 2017 12:57:09 +0100 Subject: Add basic GUI to control LED colour and transition state. --- NucLedController/NucLedController.sln | 22 ++++ NucLedController/NucLedController/App.config | 6 ++ NucLedController/NucLedController/App.xaml | 9 ++ NucLedController/NucLedController/App.xaml.cs | 17 +++ NucLedController/NucLedController/LEDColour.cs | 34 ++++++ NucLedController/NucLedController/LEDController.cs | 16 +++ NucLedController/NucLedController/LEDTransition.cs | 35 ++++++ NucLedController/NucLedController/MainWindow.xaml | 16 +++ .../NucLedController/MainWindow.xaml.cs | 50 +++++++++ .../NucLedController/NucLedController.csproj | 120 +++++++++++++++++++++ .../NucLedController/Properties/AssemblyInfo.cs | 55 ++++++++++ .../Properties/Resources.Designer.cs | 71 ++++++++++++ .../NucLedController/Properties/Resources.resx | 117 ++++++++++++++++++++ .../Properties/Settings.Designer.cs | 30 ++++++ .../NucLedController/Properties/Settings.settings | 7 ++ .../NucLedController/WMISystemManagement.cs | 41 +++++++ NucLedController/NucLedController/app.manifest | 76 +++++++++++++ NucLedController/NucLedController/packages.config | 4 + README.md | 8 +- 19 files changed, 732 insertions(+), 2 deletions(-) create mode 100644 NucLedController/NucLedController.sln create mode 100644 NucLedController/NucLedController/App.config create mode 100644 NucLedController/NucLedController/App.xaml create mode 100644 NucLedController/NucLedController/App.xaml.cs create mode 100644 NucLedController/NucLedController/LEDColour.cs create mode 100644 NucLedController/NucLedController/LEDController.cs create mode 100644 NucLedController/NucLedController/LEDTransition.cs create mode 100644 NucLedController/NucLedController/MainWindow.xaml create mode 100644 NucLedController/NucLedController/MainWindow.xaml.cs create mode 100644 NucLedController/NucLedController/NucLedController.csproj create mode 100644 NucLedController/NucLedController/Properties/AssemblyInfo.cs create mode 100644 NucLedController/NucLedController/Properties/Resources.Designer.cs create mode 100644 NucLedController/NucLedController/Properties/Resources.resx create mode 100644 NucLedController/NucLedController/Properties/Settings.Designer.cs create mode 100644 NucLedController/NucLedController/Properties/Settings.settings create mode 100644 NucLedController/NucLedController/WMISystemManagement.cs create mode 100644 NucLedController/NucLedController/app.manifest create mode 100644 NucLedController/NucLedController/packages.config diff --git a/NucLedController/NucLedController.sln b/NucLedController/NucLedController.sln new file mode 100644 index 0000000..e24d6d9 --- /dev/null +++ b/NucLedController/NucLedController.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NucLedController", "NucLedController\NucLedController.csproj", "{7CD8533F-7778-4B1C-A88D-AD1B19547A1D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7CD8533F-7778-4B1C-A88D-AD1B19547A1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7CD8533F-7778-4B1C-A88D-AD1B19547A1D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7CD8533F-7778-4B1C-A88D-AD1B19547A1D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7CD8533F-7778-4B1C-A88D-AD1B19547A1D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/NucLedController/NucLedController/App.config b/NucLedController/NucLedController/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/NucLedController/NucLedController/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/NucLedController/NucLedController/App.xaml b/NucLedController/NucLedController/App.xaml new file mode 100644 index 0000000..4acf7a4 --- /dev/null +++ b/NucLedController/NucLedController/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/NucLedController/NucLedController/App.xaml.cs b/NucLedController/NucLedController/App.xaml.cs new file mode 100644 index 0000000..020b691 --- /dev/null +++ b/NucLedController/NucLedController/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace NucLedController +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/NucLedController/NucLedController/LEDColour.cs b/NucLedController/NucLedController/LEDColour.cs new file mode 100644 index 0000000..68fb22c --- /dev/null +++ b/NucLedController/NucLedController/LEDColour.cs @@ -0,0 +1,34 @@ +using System.Collections.Immutable; + +namespace NucLedController +{ + sealed class LEDColour + { + + public static readonly ImmutableList AvailableColours = ImmutableList.Create( + new LEDColour("CYAN", "Cyan", 0x01), + new LEDColour("PINK", "Pink", 0x02), + new LEDColour("YELLOW", "Yellow", 0x03), + new LEDColour("BLUE", "Blue", 0x04), + new LEDColour("RED", "Red", 0x05), + new LEDColour("GREEN", "Green", 0x06), + new LEDColour("WHITE", "White", 0x07) + ); + + public string Identifier { get; } + public string DisplayName { get; } + public byte ByteValue { get; } + + private LEDColour(string identifier, string displayName, byte byteValue) + { + Identifier = identifier; + DisplayName = displayName; + ByteValue = byteValue; + } + + public override string ToString() + { + return this.Identifier + this.ByteValue; + } + } +} diff --git a/NucLedController/NucLedController/LEDController.cs b/NucLedController/NucLedController/LEDController.cs new file mode 100644 index 0000000..7cf4847 --- /dev/null +++ b/NucLedController/NucLedController/LEDController.cs @@ -0,0 +1,16 @@ +namespace NucLedController +{ + class LEDController + { + + private static readonly byte POWER_LED_COMMAND_CODE = 0x01; + private static readonly byte RING_LED_COMMAND_CODE = 0x02; + + public static void SetLEDState(LEDTransition transition, LEDColour colour) + { + byte brightness = 0x64; // Just hardcode to max brightness for now + WMISystemManagement.Instance.WriteData(new byte[] { RING_LED_COMMAND_CODE, brightness, transition.ByteValue, colour.ByteValue }); + } + + } +} diff --git a/NucLedController/NucLedController/LEDTransition.cs b/NucLedController/NucLedController/LEDTransition.cs new file mode 100644 index 0000000..6f226ee --- /dev/null +++ b/NucLedController/NucLedController/LEDTransition.cs @@ -0,0 +1,35 @@ +using System.Collections.Immutable; + +namespace NucLedController +{ + sealed class LEDTransition + { + + public static readonly ImmutableList AvailableTransitions = ImmutableList.Create( + new LEDTransition("ALWAYS_ON", "Always on", 0x04), + new LEDTransition("BLINK_1_HZ", "Blink at 1hz", 0x01), + new LEDTransition("BLNIK_0.5_HZ", "Blink at 0.5hz", 0x05), + new LEDTransition("BLINK_0.25_HZ", "Blink at 0.25hz", 0x02), + new LEDTransition("FADE_1_HZ", "Fade at 1hz", 0x03), + new LEDTransition("FADE_0.5_HZ", "Fade at 0.5hz", 0x07), + new LEDTransition("FADE_0.25_HZ", "Fade at 0.25hz", 0x06) + ); + + public string Identifier { get; } + public string DisplayName { get; } + public byte ByteValue { get; } + + private LEDTransition(string identifier, string displayName, byte byteValue) + { + Identifier = identifier; + DisplayName = displayName; + ByteValue = byteValue; + } + + public override string ToString() + { + return this.Identifier + this.ByteValue; + } + + } +} diff --git a/NucLedController/NucLedController/MainWindow.xaml b/NucLedController/NucLedController/MainWindow.xaml new file mode 100644 index 0000000..00b34b2 --- /dev/null +++ b/NucLedController/NucLedController/MainWindow.xaml @@ -0,0 +1,16 @@ + + + +