using RGBController2.Commands; using System.Windows; using System.Windows.Input; using RGBController2.Boards; using System.Windows.Media; namespace RGBController2.ViewModels.LightingModes { /// /// The view model for the StaticView. /// public class StaticViewModel : BaseViewModel { /// /// The Numericelector value for the red colour. /// private int _redColourSend; public int RedColourSend { get { return _redColourSend; } set { _redColourSend = value; UpdateSendColour(); } } /// /// The Numericelector value for the green colour. /// private int _greenColourSend; public int GreenColourSend { get { return _greenColourSend; } set { _greenColourSend = value; UpdateSendColour(); } } /// /// The Numericelector value for the blue colour. /// private int _blueColourSend; public int BlueColourSend { get { return _blueColourSend; } set { _blueColourSend = value; UpdateSendColour(); } } /// /// The label value for the red current colour. /// private int _redColourCurrent; public int RedColourCurrent { get { return _redColourCurrent; } set { _redColourCurrent = value; } } /// /// The label value for the blue current colour. /// private int _blueColourCurrent; public int BlueColourCurrent { get { return _blueColourCurrent; } set { _blueColourCurrent = value; } } /// /// The label value for the green current colour. /// private int _greenColourCurrent; public int GreenColourCurrent { get { return _greenColourCurrent; } set { _greenColourCurrent = value; } } /// /// The colour used for the current colour box. /// private SolidColorBrush _colourCurrent; public SolidColorBrush ColourCurrent { get { return _colourCurrent; } set { _colourCurrent = value; } } /// /// The colour used for the send colour box. /// private SolidColorBrush _colourSend; public SolidColorBrush ColourSend { get { return _colourSend; } set { _colourSend = value; } } /// /// The command used for the send button. /// public ICommand SendCommand { get; set; } /// /// The board which the class instance will control. /// private IBoard _ledBoard; /// /// Constructor for the StaticViewModel. /// /// The led device which this StaticView will control. public StaticViewModel(IBoard ledBoard) { SendCommand = new ActionCommand(o => SendButtonClick("SenderButton")); // Default values RedColourSend = 0; GreenColourSend = 255; BlueColourSend = 255; RedColourCurrent = RedColourSend; GreenColourCurrent = GreenColourSend; BlueColourCurrent = BlueColourSend; ColourCurrent = new SolidColorBrush(Color.FromRgb((byte)RedColourSend, (byte)GreenColourSend, (byte)BlueColourSend)); ColourSend = new SolidColorBrush(Color.FromRgb((byte)RedColourSend, (byte)GreenColourSend, (byte)BlueColourSend)); // This is here to allow us to interface with the board stored in the MainViewModel // ideally this would involved pointers but C# does not seem to like pointers _ledBoard = ledBoard; // ToDo load from previous values } /// /// Helper function used to update the colour of the send colour box. /// private void UpdateSendColour() { ColourSend = new SolidColorBrush(Color.FromRgb((byte)RedColourSend, (byte)GreenColourSend, (byte)BlueColourSend)); OnPropertyChanged(nameof(ColourSend)); } /// /// The call back function for the send button. /// /// private void SendButtonClick(object sender) { if (_ledBoard != null) if (_ledBoard.Connected) { _ledBoard.SetAllLeds((byte)RedColourSend, (byte)GreenColourSend, (byte)BlueColourSend); RedColourCurrent = RedColourSend; GreenColourCurrent = GreenColourSend; BlueColourCurrent = BlueColourSend; ColourCurrent = new SolidColorBrush(Color.FromRgb((byte)RedColourSend, (byte)GreenColourSend, (byte)BlueColourSend)); OnPropertyChanged(nameof(RedColourCurrent)); OnPropertyChanged(nameof(GreenColourCurrent)); OnPropertyChanged(nameof(BlueColourCurrent)); OnPropertyChanged(nameof(ColourCurrent)); } else MessageBox.Show("Error - The device has disconnected"); else MessageBox.Show("Error - No device is connected"); } } }