diff options
| author | James Barnett <james.barnett@fivium.co.uk> | 2017-08-29 12:21:38 +0100 |
|---|---|---|
| committer | James Barnett <james.barnett@fivium.co.uk> | 2017-08-29 12:21:38 +0100 |
| commit | 87ebd4bc76c85cd0f954b0e39c2e2757abff6b48 (patch) | |
| tree | 6172feb7ab8643158d8bd7481d35635e65716e1c /NucLedController | |
| parent | f51203de8436052c04b4c733a910791ed1d4e3f7 (diff) | |
| download | intel-nuc-led-controller-0.3.tar.xz intel-nuc-led-controller-0.3.zip | |
Add CPU utilisaiton indicator modev0.3
Diffstat (limited to 'NucLedController')
| -rw-r--r-- | NucLedController/BlinkColourCyclerControlMode.cs | 2 | ||||
| -rw-r--r-- | NucLedController/CPUUsageIndicatorControlMode.cs | 68 | ||||
| -rw-r--r-- | NucLedController/FadeColourCyclerControlMode.cs | 2 | ||||
| -rw-r--r-- | NucLedController/LEDColour.cs | 7 | ||||
| -rw-r--r-- | NucLedController/LEDTransition.cs | 6 | ||||
| -rw-r--r-- | NucLedController/MainWindow.xaml | 9 | ||||
| -rw-r--r-- | NucLedController/MainWindow.xaml.cs | 6 | ||||
| -rw-r--r-- | NucLedController/NucLedController.csproj | 1 |
8 files changed, 93 insertions, 8 deletions
diff --git a/NucLedController/BlinkColourCyclerControlMode.cs b/NucLedController/BlinkColourCyclerControlMode.cs index dac0a51..c95a007 100644 --- a/NucLedController/BlinkColourCyclerControlMode.cs +++ b/NucLedController/BlinkColourCyclerControlMode.cs @@ -23,7 +23,7 @@ namespace NucLedController private void Tick(object source, ElapsedEventArgs e) { - LEDController.SetLEDState(LEDTransition.AvailableTransitions.Find(t => t.Identifier.ToString() == "ALWAYS_ON"), LEDColour.AvailableColours.ElementAt(currentColourIndex)); + LEDController.SetLEDState(LEDTransition.getLEDTransition("ALWAYS_ON"), LEDColour.AvailableColours.ElementAt(currentColourIndex)); if (currentColourIndex == maxColourIndex) { currentColourIndex = 0; diff --git a/NucLedController/CPUUsageIndicatorControlMode.cs b/NucLedController/CPUUsageIndicatorControlMode.cs new file mode 100644 index 0000000..5d62339 --- /dev/null +++ b/NucLedController/CPUUsageIndicatorControlMode.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; + +namespace NucLedController +{ + class CPUUsageIndicatorControlMode : IControlMode + { + + private readonly Timer timer; + private readonly PerformanceCounter perfCounter; + private LEDColour currentColour; + + public CPUUsageIndicatorControlMode(int intervalMs) + { + timer = new Timer(); + timer.Elapsed += new ElapsedEventHandler(Tick); + timer.Interval = intervalMs; + + perfCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); + currentColour = LEDColour.getLEDColour("WHITE"); + } + + private void Tick(object source, ElapsedEventArgs e) + { + float cpuUtilisation = perfCounter.NextValue(); + + LEDColour targetColour = mapUsageToColour(cpuUtilisation); + if(currentColour != targetColour) + { + LEDController.SetLEDState(LEDTransition.getLEDTransition("ALWAYS_ON"), targetColour); + currentColour = targetColour; + } + + } + + // TODO add option to map usage to brighness + private LEDColour mapUsageToColour(float utilisation) + { + if(utilisation <= 33) + { + return LEDColour.getLEDColour("GREEN"); + } + else if (utilisation > 66) + { + return LEDColour.getLEDColour("RED"); + } + else + { + return LEDColour.getLEDColour("YELLOW"); + } + } + + public void Start() + { + timer.Start(); + } + + public void Stop() + { + timer.Start(); + } + } +} diff --git a/NucLedController/FadeColourCyclerControlMode.cs b/NucLedController/FadeColourCyclerControlMode.cs index ba982ca..9beed18 100644 --- a/NucLedController/FadeColourCyclerControlMode.cs +++ b/NucLedController/FadeColourCyclerControlMode.cs @@ -39,7 +39,7 @@ namespace NucLedController private void Tick(object source, ElapsedEventArgs e) { - LEDController.SetLEDState(LEDTransition.AvailableTransitions.Find(t => t.Identifier.ToString() == "ALWAYS_ON"), LEDColour.AvailableColours.ElementAt(currentColourIndex), currentBrightness); + LEDController.SetLEDState(LEDTransition.getLEDTransition("ALWAYS_ON"), LEDColour.AvailableColours.ElementAt(currentColourIndex), currentBrightness); // TODO more of the fade duration should be spent at the lower brightness levels, since the perceived change in brightness is much more apparent at the bottom end. // e.g. the perceived difference between 0x10 and 0x20 is much larger than 0x50 and 0x60, so scaling up linearly wastes a lot of time increasing imperceivable brightness changes at the top of the range. diff --git a/NucLedController/LEDColour.cs b/NucLedController/LEDColour.cs index 68fb22c..e512ef9 100644 --- a/NucLedController/LEDColour.cs +++ b/NucLedController/LEDColour.cs @@ -28,7 +28,12 @@ namespace NucLedController public override string ToString() { - return this.Identifier + this.ByteValue; + return Identifier + ByteValue; + } + + public static LEDColour getLEDColour(string identifier) + { + return AvailableColours.Find(c => c.Identifier == identifier); } } } diff --git a/NucLedController/LEDTransition.cs b/NucLedController/LEDTransition.cs index 6f226ee..d965158 100644 --- a/NucLedController/LEDTransition.cs +++ b/NucLedController/LEDTransition.cs @@ -28,8 +28,12 @@ namespace NucLedController public override string ToString() { - return this.Identifier + this.ByteValue; + return Identifier + ByteValue; } + public static LEDTransition getLEDTransition(string identifier) + { + return AvailableTransitions.Find(c => c.Identifier == identifier); + } } } diff --git a/NucLedController/MainWindow.xaml b/NucLedController/MainWindow.xaml index b42921e..80161ba 100644 --- a/NucLedController/MainWindow.xaml +++ b/NucLedController/MainWindow.xaml @@ -5,9 +5,9 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:NucLedController" mc:Ignorable="d" - Title="NUC LED Controller" Height="305.928" Width="382.999" SizeToContent="WidthAndHeight"> + Title="NUC LED Controller" Height="315.156" Width="382.999" SizeToContent="WidthAndHeight"> <Grid Margin="10"> - <TabControl x:Name="tabControl" Height="223" VerticalAlignment="Top"> + <TabControl x:Name="tabControl" Height="230" VerticalAlignment="Top"> <TabItem x:Name="MANUAL" Header="Manual Control"> <TabItem.Background> <LinearGradientBrush EndPoint="0,1" StartPoint="0,0"> @@ -41,10 +41,11 @@ <Label x:Name="label4_Copy" Content="(milliseconds)" HorizontalAlignment="Left" Margin="35,148,0,0" VerticalAlignment="Top" Width="73" FontSize="10" RenderTransformOrigin="0.511,0.319"/> <Slider x:Name="sliderFadeRate" HorizontalAlignment="Left" Margin="113,138,0,0" VerticalAlignment="Top" Minimum="1" Maximum="30000" Width="110" LargeChange="500" Height="20" SmallChange="100" TickPlacement="BottomRight" IsSnapToTickEnabled="True" TickFrequency="100" IsEnabled="{Binding IsChecked, ElementName=radioButtonFadeColour}" Value="500" /> <TextBox x:Name="textBoxFadeRateVal" HorizontalAlignment="Left" Height="23" Margin="228,136,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="66" Text="{Binding Value, ElementName=sliderFadeRate, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsChecked, ElementName=radioButtonFadeColour}" RenderTransformOrigin="0.52,1.217"/> + <RadioButton x:Name="radioButtonCPUUsage" Content="CPU Utilisation" HorizontalAlignment="Left" Margin="10,177,0,0" VerticalAlignment="Top" Width="98" ToolTip="LED colour will be set based on the current CPU utilisation. Green when < 33% , red when > 66%, yellow otherwise."/> </Grid> </TabItem> </TabControl> - <Button x:Name="button" Content="Apply" HorizontalAlignment="Left" Margin="0,234,0,0" VerticalAlignment="Top" Width="75" Click="applyChanges"/> - <Label x:Name="lableStatusText" Content="" Margin="92,229,0,0" VerticalAlignment="Top" Foreground="#FF807F7F"/> + <Button x:Name="button" Content="Apply" HorizontalAlignment="Left" Margin="0,240,0,0" VerticalAlignment="Top" Width="75" Click="applyChanges"/> + <Label x:Name="lableStatusText" Content="" Margin="92,235,0,0" VerticalAlignment="Top" Foreground="#FF807F7F"/> </Grid> </Window> diff --git a/NucLedController/MainWindow.xaml.cs b/NucLedController/MainWindow.xaml.cs index c33c522..81f5a55 100644 --- a/NucLedController/MainWindow.xaml.cs +++ b/NucLedController/MainWindow.xaml.cs @@ -54,6 +54,12 @@ namespace NucLedController currentControlMode.Start(); lableStatusText.Content = "Colour fade mode enabled"; } + else if (radioButtonCPUUsage.IsChecked ?? false) + { + currentControlMode = new CPUUsageIndicatorControlMode(2000); //TODO make configurable + currentControlMode.Start(); + lableStatusText.Content = "CPU utilisation indicator mode enabled"; + } } else { diff --git a/NucLedController/NucLedController.csproj b/NucLedController/NucLedController.csproj index 88bf080..048a1b5 100644 --- a/NucLedController/NucLedController.csproj +++ b/NucLedController/NucLedController.csproj @@ -64,6 +64,7 @@ <SubType>Designer</SubType> </ApplicationDefinition> <Compile Include="BlinkColourCyclerControlMode.cs" /> + <Compile Include="CPUUsageIndicatorControlMode.cs" /> <Compile Include="FadeColourCyclerControlMode.cs" /> <Compile Include="IControlMode.cs" /> <Compile Include="LEDColour.cs" /> |