public void OnTick() {
try {
if (_joystick.Acquire().IsFailure || _joystick.Poll().IsFailure || SlimDX.Result.Last.IsFailure) {
return;
}
var state = _joystick.GetCurrentState();
var i = 0;
foreach (var source in state.GetButtons().Take(_buttonsCount)) {
Buttons[i++].Value = source;
}
i = 0;
var sliders = state.GetSliders();
foreach (var source in new [] {
state.X, state.Y, state.Z,
state.RotationX, state.RotationY, state.RotationZ,
sliders[0], sliders[1]
}) {
Axles[i++].Value = source / 65535d;
}
} catch (DirectInputException e) when(e.Message.Contains(@"DIERR_UNPLUGGED")) {
Unplugged = true;
} catch (DirectInputException e) {
if (!Error){
Logging.Warning("Exception: " + e);
Error = true;
}
}
}