private async void BeginPoll()
{
try
{
if (!this.IsValid)
{
return;
}
this.IsPolling = true;
Label_007E:
if (this.cts.IsCancellationRequested)
{
return;
}
this._joystick.Poll();
BufferedDataCollection bufferedData = this._joystick.GetBufferedData();
if (bufferedData != null)
{
IEnumerator enumerator = bufferedData.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
BufferedData current = (BufferedData) enumerator.Current;
if (current.ButtonPressedData == 1)
{
int button = Array.FindIndex<byte>(this.Buttons, b => b != 0);
if (button == -1)
{
continue;
}
this.OnButtonPressed(button);
goto Label_03F5;
}
if (current.ButtonPressedData == 0)
{
if (this.LeftStickX > 0xafc8)
{
this.OnDirectionChanged("right");
await Task.Delay(250);
}
else if (this.LeftStickX < 0x4a38)
{
this.OnDirectionChanged("left");
await Task.Delay(250);
}
if (this.LeftStickY > 0xafc8)
{
this.OnDirectionChanged("down");
await Task.Delay(250);
continue;
}
if (this.LeftStickY < 0x4a38)
{
this.OnDirectionChanged("up");
await Task.Delay(250);
}
}
}
}
finally
{
IDisposable asyncVariable1;
asyncVariable1 = enumerator as IDisposable;
if (asyncVariable1 != null)
{
asyncVariable1.Dispose();
}
}
}
Label_03F5:
if (this._joystick != null)
{
switch (this.DirectionalButtons[0])
{
case 0:
this.OnDirectionChanged("up");
await Task.Delay(250);
break;
case 0x2328:
this.OnDirectionChanged("right");
await Task.Delay(250);
break;
case 0x4650:
this.OnDirectionChanged("down");
await Task.Delay(250);
break;
case 0x6978:
this.OnDirectionChanged("left");
await Task.Delay(250);
break;
}
}
goto Label_007E;
}
catch (Exception exception)
{
this.IsPolling = false;
Console.WriteLine(exception.Message);
}
}