aboutsummaryrefslogtreecommitdiff
path: root/NucLedController
diff options
context:
space:
mode:
authorJames Barnett <james.barnett@fivium.co.uk>2017-08-01 12:52:13 +0100
committerJames Barnett <james.barnett@fivium.co.uk>2017-08-01 12:52:13 +0100
commitcd68a397f67308a9b915a98837780813750e29c5 (patch)
treefcd3694a286c5a98f3a7904ffdc6b446557065d8 /NucLedController
parent36776bfbff6f15f7239924777651392945ebb2a0 (diff)
downloadintel-nuc-led-controller-cd68a397f67308a9b915a98837780813750e29c5.tar.xz
intel-nuc-led-controller-cd68a397f67308a9b915a98837780813750e29c5.zip
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
Diffstat (limited to 'NucLedController')
-rw-r--r--NucLedController/BlinkColourCyclerControlMode.cs47
-rw-r--r--NucLedController/IControlMode.cs14
-rw-r--r--NucLedController/LEDController.cs5
-rw-r--r--NucLedController/MainWindow.xaml41
-rw-r--r--NucLedController/MainWindow.xaml.cs55
-rw-r--r--NucLedController/NucLedController.csproj2
6 files changed, 143 insertions, 21 deletions
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">
<Grid Margin="10">
- <ComboBox x:Name="comboBoxColour" HorizontalAlignment="Left" Margin="100,10,0,0" VerticalAlignment="Top" Width="83"/>
- <Button x:Name="button" Content="Apply" HorizontalAlignment="Left" Margin="10,91,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
- <Label x:Name="label" Content="Colour" HorizontalAlignment="Left" Margin="40,10,0,0" VerticalAlignment="Top"/>
- <ComboBox x:Name="comboBoxTransition" HorizontalAlignment="Left" Margin="100,55,0,0" VerticalAlignment="Top" Width="123"/>
- <Label x:Name="label1" Content="Transition" HorizontalAlignment="Left" Margin="24,51,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.165,0.065"/>
+ <TabControl x:Name="tabControl" Height="156" VerticalAlignment="Top">
+ <TabItem x:Name="MANUAL" Header="Manual Control">
+ <TabItem.Background>
+ <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
+ <GradientStop Color="#FFF0F0F0" Offset="0"/>
+ <GradientStop Color="#FFFFFEFE" Offset="1"/>
+ </LinearGradientBrush>
+ </TabItem.Background>
+ <Grid Background="White" HorizontalAlignment="Left" Width="332" Margin="0,0,-2,0">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition/>
+ <ColumnDefinition Width="2*"/>
+ </Grid.ColumnDefinitions>
+ <RadioButton x:Name="radioButtonEnableLed" Content="Enable LED" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" GroupName="LEDControl" IsChecked="True"/>
+ <ComboBox x:Name="comboBoxColour" HorizontalAlignment="Left" Margin="102,37,0,0" VerticalAlignment="Top" Width="83" IsEnabled="{Binding IsChecked, ElementName=radioButtonEnableLed}" Grid.ColumnSpan="2"/>
+ <Label x:Name="label" Content="Colour" HorizontalAlignment="Left" Margin="46,33,0,0" VerticalAlignment="Top"/>
+ <ComboBox x:Name="comboBoxTransition" HorizontalAlignment="Left" Margin="102,70,0,0" VerticalAlignment="Top" Width="123" IsEnabled="{Binding IsChecked, ElementName=radioButtonEnableLed}" Grid.ColumnSpan="2"/>
+ <Label x:Name="label1" Content="Transition" HorizontalAlignment="Left" Margin="30,66,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.165,0.065"/>
+ <RadioButton x:Name="radioButtonDisableLed" Content="Disable LED" HorizontalAlignment="Left" Margin="10,107,0,0" VerticalAlignment="Top" GroupName="LEDControl"/>
+ </Grid>
+ </TabItem>
+ <TabItem x:Name="AUTO" Header="Auto">
+ <Grid Background="White" HorizontalAlignment="Left" Width="332" Margin="0,0,-2,0">
+ <RadioButton x:Name="radioButtonCycleColour" Content="Cycle Colours" HorizontalAlignment="Left" Margin="10,54,0,0" VerticalAlignment="Top" Width="95"/>
+ <Label x:Name="label2" Content="The following additional modes are not provided by the Intel WMI&#xA;Interface, they are generated and controlled by this program. They will&#xD;&#xA;only work while this program is running." HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Width="340" Height="54" FontSize="10"/>
+ <Slider x:Name="sliderCycleRate" HorizontalAlignment="Left" Margin="113,81,0,0" VerticalAlignment="Top" Minimum="1" Maximum="5000" Width="110" LargeChange="100" Height="20" SmallChange="10" TickPlacement="BottomRight" IsSnapToTickEnabled="True" TickFrequency="10" IsEnabled="{Binding IsChecked, ElementName=radioButtonCycleColour}" Value="500" />
+ <Label x:Name="label3" Content="Cycle Rate " HorizontalAlignment="Left" Margin="40,74,0,0" VerticalAlignment="Top"/>
+ <TextBox x:Name="textBoxCycleRateVal" HorizontalAlignment="Left" Height="23" Margin="230,78,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="66" Text="{Binding ElementName=sliderCycleRate, Path=Value, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsChecked, ElementName=radioButtonCycleColour}"/>
+ <Label x:Name="label4" Content="(milliseconds)" HorizontalAlignment="Left" Margin="35,91,0,0" VerticalAlignment="Top" Width="73" FontSize="10" RenderTransformOrigin="0.511,0.319"/>
+ </Grid>
+ </TabItem>
+ </TabControl>
+ <Button x:Name="button" Content="Apply" HorizontalAlignment="Left" Margin="10,168,0,0" VerticalAlignment="Top" Width="75" Click="applyChanges"/>
+ <Label x:Name="lableStatusText" Content="" Margin="100,162,10,0" VerticalAlignment="Top" Foreground="#FF807F7F"/>
</Grid>
</Window>
diff --git a/NucLedController/MainWindow.xaml.cs b/NucLedController/MainWindow.xaml.cs
index 2c26c7e..0d943c7 100644
--- a/NucLedController/MainWindow.xaml.cs
+++ b/NucLedController/MainWindow.xaml.cs
@@ -1,17 +1,8 @@
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Timers;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
namespace NucLedController
{
@@ -20,25 +11,59 @@ namespace NucLedController
/// </summary>
public partial class MainWindow : Window
{
+ private IControlMode currentControlMode = null;
+
public MainWindow()
{
InitializeComponent();
- //comboBoxColour.ItemsSource = Enum.GetValues(typeof(LEDController.Colour));
comboBoxColour.ItemsSource = LEDColour.AvailableColours;
comboBoxColour.DisplayMemberPath = "DisplayName";
comboBoxColour.SelectedIndex = 0;
- //comboBoxColour.SelectedValuePath = "ByteValue";
comboBoxTransition.ItemsSource = LEDTransition.AvailableTransitions;
comboBoxTransition.DisplayMemberPath = "DisplayName";
comboBoxTransition.SelectedIndex = 0;
+
}
- private void button_Click(object sender, RoutedEventArgs e)
+ private void applyChanges(object sender, RoutedEventArgs e)
{
- Console.WriteLine("clicked! " + (LEDColour)comboBoxColour.SelectedItem);
+
try
{
- LEDController.SetLEDState((LEDTransition)comboBoxTransition.SelectedItem, (LEDColour)comboBoxColour.SelectedItem);
+
+ // Stop the current control mode if there is one
+ if(currentControlMode != null)
+ {
+ currentControlMode.Stop();
+ }
+
+ TabItem tabItem = tabControl.SelectedItem as TabItem;
+ if(tabItem.Name.ToString() == "AUTO")
+ {
+ if(radioButtonCycleColour.IsChecked ?? false)
+ {
+ currentControlMode = new BlinkColourCyclerControlMode((int) sliderCycleRate.Value);
+ currentControlMode.Start();
+ lableStatusText.Content = "Colour cycle mode enabled";
+ }
+ }
+ else
+ {
+ if (radioButtonDisableLed.IsChecked ?? false)
+ {
+ LEDController.DisableLED();
+ lableStatusText.Content = "LED disabled";
+ }
+ else
+ {
+ LEDTransition transition = comboBoxTransition.SelectedItem as LEDTransition;
+ LEDColour colour = comboBoxColour.SelectedItem as LEDColour;
+ LEDController.SetLEDState(transition, colour);
+ lableStatusText.Content = $"LED set: {colour.DisplayName} - {transition.DisplayName}";
+ }
+
+ }
+
}
catch (Exception ex)
{
diff --git a/NucLedController/NucLedController.csproj b/NucLedController/NucLedController.csproj
index 06c894f..b5849c2 100644
--- a/NucLedController/NucLedController.csproj
+++ b/NucLedController/NucLedController.csproj
@@ -63,6 +63,8 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
+ <Compile Include="BlinkColourCyclerControlMode.cs" />
+ <Compile Include="IControlMode.cs" />
<Compile Include="LEDColour.cs" />
<Compile Include="LEDController.cs" />
<Compile Include="LEDTransition.cs" />