예제 #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);
     }
     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);
 }
예제 #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              = 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);
 }