Exemplo n.º 1
0
        void parseChMap(string[] parms)
        {
            if (!BuildingChannelMap)
            {
                return;
            }
            if (parms[1] == "done")
            {
                BuildingChannelMap = false;
            }
            else if (parms[1] == "ins")
            {
                ChannelMappingData chMapData = new ChannelMappingData();
                int modeIndex = int.Parse(parms[2]);
                chMapData.Type           = (MappingType)int.Parse(parms[3]);
                chMapData.ServoIndices   = GetValueArrayFromString <int>(parms[4]);
                chMapData.ChannelIndices = GetValueArrayFromString <int>(parms[5]);
                chMapData.Positionning   = (PositionningType)int.Parse(parms[6]);

                chMapData.Params     = new decimal[chMapData.Type == MappingType.IK ? 2 : 0];
                chMapData.chMapIndex = chMapIndex++;

                ucMappingBase ucMapping = null;
                switch (chMapData.Type)
                {
                case MappingType.Direct:
                    ucMapping = new ucMappingDirect(inputCount, outputCount);
                    break;

                case MappingType.TankMix:
                    ucMapping = new ucMappingTankMix(inputCount, outputCount);
                    break;

                case MappingType.IK:
                    ucMapping = new ucMappingIK(inputCount, outputCount);
                    break;
                }
                ucMapping.chMapData           = chMapData;
                ucMapping.Top                 = buildHeight;
                buildHeight                  += ucMapping.Height;
                ucMapping.Width               = panelChannelMap.Width - 20;
                ucMapping.OnCommand          += OnCommandReceived;
                ucMapping.OnChMapTypeChanged += ucMapping_OnChMapTypeChanged;
                AddControlToContainer(panelChannelMap, ucMapping);
            }
            else if (parms[1] == "setParams")
            {
                // chMap setParams <modeIndex> <chMapIndex> <param1>,<param2>...
                int modeIndex  = int.Parse(parms[2]);
                int chMapIndex = int.Parse(parms[3]);

                List <ucMappingBase> controlList = new List <ucMappingBase>(panelChannelMap.Controls.OfType <ucMappingBase>());
                ucMappingIK          uc          = (ucMappingIK)controlList.Where(v => v.chMapData.chMapIndex == chMapIndex).FirstOrDefault();
                ChannelMappingData   chMapData   = uc.chMapData;
                chMapData.Params = GetValueArrayFromString <decimal>(parms[4]);
                uc.SetControlValues();
            }
        }
Exemplo n.º 2
0
        void ucMapping_OnChMapTypeChanged(object sender, ChMapTypeChangedEventArgs e)
        {
            if (updating)
            {
                return;
            }
            updating = true;
            ChannelMappingData chMapData = e.chMapData;
            ucMappingBase      ucMapping = null;

            switch (chMapData.Type)
            {
            case MappingType.Direct:
                ucMapping = new ucMappingDirect(inputCount, outputCount);
                Array.Resize(ref chMapData.ChannelIndices, 1);
                Array.Resize(ref chMapData.ServoIndices, 1);
                break;

            case MappingType.TankMix:
                ucMapping = new ucMappingTankMix(inputCount, outputCount);
                Array.Resize(ref chMapData.ChannelIndices, 2);
                Array.Resize(ref chMapData.ServoIndices, 2);
                break;

            case MappingType.IK:
                ucMapping = new ucMappingIK(inputCount, outputCount);
                Array.Resize(ref chMapData.ChannelIndices, 3);
                Array.Resize(ref chMapData.ServoIndices, 3);
                Array.Resize(ref chMapData.Params, 2);
                break;
            }
            ucMapping.chMapData = chMapData;
            //ucMapping.Top = ucMapping.Height * chMapData.chMapIndex;
            ucMapping.Width               = panelChannelMap.Width - 20;
            ucMapping.OnCommand          += OnCommandReceived;
            ucMapping.OnChMapTypeChanged += ucMapping_OnChMapTypeChanged;

            panelChannelMap.Controls.RemoveAt(chMapData.chMapIndex);
            AddControlToContainer(panelChannelMap, ucMapping);
            RearrangeMappingControls();
            updating = false;
        }
Exemplo n.º 3
0
        void AddNewChMap()
        {
            ChannelMappingData chMapData = new ChannelMappingData();

            chMapData.chMapIndex     = panelChannelMap.Controls.Count;
            chMapData.ServoIndices   = new int[] { 0 };
            chMapData.ChannelIndices = new int[] { 0 };
            chMapData.Params         = new decimal[0];
            chMapData.Type           = MappingType.Direct;
            chMapData.Positionning   = PositionningType.Absolute;
            chMapData.IsNew          = true;

            ucMappingBase ucMapping = new ucMappingDirect(inputCount, outputCount);;

            ucMapping.chMapData           = chMapData;
            ucMapping.Width               = panelChannelMap.Width - 20;
            ucMapping.Anchor             |= AnchorStyles.Right;
            ucMapping.Top                 = buildHeight;
            buildHeight                  += ucMapping.Height;
            ucMapping.OnCommand          += OnCommandReceived;
            ucMapping.OnChMapTypeChanged += new EventHandler <ChMapTypeChangedEventArgs>(ucMapping_OnChMapTypeChanged);
            AddControlToContainer(panelChannelMap, ucMapping);
            CreatingChMap = true;
        }
Exemplo n.º 4
0
        void OnCommandReceived(object sender, CommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "calibrate":
                sendData("servo calibrate " + e.Param[0].ToString() + " " + e.Param[1].ToString() + " " + e.Param[2].ToString());
                break;

            case "reverse":
                sendData("servo reverse " + e.Param[0].ToString() + " " + e.Param[1].ToString());
                break;

            case "trim":
                sendData("servo subtrim " + e.Param[0].ToString() + " " + e.Param[1].ToString());
                break;

            case "servoAngle":
                sendData("servo angle " + e.Param[0].ToString() + " " + e.Param[1].ToString());
                break;

            case "servoPWM":
                sendData("servo pwm " + e.Param[0].ToString() + " " + e.Param[1].ToString());
                break;

            case "input":
                sendData("input " + e.Param[0].ToString() + " " + (((float)(int)e.Param[1]) / 100).ToString());
                break;

            case "chMap":
                ChannelMappingData chMapData = (ChannelMappingData)e.Param[1];
                string             dataStr   = "chMap " + e.Param[0] + " ";
                // modeIndex
                dataStr += cboMappingMode.SelectedIndex.ToString() + " ";
                if ((string)e.Param[0] == "upd" || (string)e.Param[0] == "ins")
                {
                    // chMap ins <modeIndex> <ChMapType> <servo1>,<servo2>... <ch1>,<ch2>... <positionning>
                    // chMap upd <modeIndex> <ChMapType> <servo1>,<servo2>... <ch1>,<ch2>... <positionning> <chMapIndex>

                    // chMapType
                    dataStr += ((int)chMapData.Type).ToString() + " ";

                    // Servos
                    for (int i = 0; i < chMapData.ServoIndices.Length; i++)
                    {
                        if (i > 0)
                        {
                            dataStr += ",";
                        }
                        dataStr += chMapData.ServoIndices[i].ToString();
                    }
                    dataStr += " ";

                    // Channels
                    for (int i = 0; i < chMapData.ChannelIndices.Length; i++)
                    {
                        if (i > 0)
                        {
                            dataStr += ",";
                        }
                        dataStr += chMapData.ChannelIndices[i].ToString();
                    }
                    dataStr += " ";

                    //Positionning
                    dataStr += ((int)chMapData.Positionning).ToString() + " ";
                    // chMapIndex
                    if ((string)e.Param[0] == "upd")
                    {
                        dataStr += chMapData.chMapIndex.ToString();
                    }

                    // Build params string
                    if (chMapData.Type == MappingType.IK)
                    {
                        // chMap setParams <modeIndex> <chMapIndex> <param1>,<param2>...
                        string paramsStr = "chMap setParams ";
                        // modeIndex
                        paramsStr += cboMappingMode.SelectedIndex.ToString() + " ";

                        // chMapIndex
                        paramsStr += chMapData.chMapIndex.ToString() + " ";

                        // Params
                        for (int i = 0; i < chMapData.Params.Length; i++)
                        {
                            if (i > 0)
                            {
                                paramsStr += ",";
                            }
                            paramsStr += chMapData.Params[i].ToString();
                        }
                        commandList.Add(paramsStr);
                    }
                    sendData(dataStr);
                    CreatingChMap = false;
                }
                else if ((string)e.Param[0] == "del")
                {
                    if (!chMapData.IsNew)
                    {
                        BuildchannelMapControls(false);
                        dataStr += chMapData.chMapIndex.ToString();
                        sendData(dataStr);
                    }
                    //panelChannelMap.Controls.RemoveAt(chMapData.chMapIndex);
                }
                break;
            }
        }
Exemplo n.º 5
0
 public ChMapTypeChangedEventArgs(ChannelMappingData chMapData)
 {
     this.chMapData = chMapData;
 }