Exemplo n.º 1
0
        private InputVariable FindAxis(Controller controller, Guid axisType, string axisName, int number)
        {
            InputVariable result = null;
            AxisType      axis   = AxisTypeUtils.ObjectGuidTypeToAxisType(axisType, number);

            if (controller.Variables != null)
            {
                for (int i = 0; i < controller.Variables.Length; i++)
                {
                    if (controller.Variables[i].InputType == InputType.Axis)
                    {
                        if (((IAxis)controller.Variables[i]).SliderType == axis)
                        {
                            result = controller.Variables[i];
                            break;
                        }
                    }
                }
            }
            if (result == null)
            {
                result = new SimpleAxisInput()
                {
                    Controller  = controller,
                    Description = "",
                    ID          = string.Format("axis_{0}", axis.ToString()),
                    AxisName    = axisName,
                    Max         = 100,
                    Min         = 0,
                    Reverse     = false,
                    SliderType  = axis
                };
            }
            return(result);
        }
Exemplo n.º 2
0
        private InputVariable FindButton(Controller controller, int buttonIndex)
        {
            InputVariable result = null;

            if (controller.Variables != null)
            {
                for (int i = 0; i < controller.Variables.Length; i++)
                {
                    if (controller.Variables[i].InputType == InputType.Button)
                    {
                        if (((IButton)controller.Variables[i]).Index == buttonIndex)
                        {
                            result = controller.Variables[i];
                            break;
                        }
                    }
                }
            }
            if (result == null)
            {
                result = new SimpleButtonInput()
                {
                    Controller  = controller,
                    Description = "",
                    ID          = string.Format("przycisk_{0}", buttonIndex.ToString("000")),
                    Index       = buttonIndex
                };
            }
            return(result);
        }
Exemplo n.º 3
0
        private InputVariable FindHAT(Controller controller, int hatIndex)
        {
            InputVariable result = null;

            if (controller.Variables != null)
            {
                for (int i = 0; i < controller.Variables.Length; i++)
                {
                    if (controller.Variables[i].InputType == InputType.HATSwitch)
                    {
                        if (((IHAT)controller.Variables[i]).Index == hatIndex)
                        {
                            result = controller.Variables[i];
                            break;
                        }
                    }
                }
            }
            if (result == null)
            {
                result = new HatSwitchInput()
                {
                    Controller  = controller,
                    Description = "",
                    ID          = string.Format("hat_{0}", hatIndex.ToString("000")),
                    Index       = hatIndex
                };
            }
            return(result);
        }
        public static ModuleConfiguration Load(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(fileName);
            }
            ModuleConfiguration c   = new ModuleConfiguration();
            XmlDocument         xml = new XmlDocument();

            xml.Load(fileName);

            List <InputVariable> variables   = new List <InputVariable>();
            List <Controller>    controllers = new List <Controller>();

            // pobranie konfiguracji wszystkich kontrolerów
            XmlNodeList nodes = xml.SelectNodes("configuration/controllers/controller");

            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    Controller controller = new Controller()
                    {
                        Name                 = node.Attributes["name"].Value,
                        Alias                = node.Attributes["alias"].Value,
                        Id                   = new Guid(node.Attributes["id"].Value),
                        Index                = int.Parse(node.Attributes["index"].Value),
                        UpdateType           = UpdateStateType.ByEvent,
                        ReadingStateInterval = 20,
                    };

                    if (node.Attributes["update"] != null)
                    {
                        controller.UpdateType = (UpdateStateType)Enum.Parse(typeof(UpdateStateType), node.Attributes["update"].Value);
                    }
                    if (node.Attributes["updateInterval"] != null)
                    {
                        controller.ReadingStateInterval = int.Parse(node.Attributes["updateInterval"].Value);
                    }

                    List <InputVariable> controllersVariables = new List <InputVariable>();

                    // pobranie listy przycisków
                    XmlNodeList buttonsNodes = node.SelectNodes("buttons/button");
                    if (buttonsNodes != null && buttonsNodes.Count > 0)
                    {
                        foreach (XmlNode buttonNode in buttonsNodes)
                        {
                            InputVariable iv          = null;
                            SwitchType    type        = (SwitchType)Enum.Parse(typeof(SwitchType), buttonNode.Attributes["type"].Value);
                            bool          repeat      = bool.Parse(buttonNode.Attributes["repeat"].Value);
                            string        description = buttonNode.Attributes["description"] != null ? buttonNode.Attributes["description"].Value : null;

                            switch (type)
                            {
                            case SwitchType.Button:
                                if (repeat)
                                {
                                    iv = new RepeatableButton()
                                    {
                                        Type           = HomeSimCockpitSDK.VariableType.Bool,
                                        Index          = int.Parse(buttonNode.Attributes["index"].Value),
                                        Description    = description ?? "Zwykły przycisk kontrolera, z powtarzaniem sygnału przy długim naciśnięciu.",
                                        RepeatAfter    = int.Parse(buttonNode.Attributes["repeatAfter"].Value),
                                        RepeatInterval = int.Parse(buttonNode.Attributes["repeatInterval"].Value)
                                    };
                                }
                                else
                                {
                                    iv = new SimpleButtonInput()
                                    {
                                        Type        = HomeSimCockpitSDK.VariableType.Bool,
                                        Index       = int.Parse(buttonNode.Attributes["index"].Value),
                                        Description = description ?? "Zwykły przycisk kontrolera, bez powtarzania sygnału przy długim naciśnięciu."
                                    };
                                }
                                break;

                            case SwitchType.HatSwitch:
                                if (repeat)
                                {
                                    iv = new RepeatableHatSwitchInput()
                                    {
                                        Type           = HomeSimCockpitSDK.VariableType.Int,
                                        Index          = int.Parse(buttonNode.Attributes["index"].Value),
                                        Description    = description ?? "Zwykły przycisk HAT kontrolera, z powtarzaniem sygnału przy długim naciśnięciu.",
                                        RepeatAfter    = int.Parse(buttonNode.Attributes["repeatAfter"].Value),
                                        RepeatInterval = int.Parse(buttonNode.Attributes["repeatInterval"].Value)
                                    };
                                }
                                else
                                {
                                    iv = new HatSwitchInput()
                                    {
                                        Type        = HomeSimCockpitSDK.VariableType.Int,
                                        Index       = int.Parse(buttonNode.Attributes["index"].Value),
                                        Description = description ?? "Zwykły przycisk HAT kontrolera, bez powtarzania sygnału przy długim naciśnięciu."
                                    };
                                }
                                break;
                            }

                            if (iv != null)
                            {
                                iv.Controller = controller;
                                iv.ID         = buttonNode.Attributes["alias"].Value;
                                controllersVariables.Add(iv);
                            }
                        }
                    }

                    // pobranie listy osi
                    XmlNodeList slidersNodes = node.SelectNodes("axes/axis");
                    if (slidersNodes != null && slidersNodes.Count > 0)
                    {
                        foreach (XmlNode sliderNode in slidersNodes)
                        {
                            InputVariable iv          = null;
                            AxisType      type        = (AxisType)Enum.Parse(typeof(AxisType), sliderNode.Attributes["type"].Value);
                            int           min         = short.Parse(sliderNode.Attributes["min"].Value);
                            int           max         = short.Parse(sliderNode.Attributes["max"].Value);
                            string        axisName    = sliderNode.Attributes["axisName"] != null ? sliderNode.Attributes["axisName"].Value : "";
                            string        description = sliderNode.Attributes["description"] != null ? sliderNode.Attributes["description"].Value : null;
                            bool          reverse     = bool.Parse(sliderNode.Attributes["reverse"].Value);
                            bool          ranges      = sliderNode.HasChildNodes;
                            if (ranges)
                            {
                            }
                            else
                            {
                                iv = new SimpleAxisInput()
                                {
                                    Min         = min,
                                    Max         = max,
                                    SliderType  = type,
                                    Description = description ?? "Zwykła oś kontrolera.",
                                    AxisName    = axisName,
                                    Reverse     = reverse
                                };
                            }

                            if (iv != null)
                            {
                                iv.Controller = controller;
                                iv.Type       = HomeSimCockpitSDK.VariableType.Int;
                                iv.ID         = sliderNode.Attributes["alias"].Value;
                                controllersVariables.Add(iv);
                            }
                        }
                    }

                    variables.AddRange(controllersVariables);
                    controller.Variables = controllersVariables.ToArray();
                    controllers.Add(controller);
                }
            }

            c.Controllers    = controllers.ToArray();
            c.InputVariables = variables.ToArray();
            return(c);
        }
Exemplo n.º 5
0
        private void ShowSelected()
        {
            StopListening();

            if (!SaveCurrent())
            {
                _ingoreSelecting        = true;
                comboBox1.SelectedIndex = _lastIndex;
                _ingoreSelecting        = false;
                //return;
            }

            // wyczyszczenie
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            dataGridView1.Rows.Clear();
            dataGridView2.Rows.Clear();
            radioButton1.Checked = true;
            radioButton2.Checked = false;
            numericUpDown1.Value = 20;

            _lastIndex = comboBox1.SelectedIndex;

            Ctrl c = comboBox1.SelectedItem as Ctrl;

            if (c != null)
            {
                // poszukanie odpowiednika w konfiguracji
                _controller = FindController(c);

                textBox1.Text = _controller.Alias;
                textBox2.Text = _controller.Id.ToString();
                textBox3.Text = _controller.Index.ToString();
                if (_controller.UpdateType == UpdateStateType.ByChecking)
                {
                    radioButton2.Checked = true;
                }
                numericUpDown1.Value = _controller.ReadingStateInterval;

                // odczytanie systemowych informacji o kontrolerze
                if (_device != null)
                {
                    _device.Dispose();
                    _device = null;
                }
                if (c.Connected)
                {
                    _device        = new Device(c.ID);
                    _buttonsStates = new bool?[_device.Caps.NumberButtons];
                    _hatsStates    = new int[_device.Caps.NumberPointOfViews];
                    for (int i = 0; i < _hatsStates.Length; i++)
                    {
                        _hatsStates[i] = -2;
                    }
                    _axes = new int[8];
                }
                else
                {
                    _buttonsStates = new bool?[_controller.NumberOfObjects(InputType.Button)];
                    _hatsStates    = new int[_controller.NumberOfObjects(InputType.HATSwitch)];
                    for (int i = 0; i < _hatsStates.Length; i++)
                    {
                        _hatsStates[i] = -2;
                    }
                    _axes = new int[8];
                }

                textBox4.Text = c.Connected ? "podłączony" : "niepodłączony";

                // pokazanie konfiguracji przycisków

                // zwykłe przyciski
                for (int i = 0; i < _buttonsStates.Length; i++)
                {
                    int           index = 0;
                    InputVariable iv    = FindButton(_controller, i);
                    if (iv is IRepeatable)
                    {
                        index = dataGridView1.Rows.Add(string.Format("przycisk_{0}", i.ToString("000")), "False", iv.InternalID, iv.Description, iv.InputType, iv.Type, true, ((IRepeatable)iv).RepeatAfter, ((IRepeatable)iv).RepeatInterval);
                    }
                    else
                    {
                        index = dataGridView1.Rows.Add(string.Format("przycisk_{0}", i.ToString("000")), "False", iv.InternalID, iv.Description, iv.InputType, iv.Type, false, 250, 100);
                        dataGridView1.Rows[index].Cells[_powtarzajPo.Index].ReadOnly = true;
                        dataGridView1.Rows[index].Cells[_powtarzajCo.Index].ReadOnly = true;
                    }
                    dataGridView1.Rows[index].Tag = iv;
                }
                // przyciski HAT
                for (int i = 0; i < _hatsStates.Length; i++)
                {
                    int           index = 0;
                    InputVariable iv    = FindHAT(_controller, i);
                    if (iv is IRepeatable)
                    {
                        index = dataGridView1.Rows.Add(string.Format("hat_{0}", i.ToString("000")), "-1", iv.InternalID, iv.Description, iv.InputType, iv.Type, true, ((IRepeatable)iv).RepeatAfter, ((IRepeatable)iv).RepeatInterval);
                    }
                    else
                    {
                        index = dataGridView1.Rows.Add(string.Format("hat_{0}", i.ToString("000")), "-1", iv.InternalID, iv.Description, iv.InputType, iv.Type, false, 250, 100);
                        dataGridView1.Rows[index].Cells[_powtarzajPo.Index].ReadOnly = true;
                        dataGridView1.Rows[index].Cells[_powtarzajCo.Index].ReadOnly = true;
                    }
                    dataGridView1.Rows[index].Tag = iv;
                }

                dataGridView1.PerformLayout();

                // pokazanie konfiguracji osi
                if (_device != null)
                {
                    List <Guid> axes     = new List <Guid>();
                    int         extCount = 0;
                    Microsoft.DirectX.DirectInput.DeviceObjectList list = _device.GetObjects(Microsoft.DirectX.DirectInput.DeviceObjectTypeFlags.Axis);
                    foreach (Microsoft.DirectX.DirectInput.DeviceObjectInstance o in list)
                    {
                        if (AxisTypeUtils.IsProperGuidForAxis(o.ObjectType))
                        {
                            if (axes.Contains(o.ObjectType))
                            {
                                continue;
                            }
                            _device.Properties.SetRange(Microsoft.DirectX.DirectInput.ParameterHow.ById, o.ObjectId, new Microsoft.DirectX.DirectInput.InputRange(0, iAXIS_MAX));
                            InputVariable iv    = FindAxis(_controller, o.ObjectType, o.Name, extCount);
                            int           index = dataGridView2.Rows.Add(o.Name, iv.InternalID, iv.Description, ((IAxis)iv).Reverse, ((IAxis)iv).Min, ((IAxis)iv).Max, 0);
                            dataGridView2.Rows[index].Tag = iv;
                            if (o.ObjectType == Microsoft.DirectX.DirectInput.ObjectTypeGuid.Slider)
                            {
                                extCount++;
                            }
                        }
                    }
                }
                else
                {
                    // kontroler nie jest podłączony
                    for (int i = 0; i < _controller.Variables.Length; i++)
                    {
                        if (_controller.Variables[i].InputType == InputType.Axis)
                        {
                            InputVariable iv    = _controller.Variables[i];
                            int           index = dataGridView2.Rows.Add(((IAxis)iv).AxisName, iv.InternalID, iv.Description, ((IAxis)iv).Reverse, ((IAxis)iv).Min, ((IAxis)iv).Max, 0);
                            dataGridView2.Rows[index].Tag = iv;
                        }
                    }
                }

                dataGridView2.PerformLayout();

                StartListening();
            }
        }