Example #1
0
        private void OnNewJoyCon(IJoyCon joyCon)
        {
            Logger.Info("New JoyCon " + joyCon);

            JoyConPlayer?player = JoyConPlayer.First;

            while (player != null)
            {
                if (_virtualJoystickDict.Values.Any(vjoy => vjoy.DeviceId == (uint)player))
                {
                    player = player.Value.Next();
                    continue;
                }

                var virtualJoystick = new VirtualJoystick((uint)player.Value,
                                                          joyCon is JoyCon ? VJoyDeviceProfile.Small : VJoyDeviceProfile.Full);
                if (virtualJoystick.UsageState != UsageState.Free)
                {
                    virtualJoystick.Dispose();
                    player = player.Value.Next();
                    continue;
                }

                Logger.Debug(">>> Register JoyCon as " + (uint)player.Value);

                joyCon.DataUpdated += OnJoyConDataUpdate;
                joyCon.Acquire(player.Value);

                virtualJoystick.Aquire();
                _virtualJoystickDict.Add(joyCon, virtualJoystick);

                break;
            }

            if (player == null)
            {
                Logger.Warn(">>> Cannot register JoyCon: Not enought VJoy Controller found (max. 4)");
                joyCon.SetupLeds(JoyConSingleLed.Flash, JoyConSingleLed.Off, JoyConSingleLed.Off,
                                 JoyConSingleLed.Flash);
            }
        }