mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-02 05:54:20 +01:00
df43fd0d74
I kinda just felt like doing it :P wanted to test myself, trying to make a cleaner UI
42 lines
1018 B
C#
42 lines
1018 B
C#
using System;
|
|
using System.Threading;
|
|
|
|
namespace HidLibrary
|
|
{
|
|
internal class HidDeviceEventMonitor
|
|
{
|
|
public event RemovedEventHandler Removed;
|
|
|
|
public delegate void InsertedEventHandler();
|
|
public delegate void RemovedEventHandler();
|
|
|
|
private readonly HidDevice _device;
|
|
|
|
public HidDeviceEventMonitor(HidDevice device)
|
|
{
|
|
_device = device;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
var eventMonitor = new Action(DeviceEventMonitor);
|
|
eventMonitor.BeginInvoke(DisposeDeviceEventMonitor, eventMonitor);
|
|
}
|
|
|
|
private void DeviceEventMonitor()
|
|
{
|
|
_device.Tick();
|
|
if (_device.IsTimedOut && Removed != null)
|
|
Removed();
|
|
|
|
Thread.Sleep(500);
|
|
if (_device.MonitorDeviceEvents) Init();
|
|
}
|
|
|
|
private static void DisposeDeviceEventMonitor(IAsyncResult ar)
|
|
{
|
|
((Action)ar.AsyncState).EndInvoke(ar);
|
|
}
|
|
}
|
|
}
|