Colore icon indicating copy to clipboard operation
Colore copied to clipboard

Enhanced queries for connected devices

Open njbmartin opened this issue 9 years ago • 9 comments

Was just asked whether there was an easy way to get the following:

  • A list of all the devices connected
  • Easily query if a certain device type is connected (ie. keyboard, mouse etc.)

Right now, you can query a specific device with the following: Corale.Colore.Core.Chroma.Instance.Query(Corale.Colore.Razer.Devices.Tartarus).Connected

I'm proposing and plan to implement the following methods: Chroma.Instance.Query(Corale.Colore.Razer.DeviceType deviceType).Connected

Chroma.Instance.ConnectedDevices() which returns List<DeviceInfo>()

njbmartin avatar Jan 23 '16 17:01 njbmartin

Please let me know if you could suggest better methods.

njbmartin avatar Jan 23 '16 17:01 njbmartin

Just realised a better way to query a connected devicetype would be this:

Chroma.Instance.Headset.Connected

njbmartin avatar Jan 23 '16 17:01 njbmartin

There is some value to this change, but for keyboards, given the different layouts it may simplify the checks too much?

brandonscott avatar Jan 23 '16 17:01 brandonscott

@brandonscott That is true. For keyboards you may still have to query which device it is. However, lets say you separate out the logic per device type, or simply want to show / hide options based on connected types, then this would definitely be handy.

As for layouts, I personally think there should be a definition for each layout, as a few share the same and I'm sure more devices will in the future too. We would then have the ability to query as to which layout it is instead of individual devices.

example:

switch(Keyboard.Layout){
     case Razer.Keyboard.Layouts.Standard:
     // do something
     break;
     case Razer.Keyboard.Layouts.Mini:
     // do something else
}

We should raise this with Razer if we agree this would make beneficial to most.

njbmartin avatar Jan 24 '16 00:01 njbmartin

Also, if you wanted keyboard device specific code, you would currently have to do something like this:

function Connected(DeviceInfo d){
    return c.Query(d).Connected;
}

if(Connected(Razer.Devices.Blackwidow)){
    // Do something
}else if(Connected(Razer.Devices.BlackwidowTe)){
    // Do something else
}else if(Connected(Razer.Devices.Deathstalker)){
    // Do something very different
}

Could potentially be shortened to a switch statement:


switch(Keyboard.Instance.Device)){
    case Razer.Devices.Deathstalker:
        // Do something
    break;
    case Razer.Devices.BlackwidowTe:
        // Do something else
    break;
    case Razer.Devices.Deathstalker:
        // Do something
    break;
    default:
        // Keyboard.Instance.Device.None for none connected.
}

It just feels cleaner.

Granted, in the rare case someone may have two of the same devices / device types connected.

njbmartin avatar Jan 24 '16 00:01 njbmartin

Granted, in the rare case someone may have two of the same devices / device types connected.

This is the big issue with having a Layout property. The Keyboard class doesn't represent a single device with its own layout, it represents every (Chroma) keyboard device connected to the system and method calls to it will affect every connected device of the applicable type.

IIRC we raised this issue with Razer before regarding detecting different physical layouts and their response was basically "Nope, we just expect everyone to only ever have a single of any possible device type connected.".

Sharparam avatar Jan 24 '16 12:01 Sharparam

Ok, so having created a new method for listing the connected devices, which is just a simple List<Devices>(), seems we should also add the Device Name to DeviceInfo.

njbmartin avatar May 08 '16 19:05 njbmartin

Or at least attach the Guid.

njbmartin avatar May 08 '16 19:05 njbmartin

_devices = new Dictionary<Guid, DeviceInfo>(); this is the easiest solution specifically for the list of connected devices.

DeviceInfo alone contains no reference to the device itself.

njbmartin avatar May 09 '16 08:05 njbmartin