Ejemplo n.º 1
0
 private void cmbJoySelect_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cmbJoySelect.SelectedIndex != -1)
     {
         JoystickApi.SelectJoystick(cmbJoySelect.SelectedIndex);
     }
 }
Ejemplo n.º 2
0
        public void enumerateDevices()
        {
            JoystickApi.EnumerateJoystick();
            int joyNum = JoystickManager.AttachedJoysticks.Length;

            cmbJoySelect.Items.Clear();

            if (joyNum == 0)
            {
                return;
            }

            cmbJoySelect.MaxDropDownItems = joyNum;

            for (int i = 0; i < joyNum; ++i)
            {
                cmbJoySelect.Items.Add(JoystickManager.AttachedJoysticks[i].Name);

                if (m_saveData.guid == JoystickManager.AttachedJoysticks[i].Guid)
                {
                    JoystickApi.SelectJoystick(i);
                    cmbJoySelect.SelectedIndex = i;
                }
            }

            if (cmbJoySelect.SelectedIndex == -1)
            {
                cmbJoySelect.SelectedIndex = joyNum - 1;
            }
        }
Ejemplo n.º 3
0
        private ConfigFormSaveData saveConfiguration()
        {
            ConfigFormSaveData saveData = new ConfigFormSaveData();

            if (JoystickApi.currentDevice != -1)
            {
                saveData.guid = JoystickApi.GetGuid();
            }

            saveData.switchS               = fromSwitchString(txtSwS.Text);
            saveData.switchA1              = fromSwitchString(txtSwA1.Text);
            saveData.switchA2              = fromSwitchString(txtSwA2.Text);
            saveData.switchB1              = fromSwitchString(txtSwB1.Text);
            saveData.switchB2              = fromSwitchString(txtSwB2.Text);
            saveData.switchC1              = fromSwitchString(txtSwC1.Text);
            saveData.switchC2              = fromSwitchString(txtSwC2.Text);
            saveData.switchD               = fromSwitchString(txtSwD.Text);
            saveData.switchE               = fromSwitchString(txtSwE.Text);
            saveData.switchF               = fromSwitchString(txtSwF.Text);
            saveData.switchG               = fromSwitchString(txtSwG.Text);
            saveData.switchH               = fromSwitchString(txtSwH.Text);
            saveData.switchI               = fromSwitchString(txtSwI.Text);
            saveData.switchJ               = fromSwitchString(txtSwJ.Text);
            saveData.switchK               = fromSwitchString(txtSwK.Text);
            saveData.switchL               = fromSwitchString(txtSwL.Text);
            saveData.switchReverserFront   = fromSwitchString(txtSwReverserFront.Text);
            saveData.switchReverserNeutral = fromSwitchString(txtSwReverserNeutral.Text);
            saveData.switchReverserBack    = fromSwitchString(txtSwReverserBack.Text);
            saveData.switchHorn1           = fromSwitchString(txtSwHorn1.Text);
            saveData.switchHorn2           = fromSwitchString(txtSwHorn2.Text);
            saveData.switchMusicHorn       = fromSwitchString(txtSwMusicHorn.Text);
            saveData.switchConstSpeed      = fromSwitchString(txtSwConstSpeed.Text);

            return(saveData);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// A function call when the plugin is loading
        /// </summary>
        /// <param name="fileSystem">The instance of FileSytem class</param>
        /// <returns>Check the plugin loading process is successfully</returns>
        public bool Load(FileSystem fileSystem)
        {
            m_first = true;
            JoystickApi.Init();

            m_configForm = new ConfigForm();
            string settingsPath = fileSystem.SettingsFolder + System.IO.Path.DirectorySeparatorChar + "1.5.0";

            m_configForm.loadConfigurationFile(settingsPath);
            m_configForm.Hide();

            _reverserPos     = 0;
            _lastReverserPos = -128;
            _handlePos       = 0;
            _lastHandlePos   = -128;

            Controls            = new InputControl[39];
            Controls[0].Command = Translations.Command.BrakeEmergency;
            for (int i = 1; i < 10; i++)
            {
                Controls[i].Command = Translations.Command.BrakeAnyNotch;
                Controls[i].Option  = 9 - i;
            }
            for (int i = 10; i < 16; i++)
            {
                Controls[i].Command = Translations.Command.PowerAnyNotch;
                Controls[i].Option  = i - 10;
            }
            for (int i = 16; i < 19; i++)
            {
                Controls[i].Command = Translations.Command.ReverserAnyPostion;
                Controls[i].Option  = 17 - i;
            }
#pragma warning disable 618
            Controls[19].Command = Translations.Command.SecurityS;
            Controls[20].Command = Translations.Command.SecurityA1;
            Controls[21].Command = Translations.Command.SecurityA2;
            Controls[22].Command = Translations.Command.SecurityB1;
            Controls[23].Command = Translations.Command.SecurityB2;
            Controls[24].Command = Translations.Command.SecurityC1;
            Controls[25].Command = Translations.Command.SecurityC2;
            Controls[26].Command = Translations.Command.SecurityD;
            Controls[27].Command = Translations.Command.SecurityE;
            Controls[28].Command = Translations.Command.SecurityF;
            Controls[29].Command = Translations.Command.SecurityG;
            Controls[30].Command = Translations.Command.SecurityH;
            Controls[31].Command = Translations.Command.SecurityI;
            Controls[32].Command = Translations.Command.SecurityJ;
            Controls[33].Command = Translations.Command.SecurityK;
            Controls[34].Command = Translations.Command.SecurityL;
#pragma warning restore 618
            Controls[35].Command = Translations.Command.HornPrimary;
            Controls[36].Command = Translations.Command.HornSecondary;
            Controls[37].Command = Translations.Command.HornMusic;
            Controls[38].Command = Translations.Command.DeviceConstSpeed;
            return(true);
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// A function that calls each frame
        /// </summary>
        public void OnUpdateFrame()
        {
            if (m_pauseTick)
            {
                return;
            }

            if (m_first)
            {
                m_configForm.enumerateDevices();
                m_first = false;
            }

            JoystickApi.Update();

            setReverserPos();
            setHandlePos();
            setSwitchState();
        }
Ejemplo n.º 8
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]));
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
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;
                }
            }
        }