private void setHandlePos() { var buttonsState = JoystickApi.GetButtonsState(); if (InputTranslator.TranslateNotchPosition(buttonsState, out _handlePos)) { return; } var isNotchIntermediateEstimated = false; // Problem between P1 and P2 // https://twitter.com/SanYingOfficial/status/1088429762698129408 // // P5 may be output when the notch is between P1 and P2. // This is an unintended output and should be excluded. if (_handlePos == 5) { if (_lastHandlePos == 1) { isNotchIntermediateEstimated = true; } else if (_lastHandlePos == 2) { isNotchIntermediateEstimated = true; } } if (!isNotchIntermediateEstimated) { for (int i = 0; i < 16; i++) { OnKeyUp(new InputEventArgs(Controls[i])); } if (_handlePos != _lastHandlePos) { if (_handlePos <= 0) { OnKeyDown(new InputEventArgs(Controls[_handlePos + 9])); } if (_handlePos >= 0) { OnKeyDown(new InputEventArgs(Controls[_handlePos + 10])); } } } _lastHandlePos = _handlePos; }
private void setReverserPos() { var axises = JoystickApi.GetAxises(); InputTranslator.TranslateReverserPosition(axises, out _reverserPos); for (int i = 16; i < 19; i++) { OnKeyUp(new InputEventArgs(Controls[i])); } if (_reverserPos != _lastReverserPos) { OnKeyDown(new InputEventArgs(Controls[17 - _reverserPos])); } _lastReverserPos = _reverserPos; }
private void timer1_Tick(object sender, EventArgs e) { JoystickApi.Update(); if (JoystickApi.currentDevice != -1) { var buttonsState = JoystickApi.GetButtonsState(); var axises = JoystickApi.GetAxises(); int lastNotchPosition = _notchPosition; if (InputTranslator.TranslateNotchPosition(buttonsState, out _notchPosition)) { _notchPosition = lastNotchPosition; } InputTranslator.TranslateReverserPosition(axises, out _reverserPosition); { uint notchButtonsState; InputTranslator.MakeBitFromNotchButtons(buttonsState, out notchButtonsState); txtInfoBt7.Text = ((notchButtonsState & (uint)InputTranslator.BT7_10_Pressed.BT7) != 0) ? "1" : "0"; txtInfoBt8.Text = ((notchButtonsState & (uint)InputTranslator.BT7_10_Pressed.BT8) != 0) ? "1" : "0"; txtInfoBt9.Text = ((notchButtonsState & (uint)InputTranslator.BT7_10_Pressed.BT9) != 0) ? "1" : "0"; txtInfoBt10.Text = ((notchButtonsState & (uint)InputTranslator.BT7_10_Pressed.BT10) != 0) ? "1" : "0"; } { if (_reverserPosition > 0) { txtInfoUp.Text = "1"; txtInfoDown.Text = "0"; } else if (_reverserPosition < 0) { txtInfoUp.Text = "0"; txtInfoDown.Text = "1"; } else { txtInfoUp.Text = "0"; txtInfoDown.Text = "0"; } } string notchPositionString; string reverserPositionString; if (_notchPosition > 0) { notchPositionString = string.Format("P{0}", _notchPosition); } else if (_notchPosition < 0) { if (_notchPosition > -9) { notchPositionString = string.Format("B{0}", _notchPosition); } else { notchPositionString = "EB"; } } else { notchPositionString = "N"; } if (_reverserPosition > 0) { reverserPositionString = "F"; } else if (_reverserPosition < 0) { reverserPositionString = "B"; } else { reverserPositionString = "N"; } labelTch.Text = notchPositionString; labelReverser.Text = reverserPositionString; configurateSwitch(); } else { enumerateDevices(); } }