예제 #1
0
        private void ListenLoop()
        {
            while (!_isStopRequested)
            {
                if (Joystick == null)
                {
                    return;
                }
                Thread.Sleep(10);//give CPU back

                //if exception due to lost device, then break out of loop so the user can refresh the device list and start over
                Joystick.Poll();
                JoystickUpdate[] data = { };
                try
                {
                    data = Joystick.GetBufferedData();
                }
                catch (Exception e)
                {
                    Logging.Log.Info($"Stopping in HOTAS Queue ListenLoop: {e}");
                    _actionJobs.CompleteAdding();
                    _isStopRequested = true;
                    LostConnectionToDevice?.Invoke(this, EventArgs.Empty);
                }

                foreach (var state in data)
                {
                    var offset = (JoystickOffset)state.Offset;
                    if (offset >= JoystickOffset.Button1 && offset <= JoystickOffset.Button128)
                    {
                        Logging.Log.Debug($"Offset:{offset}({state.RawOffset}), Seq:{state.Sequence}, Value:{state.Value}");
                        HandleStandardButton((int)offset, state.Value);
                        continue;
                    }

                    if (offset == JoystickOffset.POV1 ||
                        offset == JoystickOffset.POV2 ||
                        offset == JoystickOffset.POV3 ||
                        offset == JoystickOffset.POV4)
                    {
                        Logging.Log.Debug($"Offset:{offset}({state.RawOffset}), POV:{TranslatePointOfViewOffset(offset, state.Value)}, Seq:{state.Sequence}, Value:{state.Value}");
                        HandlePovButton((JoystickOffset)state.Offset, state.Value);
                        continue;
                    }

                    if (offset == JoystickOffset.X ||
                        offset == JoystickOffset.Y ||
                        offset == JoystickOffset.Z ||
                        offset == JoystickOffset.RX ||
                        offset == JoystickOffset.RY ||
                        offset == JoystickOffset.RZ ||
                        offset == JoystickOffset.Slider1 ||
                        offset == JoystickOffset.Slider2
                        )
                    {
                        if (!_jitterDetectionDictionary.ContainsKey(state.RawOffset))
                        {
                            _jitterDetectionDictionary.Add(state.RawOffset, new JitterDetection());
                        }
                        if (_jitterDetectionDictionary[state.RawOffset].IsJitter(state.Value))
                        {
                            continue;
                        }

                        HandleAxis(state);
                        OnAxisChanged(state);
                        continue;
                    }
                }
            }
        }
예제 #2
0
 private void Device_LostConnectionToDevice(object sender, LostConnectionToDeviceEventArgs e)
 {
     LostConnectionToDevice?.Invoke(sender, e);
 }
예제 #3
0
 private void OnLostConnectionToDevice(object sender, EventArgs e)
 {
     Joystick     = null;
     Capabilities = null;
     LostConnectionToDevice?.Invoke(sender, new LostConnectionToDeviceEventArgs(this));
 }