finished adding support for chroma devices
This commit is contained in:
		
							parent
							
								
									2cee3f4efc
								
							
						
					
					
						commit
						cd252ddca4
					
				
										
											Binary file not shown.
										
									
								
							@ -8,7 +8,12 @@ namespace RGBController2.Boards
 | 
			
		||||
{
 | 
			
		||||
    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,
 | 
			
		||||
            Keypad,
 | 
			
		||||
@ -17,23 +22,19 @@ namespace RGBController2.Boards
 | 
			
		||||
            Mouse
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool _connected;
 | 
			
		||||
        //private IChroma _device;
 | 
			
		||||
        public bool Connected
 | 
			
		||||
        {
 | 
			
		||||
            get { return _connected; }
 | 
			
		||||
        }
 | 
			
		||||
        private DeviceTypes _deviceType;
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
           // ConnectToDevice();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async void ConnectToDevice()
 | 
			
		||||
        {
 | 
			
		||||
          //  _device = await ColoreProvider.CreateNativeAsync();
 | 
			
		||||
            Connected = true;
 | 
			
		||||
            _deviceType = deviceType;
 | 
			
		||||
            // 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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@ -42,16 +43,28 @@ namespace RGBController2.Boards
 | 
			
		||||
        /// <param name="red">The red value</param>
 | 
			
		||||
        /// <param name="green">The green 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);
 | 
			
		||||
            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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@ using System.Windows;
 | 
			
		||||
using System.Xml;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using RGBController2.Boards;
 | 
			
		||||
 | 
			
		||||
namespace RGBController2.ViewModels
 | 
			
		||||
{
 | 
			
		||||
@ -126,6 +127,24 @@ namespace RGBController2.ViewModels
 | 
			
		||||
                                case "chroma":
 | 
			
		||||
                                    {
 | 
			
		||||
                                        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);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    }
 | 
			
		||||
@ -239,7 +258,7 @@ namespace RGBController2.ViewModels
 | 
			
		||||
                        xmlWriter.WriteString("chroma");
 | 
			
		||||
                        xmlWriter.WriteEndElement();
 | 
			
		||||
                        xmlWriter.WriteStartElement("device");
 | 
			
		||||
                        xmlWriter.WriteString("not used");
 | 
			
		||||
                        xmlWriter.WriteString(((ChromaDeviceTab)tab).SelectedDevice.ToString());
 | 
			
		||||
                        xmlWriter.WriteEndElement();
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,30 @@ namespace RGBController2.ViewModels.Tabs
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    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>
 | 
			
		||||
        /// Construcats a ChromaDeviecTabViewModel.
 | 
			
		||||
@ -24,20 +48,16 @@ namespace RGBController2.ViewModels.Tabs
 | 
			
		||||
            Name = name;
 | 
			
		||||
            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
 | 
			
		||||
            SelectedLightingMode = new InformationViewModel();
 | 
			
		||||
            OnPropertyChanged(nameof(SelectedLightingMode));
 | 
			
		||||
 | 
			
		||||
            // REMOVE ME - when fully impliment device selection
 | 
			
		||||
            EnableSelectLightingMode = true;
 | 
			
		||||
            OnPropertyChanged(nameof(EnableSelectLightingMode));
 | 
			
		||||
 | 
			
		||||
            // Set the availble devices in the GUI
 | 
			
		||||
            // For now we have no method of finding which chroma devices are connected
 | 
			
		||||
            // 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));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user