aboutsummaryrefslogtreecommitdiff
path: root/NucLedController/MainWindow.xaml.cs
blob: c33c52222ca0703c5264da366ef75e3b3e90ac74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Diagnostics;
using System.Linq;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace NucLedController
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private IControlMode currentControlMode = null;

        public MainWindow()
        {
            InitializeComponent();
            comboBoxColour.ItemsSource = LEDColour.AvailableColours;
            comboBoxColour.DisplayMemberPath = "DisplayName";
            comboBoxColour.SelectedIndex = 0;
            comboBoxTransition.ItemsSource = LEDTransition.AvailableTransitions;
            comboBoxTransition.DisplayMemberPath = "DisplayName";
            comboBoxTransition.SelectedIndex = 0;

        }

        private void applyChanges(object sender, RoutedEventArgs e)
        {

            try
            {

                // 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 (radioButtonFadeColour.IsChecked ?? false)
                    {
                        currentControlMode = new FadeColourCyclerControlMode((int) sliderFadeRate.Value);
                        currentControlMode.Start();
                        lableStatusText.Content = "Colour fade 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)
            {
                MessageBox.Show($"Error setting LED: {ex.Message.ToString()}", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

        }

    }
}