Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        private void setSwitchState()
        {
            if (JoystickApi.currentDevice == -1)
            {
                return;
            }

            var currentButtonState = JoystickApi.GetButtonsState();
            int buttonNum          = 6;

            if (currentButtonState.Count < buttonNum || JoystickApi.lastButtonState.Count < buttonNum)
            {
                return;
            }

            for (int i = 0; i < buttonNum; ++i)
            {
                if (currentButtonState[i] != JoystickApi.lastButtonState[i])
                {
                    if (currentButtonState[i] == OpenTK.Input.ButtonState.Pressed)
                    {
                        int keyIdx = getKeyIdx(i);
                        if (keyIdx != -1)
                        {
                            OnKeyDown(new InputEventArgs(Controls[keyIdx]));
                        }
                    }
                    else if (currentButtonState[i] == OpenTK.Input.ButtonState.Released)
                    {
                        int keyIdx = getKeyIdx(i);
                        if (keyIdx != -1)
                        {
                            OnKeyUp(new InputEventArgs(Controls[keyIdx]));
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        private void configurateSwitch()
        {
            int buttonNum = 6;

            var currentButtonState = JoystickApi.GetButtonsState();

            if (currentButtonState.Count < buttonNum)
            {
                return;
            }

            if (JoystickApi.lastButtonState.Count < buttonNum)
            {
                return;
            }

            for (int i = 0; i < buttonNum; ++i)
            {
                if (currentButtonState[i] != JoystickApi.lastButtonState[i])
                {
                    if (txtSwS.Focused)
                    {
                        txtSwS.Text = toSwitchString(i);
                    }
                    else if (txtSwA1.Focused)
                    {
                        txtSwA1.Text = toSwitchString(i);
                    }
                    else if (txtSwA2.Focused)
                    {
                        txtSwA2.Text = toSwitchString(i);
                    }
                    else if (txtSwB1.Focused)
                    {
                        txtSwB1.Text = toSwitchString(i);
                    }
                    else if (txtSwB2.Focused)
                    {
                        txtSwB2.Text = toSwitchString(i);
                    }
                    else if (txtSwC1.Focused)
                    {
                        txtSwC1.Text = toSwitchString(i);
                    }
                    else if (txtSwC2.Focused)
                    {
                        txtSwC2.Text = toSwitchString(i);
                    }
                    else if (txtSwD.Focused)
                    {
                        txtSwD.Text = toSwitchString(i);
                    }
                    else if (txtSwE.Focused)
                    {
                        txtSwE.Text = toSwitchString(i);
                    }
                    else if (txtSwF.Focused)
                    {
                        txtSwF.Text = toSwitchString(i);
                    }
                    else if (txtSwG.Focused)
                    {
                        txtSwG.Text = toSwitchString(i);
                    }
                    else if (txtSwH.Focused)
                    {
                        txtSwH.Text = toSwitchString(i);
                    }
                    else if (txtSwI.Focused)
                    {
                        txtSwI.Text = toSwitchString(i);
                    }
                    else if (txtSwJ.Focused)
                    {
                        txtSwJ.Text = toSwitchString(i);
                    }
                    else if (txtSwK.Focused)
                    {
                        txtSwK.Text = toSwitchString(i);
                    }
                    else if (txtSwL.Focused)
                    {
                        txtSwL.Text = toSwitchString(i);
                    }
                    else if (txtSwReverserFront.Focused)
                    {
                        txtSwReverserFront.Text = toSwitchString(i);
                    }
                    else if (txtSwReverserNeutral.Focused)
                    {
                        txtSwReverserNeutral.Text = toSwitchString(i);
                    }
                    else if (txtSwReverserBack.Focused)
                    {
                        txtSwReverserBack.Text = toSwitchString(i);
                    }
                    else if (txtSwHorn1.Focused)
                    {
                        txtSwHorn1.Text = toSwitchString(i);
                    }
                    else if (txtSwHorn2.Focused)
                    {
                        txtSwHorn2.Text = toSwitchString(i);
                    }
                    else if (txtSwMusicHorn.Focused)
                    {
                        txtSwMusicHorn.Text = toSwitchString(i);
                    }
                    else if (txtSwConstSpeed.Focused)
                    {
                        txtSwConstSpeed.Text = toSwitchString(i);
                    }

                    break;
                }
            }
        }