Пример #1
0
        private void ShiftRegistersVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            DeviceConfig tmp = Config;

            for (int i = 0; i < tmp.ShiftRegistersConfig.Count; i++)
            {
                tmp.ShiftRegistersConfig[i].Type      = ShiftRegisters[i].Type;
                tmp.ShiftRegistersConfig[i].ButtonCnt = (byte)ShiftRegisters[i].ButtonCnt;
            }

            Config = tmp;
            ConfigChanged();
        }
Пример #2
0
        public void Update(DeviceConfig config)
        {
            Config = config;

            for (int i = 0; i < Config.AxisConfig.Count; i++)
            {
                Curve tmp = new Curve(FullScaleX, FullScaleY, i + 1);

                for (int j = 0; j < Config.AxisConfig[i].CurveShape.Count; j++)
                {
                    tmp.Points.Add(new Point((int)(Config.AxisConfig[i].CurveShape[j].X * FullScaleX / (Config.AxisConfig[i].CurveShape.Count - 1)),
                                             (int)((FullScaleY / 2) + (FullScaleY / 2) * Config.AxisConfig[i].CurveShape[j].Y / 100)));
                }
                foreach (var item in tmp.Points)
                {
                    tmp.Sliders.Add(item);
                }

                for (int j = tmp.Points.Count - 1; j >= 0; j--)
                {
                    double delta     = (tmp.Points[1].X - tmp.Points[0].X);
                    double delta_ref = delta / 3;

                    if (j == tmp.Points.Count - 1)
                    {
                        double koeff = FindRefKoeff(tmp.Points[j - 1], tmp.Points[j], delta);
                        Point  left  = GetLeftRefPoint(koeff, delta_ref, tmp.Points[j]);
                        tmp.Points.Insert(j, left);
                    }
                    else if (j == 0)
                    {
                        double koeff = FindRefKoeff(tmp.Points[j], tmp.Points[j + 1], delta);
                        Point  right = GetRightRefPoint(koeff, delta_ref, tmp.Points[j]);
                        tmp.Points.Insert(j + 1, right);
                    }
                    else
                    {
                        double koeff = FindRefKoeff(tmp.Points[j - 1], tmp.Points[j], tmp.Points[j + 1], delta);
                        Point  right = GetRightRefPoint(koeff, delta_ref, tmp.Points[j]);
                        Point  left  = GetLeftRefPoint(koeff, delta_ref, tmp.Points[j]);

                        tmp.Points.Insert(j + 1, right);
                        tmp.Points.Insert(j, left);
                    }
                }

                _curves[i] = tmp;
                _curves[i].Sliders.CollectionChanged += Sliders_CollectionChanged;
            }
        }
Пример #3
0
        private void Led_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            DeviceConfig tmp = Config;

            for (int i = 0; i < Leds.Count; i++)
            {
                tmp.LedConfig[i].InputNumber = (sbyte)Leds[i].InputNumber;
                tmp.LedConfig[i].Type        = Leds[i].Type;
            }
            Config = tmp;

            RaisePropertyChanged(nameof(Leds));
            ConfigChanged();
        }
Пример #4
0
        private void ConfigReceived(DeviceConfig deviceConfig)
        {
            Config = deviceConfig;

            DeviceFirmwareVersionVM = "Device firmware v" + Config.FirmwareVersion.ToString("X3").Insert(1, ".").Insert(3, ".").Insert(5, "b");

            PinsVM.Update(Config);
            ButtonsVM.Update(Config);
            AxesVM.Update(Config);
            AxesToButtonsVM.Update(Config);
            ShiftRegistersVM.Update(Config);

            WriteLog("Config received", false);
            RaisePropertyChanged(nameof(Config));
        }
Пример #5
0
        public EncodersVM(DeviceConfig deviceConfig)
        {
            _config = deviceConfig;

            _encoders = new ObservableCollection <Encoder>();

            // fast encoder
            _encoders.Add(new Encoder(0, EncoderType.Encoder_1x, -1, -1));

            // polling encoders
            for (int i = 1; i < 16; i++)
            {
                _encoders.Add(new Encoder(i, EncoderType.Encoder_1x));
                _encoders[i].PropertyChanged += EncodersVM_PropertyChanged;
            }
        }
Пример #6
0
        public void SendConfig(DeviceConfig config)
        {
            byte[] buffer = new byte[1];

            buffer[0] = 255;
            Hid.ReportSend((byte)ReportID.CONFIG_IN_REPORT, buffer);
            Console.WriteLine("Setting device into config mode");

            Task.Delay(250);

            List <HidReport> hr;

            _config = config;

            hr = ReportConverter.ConfigToReports(_config);

            Hid.ReportSend(hr[0]);
            Console.WriteLine("Sending config packet..: 1");
        }
Пример #7
0
        public ButtonsVM(Joystick joystick, DeviceConfig deviceConfig)
        {
            Joystick = joystick;
            Joystick.PropertyChanged += Joystick_PropertyChanged;
            _config = deviceConfig;

            _logicalButtons = new ObservableCollection <Button>();
            for (int i = 0; i < 128; i++)
            {
                _logicalButtons.Add(new Button(i + 1, 0));
            }
            foreach (var button in _logicalButtons)
            {
                button.Config.PropertyChanged += Button_PropertyChanged;
            }

            _physicalButtons = new ObservableCollection <Button>();
            _shiftButtons    = new ObservableCollection <Button>(Joystick.ShiftButtons);
        }
Пример #8
0
        private void EncodersVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            DeviceConfig tmp = Config;

            for (int i = 0; i < tmp.EncodersConfig.Count; i++)
            {
                tmp.EncodersConfig[i].Type = Encoders[i].Type;
            }

            // fast encoder can not be x1 encoder
            if (tmp.EncodersConfig[0].Type == EncoderType.Encoder_1x)
            {
                tmp.EncodersConfig[0].Type = EncoderType.Encoder_2x;
                Encoders[0].Type           = EncoderType.Encoder_2x;
                Update(tmp);
            }

            Config = tmp;
            ConfigChanged();
        }
Пример #9
0
        private void AxesToButtonsVM_Range_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            DeviceConfig conf = Config;

            for (int i = 0; i < conf.AxisToButtonsConfig.Count; i++)
            {
                conf.AxisToButtonsConfig[i].ButtonsCnt = (byte)AxesToButtons[i].ButtonCnt;

                for (int j = 0; j < AxesToButtons[i].ButtonCnt; j++)
                {
                    conf.AxisToButtonsConfig[i].Points[j] = (byte)AxesToButtons[i].RangeItems[j].From;
                }
                conf.AxisToButtonsConfig[i].Points[AxesToButtons[i].ButtonCnt] =
                    (byte)AxesToButtons[i].RangeItems.Last().To;

                conf.AxisToButtonsConfig[i].IsEnabled = AxesToButtons[i].IsEnabled;
            }
            Config = conf;

            ConfigChanged();
        }
Пример #10
0
        public AxesToButtonsVM(Joystick joystick, DeviceConfig deviceConfig)
        {
            _joystick = joystick;
            _config   = deviceConfig;
            Axes      = new ObservableCollection <Axis>(_joystick.Axes);

            axesToButtons = new ObservableCollection <AxisToButtons>();

            for (int i = 0; i < Config.AxisToButtonsConfig.Count; i++)
            {
                axesToButtons.Add(new AxisToButtons());
            }

            for (int i = 0; i < Config.AxisToButtonsConfig.Count; i++)
            {
                AxesToButtons[i].PropertyChanged += AxesToButtonsVM_PropertyChanged;
                for (int k = 0; k < AxesToButtons[i].RangeItems.Count; k++)
                {
                    AxesToButtons[i].RangeItems[k].PropertyChanged += AxesToButtonsVM_Range_PropertyChanged;
                }
            }
        }
Пример #11
0
        public void Update(DeviceConfig config)
        {
            Config = config;

            ObservableCollection <Led> tmp = new ObservableCollection <Led>();

            _totalLedCnt = 0;
            for (int i = 0; i < config.PinConfig.Count; i++)
            {
                // led matrix
                if (config.PinConfig[i] == PinType.LED_Row)
                {
                    for (int k = 0; k < config.PinConfig.Count; k++)
                    {
                        if (config.PinConfig[k] == PinType.LED_Column)
                        {
                            tmp.Add(new Led(_totalLedCnt + 1, config.LedConfig[_totalLedCnt].InputNumber, config.LedConfig[_totalLedCnt].Type));
                            _totalLedCnt++;
                        }
                    }
                }
                else if (config.PinConfig[i] == PinType.LED_Single)
                {
                    tmp.Add(new Led(_totalLedCnt + 1, config.LedConfig[_totalLedCnt].InputNumber, config.LedConfig[_totalLedCnt].Type));
                    _totalLedCnt++;
                }
            }

            Leds = tmp;

            for (int i = 0; i < Leds.Count; i++)
            {
                Leds[i].PropertyChanged += Led_PropertyChanged;
            }

            Led_PropertyChanged(null, null);
        }
Пример #12
0
        public void Update(DeviceConfig config)
        {
            Config = config;

            for (int i = 0; i < Config.PinConfig.Count; i++)
            {
                if (Config.PinConfig[i] == PinType.TLE501x_CS || Config.PinConfig[i] == PinType.Axis_Analog)
                {
                    foreach (var axis in Axes)
                    {
                        if (!axis.AllowedSources.Contains((AxisSourceType)i))
                        {
                            axis.AllowedSources.Add((AxisSourceType)i);
                        }
                    }
                }
                else
                {
                    foreach (var axis in Axes)
                    {
                        if (axis.AxisConfig.SourceMain == (AxisSourceType)i)
                        {
                            axis.AxisConfig.SourceMain = AxisSourceType.Buttons;
                        }
                        axis.AllowedSources.Remove((AxisSourceType)i);
                    }
                }
            }

            for (int i = 0; i < Config.AxisConfig.Count; i++)
            {
                Axes[i].AxisConfig = Config.AxisConfig[i];
            }


            AxesCurvesVM.Update(Config);
        }
Пример #13
0
        public PinsVM(DeviceConfig deviceConfig)
        {
            Config = deviceConfig;

            _pins = new ObservableCollection <PinVMConverter>();
            for (int i = 0; i < Config.PinConfig.Count; i++)
            {
                Pins.Add(new PinVMConverter());
                //if (i < 8) Pins[i].AllowedTypes.Add(PinType.AxisAnalog);
                //if (i < 8) Pins[i].AllowedTypes.Add(PinType.AxisToButtons);
                //if (i == 14)
                //{
                //    Pins[i].AllowedTypes.Remove(PinType.TLE5011_CS);
                //    Pins[i].AllowedTypes.Remove(PinType.ShiftReg_CS);
                //    Pins[i].AllowedTypes.Remove(PinType.ShiftReg_Data);
                //    Pins[i].AllowedTypes.Add(PinType.SPI_SCK);
                //}
                //if (i == 16 || i == 17)
                //{
                //    Pins[i].AllowedTypes.Remove(PinType.TLE5011_CS);
                //}
                Pins[i].PropertyChanged += PinsVM_PropertyChanged;
            }
        }
        public static void ReportToConfig(ref DeviceConfig config, HidReport hr)
        {
            if (hr.Data[0] == 1)
            {
                char[] chars = new char[20];

                config.FirmwareVersion = (ushort)(hr.Data[2] << 8 | hr.Data[1]);
                for (int i = 0; i < 20; i++)
                {
                    chars[i] = (char)hr.Data[i + 3];
                    if (chars[i] == 0)
                    {
                        break;                  // end of string
                    }
                }
                config.DeviceName = new string(chars);
                config.DeviceName.TrimEnd('\0');
                config.ButtonDebounceMs = (ushort)(hr.Data[24] << 8 | hr.Data[23]);
                config.TogglePressMs    = (ushort)(hr.Data[26] << 8 | hr.Data[25]);
                config.EncoderPressMs   = (ushort)(hr.Data[28] << 8 | hr.Data[27]);
                config.ExchangePeriod   = (ushort)(hr.Data[30] << 8 | hr.Data[29]);

                for (int i = 0; i < config.PinConfig.Count; i++)
                {
                    config.PinConfig[i] = (PinType)hr.Data[i + 32];
                }
            }
            else if (hr.Data[0] == 2)
            {
                config.AxisConfig[0]              = new AxisConfig();
                config.AxisConfig[0].CalibMin     = (short)(hr.Data[2] << 8 | hr.Data[1]);
                config.AxisConfig[0].CalibCenter  = (short)(hr.Data[4] << 8 | hr.Data[3]);
                config.AxisConfig[0].CalibMax     = (short)(hr.Data[6] << 8 | hr.Data[5]);
                config.AxisConfig[0].IsOutEnabled = Convert.ToBoolean(hr.Data[7] & 0x01);
                config.AxisConfig[0].IsInverted   = Convert.ToBoolean(hr.Data[7] & 0x02);
                config.AxisConfig[0].Function     = (AxisFunction)((hr.Data[7] & 0x0C) >> 2);
                config.AxisConfig[0].FilterLevel  = (byte)((hr.Data[7] & 0xE0) >> 5);
                for (int i = 0; i < 11; i++)
                {
                    config.AxisConfig[0].CurveShape[i] = new System.Windows.Point(i, (sbyte)hr.Data[8 + i]);
                }
                config.AxisConfig[0].Resolution        = (byte)((hr.Data[19] & 0x0F) + 1);
                config.AxisConfig[0].AdcChannel        = (byte)(hr.Data[19] >> 4);
                config.AxisConfig[0].Deadband          = (byte)(hr.Data[20] & 0x7F);
                config.AxisConfig[0].IsDynamicDeadband = (hr.Data[20] & 0x80) > 0 ? true : false;
                config.AxisConfig[0].SourceMain        = (AxisSourceType)(hr.Data[21]);
                config.AxisConfig[0].SourceSecondary   = (AxisType)(hr.Data[22] & 0x07);
                config.AxisConfig[0].OffsetAngle       = (hr.Data[22] >> 3) * 15;
                config.AxisConfig[0].DecrementButton   = (sbyte)(hr.Data[23] + 1);
                config.AxisConfig[0].CenterButton      = (sbyte)(hr.Data[24] + 1);
                config.AxisConfig[0].IncrementButton   = (sbyte)(hr.Data[25] + 1);
                config.AxisConfig[0].Step = hr.Data[26];

                config.AxisConfig[1]              = new AxisConfig();
                config.AxisConfig[1].CalibMin     = (short)(hr.Data[32] << 8 | hr.Data[31]);
                config.AxisConfig[1].CalibCenter  = (short)(hr.Data[34] << 8 | hr.Data[33]);
                config.AxisConfig[1].CalibMax     = (short)(hr.Data[36] << 8 | hr.Data[35]);
                config.AxisConfig[1].IsOutEnabled = Convert.ToBoolean(hr.Data[37] & 0x01);
                config.AxisConfig[1].IsInverted   = Convert.ToBoolean(hr.Data[37] & 0x02);
                config.AxisConfig[1].Function     = (AxisFunction)((hr.Data[37] & 0x0C) >> 2);
                config.AxisConfig[1].FilterLevel  = (byte)((hr.Data[37] & 0xE0) >> 5);
                for (int i = 0; i < 11; i++)
                {
                    config.AxisConfig[1].CurveShape[i] = new System.Windows.Point(i, (sbyte)hr.Data[38 + i]);
                }
                config.AxisConfig[1].Resolution        = (byte)((hr.Data[49] & 0x0F) + 1);
                config.AxisConfig[1].AdcChannel        = (byte)(hr.Data[49] >> 4);
                config.AxisConfig[1].Deadband          = (byte)(hr.Data[50] & 0x7F);
                config.AxisConfig[1].IsDynamicDeadband = (hr.Data[50] & 0x80) > 0 ? true : false;
                config.AxisConfig[1].SourceMain        = (AxisSourceType)hr.Data[51];
                config.AxisConfig[1].SourceSecondary   = (AxisType)(hr.Data[52] & 0x07);
                config.AxisConfig[1].OffsetAngle       = (hr.Data[52] >> 3) * 15;
                config.AxisConfig[1].DecrementButton   = (sbyte)(hr.Data[53] + 1);
                config.AxisConfig[1].CenterButton      = (sbyte)(hr.Data[54] + 1);
                config.AxisConfig[1].IncrementButton   = (sbyte)(hr.Data[55] + 1);
                config.AxisConfig[1].Step = hr.Data[56];
            }
            else if (hr.Data[0] == 3)
            {
                config.AxisConfig[2]              = new AxisConfig();
                config.AxisConfig[2].CalibMin     = (short)(hr.Data[2] << 8 | hr.Data[1]);
                config.AxisConfig[2].CalibCenter  = (short)(hr.Data[4] << 8 | hr.Data[3]);
                config.AxisConfig[2].CalibMax     = (short)(hr.Data[6] << 8 | hr.Data[5]);
                config.AxisConfig[2].IsOutEnabled = Convert.ToBoolean(hr.Data[7] & 0x01);
                config.AxisConfig[2].IsInverted   = Convert.ToBoolean(hr.Data[7] & 0x02);
                config.AxisConfig[2].Function     = (AxisFunction)((hr.Data[7] & 0x0C) >> 2);
                config.AxisConfig[2].FilterLevel  = (byte)((hr.Data[7] & 0xE0) >> 5);
                for (int i = 0; i < 11; i++)
                {
                    config.AxisConfig[2].CurveShape[i] = new System.Windows.Point(i, (sbyte)hr.Data[8 + i]);
                }
                config.AxisConfig[2].Resolution        = (byte)((hr.Data[19] & 0x0F) + 1);
                config.AxisConfig[2].AdcChannel        = (byte)(hr.Data[19] >> 4);
                config.AxisConfig[2].Deadband          = (byte)(hr.Data[20] & 0x7F);
                config.AxisConfig[2].IsDynamicDeadband = (hr.Data[20] & 0x80) > 0 ? true : false;
                config.AxisConfig[2].SourceMain        = (AxisSourceType)(hr.Data[21]);
                config.AxisConfig[2].SourceSecondary   = (AxisType)(hr.Data[22] & 0x07);
                config.AxisConfig[2].OffsetAngle       = (hr.Data[22] >> 3) * 15;
                config.AxisConfig[2].DecrementButton   = (sbyte)(hr.Data[23] + 1);
                config.AxisConfig[2].CenterButton      = (sbyte)(hr.Data[24] + 1);
                config.AxisConfig[2].IncrementButton   = (sbyte)(hr.Data[25] + 1);
                config.AxisConfig[2].Step = hr.Data[26];

                config.AxisConfig[3]              = new AxisConfig();
                config.AxisConfig[3].CalibMin     = (short)(hr.Data[32] << 8 | hr.Data[31]);
                config.AxisConfig[3].CalibCenter  = (short)(hr.Data[34] << 8 | hr.Data[33]);
                config.AxisConfig[3].CalibMax     = (short)(hr.Data[36] << 8 | hr.Data[35]);
                config.AxisConfig[3].IsOutEnabled = Convert.ToBoolean(hr.Data[37] & 0x01);
                config.AxisConfig[3].IsInverted   = Convert.ToBoolean(hr.Data[37] & 0x02);
                config.AxisConfig[3].Function     = (AxisFunction)((hr.Data[37] & 0x0C) >> 2);
                config.AxisConfig[3].FilterLevel  = (byte)((hr.Data[37] & 0xE0) >> 5);
                for (int i = 0; i < 11; i++)
                {
                    config.AxisConfig[3].CurveShape[i] = new System.Windows.Point(i, (sbyte)hr.Data[38 + i]);
                }
                config.AxisConfig[3].Resolution        = (byte)((hr.Data[49] & 0x0F) + 1);
                config.AxisConfig[3].AdcChannel        = (byte)(hr.Data[49] >> 4);
                config.AxisConfig[3].Deadband          = (byte)(hr.Data[50] & 0x7F);
                config.AxisConfig[3].IsDynamicDeadband = (hr.Data[50] & 0x80) > 0 ? true : false;
                config.AxisConfig[3].SourceMain        = (AxisSourceType)hr.Data[51];
                config.AxisConfig[3].SourceSecondary   = (AxisType)(hr.Data[52] & 0x07);
                config.AxisConfig[3].OffsetAngle       = (hr.Data[52] >> 3) * 15;
                config.AxisConfig[3].DecrementButton   = (sbyte)(hr.Data[53] + 1);
                config.AxisConfig[3].CenterButton      = (sbyte)(hr.Data[54] + 1);
                config.AxisConfig[3].IncrementButton   = (sbyte)(hr.Data[55] + 1);
                config.AxisConfig[3].Step = hr.Data[56];
            }
            else if (hr.Data[0] == 4)
            {
                config.AxisConfig[4]              = new AxisConfig();
                config.AxisConfig[4].CalibMin     = (short)(hr.Data[2] << 8 | hr.Data[1]);
                config.AxisConfig[4].CalibCenter  = (short)(hr.Data[4] << 8 | hr.Data[3]);
                config.AxisConfig[4].CalibMax     = (short)(hr.Data[6] << 8 | hr.Data[5]);
                config.AxisConfig[4].IsOutEnabled = Convert.ToBoolean(hr.Data[7] & 0x01);
                config.AxisConfig[4].IsInverted   = Convert.ToBoolean(hr.Data[7] & 0x02);
                config.AxisConfig[4].Function     = (AxisFunction)((hr.Data[7] & 0x0C) >> 2);
                config.AxisConfig[4].FilterLevel  = (byte)((hr.Data[7] & 0xE0) >> 5);
                for (int i = 0; i < 11; i++)
                {
                    config.AxisConfig[4].CurveShape[i] = new System.Windows.Point(i, (sbyte)hr.Data[8 + i]);
                }
                config.AxisConfig[4].Resolution        = (byte)((hr.Data[19] & 0x0F) + 1);
                config.AxisConfig[4].AdcChannel        = (byte)(hr.Data[19] >> 4);
                config.AxisConfig[4].Deadband          = (byte)(hr.Data[20] & 0x7F);
                config.AxisConfig[4].IsDynamicDeadband = (hr.Data[20] & 0x80) > 0 ? true : false;
                config.AxisConfig[4].SourceMain        = (AxisSourceType)(hr.Data[21]);
                config.AxisConfig[4].SourceSecondary   = (AxisType)(hr.Data[22] & 0x07);
                config.AxisConfig[4].OffsetAngle       = (hr.Data[22] >> 3) * 15;
                config.AxisConfig[4].DecrementButton   = (sbyte)(hr.Data[23] + 1);
                config.AxisConfig[4].CenterButton      = (sbyte)(hr.Data[24] + 1);
                config.AxisConfig[4].IncrementButton   = (sbyte)(hr.Data[25] + 1);
                config.AxisConfig[4].Step = hr.Data[26];

                config.AxisConfig[5]              = new AxisConfig();
                config.AxisConfig[5].CalibMin     = (short)(hr.Data[32] << 8 | hr.Data[31]);
                config.AxisConfig[5].CalibCenter  = (short)(hr.Data[34] << 8 | hr.Data[33]);
                config.AxisConfig[5].CalibMax     = (short)(hr.Data[36] << 8 | hr.Data[35]);
                config.AxisConfig[5].IsOutEnabled = Convert.ToBoolean(hr.Data[37] & 0x01);
                config.AxisConfig[5].IsInverted   = Convert.ToBoolean(hr.Data[37] & 0x02);
                config.AxisConfig[5].Function     = (AxisFunction)((hr.Data[37] & 0x0C) >> 2);
                config.AxisConfig[5].FilterLevel  = (byte)((hr.Data[37] & 0xE0) >> 5);
                for (int i = 0; i < 11; i++)
                {
                    config.AxisConfig[5].CurveShape[i] = new System.Windows.Point(i, (sbyte)hr.Data[38 + i]);
                }
                config.AxisConfig[5].Resolution        = (byte)((hr.Data[49] & 0x0F) + 1);
                config.AxisConfig[5].AdcChannel        = (byte)(hr.Data[49] >> 4);
                config.AxisConfig[5].Deadband          = (byte)(hr.Data[50] & 0x7F);
                config.AxisConfig[5].IsDynamicDeadband = (hr.Data[50] & 0x80) > 0 ? true : false;
                config.AxisConfig[5].SourceMain        = (AxisSourceType)hr.Data[51];
                config.AxisConfig[5].SourceSecondary   = (AxisType)(hr.Data[52] & 0x07);
                config.AxisConfig[5].OffsetAngle       = (hr.Data[52] >> 3) * 15;
                config.AxisConfig[5].DecrementButton   = (sbyte)(hr.Data[53] + 1);
                config.AxisConfig[5].CenterButton      = (sbyte)(hr.Data[54] + 1);
                config.AxisConfig[5].IncrementButton   = (sbyte)(hr.Data[55] + 1);
                config.AxisConfig[5].Step = hr.Data[56];
            }
            else if (hr.Data[0] == 5)
            {
                config.AxisConfig[6]              = new AxisConfig();
                config.AxisConfig[6].CalibMin     = (short)(hr.Data[2] << 8 | hr.Data[1]);
                config.AxisConfig[6].CalibCenter  = (short)(hr.Data[4] << 8 | hr.Data[3]);
                config.AxisConfig[6].CalibMax     = (short)(hr.Data[6] << 8 | hr.Data[5]);
                config.AxisConfig[6].IsOutEnabled = Convert.ToBoolean(hr.Data[7] & 0x01);
                config.AxisConfig[6].IsInverted   = Convert.ToBoolean(hr.Data[7] & 0x02);
                config.AxisConfig[6].Function     = (AxisFunction)((hr.Data[7] & 0x0C) >> 2);
                config.AxisConfig[6].FilterLevel  = (byte)((hr.Data[7] & 0xE0) >> 5);
                for (int i = 0; i < 11; i++)
                {
                    config.AxisConfig[6].CurveShape[i] = new System.Windows.Point(i, (sbyte)hr.Data[8 + i]);
                }
                config.AxisConfig[6].Resolution        = (byte)((hr.Data[19] & 0x0F) + 1);
                config.AxisConfig[6].AdcChannel        = (byte)(hr.Data[19] >> 4);
                config.AxisConfig[6].Deadband          = (byte)(hr.Data[20] & 0x7F);
                config.AxisConfig[6].IsDynamicDeadband = (hr.Data[20] & 0x80) > 0 ? true : false;
                config.AxisConfig[6].SourceMain        = (AxisSourceType)(hr.Data[21]);
                config.AxisConfig[6].SourceSecondary   = (AxisType)(hr.Data[22] & 0x07);
                config.AxisConfig[6].OffsetAngle       = (hr.Data[22] >> 3) * 15;
                config.AxisConfig[6].DecrementButton   = (sbyte)(hr.Data[23] + 1);
                config.AxisConfig[6].CenterButton      = (sbyte)(hr.Data[24] + 1);
                config.AxisConfig[6].IncrementButton   = (sbyte)(hr.Data[25] + 1);
                config.AxisConfig[6].Step = hr.Data[26];

                config.AxisConfig[7]              = new AxisConfig();
                config.AxisConfig[7].CalibMin     = (short)(hr.Data[32] << 8 | hr.Data[31]);
                config.AxisConfig[7].CalibCenter  = (short)(hr.Data[34] << 8 | hr.Data[33]);
                config.AxisConfig[7].CalibMax     = (short)(hr.Data[36] << 8 | hr.Data[35]);
                config.AxisConfig[7].IsOutEnabled = Convert.ToBoolean(hr.Data[37] & 0x01);
                config.AxisConfig[7].IsInverted   = Convert.ToBoolean(hr.Data[37] & 0x02);
                config.AxisConfig[7].Function     = (AxisFunction)((hr.Data[37] & 0x0C) >> 2);
                config.AxisConfig[7].FilterLevel  = (byte)((hr.Data[37] & 0xE0) >> 5);
                for (int i = 0; i < 11; i++)
                {
                    config.AxisConfig[7].CurveShape[i] = new System.Windows.Point(i, (sbyte)hr.Data[38 + i]);
                }
                config.AxisConfig[7].Resolution        = (byte)((hr.Data[49] & 0x0F) + 1);
                config.AxisConfig[7].AdcChannel        = (byte)(hr.Data[49] >> 4);
                config.AxisConfig[7].Deadband          = (byte)(hr.Data[50] & 0x7F);
                config.AxisConfig[7].IsDynamicDeadband = (hr.Data[50] & 0x80) > 0 ? true : false;
                config.AxisConfig[7].SourceMain        = (AxisSourceType)hr.Data[51];
                config.AxisConfig[7].SourceSecondary   = (AxisType)(hr.Data[52] & 0x07);
                config.AxisConfig[7].OffsetAngle       = (hr.Data[52] >> 3) * 15;
                config.AxisConfig[7].DecrementButton   = (sbyte)(hr.Data[53] + 1);
                config.AxisConfig[7].CenterButton      = (sbyte)(hr.Data[54] + 1);
                config.AxisConfig[7].IncrementButton   = (sbyte)(hr.Data[55] + 1);
                config.AxisConfig[7].Step = hr.Data[56];
            }
            else if (hr.Data[0] == 6)
            {
                // buttons group 1
                for (int i = 0; i < 31; i++)
                {
                    config.ButtonConfig[i].PhysicalNumber   = (sbyte)(hr.Data[2 * i + 1] + 1);
                    config.ButtonConfig[i].ShiftModificator = (ShiftType)((hr.Data[2 * i + 2] & SHIFT_MASK) >> 5);
                    config.ButtonConfig[i].Type             = (ButtonType)(hr.Data[2 * i + 2] & BUTTON_TYPE_MASK);
                }
            }
            else if (hr.Data[0] == 7)
            {
                // buttons group 2
                for (int i = 0; i < 31; i++)
                {
                    config.ButtonConfig[i + 31].PhysicalNumber   = (sbyte)(hr.Data[2 * i + 1] + 1);
                    config.ButtonConfig[i + 31].ShiftModificator = (ShiftType)((hr.Data[2 * i + 2] & SHIFT_MASK) >> 5);
                    config.ButtonConfig[i + 31].Type             = (ButtonType)(hr.Data[2 * i + 2] & BUTTON_TYPE_MASK);
                }
            }
            else if (hr.Data[0] == 8)
            {
                // buttons group 3
                for (int i = 0; i < 31; i++)
                {
                    config.ButtonConfig[i + 62].PhysicalNumber   = (sbyte)(hr.Data[2 * i + 1] + 1);
                    config.ButtonConfig[i + 62].ShiftModificator = (ShiftType)((hr.Data[2 * i + 2] & SHIFT_MASK) >> 5);
                    config.ButtonConfig[i + 62].Type             = (ButtonType)(hr.Data[2 * i + 2] & BUTTON_TYPE_MASK);
                }
            }
            else if (hr.Data[0] == 9)
            {
                // buttons group 4
                for (int i = 0; i < 31; i++)
                {
                    config.ButtonConfig[i + 93].PhysicalNumber   = (sbyte)(hr.Data[2 * i + 1] + 1);
                    config.ButtonConfig[i + 93].ShiftModificator = (ShiftType)((hr.Data[2 * i + 2] & SHIFT_MASK) >> 5);
                    config.ButtonConfig[i + 93].Type             = (ButtonType)(hr.Data[2 * i + 2] & BUTTON_TYPE_MASK);
                }
            }
            else if (hr.Data[0] == 10)
            {
                // buttons group 5
                for (int i = 0; i < 4; i++)
                {
                    config.ButtonConfig[i + 124].PhysicalNumber   = (sbyte)(hr.Data[2 * i + 1] + 1);
                    config.ButtonConfig[i + 124].ShiftModificator = (ShiftType)((hr.Data[2 * i + 2] & SHIFT_MASK) >> 5);
                    config.ButtonConfig[i + 124].Type             = (ButtonType)(hr.Data[2 * i + 2] & BUTTON_TYPE_MASK);
                }

                // axes to buttons group 1
                for (int i = 0; i < 13; i++)
                {
                    config.AxisToButtonsConfig[0].Points[i] = (sbyte)hr.Data[9 + i];
                }
                config.AxisToButtonsConfig[0].ButtonsCnt = (byte)hr.Data[22];
                config.AxisToButtonsConfig[0].IsEnabled  = (hr.Data[23] > 0) ? true : false;

                for (int i = 0; i < 13; i++)
                {
                    config.AxisToButtonsConfig[1].Points[i] = (sbyte)hr.Data[24 + i];
                }
                config.AxisToButtonsConfig[1].ButtonsCnt = (byte)hr.Data[37];
                config.AxisToButtonsConfig[1].IsEnabled  = (hr.Data[38] > 0) ? true : false;

                for (int i = 0; i < 13; i++)
                {
                    config.AxisToButtonsConfig[2].Points[i] = (sbyte)hr.Data[39 + i];
                }
                config.AxisToButtonsConfig[2].ButtonsCnt = (byte)hr.Data[52];
                config.AxisToButtonsConfig[2].IsEnabled  = (hr.Data[53] > 0) ? true : false;
            }
            else if (hr.Data[0] == 11)
            {
                // axes to buttons group 2
                for (int i = 0; i < 13; i++)
                {
                    config.AxisToButtonsConfig[3].Points[i] = (sbyte)hr.Data[1 + i];
                }
                config.AxisToButtonsConfig[3].ButtonsCnt = (byte)hr.Data[14];
                config.AxisToButtonsConfig[3].IsEnabled  = (hr.Data[15] > 0) ? true : false;

                for (int i = 0; i < 13; i++)
                {
                    config.AxisToButtonsConfig[4].Points[i] = (sbyte)hr.Data[16 + i];
                }
                config.AxisToButtonsConfig[4].ButtonsCnt = (byte)hr.Data[29];
                config.AxisToButtonsConfig[4].IsEnabled  = (hr.Data[30] > 0) ? true : false;

                for (int i = 0; i < 13; i++)
                {
                    config.AxisToButtonsConfig[5].Points[i] = (sbyte)hr.Data[31 + i];
                }
                config.AxisToButtonsConfig[5].ButtonsCnt = (byte)hr.Data[44];
                config.AxisToButtonsConfig[5].IsEnabled  = (hr.Data[45] > 0) ? true : false;

                for (int i = 0; i < 13; i++)
                {
                    config.AxisToButtonsConfig[6].Points[i] = (sbyte)hr.Data[46 + i];
                }
                config.AxisToButtonsConfig[6].ButtonsCnt = (byte)hr.Data[59];
                config.AxisToButtonsConfig[6].IsEnabled  = (hr.Data[60] > 0) ? true : false;
            }
            else if (hr.Data[0] == 12)
            {
                for (int i = 0; i < 13; i++)
                {
                    config.AxisToButtonsConfig[7].Points[i] = (sbyte)hr.Data[1 + i];
                }
                config.AxisToButtonsConfig[7].ButtonsCnt = (byte)hr.Data[14];
                config.AxisToButtonsConfig[7].IsEnabled  = (hr.Data[15] > 0) ? true : false;

                for (int i = 0; i < 4; i++)
                {
                    config.ShiftRegistersConfig[i].Type      = (ShiftRegisterType)hr.Data[4 * i + 16];
                    config.ShiftRegistersConfig[i].ButtonCnt = (byte)hr.Data[4 * i + 17];
                }

                for (int i = 0; i < 5; i++)
                {
                    config.ShiftModificatorConfig[i].Button = (sbyte)(hr.Data[32 + i] + 1);
                    //config.ShiftModificatorConfig[i].Mode = (ShiftMode)hr.Data[33 + i * 2];
                }

                config.Vid             = (ushort)((ushort)(hr.Data[38] << 8) | (ushort)hr.Data[37]);
                config.Pid             = (ushort)((ushort)(hr.Data[40] << 8) | (ushort)hr.Data[39]);
                config.IsDynamicConfig = (hr.Data[41] > 0) ? true : false;

                for (int i = 0; i < 3; i++)
                {
                    config.LedPwmConfig.DutyCycle[i] = hr.Data[42 + i];
                }
            }
            else if (hr.Data[0] == 13)
            {
                for (int i = 0; i < 24; i++)
                {
                    config.LedConfig[i].InputNumber = (sbyte)(hr.Data[2 * i + 1] + 1);
                    config.ButtonConfig[i].Type     = (ButtonType)(hr.Data[2 * i + 2] & 0x07);
                }
            }
        }
        public static List <HidReport> ConfigToReports(DeviceConfig config)
        {
            List <HidReport> hidReports = new List <HidReport>();

            byte[] buffer = new byte[64];
            byte[] chars;


            // Report 1
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = (byte)0x01;
            buffer[2] = (byte)(config.FirmwareVersion & 0xFF);
            buffer[3] = (byte)(config.FirmwareVersion >> 8);
            chars     = Encoding.ASCII.GetBytes(config.DeviceName);
            Array.ConstrainedCopy(chars, 0, buffer, 4, (chars.Length > 20) ? 20 : chars.Length);
            buffer[24] = (byte)(config.ButtonDebounceMs & 0xFF);
            buffer[25] = (byte)(config.ButtonDebounceMs >> 8);
            buffer[26] = (byte)(config.TogglePressMs & 0xFF);
            buffer[27] = (byte)(config.TogglePressMs >> 8);
            buffer[28] = (byte)(config.EncoderPressMs & 0xFF);
            buffer[29] = (byte)(config.EncoderPressMs >> 8);
            buffer[30] = (byte)(config.ExchangePeriod & 0xFF);
            buffer[31] = (byte)(config.ExchangePeriod >> 8);
            for (int i = 0; i < 30; i++)
            {
                buffer[i + 33] = (byte)config.PinConfig[i];
            }
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 2
            buffer.Initialize();
            buffer[0]  = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1]  = 0x02;
            buffer[2]  = (byte)(config.AxisConfig[0].CalibMin & 0xFF);
            buffer[3]  = (byte)(config.AxisConfig[0].CalibMin >> 8);
            buffer[4]  = (byte)(config.AxisConfig[0].CalibCenter & 0xFF);
            buffer[5]  = (byte)(config.AxisConfig[0].CalibCenter >> 8);
            buffer[6]  = (byte)(config.AxisConfig[0].CalibMax & 0xFF);
            buffer[7]  = (byte)(config.AxisConfig[0].CalibMax >> 8);
            buffer[8]  = (byte)(config.AxisConfig[0].IsOutEnabled ? 0x01 : 0x00);
            buffer[8] |= (byte)(config.AxisConfig[0].IsInverted ? 0x02 : 0x00);
            buffer[8] |= (byte)((byte)config.AxisConfig[0].Function << 2);
            buffer[8] |= (byte)(config.AxisConfig[0].FilterLevel << 5);
            for (int i = 0; i < 11; i++)
            {
                buffer[i + 9] = (byte)config.AxisConfig[0].CurveShape[i].Y;
            }
            buffer[20]  = (byte)(config.AxisConfig[0].Resolution - 1);
            buffer[20] |= (byte)(config.AxisConfig[0].AdcChannel << 4);
            buffer[21]  = (byte)(config.AxisConfig[0].Deadband);
            buffer[21] |= (byte)(config.AxisConfig[0].IsDynamicDeadband ? 0x80 : 0x00);
            buffer[22]  = (byte)(config.AxisConfig[0].SourceMain);
            buffer[23]  = (byte)(config.AxisConfig[0].SourceSecondary);
            buffer[23] |= (byte)((config.AxisConfig[0].OffsetAngle / 15) << 3);
            buffer[24]  = (byte)(config.AxisConfig[0].DecrementButton - 1);
            buffer[25]  = (byte)(config.AxisConfig[0].CenterButton - 1);
            buffer[26]  = (byte)(config.AxisConfig[0].IncrementButton - 1);
            buffer[27]  = (byte)(config.AxisConfig[0].Step);

            buffer[32]  = (byte)(config.AxisConfig[1].CalibMin & 0xFF);
            buffer[33]  = (byte)(config.AxisConfig[1].CalibMin >> 8);
            buffer[34]  = (byte)(config.AxisConfig[1].CalibCenter & 0xFF);
            buffer[35]  = (byte)(config.AxisConfig[1].CalibCenter >> 8);
            buffer[36]  = (byte)(config.AxisConfig[1].CalibMax & 0xFF);
            buffer[37]  = (byte)(config.AxisConfig[1].CalibMax >> 8);
            buffer[38]  = (byte)(config.AxisConfig[1].IsOutEnabled ? 0x01 : 0x00);
            buffer[38] |= (byte)(config.AxisConfig[1].IsInverted ? 0x02 : 0x00);
            buffer[38] |= (byte)((byte)config.AxisConfig[1].Function << 2);
            buffer[38] |= (byte)(config.AxisConfig[1].FilterLevel << 5);
            for (int i = 0; i < 11; i++)
            {
                buffer[i + 39] = (byte)config.AxisConfig[1].CurveShape[i].Y;
            }
            buffer[50]  = (byte)(config.AxisConfig[1].Resolution - 1);
            buffer[50] |= (byte)(config.AxisConfig[1].AdcChannel << 4);
            buffer[51]  = (byte)(config.AxisConfig[1].Deadband);
            buffer[51] |= (byte)(config.AxisConfig[1].IsDynamicDeadband ? 0x80 : 0x00);
            buffer[52]  = (byte)(config.AxisConfig[1].SourceMain);
            buffer[53]  = (byte)(config.AxisConfig[1].SourceSecondary);
            buffer[53] |= (byte)((config.AxisConfig[1].OffsetAngle / 15) << 3);
            buffer[54]  = (byte)(config.AxisConfig[1].DecrementButton - 1);
            buffer[55]  = (byte)(config.AxisConfig[1].CenterButton - 1);
            buffer[56]  = (byte)(config.AxisConfig[1].IncrementButton - 1);
            buffer[57]  = (byte)(config.AxisConfig[1].Step);
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 3
            buffer.Initialize();
            buffer[0]  = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1]  = 0x03;
            buffer[2]  = (byte)(config.AxisConfig[2].CalibMin & 0xFF);
            buffer[3]  = (byte)(config.AxisConfig[2].CalibMin >> 8);
            buffer[4]  = (byte)(config.AxisConfig[2].CalibCenter & 0xFF);
            buffer[5]  = (byte)(config.AxisConfig[2].CalibCenter >> 8);
            buffer[6]  = (byte)(config.AxisConfig[2].CalibMax & 0xFF);
            buffer[7]  = (byte)(config.AxisConfig[2].CalibMax >> 8);
            buffer[8]  = (byte)(config.AxisConfig[2].IsOutEnabled ? 0x01 : 0x00);
            buffer[8] |= (byte)(config.AxisConfig[2].IsInverted ? 0x02 : 0x00);
            buffer[8] |= (byte)((byte)config.AxisConfig[2].Function << 2);
            buffer[8] |= (byte)(config.AxisConfig[2].FilterLevel << 5);
            for (int i = 0; i < 11; i++)
            {
                buffer[i + 9] = (byte)config.AxisConfig[2].CurveShape[i].Y;
            }
            buffer[20]  = (byte)(config.AxisConfig[2].Resolution - 1);
            buffer[20] |= (byte)(config.AxisConfig[2].AdcChannel << 4);
            buffer[21]  = (byte)(config.AxisConfig[2].Deadband);
            buffer[21] |= (byte)(config.AxisConfig[2].IsDynamicDeadband ? 0x80 : 0x00);
            buffer[22]  = (byte)(config.AxisConfig[2].SourceMain);
            buffer[23]  = (byte)(config.AxisConfig[2].SourceSecondary);
            buffer[23] |= (byte)((config.AxisConfig[2].OffsetAngle / 15) << 3);
            buffer[24]  = (byte)(config.AxisConfig[2].DecrementButton - 1);
            buffer[25]  = (byte)(config.AxisConfig[2].CenterButton - 1);
            buffer[26]  = (byte)(config.AxisConfig[2].IncrementButton - 1);
            buffer[27]  = (byte)(config.AxisConfig[2].Step);

            buffer[32]  = (byte)(config.AxisConfig[3].CalibMin & 0xFF);
            buffer[33]  = (byte)(config.AxisConfig[3].CalibMin >> 8);
            buffer[34]  = (byte)(config.AxisConfig[3].CalibCenter & 0xFF);
            buffer[35]  = (byte)(config.AxisConfig[3].CalibCenter >> 8);
            buffer[36]  = (byte)(config.AxisConfig[3].CalibMax & 0xFF);
            buffer[37]  = (byte)(config.AxisConfig[3].CalibMax >> 8);
            buffer[38]  = (byte)(config.AxisConfig[3].IsOutEnabled ? 0x01 : 0x00);
            buffer[38] |= (byte)(config.AxisConfig[3].IsInverted ? 0x02 : 0x00);
            buffer[38] |= (byte)((byte)config.AxisConfig[3].Function << 2);
            buffer[38] |= (byte)(config.AxisConfig[3].FilterLevel << 5);
            for (int i = 0; i < 11; i++)
            {
                buffer[i + 39] = (byte)config.AxisConfig[3].CurveShape[i].Y;
            }
            buffer[50]  = (byte)(config.AxisConfig[3].Resolution - 1);
            buffer[50] |= (byte)(config.AxisConfig[3].AdcChannel << 4);
            buffer[51]  = (byte)(config.AxisConfig[3].Deadband);
            buffer[51] |= (byte)(config.AxisConfig[3].IsDynamicDeadband ? 0x80 : 0x00);
            buffer[52]  = (byte)(config.AxisConfig[3].SourceMain);
            buffer[53]  = (byte)(config.AxisConfig[3].SourceSecondary);
            buffer[53] |= (byte)((config.AxisConfig[3].OffsetAngle / 15) << 3);
            buffer[54]  = (byte)(config.AxisConfig[3].DecrementButton - 1);
            buffer[55]  = (byte)(config.AxisConfig[3].CenterButton - 1);
            buffer[56]  = (byte)(config.AxisConfig[3].IncrementButton - 1);
            buffer[57]  = (byte)(config.AxisConfig[3].Step);
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 4
            buffer.Initialize();
            buffer[0]  = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1]  = 0x04;
            buffer[2]  = (byte)(config.AxisConfig[4].CalibMin & 0xFF);
            buffer[3]  = (byte)(config.AxisConfig[4].CalibMin >> 8);
            buffer[4]  = (byte)(config.AxisConfig[4].CalibCenter & 0xFF);
            buffer[5]  = (byte)(config.AxisConfig[4].CalibCenter >> 8);
            buffer[6]  = (byte)(config.AxisConfig[4].CalibMax & 0xFF);
            buffer[7]  = (byte)(config.AxisConfig[4].CalibMax >> 8);
            buffer[8]  = (byte)(config.AxisConfig[4].IsOutEnabled ? 0x01 : 0x00);
            buffer[8] |= (byte)(config.AxisConfig[4].IsInverted ? 0x02 : 0x00);
            buffer[8] |= (byte)((byte)config.AxisConfig[4].Function << 2);
            buffer[8] |= (byte)(config.AxisConfig[4].FilterLevel << 5);
            for (int i = 0; i < 11; i++)
            {
                buffer[i + 9] = (byte)config.AxisConfig[4].CurveShape[i].Y;
            }
            buffer[20]  = (byte)(config.AxisConfig[4].Resolution - 1);
            buffer[20] |= (byte)(config.AxisConfig[4].AdcChannel << 4);
            buffer[21]  = (byte)(config.AxisConfig[4].Deadband);
            buffer[21] |= (byte)(config.AxisConfig[4].IsDynamicDeadband ? 0x80 : 0x00);
            buffer[22]  = (byte)(config.AxisConfig[4].SourceMain);
            buffer[23]  = (byte)(config.AxisConfig[4].SourceSecondary);
            buffer[23] |= (byte)((config.AxisConfig[4].OffsetAngle / 15) << 3);
            buffer[24]  = (byte)(config.AxisConfig[4].DecrementButton - 1);
            buffer[25]  = (byte)(config.AxisConfig[4].CenterButton - 1);
            buffer[26]  = (byte)(config.AxisConfig[4].IncrementButton - 1);
            buffer[27]  = (byte)(config.AxisConfig[4].Step);

            buffer[32]  = (byte)(config.AxisConfig[5].CalibMin & 0xFF);
            buffer[33]  = (byte)(config.AxisConfig[5].CalibMin >> 8);
            buffer[34]  = (byte)(config.AxisConfig[5].CalibCenter & 0xFF);
            buffer[35]  = (byte)(config.AxisConfig[5].CalibCenter >> 8);
            buffer[36]  = (byte)(config.AxisConfig[5].CalibMax & 0xFF);
            buffer[37]  = (byte)(config.AxisConfig[5].CalibMax >> 8);
            buffer[38]  = (byte)(config.AxisConfig[5].IsOutEnabled ? 0x01 : 0x00);
            buffer[38] |= (byte)(config.AxisConfig[5].IsInverted ? 0x02 : 0x00);
            buffer[38] |= (byte)((byte)config.AxisConfig[5].Function << 2);
            buffer[38] |= (byte)(config.AxisConfig[5].FilterLevel << 5);
            for (int i = 0; i < 11; i++)
            {
                buffer[i + 39] = (byte)config.AxisConfig[5].CurveShape[i].Y;
            }
            buffer[50]  = (byte)(config.AxisConfig[5].Resolution - 1);
            buffer[50] |= (byte)(config.AxisConfig[5].AdcChannel << 4);
            buffer[51]  = (byte)(config.AxisConfig[5].Deadband);
            buffer[51] |= (byte)(config.AxisConfig[5].IsDynamicDeadband ? 0x80 : 0x00);
            buffer[52]  = (byte)(config.AxisConfig[5].SourceMain);
            buffer[53]  = (byte)(config.AxisConfig[5].SourceSecondary);
            buffer[53] |= (byte)((config.AxisConfig[5].OffsetAngle / 15) << 3);
            buffer[54]  = (byte)(config.AxisConfig[5].DecrementButton - 1);
            buffer[55]  = (byte)(config.AxisConfig[5].CenterButton - 1);
            buffer[56]  = (byte)(config.AxisConfig[5].IncrementButton - 1);
            buffer[57]  = (byte)(config.AxisConfig[5].Step);
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 5
            buffer.Initialize();
            buffer[0]  = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1]  = 0x05;
            buffer[2]  = (byte)(config.AxisConfig[6].CalibMin & 0xFF);
            buffer[3]  = (byte)(config.AxisConfig[6].CalibMin >> 8);
            buffer[4]  = (byte)(config.AxisConfig[6].CalibCenter & 0xFF);
            buffer[5]  = (byte)(config.AxisConfig[6].CalibCenter >> 8);
            buffer[6]  = (byte)(config.AxisConfig[6].CalibMax & 0xFF);
            buffer[7]  = (byte)(config.AxisConfig[6].CalibMax >> 8);
            buffer[8]  = (byte)(config.AxisConfig[6].IsOutEnabled ? 0x01 : 0x00);
            buffer[8] |= (byte)(config.AxisConfig[6].IsInverted ? 0x02 : 0x00);
            buffer[8] |= (byte)((byte)config.AxisConfig[6].Function << 2);
            buffer[8] |= (byte)(config.AxisConfig[6].FilterLevel << 5);
            for (int i = 0; i < 11; i++)
            {
                buffer[i + 9] = (byte)config.AxisConfig[6].CurveShape[i].Y;
            }
            buffer[20]  = (byte)(config.AxisConfig[6].Resolution - 1);
            buffer[20] |= (byte)(config.AxisConfig[6].AdcChannel << 4);
            buffer[21]  = (byte)(config.AxisConfig[6].Deadband);
            buffer[21] |= (byte)(config.AxisConfig[6].IsDynamicDeadband ? 0x80 : 0x00);
            buffer[22]  = (byte)(config.AxisConfig[6].SourceMain);
            buffer[23]  = (byte)(config.AxisConfig[6].SourceSecondary);
            buffer[23] |= (byte)((config.AxisConfig[6].OffsetAngle / 15) << 3);
            buffer[24]  = (byte)(config.AxisConfig[6].DecrementButton - 1);
            buffer[25]  = (byte)(config.AxisConfig[6].CenterButton - 1);
            buffer[26]  = (byte)(config.AxisConfig[6].IncrementButton - 1);
            buffer[27]  = (byte)(config.AxisConfig[6].Step);

            buffer[32]  = (byte)(config.AxisConfig[7].CalibMin & 0xFF);
            buffer[33]  = (byte)(config.AxisConfig[7].CalibMin >> 8);
            buffer[34]  = (byte)(config.AxisConfig[7].CalibCenter & 0xFF);
            buffer[35]  = (byte)(config.AxisConfig[7].CalibCenter >> 8);
            buffer[36]  = (byte)(config.AxisConfig[7].CalibMax & 0xFF);
            buffer[37]  = (byte)(config.AxisConfig[7].CalibMax >> 8);
            buffer[38]  = (byte)(config.AxisConfig[7].IsOutEnabled ? 0x01 : 0x00);
            buffer[38] |= (byte)(config.AxisConfig[7].IsInverted ? 0x02 : 0x00);
            buffer[38] |= (byte)((byte)config.AxisConfig[7].Function << 2);
            buffer[38] |= (byte)(config.AxisConfig[7].FilterLevel << 5);
            for (int i = 0; i < 11; i++)
            {
                buffer[i + 39] = (byte)config.AxisConfig[7].CurveShape[i].Y;
            }
            buffer[50]  = (byte)(config.AxisConfig[7].Resolution - 1);
            buffer[50] |= (byte)(config.AxisConfig[7].AdcChannel << 4);
            buffer[51]  = (byte)(config.AxisConfig[7].Deadband);
            buffer[51] |= (byte)(config.AxisConfig[7].IsDynamicDeadband ? 0x80 : 0x00);
            buffer[52]  = (byte)(config.AxisConfig[7].SourceMain);
            buffer[53]  = (byte)(config.AxisConfig[7].SourceSecondary);
            buffer[53] |= (byte)((config.AxisConfig[7].OffsetAngle / 15) << 3);
            buffer[54]  = (byte)(config.AxisConfig[7].DecrementButton - 1);
            buffer[55]  = (byte)(config.AxisConfig[7].CenterButton - 1);
            buffer[56]  = (byte)(config.AxisConfig[7].IncrementButton - 1);
            buffer[57]  = (byte)(config.AxisConfig[7].Step);
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 6
            buffer.Initialize();
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = 0x06;
            for (int i = 0; i < 31; i++)
            {
                buffer[2 * i + 2]  = (byte)(config.ButtonConfig[i].PhysicalNumber - 1);
                buffer[2 * i + 3]  = (byte)config.ButtonConfig[i].Type;
                buffer[2 * i + 3] |= (byte)((byte)config.ButtonConfig[i].ShiftModificator << 5);
            }
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 7
            buffer.Initialize();
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = 0x07;
            for (int i = 0; i < 31; i++)
            {
                buffer[2 * i + 2]  = (byte)(config.ButtonConfig[i + 31].PhysicalNumber - 1);
                buffer[2 * i + 3]  = (byte)config.ButtonConfig[i + 31].Type;
                buffer[2 * i + 3] |= (byte)((byte)config.ButtonConfig[i + 31].ShiftModificator << 5);
            }
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 8
            buffer.Initialize();
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = 0x08;
            for (int i = 0; i < 31; i++)
            {
                buffer[2 * i + 2]  = (byte)(config.ButtonConfig[i + 62].PhysicalNumber - 1);
                buffer[2 * i + 3]  = (byte)config.ButtonConfig[i + 62].Type;
                buffer[2 * i + 3] |= (byte)((byte)config.ButtonConfig[i + 62].ShiftModificator << 5);
            }
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 9
            buffer.Initialize();
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = 0x09;
            for (int i = 0; i < 31; i++)
            {
                buffer[2 * i + 2]  = (byte)(config.ButtonConfig[i + 93].PhysicalNumber - 1);
                buffer[2 * i + 3]  = (byte)config.ButtonConfig[i + 93].Type;
                buffer[2 * i + 3] |= (byte)((byte)config.ButtonConfig[i + 93].ShiftModificator << 5);
            }
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 10
            buffer.Initialize();
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = 0x0A;
            for (int i = 0; i < 4; i++)
            {
                buffer[2 * i + 2]  = (byte)(config.ButtonConfig[i + 124].PhysicalNumber - 1);
                buffer[2 * i + 3]  = (byte)config.ButtonConfig[i + 124].Type;
                buffer[2 * i + 3] |= (byte)((byte)config.ButtonConfig[i + 124].ShiftModificator << 5);
            }
            // axes to buttons 1
            for (int i = 0; i < 13; i++)
            {
                buffer[i + 10] = (byte)config.AxisToButtonsConfig[0].Points[i];
            }
            buffer[23] = (byte)config.AxisToButtonsConfig[0].ButtonsCnt;
            buffer[24] = (byte)(config.AxisToButtonsConfig[0].IsEnabled ? 0x01 : 0x00);
            for (int i = 0; i < 13; i++)
            {
                buffer[i + 25] = (byte)config.AxisToButtonsConfig[1].Points[i];
            }
            buffer[38] = (byte)config.AxisToButtonsConfig[1].ButtonsCnt;
            buffer[39] = (byte)(config.AxisToButtonsConfig[1].IsEnabled ? 0x01 : 0x00);
            for (int i = 0; i < 13; i++)
            {
                buffer[i + 40] = (byte)config.AxisToButtonsConfig[2].Points[i];
            }
            buffer[53] = (byte)config.AxisToButtonsConfig[2].ButtonsCnt;
            buffer[54] = (byte)(config.AxisToButtonsConfig[2].IsEnabled ? 0x01 : 0x00);

            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 11
            buffer.Initialize();
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = 0x0B;

            // axes to buttons
            for (int i = 0; i < 13; i++)
            {
                buffer[i + 2] = (byte)config.AxisToButtonsConfig[3].Points[i];
            }
            buffer[15] = (byte)config.AxisToButtonsConfig[3].ButtonsCnt;
            buffer[16] = (byte)(config.AxisToButtonsConfig[3].IsEnabled ? 0x01 : 0x00);
            for (int i = 0; i < 13; i++)
            {
                buffer[i + 17] = (byte)config.AxisToButtonsConfig[4].Points[i];
            }
            buffer[30] = (byte)config.AxisToButtonsConfig[4].ButtonsCnt;
            buffer[31] = (byte)(config.AxisToButtonsConfig[4].IsEnabled ? 0x01 : 0x00);
            for (int i = 0; i < 13; i++)
            {
                buffer[i + 32] = (byte)config.AxisToButtonsConfig[5].Points[i];
            }
            buffer[45] = (byte)config.AxisToButtonsConfig[5].ButtonsCnt;
            buffer[46] = (byte)(config.AxisToButtonsConfig[5].IsEnabled ? 0x01 : 0x00);
            for (int i = 0; i < 13; i++)
            {
                buffer[i + 47] = (byte)config.AxisToButtonsConfig[6].Points[i];
            }
            buffer[60] = (byte)config.AxisToButtonsConfig[6].ButtonsCnt;
            buffer[61] = (byte)(config.AxisToButtonsConfig[6].IsEnabled ? 0x01 : 0x00);
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 12
            buffer.Initialize();
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = 0x0C;

            for (int i = 0; i < 13; i++)
            {
                buffer[i + 2] = (byte)config.AxisToButtonsConfig[7].Points[i];
            }
            buffer[15] = (byte)config.AxisToButtonsConfig[7].ButtonsCnt;
            buffer[16] = (byte)(config.AxisToButtonsConfig[7].IsEnabled ? 0x01 : 0x00);

            for (int i = 0; i < 4; i++)
            {
                buffer[i * 4 + 17] = (byte)config.ShiftRegistersConfig[i].Type;
                buffer[i * 4 + 18] = (byte)config.ShiftRegistersConfig[i].ButtonCnt;
                buffer[i * 4 + 19] = 0;
                buffer[i * 4 + 20] = 0;
            }


            for (int i = 0; i < 5; i++)
            {
                buffer[i + 33] = (byte)(config.ShiftModificatorConfig[i].Button - 1);
                //buffer[2 * i + 34] = (byte)config.ShiftModificatorConfig[i].Mode;
            }

            buffer[38] = (byte)(config.Vid & 0xFF);
            buffer[39] = (byte)(config.Vid >> 8);
            buffer[40] = (byte)(config.Pid & 0xFF);
            buffer[41] = (byte)(config.Pid >> 8);
            buffer[42] = (byte)(config.IsDynamicConfig ? 0x01 : 0x00);

            for (int i = 0; i < 3; i++)
            {
                buffer[43 + i] = config.LedPwmConfig.DutyCycle[i];
            }
            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            // Report 13
            buffer.Initialize();
            buffer[0] = (byte)ReportID.CONFIG_OUT_REPORT;
            buffer[1] = 0x0D;

            for (int i = 0; i < 24; i++)
            {
                buffer[2 * i + 2] = (byte)(config.LedConfig[i].InputNumber - 1);
                buffer[2 * i + 3] = (byte)config.LedConfig[i].Type;
            }

            hidReports.Add(new HidReport(64, new HidDeviceData(buffer, HidDeviceData.ReadStatus.Success)));

            return(hidReports);
        }
Пример #16
0
        public void Update(DeviceConfig config)
        {
            Config = config;

            ObservableCollection <PinVMConverter> tmp = new ObservableCollection <PinVMConverter>();

            for (int i = 0; i < Config.PinConfig.Count; i++)
            {
                tmp.Add(new PinVMConverter());
                if (i < 8)
                {
                    tmp[i].AllowedTypes.Add(PinType.Axis_Analog);
                }
                if (i == 8 || i == 9)
                {
                    tmp[i].AllowedTypes.Add(PinType.Fast_Encoder);
                }
                if (i == 12 || i == 13 || i == 15)
                {
                    if (!tmp[i].AllowedTypes.Contains(PinType.LED_PWM))
                    {
                        tmp[i].AllowedTypes.Add(PinType.LED_PWM);
                    }
                }
                if (i == 14)
                {
                    tmp[i].AllowedTypes.Remove(PinType.TLE5011_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3201_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3202_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3204_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3208_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MLX90393_CS);
                    tmp[i].AllowedTypes.Remove(PinType.ShiftReg_LATCH);
                    tmp[i].AllowedTypes.Remove(PinType.ShiftReg_DATA);
                    if (!tmp[i].AllowedTypes.Contains(PinType.SPI_SCK))
                    {
                        tmp[i].AllowedTypes.Add(PinType.SPI_SCK);
                    }
                }
                if (i == 15)
                {
                    tmp[i].AllowedTypes.Remove(PinType.TLE5011_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3201_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3202_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3204_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3208_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MLX90393_CS);
                    if (!tmp[i].AllowedTypes.Contains(PinType.SPI_MISO))
                    {
                        tmp[i].AllowedTypes.Add(PinType.SPI_MISO);
                    }
                }
                if (i == 16)
                {
                    tmp[i].AllowedTypes.Remove(PinType.TLE5011_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3201_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3202_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3204_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MCP3208_CS);
                    tmp[i].AllowedTypes.Remove(PinType.MLX90393_CS);
                    if (!tmp[i].AllowedTypes.Contains(PinType.SPI_MOSI))
                    {
                        tmp[i].AllowedTypes.Add(PinType.SPI_MOSI);
                    }
                }
                if (i == 17)
                {
                    tmp[i].AllowedTypes.Remove(PinType.TLE5011_CS);
                    if (!tmp[i].AllowedTypes.Contains(PinType.TLE5011_GEN))
                    {
                        tmp[i].AllowedTypes.Add(PinType.TLE5011_GEN);
                    }
                }
                if (i == 19)
                {
                    if (!tmp[i].AllowedTypes.Contains(PinType.I2C_SCL))
                    {
                        tmp[i].AllowedTypes.Add(PinType.I2C_SCL);
                    }
                }
                if (i == 20)
                {
                    if (!tmp[i].AllowedTypes.Contains(PinType.I2C_SDA))
                    {
                        tmp[i].AllowedTypes.Add(PinType.I2C_SDA);
                    }
                }
                tmp[i].SelectedType = Config.PinConfig[i];
            }
            Pins = new ObservableCollection <PinVMConverter>(tmp);

            foreach (var pin in Pins)
            {
                pin.PropertyChanged += PinsVM_PropertyChanged;
            }

            RaisePropertyChanged(nameof(Pins));
            PinsVM_PropertyChanged(this, null);
        }
Пример #17
0
        public void Update(DeviceConfig config)
        {
            Config = config;

            for (int i = 0; i < Config.PinConfig.Count; i++)
            {
                if (Config.PinConfig[i] == PinType.Axis_Analog ||
                    Config.PinConfig[i] == PinType.TLE5011_CS ||
                    Config.PinConfig[i] == PinType.MCP3201_CS ||
                    Config.PinConfig[i] == PinType.MCP3202_CS ||
                    Config.PinConfig[i] == PinType.MCP3204_CS ||
                    Config.PinConfig[i] == PinType.MCP3208_CS ||
                    Config.PinConfig[i] == PinType.MLX90393_CS)
                {
                    foreach (var axis in Axes)
                    {
                        if (!axis.AllowedSources.Contains((AxisSourceType)i))
                        {
                            axis.AllowedSources.Add((AxisSourceType)i);
                        }
                    }
                }
                else
                {
                    foreach (var axis in Axes)
                    {
                        if (axis.AxisConfig.SourceMain == (AxisSourceType)i)
                        {
                            axis.AxisConfig.SourceMain = AxisSourceType.Buttons;
                        }
                        axis.AllowedSources.Remove((AxisSourceType)i);
                        //
                    }
                }
            }

            if (Config.PinConfig[19] == PinType.I2C_SCL && Config.PinConfig[20] == PinType.I2C_SDA)    // PB8 and PB9
            {
                foreach (var axis in Axes)
                {
                    if (!axis.AllowedSources.Contains(AxisSourceType.I2C))
                    {
                        axis.AllowedSources.Add(AxisSourceType.I2C);
                    }
                }
            }
            else
            {
                foreach (var axis in Axes)
                {
                    if (axis.AxisConfig.SourceMain == AxisSourceType.I2C)
                    {
                        axis.AxisConfig.SourceMain = AxisSourceType.Buttons;
                    }
                    if (axis.AllowedSources.Contains(AxisSourceType.I2C))
                    {
                        axis.AllowedSources.Remove(AxisSourceType.I2C);
                    }
                }
            }

            for (int i = 0; i < Config.AxisConfig.Count; i++)
            {
                Axes[i].AxisConfig = Config.AxisConfig[i];
            }


            AxesCurvesVM.Update(Config);
        }
Пример #18
0
        private void LoadDefaultConfig()
        {
            {
                //TODO: fix serialization
                var xmlStr = Properties.Resources.default_config;


                DeviceConfig tmp = Config;
                tmp = DeSerializeObject <DeviceConfig>(xmlStr, xmlStr.Length);
                while (tmp.PinConfig.Count > 30)
                {
                    tmp.PinConfig.RemoveAt(0);
                }
                while (tmp.AxisConfig.Count > 8)
                {
                    tmp.AxisConfig.RemoveAt(0);
                }
                for (int i = 0; i < 8; i++)
                {
                    while (tmp.AxisConfig[i].CurveShape.Count > 11)
                    {
                        tmp.AxisConfig[i].CurveShape.RemoveAt(0);
                    }
                }
                while (tmp.ShiftModificatorConfig.Count > 5)
                {
                    tmp.ShiftModificatorConfig.RemoveAt(0);
                }
                while (tmp.ButtonConfig.Count > 128)
                {
                    tmp.ButtonConfig.RemoveAt(0);
                }
                while (tmp.AxisToButtonsConfig.Count > 8)
                {
                    tmp.AxisToButtonsConfig.RemoveAt(0);
                }
                for (int i = 0; i < 8; i++)
                {
                    while (tmp.AxisToButtonsConfig[i].Points.Count > 13)
                    {
                        tmp.AxisToButtonsConfig[i].Points.RemoveAt(0);
                    }
                }
                while (tmp.ShiftRegistersConfig.Count > 4)
                {
                    tmp.ShiftRegistersConfig.RemoveAt(0);
                }
                while (tmp.LedConfig.Count > 24)
                {
                    tmp.LedConfig.RemoveAt(0);
                }
                while (tmp.EncodersConfig.Count > 16)
                {
                    tmp.EncodersConfig.RemoveAt(0);
                }
                tmp.DeviceName = tmp.DeviceName.TrimEnd('\0');

                Config = tmp;

                //Version = "FreeJoy Configurator v" + Config.FirmwareVersion.ToString("X3").Insert(1, ".").Insert(3, ".").Insert(5, "b");
            }

            PinsVM.Update(Config);
        }
Пример #19
0
        public void Update(DeviceConfig config)
        {
            ColCnt             = 0;
            RowCnt             = 0;
            SingleBtnCnt       = 0;
            TotalBtnCnt        = 0;
            ButtonsFromAxesCnt = 0;
            ButtonsError       = false;

            Config = config;

            ObservableCollection <Button> tmp = new ObservableCollection <Button>();

            // matrix buttons
            for (int i = 0; i < config.PinConfig.Count; i++)
            {
                if (config.PinConfig[i] == PinType.Button_Row)
                {
                    RowCnt++;
                    for (int k = 0; k < config.PinConfig.Count; k++)
                    {
                        if (config.PinConfig[k] == PinType.Button_Column)
                        {
                            if (TotalBtnCnt < maxBtnCnt)
                            {
                                tmp.Add(new Button(TotalBtnCnt + 1));
                                tmp[TotalBtnCnt].SourceType = ButtonSourceType.MatrixButton;
                            }
                            TotalBtnCnt++;
                        }
                    }
                }
                else if (config.PinConfig[i] == PinType.Button_Column)
                {
                    ColCnt++;
                }
            }

            // Shift registers
            for (int i = 0, k = 0; i < config.PinConfig.Count; i++)
            {
                if (config.PinConfig[i] == PinType.ShiftReg_LATCH)
                {
                    for (int j = 0; j < config.ShiftRegistersConfig[k].ButtonCnt; j++)
                    {
                        if (TotalBtnCnt < maxBtnCnt)
                        {
                            tmp.Add(new Button(TotalBtnCnt + 1));
                            tmp[TotalBtnCnt].SourceType = ButtonSourceType.ShiftRegister;
                        }
                        TotalBtnCnt++;
                    }
                    k++;
                }
            }

            // axes to buttons
            for (int i = 0; i < config.AxisToButtonsConfig.Count; i++)
            {
                if (config.AxisToButtonsConfig[i].IsEnabled)
                {
                    for (int j = 0; j < config.AxisToButtonsConfig[i].ButtonsCnt; j++)
                    {
                        if (TotalBtnCnt < maxBtnCnt)
                        {
                            tmp.Add(new Button(TotalBtnCnt + 1));
                            tmp[TotalBtnCnt].SourceType = ButtonSourceType.AxisToButtons;

                            ButtonsFromAxesCnt++;
                        }
                        TotalBtnCnt++;
                    }
                }
            }
            // single buttons
            for (int i = 0; i < config.PinConfig.Count; i++)
            {
                if (config.PinConfig[i] == PinType.Button_Gnd || config.PinConfig[i] == PinType.Button_Vcc)
                {
                    if (TotalBtnCnt < maxBtnCnt)
                    {
                        tmp.Add(new Button(TotalBtnCnt + 1));
                        tmp[TotalBtnCnt].SourceType = ButtonSourceType.SingleButton;

                        SingleBtnCnt++;
                    }
                    TotalBtnCnt++;
                }
            }

            PhysicalButtons = tmp;
            RaisePropertyChanged(nameof(PhysicalButtons));

            for (int i = 0; i < LogicalButtons.Count; i++)
            {
                LogicalButtons[i].Config.PropertyChanged -= Button_PropertyChanged;
                LogicalButtons[i].MaxPhysicalNumber       = TotalBtnCnt;
                LogicalButtons[i].Config.PhysicalNumber   = config.ButtonConfig[i].PhysicalNumber;
                LogicalButtons[i].Config.ShiftModificator = config.ButtonConfig[i].ShiftModificator;
                LogicalButtons[i].Config.Type             = config.ButtonConfig[i].Type;
                if (PhysicalButtons.Count > 0)
                {
                    if (config.ButtonConfig[i].PhysicalNumber > 0 && config.ButtonConfig[i].PhysicalNumber <= TotalBtnCnt)
                    {
                        LogicalButtons[i].SourceType = PhysicalButtons[config.ButtonConfig[i].PhysicalNumber - 1].SourceType;
                    }
                    else
                    {
                        if (LogicalButtons[i].Config.PhysicalNumber >= TotalBtnCnt)
                        {
                            LogicalButtons[i].Config.PhysicalNumber = 0;
                        }
                        LogicalButtons[i].SourceType = ButtonSourceType.NoSource;
                    }
                }
            }
            // shifts
            for (int i = 0; i < config.ShiftModificatorConfig.Count; i++)
            {
                if (config.ShiftModificatorConfig[i].Button > 0)
                {
                    LogicalButtons[config.ShiftModificatorConfig[i].Button].SourceType = ButtonSourceType.Shift;
                }
            }

            foreach (var button in LogicalButtons)
            {
                button.Config.PropertyChanged += Button_PropertyChanged;
            }

            if (TotalBtnCnt > maxBtnCnt)
            {
                ButtonsError = true;
            }

            Button_PropertyChanged(null, null);
        }
Пример #20
0
 private void ConfigSent(DeviceConfig deviceConfig)
 {
     WriteLog("Config written", false);
 }
Пример #21
0
        private void LoadDefaultConfig()
        {
            {   // TODO: fix serialization
                var xmlStr = Properties.Resources.default_config;


                DeviceConfig tmp = Config;
                tmp = DeSerializeObject <DeviceConfig>(xmlStr, xmlStr.Length);
                while (tmp.PinConfig.Count > 30)
                {
                    tmp.PinConfig.RemoveAt(0);
                }
                while (tmp.AxisConfig.Count > 8)
                {
                    tmp.AxisConfig.RemoveAt(0);
                }
                for (int i = 0; i < 8; i++)
                {
                    while (tmp.AxisConfig[i].CurveShape.Count > 11)
                    {
                        tmp.AxisConfig[i].CurveShape.RemoveAt(0);
                    }
                }
                while (tmp.ShiftModificatorConfig.Count > 5)
                {
                    tmp.ShiftModificatorConfig.RemoveAt(0);
                }
                while (tmp.ButtonConfig.Count > 128)
                {
                    tmp.ButtonConfig.RemoveAt(0);
                }
                while (tmp.AxisToButtonsConfig.Count > 8)
                {
                    tmp.AxisToButtonsConfig.RemoveAt(0);
                }
                for (int i = 0; i < 8; i++)
                {
                    while (tmp.AxisToButtonsConfig[i].Points.Count > 13)
                    {
                        tmp.AxisToButtonsConfig[i].Points.RemoveAt(0);
                    }
                }
                while (tmp.ShiftRegistersConfig.Count > 4)
                {
                    tmp.ShiftRegistersConfig.RemoveAt(0);
                }
                tmp.DeviceName = tmp.DeviceName.TrimEnd('\0');

                Config = tmp;
            }

            PinsVM.Config    = Config;
            AxesVM.Config    = Config;
            ButtonsVM.Config = Config;

            PinsVM.Update(Config);
            ButtonsVM.Update(Config);
            AxesVM.Update(Config);
            AxesToButtonsVM.Update(Config);
            ShiftRegistersVM.Update(Config);
        }
Пример #22
0
        private void ReadConfigFromFile()
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = ".conf";
            dlg.Filter     = "Config files (*.conf)|*.conf|All files (*.*)|*.*";
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                {   // TODO: fix serialization
                    DeviceConfig tmp = DeSerializeObject <DeviceConfig>(dlg.FileName);

                    if (tmp != null && (tmp.FirmwareVersion & 0xFFF0) != (Config.FirmwareVersion & 0xFFF0))
                    {
                        MessageBoxService mbs = new MessageBoxService();

                        mbs.ShowMessage("Config file is broken or was created in other version of configurator!\r\n" +
                                        "Configuration loading will be canceled", "Error");
                        return;
                    }

                    while (tmp.PinConfig.Count > 30)
                    {
                        tmp.PinConfig.RemoveAt(0);
                    }
                    while (tmp.AxisConfig.Count > 8)
                    {
                        tmp.AxisConfig.RemoveAt(0);
                    }
                    for (int i = 0; i < 8; i++)
                    {
                        while (tmp.AxisConfig[i].CurveShape.Count > 11)
                        {
                            tmp.AxisConfig[i].CurveShape.RemoveAt(0);
                        }
                    }
                    while (tmp.ShiftModificatorConfig.Count > 5)
                    {
                        tmp.ShiftModificatorConfig.RemoveAt(0);
                    }
                    while (tmp.ButtonConfig.Count > 128)
                    {
                        tmp.ButtonConfig.RemoveAt(0);
                    }
                    while (tmp.AxisToButtonsConfig.Count > 8)
                    {
                        tmp.AxisToButtonsConfig.RemoveAt(0);
                    }
                    for (int i = 0; i < 8; i++)
                    {
                        while (tmp.AxisToButtonsConfig[i].Points.Count > 13)
                        {
                            tmp.AxisToButtonsConfig[i].Points.RemoveAt(0);
                        }
                    }
                    while (tmp.ShiftRegistersConfig.Count > 4)
                    {
                        tmp.ShiftRegistersConfig.RemoveAt(0);
                    }
                    tmp.DeviceName = tmp.DeviceName.TrimEnd('\0');

                    Config = tmp;
                }
                PinsVM.Config    = Config;
                AxesVM.Config    = Config;
                ButtonsVM.Config = Config;

                PinsVM.Update(Config);
                ButtonsVM.Update(Config);
                AxesVM.Update(Config);
                AxesToButtonsVM.Update(Config);
                ShiftRegistersVM.Update(Config);
            }
        }
Пример #23
0
 public DeviceConfigExchangerVM()
 {
     _config = new DeviceConfig();
     //Hid.Connect();
     Hid.PacketReceived += PacketReceivedEventHandler;
 }
Пример #24
0
        public void Update(DeviceConfig config)
        {
            Config = config;

            // disabling events
            for (int i = 0; i < Config.AxisToButtonsConfig.Count; i++)
            {
                AxesToButtons[i].PropertyChanged -= AxesToButtonsVM_PropertyChanged;
                for (int k = 0; k < AxesToButtons[i].RangeItems.Count; k++)
                {
                    AxesToButtons[i].RangeItems[k].PropertyChanged -= AxesToButtonsVM_Range_PropertyChanged;
                }
            }

            for (int i = 0; i < Config.AxisToButtonsConfig.Count; i++)
            {
                if (Config.AxisToButtonsConfig[i].IsEnabled)
                {
                    AxesToButtons[i].IsEnabled = true;
                }
                else
                {
                    AxesToButtons[i].IsEnabled = false;
                    AxesToButtons[i].ButtonCnt = 2;
                }
                // change button count
                AxesToButtons[i].ButtonCnt = Config.AxisToButtonsConfig[i].ButtonsCnt;

                // change range count
                while (AxesToButtons[i].ButtonCnt > AxesToButtons[i].RangeItems.Count)
                {
                    for (int j = 0; j < AxesToButtons[i].RangeItems.Count; j++)
                    {
                        AxesToButtons[i].RangeItems[j].From = (int)(j * (255.0 / (AxesToButtons[i].RangeItems.Count + 1)));
                        AxesToButtons[i].RangeItems[j].To   = (int)((j + 1) * (255.0 / (AxesToButtons[i].RangeItems.Count + 1)));
                    }
                    AxesToButtons[i].RangeItems.Add(new RangeItem {
                        From = AxesToButtons[i].RangeItems.Last().To, To = 255
                    });
                }
                while (AxesToButtons[i].ButtonCnt < AxesToButtons[i].RangeItems.Count)
                {
                    for (int j = AxesToButtons[i].RangeItems.Count - 2; j >= 0; j--)
                    {
                        AxesToButtons[i].RangeItems[j].From = (int)(j * (255.0 / (AxesToButtons[i].RangeItems.Count - 1)));
                        AxesToButtons[i].RangeItems[j].To   = (int)((j + 1) * (255.0 / (AxesToButtons[i].RangeItems.Count - 1)));
                    }
                    AxesToButtons[i].RangeItems[AxesToButtons[i].RangeItems.Count - 1].To = 255;
                    AxesToButtons[i].RangeItems.Remove(AxesToButtons[i].RangeItems.Last());
                }

                // change ranges
                for (int j = 0; j < AxesToButtons[i].RangeItems.Count; j++)
                {
                    AxesToButtons[i].RangeItems[j].From = Config.AxisToButtonsConfig[i].Points[j];
                    AxesToButtons[i].RangeItems[j].To   = Config.AxisToButtonsConfig[i].Points[j + 1];
                }
            }

            // enabling events
            for (int i = 0; i < Config.AxisToButtonsConfig.Count; i++)
            {
                AxesToButtons[i].PropertyChanged += AxesToButtonsVM_PropertyChanged;
                for (int k = 0; k < AxesToButtons[i].RangeItems.Count; k++)
                {
                    AxesToButtons[i].RangeItems[k].PropertyChanged += AxesToButtonsVM_Range_PropertyChanged;
                }
            }

            RaisePropertyChanged(nameof(AxesToButtons));
        }
        public void Update(DeviceConfig config)
        {
            Config = config;

            ObservableCollection <AxisToButtons> tmp = new ObservableCollection <AxisToButtons>();

            for (int i = 0; i < Config.AxisToButtonsConfig.Count; i++)
            {
                tmp.Add(new AxisToButtons());

                if (Config.AxisToButtonsConfig[i].IsEnabled)
                {
                    tmp[i].IsEnabled = true;

                    // change button count
                    tmp[i].ButtonCnt = Config.AxisToButtonsConfig[i].ButtonsCnt;

                    // change range count
                    while (tmp[i].ButtonCnt > tmp[i].RangeItems.Count)
                    {
                        for (int j = 0; j < tmp[i].RangeItems.Count; j++)
                        {
                            tmp[i].RangeItems[j].From = j * (100 / (tmp[i].RangeItems.Count + 1));
                            tmp[i].RangeItems[j].To   = (j + 1) * (100 / (tmp[i].RangeItems.Count + 1));
                        }
                        tmp[i].RangeItems.Add(new RangeItem {
                            From = tmp[i].RangeItems.Last().To, To = 100
                        });
                    }
                    while (tmp[i].ButtonCnt < tmp[i].RangeItems.Count)
                    {
                        for (int j = tmp[i].RangeItems.Count - 2; j >= 0; j--)
                        {
                            tmp[i].RangeItems[j].From = j * (100 / (tmp[i].RangeItems.Count - 1));
                            tmp[i].RangeItems[j].To   = (j + 1) * (100 / (tmp[i].RangeItems.Count - 1));
                        }
                        tmp[i].RangeItems[tmp[i].RangeItems.Count - 1].To = 100;
                        tmp[i].RangeItems.Remove(tmp[i].RangeItems.Last());
                    }

                    // change ranges
                    for (int j = 0; j < tmp[i].RangeItems.Count; j++)
                    {
                        tmp[i].RangeItems[j].From = Config.AxisToButtonsConfig[i].Points[j];
                        tmp[i].RangeItems[j].To   = Config.AxisToButtonsConfig[i].Points[j + 1];
                    }
                }
                else
                {
                    tmp[i].IsEnabled = false;
                    tmp[i].ButtonCnt = 2;
                }
            }


            for (int i = 0; i < AxesToButtons.Count; i++)
            {
                AxesToButtons[i].PropertyChanged -= AxesToButtonsVM_PropertyChanged;
                AxesToButtons[i].IsEnabled        = tmp[i].IsEnabled;
                AxesToButtons[i].ButtonCnt        = tmp[i].ButtonCnt;

                AxesToButtons[i].PropertyChanged += AxesToButtonsVM_PropertyChanged;
                for (int j = 0; j < AxesToButtons[i].RangeItems.Count; j++)
                {
                    AxesToButtons[i].RangeItems[j].PropertyChanged -= AxesToButtonsVM_Range_PropertyChanged;
                    AxesToButtons[i].RangeItems[j] = tmp[i].RangeItems[j];
                    AxesToButtons[i].RangeItems[j].PropertyChanged += AxesToButtonsVM_Range_PropertyChanged;
                }
            }
        }
Пример #26
0
        // Some dirty logic to display only allowed pin types
        private void PinsVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            _shiftRegisterCsCnt   = 0;
            _shiftRegisterDataCnt = 0;
            _rowCnt       = 0;
            _colCnt       = 0;
            _singleBtnCnt = 0;
            _ledColCnt    = 0;
            _ledRowCnt    = 0;
            _singleLedCnt = 0;
            TotalLedCnt   = 0;

            AxesCnt           = 0;
            AxesToButtonsCnt  = 0;
            _spiDevicesCnt    = 0;
            _spiHalfDuplexCnt = 0;
            _spiFullDuplexCnt = 0;

            _isI2cEnabled = false;

            AxesError = false;
            LedsError = false;

            // count buttons and axes
            for (int i = 0; i < Pins.Count; i++)
            {
                if (Pins[i].SelectedType == PinType.Button_Gnd || Pins[i].SelectedType == PinType.Button_Vcc)
                {
                    _singleBtnCnt++;
                }
                else if (Pins[i].SelectedType == PinType.Button_Row)
                {
                    _rowCnt++;
                }
                else if (Pins[i].SelectedType == PinType.Button_Column)
                {
                    _colCnt++;
                }
                else if (Pins[i].SelectedType == PinType.Axis_Analog)
                {
                    AxesCnt++;
                }
                else if (Pins[i].SelectedType == PinType.ShiftReg_LATCH)
                {
                    _shiftRegisterCsCnt++;
                    _spiDevicesCnt++;
                }
                else if (Pins[i].SelectedType == PinType.TLE5011_CS)
                {
                    AxesCnt++;
                    _spiDevicesCnt++;
                    _spiHalfDuplexCnt++;
                }
                else if (Pins[i].SelectedType == PinType.MCP3201_CS)
                {
                    AxesCnt++;
                    _spiDevicesCnt++;
                    _spiFullDuplexCnt++;
                }
                else if (Pins[i].SelectedType == PinType.MCP3202_CS)
                {
                    AxesCnt++;
                    _spiDevicesCnt++;
                    _spiFullDuplexCnt++;
                }
                else if (Pins[i].SelectedType == PinType.MCP3204_CS)
                {
                    AxesCnt++;
                    _spiDevicesCnt++;
                    _spiFullDuplexCnt++;
                }
                else if (Pins[i].SelectedType == PinType.MCP3208_CS)
                {
                    AxesCnt++;
                    _spiDevicesCnt++;
                    _spiFullDuplexCnt++;
                }
                else if (Pins[i].SelectedType == PinType.MLX90393_CS)
                {
                    AxesCnt++;
                    _spiDevicesCnt++;
                    _spiFullDuplexCnt++;
                }
                else if (Pins[i].SelectedType == PinType.LED_Single)
                {
                    _singleLedCnt++;
                }
                else if (Pins[i].SelectedType == PinType.LED_Row)
                {
                    _ledRowCnt++;
                }
                else if (Pins[i].SelectedType == PinType.LED_Column)
                {
                    _ledColCnt++;
                }
                else if (Pins[i].SelectedType == PinType.I2C_SCL)
                {
                    _isI2cEnabled = true;
                }
            }
            for (int i = 0; i < Config.AxisToButtonsConfig.Count; i++)
            {
                if (Config.AxisToButtonsConfig[i].IsEnabled)
                {
                    AxesToButtonsCnt++;
                }
            }

            TotalLedCnt = _singleLedCnt + _ledColCnt * _ledRowCnt;

            if (AxesCnt > maxAxesCnt)
            {
                AxesError = true;
            }
            if (TotalLedCnt > maxLedCnt)
            {
                LedsError = true;
            }

            // SPI and I2C pins management
            if (_spiDevicesCnt <= 0)
            {
                if (!Pins[14].AllowedTypes.Contains(PinType.Not_Used))
                {
                    Pins[14].AllowedTypes.Insert(0, PinType.Not_Used);
                }
                if (!Pins[14].AllowedTypes.Contains(PinType.Button_Gnd))
                {
                    Pins[14].AllowedTypes.Insert(1, PinType.Button_Gnd);
                }
                if (!Pins[14].AllowedTypes.Contains(PinType.Button_Vcc))
                {
                    Pins[14].AllowedTypes.Insert(2, PinType.Button_Vcc);
                }
                if (!Pins[14].AllowedTypes.Contains(PinType.Button_Row))
                {
                    Pins[14].AllowedTypes.Insert(3, PinType.Button_Row);
                }
                if (!Pins[14].AllowedTypes.Contains(PinType.Button_Column))
                {
                    Pins[14].AllowedTypes.Insert(4, PinType.Button_Column);
                }
                if (!Pins[14].AllowedTypes.Contains(PinType.SPI_SCK))
                {
                    Pins[14].AllowedTypes.Insert(5, PinType.SPI_SCK);
                }

                Pins[14].AllowedTypes.Remove(PinType.TLE5011_CS);
                Pins[14].AllowedTypes.Remove(PinType.ShiftReg_LATCH);
                Pins[14].AllowedTypes.Remove(PinType.ShiftReg_DATA);
            }
            if (_spiFullDuplexCnt <= 0)
            {
                if (!Pins[15].AllowedTypes.Contains(PinType.Not_Used))
                {
                    Pins[15].AllowedTypes.Insert(0, PinType.Not_Used);
                }
                if (!Pins[15].AllowedTypes.Contains(PinType.Button_Gnd))
                {
                    Pins[15].AllowedTypes.Insert(1, PinType.Button_Gnd);
                }
                if (!Pins[15].AllowedTypes.Contains(PinType.Button_Vcc))
                {
                    Pins[15].AllowedTypes.Insert(2, PinType.Button_Vcc);
                }
                if (!Pins[15].AllowedTypes.Contains(PinType.Button_Row))
                {
                    Pins[15].AllowedTypes.Insert(3, PinType.Button_Row);
                }
                if (!Pins[15].AllowedTypes.Contains(PinType.Button_Column))
                {
                    Pins[15].AllowedTypes.Insert(4, PinType.Button_Column);
                }
                if (!Pins[15].AllowedTypes.Contains(PinType.SPI_MISO))
                {
                    Pins[15].AllowedTypes.Insert(5, PinType.SPI_MISO);
                }
            }
            if (_spiHalfDuplexCnt <= 0)
            {
                if (!Pins[16].AllowedTypes.Contains(PinType.Not_Used))
                {
                    Pins[16].AllowedTypes.Insert(0, PinType.Not_Used);
                }
                if (!Pins[16].AllowedTypes.Contains(PinType.Button_Gnd))
                {
                    Pins[16].AllowedTypes.Insert(1, PinType.Button_Gnd);
                }
                if (!Pins[16].AllowedTypes.Contains(PinType.Button_Vcc))
                {
                    Pins[16].AllowedTypes.Insert(2, PinType.Button_Vcc);
                }
                if (!Pins[16].AllowedTypes.Contains(PinType.Button_Row))
                {
                    Pins[16].AllowedTypes.Insert(3, PinType.Button_Row);
                }
                if (!Pins[16].AllowedTypes.Contains(PinType.Button_Column))
                {
                    Pins[16].AllowedTypes.Insert(4, PinType.Button_Column);
                }
                if (!Pins[16].AllowedTypes.Contains(PinType.SPI_MOSI))
                {
                    Pins[16].AllowedTypes.Insert(5, PinType.SPI_MOSI);
                }

                Pins[16].AllowedTypes.Remove(PinType.TLE5011_CS);
                Pins[16].AllowedTypes.Remove(PinType.ShiftReg_LATCH);
                Pins[16].AllowedTypes.Remove(PinType.ShiftReg_DATA);

                if (!Pins[17].AllowedTypes.Contains(PinType.Not_Used))
                {
                    Pins[17].AllowedTypes.Insert(0, PinType.Not_Used);
                }
                if (!Pins[17].AllowedTypes.Contains(PinType.Button_Gnd))
                {
                    Pins[17].AllowedTypes.Insert(1, PinType.Button_Gnd);
                }
                if (!Pins[17].AllowedTypes.Contains(PinType.Button_Vcc))
                {
                    Pins[17].AllowedTypes.Insert(2, PinType.Button_Vcc);
                }
                if (!Pins[17].AllowedTypes.Contains(PinType.Button_Row))
                {
                    Pins[17].AllowedTypes.Insert(3, PinType.Button_Row);
                }
                if (!Pins[17].AllowedTypes.Contains(PinType.Button_Column))
                {
                    Pins[17].AllowedTypes.Insert(4, PinType.Button_Column);
                }
                if (!Pins[17].AllowedTypes.Contains(PinType.TLE5011_GEN))
                {
                    Pins[17].AllowedTypes.Insert(5, PinType.TLE5011_GEN);
                }

                Pins[17].AllowedTypes.Remove(PinType.TLE5011_CS);
            }
            if (!_isI2cEnabled)
            {
                if (!Pins[19].AllowedTypes.Contains(PinType.Not_Used))
                {
                    Pins[19].AllowedTypes.Insert(0, PinType.Not_Used);
                }
                if (!Pins[19].AllowedTypes.Contains(PinType.Button_Gnd))
                {
                    Pins[19].AllowedTypes.Insert(1, PinType.Button_Gnd);
                }
                if (!Pins[19].AllowedTypes.Contains(PinType.Button_Vcc))
                {
                    Pins[19].AllowedTypes.Insert(2, PinType.Button_Vcc);
                }
                if (!Pins[19].AllowedTypes.Contains(PinType.Button_Row))
                {
                    Pins[19].AllowedTypes.Insert(3, PinType.Button_Row);
                }
                if (!Pins[19].AllowedTypes.Contains(PinType.Button_Column))
                {
                    Pins[19].AllowedTypes.Insert(4, PinType.Button_Column);
                }
                if (!Pins[19].AllowedTypes.Contains(PinType.I2C_SCL))
                {
                    Pins[19].AllowedTypes.Insert(5, PinType.I2C_SCL);
                }

                if (!Pins[20].AllowedTypes.Contains(PinType.Not_Used))
                {
                    Pins[20].AllowedTypes.Insert(0, PinType.Not_Used);
                }
                if (!Pins[20].AllowedTypes.Contains(PinType.Button_Gnd))
                {
                    Pins[20].AllowedTypes.Insert(1, PinType.Button_Gnd);
                }
                if (!Pins[20].AllowedTypes.Contains(PinType.Button_Vcc))
                {
                    Pins[20].AllowedTypes.Insert(2, PinType.Button_Vcc);
                }
                if (!Pins[20].AllowedTypes.Contains(PinType.Button_Row))
                {
                    Pins[20].AllowedTypes.Insert(3, PinType.Button_Row);
                }
                if (!Pins[20].AllowedTypes.Contains(PinType.Button_Column))
                {
                    Pins[20].AllowedTypes.Insert(4, PinType.Button_Column);
                }
                if (!Pins[20].AllowedTypes.Contains(PinType.I2C_SDA))
                {
                    Pins[20].AllowedTypes.Insert(5, PinType.I2C_SDA);
                }
            }



            // section of disabling not allowed types
            if (maxBtnCnt - _singleBtnCnt < _rowCnt * (_colCnt + 1))
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.Button_Column)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.Button_Column);
                    }
                }
            }
            if (maxBtnCnt - _singleBtnCnt < _colCnt * (_rowCnt + 1))
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.Button_Row)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.Button_Row);
                    }
                }
            }
            if (maxBtnCnt - _singleBtnCnt <= _rowCnt * _colCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.Button_Gnd &&
                        Pins[i].SelectedType != PinType.Button_Row && Pins[i].SelectedType != PinType.Button_Column)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.Button_Gnd);
                    }
                    if (Pins[i].SelectedType != PinType.Button_Vcc &&
                        Pins[i].SelectedType != PinType.Button_Row && Pins[i].SelectedType != PinType.Button_Column)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.Button_Vcc);
                    }
                }
            }
            if (maxLedCnt - _singleLedCnt < _ledRowCnt * (_ledColCnt + 1))
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.LED_Column)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.LED_Column);
                    }
                }
            }
            if (maxLedCnt - _singleLedCnt < _ledColCnt * (_ledRowCnt + 1))
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.LED_Row)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.LED_Row);
                    }
                }
            }
            if (maxLedCnt - _singleLedCnt <= _ledRowCnt * _ledRowCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.LED_Single &&
                        Pins[i].SelectedType != PinType.LED_Row && Pins[i].SelectedType != PinType.LED_Column)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.LED_Single);
                    }
                }
            }

            if (_shiftRegisterCsCnt >= maxShiftRegistersCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.ShiftReg_LATCH)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.ShiftReg_LATCH);
                    }
                }
            }
            if (_shiftRegisterDataCnt >= maxShiftRegistersCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.ShiftReg_DATA)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.ShiftReg_DATA);
                    }
                }
            }
            if (AxesCnt >= maxAxesCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (Pins[i].SelectedType != PinType.TLE5011_CS)
                    {
                        Pins[i].AllowedTypes.Remove(PinType.TLE5011_CS);
                    }
                }
            }

            // section for enabling allowed types
            for (int i = 0; i < Pins.Count; i++)
            {
                if (Pins[i].SelectedType == PinType.Button_Row && !Pins[i].AllowedTypes.Contains(PinType.Button_Column))
                {
                    Pins[i].AllowedTypes.Add(PinType.Button_Column);
                }
                if (Pins[i].SelectedType == PinType.Button_Column && !Pins[i].AllowedTypes.Contains(PinType.Button_Row))
                {
                    Pins[i].AllowedTypes.Add(PinType.Button_Row);
                }
            }
            if (maxBtnCnt - _singleBtnCnt >= _colCnt * (_rowCnt + 1))
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.Button_Gnd))
                    {
                        Pins[i].AllowedTypes.Add(PinType.Button_Gnd);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.Button_Vcc))
                    {
                        Pins[i].AllowedTypes.Add(PinType.Button_Vcc);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.Button_Row))
                    {
                        Pins[i].AllowedTypes.Add(PinType.Button_Row);
                    }
                }
            }
            if (maxBtnCnt - _singleBtnCnt >= _rowCnt * (_colCnt + 1))
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.Button_Gnd))
                    {
                        Pins[i].AllowedTypes.Add(PinType.Button_Gnd);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.Button_Vcc))
                    {
                        Pins[i].AllowedTypes.Add(PinType.Button_Vcc);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.Button_Column))
                    {
                        Pins[i].AllowedTypes.Add(PinType.Button_Column);
                    }
                }
            }
            if (maxBtnCnt - _singleBtnCnt > _rowCnt * _colCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.Button_Gnd))
                    {
                        Pins[i].AllowedTypes.Add(PinType.Button_Gnd);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.Button_Vcc))
                    {
                        Pins[i].AllowedTypes.Add(PinType.Button_Vcc);
                    }
                }
            }

            for (int i = 0; i < Pins.Count; i++)
            {
                if (Pins[i].SelectedType == PinType.LED_Row && !Pins[i].AllowedTypes.Contains(PinType.LED_Column))
                {
                    Pins[i].AllowedTypes.Add(PinType.LED_Column);
                }
                if (Pins[i].SelectedType == PinType.LED_Column && !Pins[i].AllowedTypes.Contains(PinType.LED_Row))
                {
                    Pins[i].AllowedTypes.Add(PinType.LED_Row);
                }
            }
            if (maxLedCnt - _singleLedCnt >= _ledColCnt * (_ledRowCnt + 1))
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.LED_Single))
                    {
                        Pins[i].AllowedTypes.Add(PinType.LED_Single);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.LED_Row))
                    {
                        Pins[i].AllowedTypes.Add(PinType.LED_Row);
                    }
                }
            }
            if (maxLedCnt - _singleLedCnt >= _ledRowCnt * (_ledColCnt + 1))
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.LED_Single))
                    {
                        Pins[i].AllowedTypes.Add(PinType.LED_Single);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.LED_Column))
                    {
                        Pins[i].AllowedTypes.Add(PinType.LED_Column);
                    }
                }
            }
            if (maxLedCnt - _singleLedCnt > _ledRowCnt * _ledColCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.LED_Single))
                    {
                        Pins[i].AllowedTypes.Add(PinType.LED_Single);
                    }
                }
            }

            if (_shiftRegisterCsCnt < maxShiftRegistersCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.ShiftReg_LATCH) && i != 14)
                    {
                        Pins[i].AllowedTypes.Add(PinType.ShiftReg_LATCH);
                    }
                }
            }
            if (_shiftRegisterDataCnt < maxShiftRegistersCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.ShiftReg_DATA) && i != 14)
                    {
                        Pins[i].AllowedTypes.Add(PinType.ShiftReg_DATA);
                    }
                }
            }
            if (AxesCnt < maxAxesCnt)
            {
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (!Pins[i].AllowedTypes.Contains(PinType.TLE5011_CS) && i != 14 && i != 16 && i != 17)
                    {
                        Pins[i].AllowedTypes.Add(PinType.TLE5011_CS);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.MCP3201_CS) && i != 14 && i != 16 && i != 17)
                    {
                        Pins[i].AllowedTypes.Add(PinType.MCP3201_CS);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.MCP3202_CS) && i != 14 && i != 15 && i != 16 && i != 17)
                    {
                        Pins[i].AllowedTypes.Add(PinType.MCP3202_CS);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.MCP3204_CS) && i != 14 && i != 15 && i != 16 && i != 17)
                    {
                        Pins[i].AllowedTypes.Add(PinType.MCP3204_CS);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.MCP3208_CS) && i != 14 && i != 15 && i != 16 && i != 17)
                    {
                        Pins[i].AllowedTypes.Add(PinType.MCP3208_CS);
                    }
                    if (!Pins[i].AllowedTypes.Contains(PinType.MLX90393_CS) && i != 14 && i != 15 && i != 16 && i != 17)
                    {
                        Pins[i].AllowedTypes.Add(PinType.MLX90393_CS);
                    }
                }
            }

            // SPI pins management
            if (_spiDevicesCnt > 0)
            {
                Pins[14].AllowedTypes.Clear();
                Pins[14].AllowedTypes.Add(PinType.SPI_SCK);
                Pins[14].SelectedType = PinType.SPI_SCK;
            }
            if (_spiFullDuplexCnt > 0)
            {
                Pins[15].AllowedTypes.Clear();
                Pins[15].AllowedTypes.Add(PinType.SPI_MISO);
                Pins[15].SelectedType = PinType.SPI_MISO;

                Pins[16].AllowedTypes.Clear();
                Pins[16].AllowedTypes.Add(PinType.SPI_MOSI);
                Pins[16].SelectedType = PinType.SPI_MOSI;
            }
            if (_spiHalfDuplexCnt > 0)
            {
                Pins[16].AllowedTypes.Clear();
                Pins[16].AllowedTypes.Add(PinType.SPI_MOSI);
                Pins[16].SelectedType = PinType.SPI_MOSI;

                Pins[17].SelectedType = PinType.TLE5011_GEN;
            }
            if (_isI2cEnabled)
            {
                Pins[20].AllowedTypes.Clear();
                Pins[20].AllowedTypes.Add(PinType.I2C_SDA);
                Pins[20].SelectedType = PinType.I2C_SDA;
            }


            // update config
            DeviceConfig tmp = Config;

            for (int i = 0; i < tmp.PinConfig.Count; i++)
            {
                tmp.PinConfig[i] = Pins[i].SelectedType;
            }
            Config = tmp;

            // let bindings know about changes
            RaisePropertyChanged(nameof(Pins));
            ConfigChanged();
        }
Пример #27
0
        private void Button_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            for (int i = 0; i < LogicalButtons.Count; i++)
            {
                if (LogicalButtons[i].Config.PhysicalNumber > 0 && LogicalButtons[i].Config.PhysicalNumber <= TotalBtnCnt)
                {
                    LogicalButtons[i].SourceType = PhysicalButtons[LogicalButtons[i].Config.PhysicalNumber - 1].SourceType;

                    for (int j = 0; j < Config.ShiftModificatorConfig.Count; j++)
                    {
                        if (Config.ShiftModificatorConfig[j].Button == i + 1)
                        {
                            LogicalButtons[j].SourceType = ButtonSourceType.Shift;
                        }
                    }
                }
                else
                {
                    if (LogicalButtons[i].Config.PhysicalNumber >= TotalBtnCnt)
                    {
                        LogicalButtons[i].Config.PhysicalNumber = 0;
                    }
                    LogicalButtons[i].SourceType = ButtonSourceType.NoSource;
                }

                switch (LogicalButtons[i].SourceType)
                {
                case ButtonSourceType.SingleButton:
                case ButtonSourceType.ShiftRegister:
                case ButtonSourceType.MatrixButton:
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Normal))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(0, ButtonType.Button_Normal);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Inverted))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(1, ButtonType.Button_Inverted);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Toggle))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(2, ButtonType.Button_Toggle);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_OnOff))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(3, ButtonType.ToggleSwitch_OnOff);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_On))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(4, ButtonType.ToggleSwitch_On);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_Off))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(5, ButtonType.ToggleSwitch_Off);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov1_Down))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(6, ButtonType.Pov1_Down);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov1_Up))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(7, ButtonType.Pov1_Up);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov1_Left))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(8, ButtonType.Pov1_Left);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov1_Right))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(9, ButtonType.Pov1_Right);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov2_Down))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(10, ButtonType.Pov2_Down);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov2_Up))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(11, ButtonType.Pov2_Up);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov2_Left))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(12, ButtonType.Pov2_Left);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov2_Right))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(13, ButtonType.Pov2_Right);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov3_Down))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(14, ButtonType.Pov3_Down);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov3_Up))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(15, ButtonType.Pov3_Up);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov3_Left))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(16, ButtonType.Pov3_Left);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov3_Right))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(17, ButtonType.Pov3_Right);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov4_Down))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(18, ButtonType.Pov4_Down);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov4_Up))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(19, ButtonType.Pov4_Up);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov4_Left))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(20, ButtonType.Pov4_Left);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov4_Right))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(21, ButtonType.Pov4_Right);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton1))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(22, ButtonType.RadioButton1);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton2))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(23, ButtonType.RadioButton2);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton3))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(24, ButtonType.RadioButton3);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton4))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(25, ButtonType.RadioButton4);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Sequential_Button))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(26, ButtonType.Sequential_Button);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Encoder_A))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(27, ButtonType.Encoder_A);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Encoder_B))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(28, ButtonType.Encoder_B);
                    }
                    break;

                case ButtonSourceType.AxisToButtons:
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Normal))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(0, ButtonType.Button_Normal);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Inverted))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(1, ButtonType.Button_Inverted);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Toggle))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(2, ButtonType.Button_Toggle);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_OnOff))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(3, ButtonType.ToggleSwitch_OnOff);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_On))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(4, ButtonType.ToggleSwitch_On);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_Off))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(5, ButtonType.ToggleSwitch_Off);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov1_Down))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(6, ButtonType.Pov1_Down);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov1_Up))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(7, ButtonType.Pov1_Up);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov1_Left))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(8, ButtonType.Pov1_Left);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov1_Right))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(9, ButtonType.Pov1_Right);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov2_Down))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(10, ButtonType.Pov2_Down);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov2_Up))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(11, ButtonType.Pov2_Up);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov2_Left))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(12, ButtonType.Pov2_Left);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov2_Right))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(13, ButtonType.Pov2_Right);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov3_Down))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(14, ButtonType.Pov3_Down);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov3_Up))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(15, ButtonType.Pov3_Up);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov3_Left))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(16, ButtonType.Pov3_Left);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov3_Right))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(17, ButtonType.Pov3_Right);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov4_Down))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(18, ButtonType.Pov4_Down);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov4_Up))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(19, ButtonType.Pov4_Up);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov4_Left))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(20, ButtonType.Pov4_Left);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Pov4_Right))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(21, ButtonType.Pov4_Right);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton1))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(22, ButtonType.RadioButton1);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton2))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(23, ButtonType.RadioButton2);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton3))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(24, ButtonType.RadioButton3);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton4))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(25, ButtonType.RadioButton4);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Sequential_Button))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(26, ButtonType.Sequential_Button);
                    }

                    if (LogicalButtons[i].Config.Type == ButtonType.Encoder_A ||
                        LogicalButtons[i].Config.Type == ButtonType.Encoder_B)
                    {
                        LogicalButtons[i].Config.Type = ButtonType.Button_Normal;
                    }

                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Encoder_A);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Encoder_B);
                    break;

                case ButtonSourceType.Shift:
                default:
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Normal))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(0, ButtonType.Button_Normal);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Inverted))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(1, ButtonType.Button_Inverted);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Button_Toggle))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(2, ButtonType.Button_Toggle);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_OnOff))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(3, ButtonType.ToggleSwitch_OnOff);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_On))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(4, ButtonType.ToggleSwitch_On);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.ToggleSwitch_Off))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(5, ButtonType.ToggleSwitch_Off);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton1))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(6, ButtonType.RadioButton1);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton2))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(7, ButtonType.RadioButton2);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton3))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(8, ButtonType.RadioButton3);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.RadioButton4))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(9, ButtonType.RadioButton4);
                    }
                    if (!LogicalButtons[i].AllowedTypes.Contains(ButtonType.Sequential_Button))
                    {
                        LogicalButtons[i].AllowedTypes.Insert(10, ButtonType.Sequential_Button);
                    }

                    if (LogicalButtons[i].Config.Type == ButtonType.Encoder_A ||
                        LogicalButtons[i].Config.Type == ButtonType.Encoder_B ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov1_Down ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov1_Up ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov1_Left ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov1_Right ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov2_Down ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov2_Up ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov2_Left ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov2_Right ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov3_Down ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov3_Up ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov3_Left ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov3_Right ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov4_Down ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov4_Up ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov4_Left ||
                        LogicalButtons[i].Config.Type == ButtonType.Pov4_Right)
                    {
                        LogicalButtons[i].Config.Type = ButtonType.Button_Normal;
                    }

                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Encoder_A);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Encoder_B);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov1_Down);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov1_Up);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov1_Left);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov1_Right);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov2_Down);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov2_Up);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov2_Left);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov2_Right);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov3_Down);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov3_Up);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov3_Left);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov3_Right);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov4_Down);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov4_Up);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov4_Left);
                    LogicalButtons[i].AllowedTypes.Remove(ButtonType.Pov4_Right);


                    break;
                }
            }


            DeviceConfig tmp = Config;

            for (int i = 0; i < LogicalButtons.Count; i++)
            {
                tmp.ButtonConfig[i].PhysicalNumber   = (sbyte)LogicalButtons[i].Config.PhysicalNumber;
                tmp.ButtonConfig[i].ShiftModificator = LogicalButtons[i].Config.ShiftModificator;
                tmp.ButtonConfig[i].Type             = LogicalButtons[i].Config.Type;
            }
            Config = tmp;

            RaisePropertyChanged(nameof(LogicalButtons));
            ConfigChanged();
        }
Пример #28
0
        public MainVM()
        {
            // getting current version
            Assembly        assembly        = Assembly.GetExecutingAssembly();
            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);

            _config          = new DeviceConfig();
            _configExchanger = new DeviceConfigExchangerVM();

            _configExchanger.Received += ConfigReceived;
            _configExchanger.Sent     += ConfigSent;

            PinsVM = new PinsVM(Config);
            PinsVM.ConfigChanged += PinConfigChanged;

            _joystick = new Joystick(Config);
            AxesVM    = new AxesVM(_joystick, Config);
            ButtonsVM = new ButtonsVM(_joystick, Config);
            ButtonsVM.ConfigChanged        += ButtonsVM_ConfigChanged;
            AxesToButtonsVM                 = new AxesToButtonsVM(_joystick, Config);
            AxesToButtonsVM.ConfigChanged  += AxesToButtonsVM_ConfigChanged;
            ShiftRegistersVM                = new ShiftRegistersVM(Config);
            ShiftRegistersVM.ConfigChanged += ShiftRegistersVM_ConfigChanged;
            EncodersVM = new EncodersVM(Config);
            EncodersVM.ConfigChanged += EncodersVM_ConfigChanged;
            LedVM = new LedVM(_joystick, Config);
            LedVM.ConfigChanged += LedVM_ConfigChanged;

            FirmwareUpdaterVM = new FirmwareUpdaterVM();

            GetDeviceConfig = new DelegateCommand(() =>
            {
                _configExchanger.GetConfigRequest();
                WriteLog("Requesting config..", false);
            });
            SendDeviceConfig = new DelegateCommand(() =>
            {
                _configExchanger.SendConfig(Config);
                WriteLog("Writting config..", false);
            });

            ResetAllPins = new DelegateCommand(() => PinsVM.ResetPins());
            SaveConfig   = new DelegateCommand(() => SaveConfigToFile());
            LoadConfig   = new DelegateCommand(() => ReadConfigFromFile());
            SetDefault   = new DelegateCommand(() => LoadDefaultConfig());

            LoadDefaultConfig();

            Hid.Start(Config.Vid);

            Hid.DeviceAdded       += DeviceAddedEventHandler;
            Hid.DeviceRemoved     += DeviceRemovedEventHandler;
            Hid.DeviceListUpdated += Hid_DeviceListUpdated;

            // Try to connect to device
            if (HidDevices.Count > 0)
            {
                SelectedDeviceIndex = 0;
            }

            WriteLog("Program started", true);
        }