Пример #1
0
 /// <summary>
 /// Starts the emulation of the device
 /// </summary>
 public int Start(Action onStop = null)
 {
     if (!HasXOutputInstalled)
     {
         return(0);
     }
     if (controller != null)
     {
         controller.FeedbackReceived -= ControllerFeedbackReceived;
     }
     if (xOutputManager.Stop(controllerCount))
     {
         // Wait for unplugging
         Thread.Sleep(10);
     }
     controllerCount = xOutputManager.Start();
     if (controllerCount != 0)
     {
         threadContext = ThreadCreator.Create($"Emulated controller {controllerCount} output refresher", token => ReadAndReportValues(token, onStop)).Start();
         running       = true;
         logger.Info($"Emulation started on {ToString()}.");
         if (ForceFeedbackSupported)
         {
             logger.Info($"Force feedback mapping is connected on {ToString()}.");
             controller = ((VigemDevice)xOutputManager.XOutputDevice).GetController(controllerCount);
             controller.FeedbackReceived += ControllerFeedbackReceived;
         }
     }
     return(controllerCount);
 }
Пример #2
0
 /// <summary>
 /// Starts the emulation of the device
 /// </summary>
 public int Start(Action onStop = null)
 {
     if (!HasXOutputInstalled)
     {
         return(0);
     }
     if (controller != null)
     {
         controller.FeedbackReceived -= ControllerFeedbackReceived;
     }
     if (xOutputManager.Stop(controllerCount))
     {
         // Wait for unplugging
         Thread.Sleep(10);
     }
     controllerCount = xOutputManager.Start();
     if (controllerCount != 0)
     {
         thread = ThreadHelper.CreateAndStart(new ThreadStartParameters {
             Name         = $"Emulated controller {controllerCount} output refresher",
             IsBackground = true,
             Task         = () => ReadAndReportValues(),
             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)xOutputManager.XOutputDevice).GetController(controllerCount);
             controller.FeedbackReceived += ControllerFeedbackReceived;
         }
     }
     return(controllerCount);
 }
Пример #3
0
 public void Stop()
 {
     if (running)
     {
         running              = false;
         XInput.InputChanged -= XInputInputChanged;
         client.Feedback     -= FeedbackReceived;
         logger.Info($"Force feedback mapping is disconnected on {ToString()}.");
         xOutputManager.Stop(client);
         logger.Info($"Emulation stopped on {ToString()}.");
         if (threadContext != null)
         {
             threadContext.Cancel().Wait();
         }
     }
 }