RGBController/RGBController2/ViewModels/Tabs/CUEDeviceTab.cs

80 lines
2.7 KiB
C#
Raw Normal View History

2020-10-27 20:07:26 +00:00
using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
using RGBController2.Boards;
using System.ComponentModel;
using RGBController2.ViewModels.LightingModes;
using CUE.NET.Devices.Generic.Enums;
namespace RGBController2.ViewModels.Tabs
{
public class CueDeviceTab : Tab, INotifyPropertyChanged
{
2020-11-08 13:08:52 +00:00
/// <summary>
/// An array of the available CUE Devices
/// Use for the items of the combo box
/// </summary>
2020-10-27 20:07:26 +00:00
private CorsairDeviceType[] _availableDevices;
public CorsairDeviceType[] AvailableDevices
{
get { return _availableDevices; }
}
2020-11-08 13:08:52 +00:00
/// <summary>
/// The selected index of the combo box.
/// </summary>
2020-10-27 20:07:26 +00:00
private CorsairDeviceType _selectedDevice;
public CorsairDeviceType SelectedDevice
{
get { return _selectedDevice; }
set
{
if (value != _selectedDevice)
{
_selectedDevice = value;
2020-10-27 20:07:26 +00:00
// Connect to the device
2020-11-08 13:08:52 +00:00
((CUEDeviceBoard)_device).ConnectToDevice(value);
if (_device.Connected)
2020-10-27 20:07:26 +00:00
{
ConnectionStatus = "Device Connected";
2020-11-08 13:08:52 +00:00
EnableSelectLightingMode = true;
2020-10-27 20:07:26 +00:00
// Set the page to static lighting mode to allow the user to change the
// lighting mode now that we are connected to the CUE Device
2020-11-08 13:08:52 +00:00
SelectedLightingMode = new StaticViewModel(_device);
2020-10-27 20:07:26 +00:00
OnPropertyChanged(nameof(SelectedLightingMode));
}
else
2020-11-08 13:08:52 +00:00
{
2020-10-27 20:07:26 +00:00
ConnectionStatus = "Failed to connect to device";
2020-11-08 13:08:52 +00:00
EnableSelectLightingMode = false;
}
2020-10-27 20:07:26 +00:00
OnPropertyChanged(nameof(ConnectionStatus));
2020-11-08 13:08:52 +00:00
OnPropertyChanged(nameof(EnableSelectLightingMode));
2020-10-27 20:07:26 +00:00
}
}
}
2020-11-08 13:08:52 +00:00
/// <summary>
/// Creates a tab for a CUE device.
/// </summary>
/// <param name="name">The name of the tab header.</param>
2020-10-27 20:07:26 +00:00
public CueDeviceTab(string name)
{
TabType = tabType.CUE;
Name = name;
ConnectionStatus = "Device Disconnected";
// Create the device object
2020-11-08 13:08:52 +00:00
_device = new CUEDeviceBoard();
2020-10-27 20:07:26 +00:00
// Get a list of the available cue devices
2020-11-08 13:08:52 +00:00
_availableDevices = ((CUEDeviceBoard)_device).AvailableDevices;
2020-10-27 20:07:26 +00:00
// This is a temporary viewmodel that is used before the user has connected to a device
2020-11-08 13:08:52 +00:00
SelectedLightingMode = new InformationViewModel();
2020-10-27 20:07:26 +00:00
}
}
}