RGBController/RGBController2/ViewModels/LightingModes/StaticViewModel.cs

135 lines
4.3 KiB
C#

using RGBController2.Commands;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Input;
using RGBController2.Boards;
using System.Windows.Media;
namespace RGBController2.ViewModels.LightingModes
{
public class StaticViewModel : BaseViewModel
{
private int _redColourSend;
public int RedColourSend
{
get { return _redColourSend; }
set
{
_redColourSend = value;
UpdateSendColour();
}
}
private int _greenColourSend;
public int GreenColourSend
{
get { return _greenColourSend; }
set
{
_greenColourSend = value;
UpdateSendColour();
}
}
private int _blueColourSend;
public int BlueColourSend
{
get { return _blueColourSend; }
set
{
_blueColourSend = value;
UpdateSendColour();
}
}
private int _redColourCurrent;
public int RedColourCurrent
{
get { return _redColourCurrent; }
set { _redColourCurrent = value; }
}
private int _blueColourCurrent;
public int BlueColourCurrent
{
get { return _blueColourCurrent; }
set { _blueColourCurrent = value; }
}
private int _greenColourCurrent;
public int GreenColourCurrent
{
get { return _greenColourCurrent; }
set { _greenColourCurrent = value; }
}
private SolidColorBrush _colourCurrent;
public SolidColorBrush ColourCurrent
{
get { return _colourCurrent; }
set { _colourCurrent = value; }
}
private SolidColorBrush _colourSend;
public SolidColorBrush ColourSend
{
get { return _colourSend; }
set { _colourSend = value; }
}
public ICommand SendCommand { get; set; }
private IBoard _ledBoard;
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
}
private void UpdateSendColour()
{
ColourSend = new SolidColorBrush(Color.FromRgb((byte)RedColourSend, (byte)GreenColourSend, (byte)BlueColourSend));
OnPropertyChanged(nameof(ColourSend));
}
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");
}
}
}