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/MainWindow.xaml.cs | 55 +++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'NucLedController/MainWindow.xaml.cs') 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 /// 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) { -- cgit v1.2.3