Пример #1
0
        public bool Stop(int controllerCount)
        {
            if (!HasDevice)
            {
                return(false);
            }
            bool result = xOutputDevice.Unplug(controllerCount);

            if (result)
            {
                Controllers.Instance.DisposeId(controllerCount);
            }
            return(result);
        }
Пример #2
0
 /// <summary>
 /// Stops the emulation of the device
 /// </summary>
 public void Stop()
 {
     if (running)
     {
         running              = false;
         XInput.InputChanged -= XInputInputChanged;
         if (ForceFeedbackSupported)
         {
             controller.FeedbackReceived -= ControllerFeedbackReceived;
             logger.Info($"Force feedback mapping is disconnected on {ToString()}.");
         }
         xOutputInterface?.Unplug(controllerCount);
         logger.Info($"Emulation stopped on {ToString()}.");
         resetId();
         thread?.Abort();
     }
 }
Пример #3
0
 /// <summary>
 /// Starts the emulation of the device
 /// </summary>
 public int Start(Action onStop = null)
 {
     if (!HasXOutputInstalled)
     {
         return(0);
     }
     controllerCount = Controllers.Instance.GetId();
     if (controller != null)
     {
         controller.FeedbackReceived -= ControllerFeedbackReceived;
     }
     if (xOutputInterface.Unplug(controllerCount))
     {
         // Wait for unplugging
         Thread.Sleep(10);
     }
     if (xOutputInterface.Plugin(controllerCount))
     {
         thread = ThreadHelper.CreateAndStart(new ThreadStartParameters {
             Name         = $"Emulated controller {controllerCount} output refresher",
             IsBackground = true,
             Task         = () => ReadAndReportValues(onStop),
             Error        = (ex) => {
                 logger.Error("Failed to read from device", ex);
                 Stop();
             },
             Finally = onStop,
         });
         running = true;
         logger.Info($"Emulation started on {ToString()}.");
         if (ForceFeedbackSupported)
         {
             logger.Info($"Force feedback mapping is connected on {ToString()}.");
             controller = ((VigemDevice)xOutputInterface).GetController(controllerCount);
             controller.FeedbackReceived += ControllerFeedbackReceived;
         }
     }
     else
     {
         resetId();
     }
     return(controllerCount);
 }
Пример #4
0
 /// <summary>
 /// Starts the emulation of the device
 /// </summary>
 public int Start(Action onStop = null)
 {
     if (!HasXOutputInstalled)
     {
         return(0);
     }
     controllerCount = controllers.GetId();
     if (controller != null)
     {
         controller.FeedbackReceived -= ControllerFeedbackReceived;
     }
     if (xOutputInterface.Unplug(controllerCount))
     {
         // Wait for unplugging
         Thread.Sleep(10);
     }
     if (xOutputInterface.Plugin(controllerCount))
     {
         thread              = new Thread(() => ReadAndReportValues(onStop));
         running             = true;
         thread.Name         = $"Emulated controller {controllerCount} output refresher";
         thread.IsBackground = true;
         thread.Start();
         logger.Info($"Emulation started on {ToString()}.");
         if (ForceFeedbackSupported)
         {
             logger.Info($"Force feedback mapping is connected on {ToString()}.");
             controller = ((VigemDevice)xOutputInterface).GetController(controllerCount);
             controller.FeedbackReceived += ControllerFeedbackReceived;
         }
     }
     else
     {
         resetId();
     }
     return(controllerCount);
 }