finished adding support for chroma devices

This commit is contained in:
Conor 2020-11-08 13:45:24 +00:00
parent 2cee3f4efc
commit cd252ddca4
5 changed files with 87 additions and 35 deletions

Binary file not shown.

View File

@ -8,7 +8,12 @@ namespace RGBController2.Boards
{ {
public class ChromaDeviceBoard : IBoard public class ChromaDeviceBoard : IBoard
{ {
enum deviceTypes /// <summary>
/// True is communication has been established with the Arduino, false otherwise.
/// </summary>
public bool Connected { get; }
public enum DeviceTypes
{ {
Mousepad, Mousepad,
Keypad, Keypad,
@ -17,23 +22,19 @@ namespace RGBController2.Boards
Mouse Mouse
} }
private bool _connected; private DeviceTypes _deviceType;
//private IChroma _device;
public bool Connected
{
get { return _connected; }
}
public ChromaDeviceBoard() /// <summary>
/// Constructs a ChromaDeviceBoard for controlling a Chroma device.
/// </summary>
/// <param name="deviceType">The type of the chroma device to control.</param>
public ChromaDeviceBoard(DeviceTypes deviceType)
{ {
// ToDo add device type selection here Connected = true;
_connected = true; _deviceType = deviceType;
// ConnectToDevice(); // This is here because the device needs to be initilised by the first call
} // This won't actually set the colour
SetAllLeds(255, 255, 255);
public async void ConnectToDevice()
{
// _device = await ColoreProvider.CreateNativeAsync();
} }
/// <summary> /// <summary>
@ -42,16 +43,28 @@ namespace RGBController2.Boards
/// <param name="red">The red value</param> /// <param name="red">The red value</param>
/// <param name="green">The green value</param> /// <param name="green">The green value</param>
/// <param name="blue">The blue value</param> /// <param name="blue">The blue value</param>
public async void SetAllLeds(byte red, byte green, byte blue) public void SetAllLeds(byte red, byte green, byte blue)
{ {
//if (_device.Initialized)
//{
// var colour = new ColoreColor((byte)red, (byte)green, (byte)blue);
// await _device.Mouse.SetAllAsync(colour);
//}
var colour = new ColoreColor((byte)red, (byte)green, (byte)blue); var colour = new ColoreColor((byte)red, (byte)green, (byte)blue);
Chroma.Instance.SetAll(colour);
}
switch (_deviceType)
{
case DeviceTypes.Mousepad:
Chroma.Instance.Mousepad.SetAll(colour);
break;
case DeviceTypes.Mouse:
Chroma.Instance.Mouse.SetAll(colour);
break;
case DeviceTypes.Keypad:
Chroma.Instance.Keypad.SetAll(colour);
break;
case DeviceTypes.Keyboard:
Chroma.Instance.Keyboard.SetAll(colour);
break;
case DeviceTypes.Headset:
Chroma.Instance.Headset.SetAll(colour);
break;
}
}
} }
} }

View File

@ -11,6 +11,7 @@ using System.Windows;
using System.Xml; using System.Xml;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using RGBController2.Boards;
namespace RGBController2.ViewModels namespace RGBController2.ViewModels
{ {
@ -126,6 +127,24 @@ namespace RGBController2.ViewModels
case "chroma": case "chroma":
{ {
var tab = new ChromaDeviceTab(name); var tab = new ChromaDeviceTab(name);
switch (device)
{
case "Mousepad":
tab.SelectedDevice = ChromaDeviceBoard.DeviceTypes.Mousepad;
break;
case "Keypad":
tab.SelectedDevice = ChromaDeviceBoard.DeviceTypes.Keypad;
break;
case "Headset":
tab.SelectedDevice = ChromaDeviceBoard.DeviceTypes.Headset;
break;
case "Keyboard":
tab.SelectedDevice = ChromaDeviceBoard.DeviceTypes.Keyboard;
break;
case "Mouse":
tab.SelectedDevice = ChromaDeviceBoard.DeviceTypes.Mouse;
break;
}
_tabs.Add(tab); _tabs.Add(tab);
break; break;
} }
@ -239,7 +258,7 @@ namespace RGBController2.ViewModels
xmlWriter.WriteString("chroma"); xmlWriter.WriteString("chroma");
xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("device"); xmlWriter.WriteStartElement("device");
xmlWriter.WriteString("not used"); xmlWriter.WriteString(((ChromaDeviceTab)tab).SelectedDevice.ToString());
xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement();
break; break;
} }

View File

@ -13,6 +13,30 @@ namespace RGBController2.ViewModels.Tabs
/// </summary> /// </summary>
public class ChromaDeviceTab : Tab, INotifyPropertyChanged public class ChromaDeviceTab : Tab, INotifyPropertyChanged
{ {
private ChromaDeviceBoard.DeviceTypes[] _availableDevices;
public ChromaDeviceBoard.DeviceTypes[] AvailableDevices
{
get { return _availableDevices; }
}
private ChromaDeviceBoard.DeviceTypes _selectedDevice;
public ChromaDeviceBoard.DeviceTypes SelectedDevice
{
get { return _selectedDevice; }
set
{
if (value != _selectedDevice)
{
_selectedDevice = value;
EnableSelectLightingMode = true;
OnPropertyChanged(nameof(EnableSelectLightingMode));
_device = new ChromaDeviceBoard(value);
SelectedLightingMode = new StaticViewModel(_device);
OnPropertyChanged(nameof(SelectedLightingMode));
}
}
}
/// <summary> /// <summary>
/// Construcats a ChromaDeviecTabViewModel. /// Construcats a ChromaDeviecTabViewModel.
@ -24,20 +48,16 @@ namespace RGBController2.ViewModels.Tabs
Name = name; Name = name;
ConnectionStatus = "Device Disconnected"; ConnectionStatus = "Device Disconnected";
// Create the device object
_device = new ChromaDeviceBoard();
// Get a list of the available cue devices
//_availableDevices = ((CUEDeviceBoard)_device).AvailableDevices;
// This is a temporary viewmodel that is used before the user has connected to a device // This is a temporary viewmodel that is used before the user has connected to a device
SelectedLightingMode = new InformationViewModel(); SelectedLightingMode = new InformationViewModel();
OnPropertyChanged(nameof(SelectedLightingMode)); OnPropertyChanged(nameof(SelectedLightingMode));
// REMOVE ME - when fully impliment device selection // Set the availble devices in the GUI
EnableSelectLightingMode = true; // For now we have no method of finding which chroma devices are connected
OnPropertyChanged(nameof(EnableSelectLightingMode)); // So we will give the user a choice of all of them
_availableDevices = new ChromaDeviceBoard.DeviceTypes[] {ChromaDeviceBoard.DeviceTypes.Headset, ChromaDeviceBoard.DeviceTypes.Keyboard, ChromaDeviceBoard.DeviceTypes.Keypad,
ChromaDeviceBoard.DeviceTypes.Mouse, ChromaDeviceBoard.DeviceTypes.Mousepad};
OnPropertyChanged(nameof(AvailableDevices));
} }
} }