From cd68a397f67308a9b915a98837780813750e29c5 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 1 Aug 2017 12:52:13 +0100 Subject: Add options to disable LED and cycle colours - Add disable option in manual LED control - Add mode to cycle through all colours at a given rate --- NucLedController/BlinkColourCyclerControlMode.cs | 47 ++++++++++++++++++++ NucLedController/IControlMode.cs | 14 ++++++ NucLedController/LEDController.cs | 5 +++ NucLedController/MainWindow.xaml | 41 +++++++++++++++--- NucLedController/MainWindow.xaml.cs | 55 +++++++++++++++++------- NucLedController/NucLedController.csproj | 2 + 6 files changed, 143 insertions(+), 21 deletions(-) create mode 100644 NucLedController/BlinkColourCyclerControlMode.cs create mode 100644 NucLedController/IControlMode.cs diff --git a/NucLedController/BlinkColourCyclerControlMode.cs b/NucLedController/BlinkColourCyclerControlMode.cs new file mode 100644 index 0000000..dac0a51 --- /dev/null +++ b/NucLedController/BlinkColourCyclerControlMode.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; + +namespace NucLedController +{ + class BlinkColourCyclerControlMode : IControlMode + { + + private readonly Timer timer; + private int currentColourIndex; + private readonly int maxColourIndex = LEDColour.AvailableColours.Count - 1; + + public BlinkColourCyclerControlMode(int intervalMs) + { + timer = new Timer(); + timer.Elapsed += new ElapsedEventHandler(Tick); + timer.Interval = intervalMs; + } + + private void Tick(object source, ElapsedEventArgs e) + { + LEDController.SetLEDState(LEDTransition.AvailableTransitions.Find(t => t.Identifier.ToString() == "ALWAYS_ON"), LEDColour.AvailableColours.ElementAt(currentColourIndex)); + if (currentColourIndex == maxColourIndex) + { + currentColourIndex = 0; + } + else + { + currentColourIndex++; + } + } + + public void Start() + { + timer.Start(); + } + + public void Stop() + { + timer.Stop(); + } + } +} diff --git a/NucLedController/IControlMode.cs b/NucLedController/IControlMode.cs new file mode 100644 index 0000000..04a6c07 --- /dev/null +++ b/NucLedController/IControlMode.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NucLedController +{ + interface IControlMode + { + void Start(); + void Stop(); + } +} diff --git a/NucLedController/LEDController.cs b/NucLedController/LEDController.cs index 7cf4847..31dc1b0 100644 --- a/NucLedController/LEDController.cs +++ b/NucLedController/LEDController.cs @@ -12,5 +12,10 @@ WMISystemManagement.Instance.WriteData(new byte[] { RING_LED_COMMAND_CODE, brightness, transition.ByteValue, colour.ByteValue }); } + public static void DisableLED() + { + WMISystemManagement.Instance.WriteData(new byte[] { RING_LED_COMMAND_CODE, 0x00, 0x00, 0x00 }); + } + } } diff --git a/NucLedController/MainWindow.xaml b/NucLedController/MainWindow.xaml index 00b34b2..dbe0113 100644 --- a/NucLedController/MainWindow.xaml +++ b/NucLedController/MainWindow.xaml @@ -5,12 +5,41 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:NucLedController" mc:Ignorable="d" - Title="NUC LED Controller" Height="173.928" Width="316.206" SizeToContent="WidthAndHeight"> + Title="NUC LED Controller" Height="243.262" Width="364.333" SizeToContent="WidthAndHeight"> - -