void createValueControl(KeyValuePair<string,string> x)
        {
            ParameterMetaDataRepository _parameterMetaDataRepository = new ParameterMetaDataRepository();

            string value = ((float)MainV2.comPort.MAV.param[x.Key]).ToString("0.###", CultureInfo.InvariantCulture);
            string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description);
            string displayName = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.DisplayName) +" (" + x.Key + ")";
            string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units);

            var valueControl = new ValuesControl();
            valueControl.Name = x.Key;
            valueControl.DescriptionText = FitDescriptionText(units, description);
            valueControl.LabelText = displayName;

            ThemeManager.ApplyThemeTo(valueControl);

            valueControl.ComboBoxControl.DisplayMember = "Value";
            valueControl.ComboBoxControl.ValueMember = "Key";
            valueControl.ComboBoxControl.DataSource = _parameterMetaDataRepository.GetParameterOptionsInt(x.Key);
            valueControl.ComboBoxControl.SelectedItem = value;

            valueControl.ValueChanged += valueControl_ValueChanged;

            flowLayoutPanel1.Controls.Add(valueControl);
        }
        //, ref int ypos)
        void AddControl(KeyValuePair<string,string> x)
        {
            if (!String.IsNullOrEmpty(x.Key))
            {
                try
                {
                    bool controlAdded = false;

                    string value = ((float)MainV2.comPort.MAV.param[x.Key]).ToString("0.###", CultureInfo.InvariantCulture);
                    string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description);
                    string displayName = x.Value + " (" + x.Key + ")";
                    string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units);

                    // If this is a range
                    string rangeRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range);
                    string incrementRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment);

                    if (!String.IsNullOrEmpty(rangeRaw) && !String.IsNullOrEmpty(incrementRaw))
                    {
                        float increment, intValue;
                        float.TryParse(incrementRaw, out increment);
                        float.TryParse(value, out intValue);

                        string[] rangeParts = rangeRaw.Split(new[] { ' ' });
                        if (rangeParts.Count() == 2 && increment > 0)
                        {
                            float lowerRange;
                            float.TryParse(rangeParts[0], out lowerRange);
                            float upperRange;
                            float.TryParse(rangeParts[1], out upperRange);

                            float displayscale = 1;

                        //    var rangeControl = new RangeControl();

                            if (units.ToLower() == "centi-degrees")
                            {
                                //Console.WriteLine(x.Key + " scale");
                                displayscale = 100;
                                units = "Degrees (Scaled)";
                                increment /= 100;
                            } else if (units.ToLower() == "centimeters")
                            {
                                //Console.WriteLine(x.Key + " scale");
                                displayscale = 100;
                                units = "Meters (Scaled)";
                                increment /= 100;
                            }

                            var rangeControl = new RangeControl(x.Key, FitDescriptionText(units, description), displayName, increment, displayscale, lowerRange, upperRange, value);

                            //Console.WriteLine("{0} {1} {2} {3} {4}", x.Key, increment, lowerRange, upperRange, value);

                            ThemeManager.ApplyThemeTo(rangeControl);

                            if (intValue < lowerRange)
                                rangeControl.NumericUpDownControl.BackColor = Color.Orange;

                            if (intValue > upperRange)
                                rangeControl.NumericUpDownControl.BackColor = Color.Orange;

                            rangeControl.AttachEvents();

                            rangeControl.ValueChanged += Control_ValueChanged;

                            // set pos
            //                            rangeControl.Location = new Point(0, ypos);
                            // add control - let it autosize height
                            tableLayoutPanel1.Controls.Add(rangeControl);
                            // add height for next control
            //                            ypos += rangeControl.Height;

                            controlAdded = true;
                        }
                    }

                    if (!controlAdded)
                    {
                        // If this is a subset of values
                        string availableValuesRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values);
                        if (!String.IsNullOrEmpty(availableValuesRaw))
                        {
                            string[] availableValues = availableValuesRaw.Split(new[] { ',' });
                            if (availableValues.Any())
                            {
                                var valueControl = new ValuesControl();
                                valueControl.Name = x.Key;
                                valueControl.DescriptionText = FitDescriptionText(units, description);
                                valueControl.LabelText = displayName;

                                ThemeManager.ApplyThemeTo(valueControl);

                                var splitValues = new List<KeyValuePair<string, string>>();
                                // Add the values to the ddl
                                foreach (string val in availableValues)
                                {
                                    string[] valParts = val.Split(new[] { ':' });
                                    splitValues.Add(new KeyValuePair<string, string>(valParts[0].Trim(), (valParts.Length > 1) ? valParts[1].Trim() : valParts[0].Trim()));
                                };
                                valueControl.ComboBoxControl.DisplayMember = "Value";
                                valueControl.ComboBoxControl.ValueMember = "Key";
                                valueControl.ComboBoxControl.DataSource = splitValues;
                                valueControl.ComboBoxControl.SelectedValue = value;

                                valueControl.ValueChanged += Control_ValueChanged;

                                // set pos
            //                                valueControl.Location = new Point(0, ypos);
                                // add control - let it autosize height
                                tableLayoutPanel1.Controls.Add(valueControl);
                                // add height for next control
            //                                ypos += valueControl.Height;
                            }
                        }
                    }
                } // if there is an error simply dont show it, ie bad pde file, bad scale etc
                catch (Exception ex) { log.Error(ex); }
            }
        }
        /// <summary>
        /// Binds the param list.
        /// </summary>
        private void BindParamList()
        {
            tableLayoutPanel1.Controls.Clear();
            if (_params == null || _params.Count == 0) SortParamList();
            _params.ForEach(x =>
             {
            if(!String.IsNullOrEmpty(x.Key))
            {
                try
                {
                    bool controlAdded = false;

                    string value = ((float)MainV2.comPort.param[x.Key]).ToString("0.###");
                    string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description);
                    string displayName = x.Value;
                    string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units);

                    // If this is a range
                    string rangeRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range);
                    string incrementRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment);
                    if (!String.IsNullOrEmpty(rangeRaw) && !String.IsNullOrEmpty(incrementRaw))
                    {
                        float increment, intValue;
                        float.TryParse(incrementRaw, out increment);
                        float.TryParse(value, out intValue);

                        string[] rangeParts = rangeRaw.Split(new[] { ' ' });
                        if (rangeParts.Count() == 2 && increment > 0)
                        {
                            float lowerRange;
                            float.TryParse(rangeParts[0], out lowerRange);
                            float upperRange;
                            float.TryParse(rangeParts[1], out upperRange);

                            int scaler = (int)float.Parse((1 / increment).ToString(CultureInfo.InvariantCulture));
                            int scaledLowerRange = 0, scaledUpperRange = 0;
                            int scaledIncrement = (int)increment;
                            if (scaler > 0)
                            {
                                scaledLowerRange = (int)(lowerRange * scaler);
                                scaledUpperRange = (int)(upperRange * scaler);
                                scaledIncrement = (int)float.Parse((increment * scaler).ToString(CultureInfo.InvariantCulture));
                                intValue *= scaler;
                            }

                            var rangeControl = new RangeControl();
                            rangeControl.Name = x.Key;
                            rangeControl.Scaler = scaler;
                            rangeControl.DescriptionText = FitDescriptionText(units, description);
                            rangeControl.LabelText = displayName;
                            rangeControl.TrackBarControl.Minimum = scaledLowerRange;
                            rangeControl.TrackBarControl.Maximum = scaledUpperRange;
                            rangeControl.TrackBarControl.TickFrequency = scaledIncrement;
                            rangeControl.TrackBarControl.Value = (int)intValue;

                            rangeControl.NumericUpDownControl.Increment = (decimal)increment;
                            rangeControl.NumericUpDownControl.DecimalPlaces = scaler.ToString(CultureInfo.InvariantCulture).Length - 1;
                            rangeControl.NumericUpDownControl.Minimum = (decimal)lowerRange;
                            rangeControl.NumericUpDownControl.Maximum = (decimal)upperRange;
                            rangeControl.NumericUpDownControl.Value = (decimal)((float)MainV2.comPort.param[x.Key]);

                            rangeControl.AttachEvents();

                            tableLayoutPanel1.Controls.Add(rangeControl);

                            controlAdded = true;
                        }
                    }

                    if (!controlAdded)
                    {
                        // If this is a subset of values
                        string availableValuesRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values);
                        if (!String.IsNullOrEmpty(availableValuesRaw))
                        {
                            string[] availableValues = availableValuesRaw.Split(new[] { ',' });
                            if (availableValues.Any())
                            {
                                var valueControl = new ValuesControl();
                                valueControl.Name = x.Key;
                                valueControl.DescriptionText = FitDescriptionText(units, description);
                                valueControl.LabelText = displayName;

                                var splitValues = new List<KeyValuePair<string, string>>();
                                // Add the values to the ddl
                                availableValues.ForEach(val =>
                                {
                                    string[] valParts = val.Split(new[] { ':' });
                                    splitValues.Add(new KeyValuePair<string, string>(valParts[0], (valParts.Length > 1) ? valParts[1] : valParts[0]));
                                });
                                valueControl.ComboBoxControl.DisplayMember = "Value";
                                valueControl.ComboBoxControl.ValueMember = "Key";
                                valueControl.ComboBoxControl.DataSource = splitValues;
                                valueControl.ComboBoxControl.SelectedValue = value;

                                tableLayoutPanel1.Controls.Add(valueControl);
                            }
                        }
                    }
                } // if there is an error simply dont show it, ie bad pde file, bad scale etc
                catch (Exception ex) { log.Error(ex); }
            }
             });
        }
        /// <summary>
        /// Binds the param list.
        /// </summary>
        private void BindParamList()
        {
            tableLayoutPanel1.Controls.Clear();
            if (_params == null || _params.Count == 0) SortParamList();

            // get the params if nothing exists already
            if (_params != null && _params.Count == 0)
            {
                try
                {
                    Utilities.ParameterMetaDataParser.GetParameterInformation();

                    _parameterMetaDataRepository.Reload();

                    SortParamList();
                }
                catch (Exception exp) { log.Error(exp); } // just to cleanup any errors
            }

            this.SuspendLayout();

            _params.OrderBy(x => x.Key).ForEach(x => 
         {
            if(!String.IsNullOrEmpty(x.Key))
            {
                try
                {
                    bool controlAdded = false;

                    if (!x.Key.StartsWith("MNT_"))
                        return;

                    string value = ((float)MainV2.comPort.param[x.Key]).ToString("0.###", CultureInfo.InvariantCulture);
                    string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description);
                    string displayName = x.Value + " (" + x.Key + ")";
                    string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units);

                    // If this is a range
                    string rangeRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range);
                    string incrementRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment);

                    // modify for scaling
                    float test = 1;
                    MAVLink.modifyParamForDisplay(true, x.Key, ref test);

                    if (test != 1)
                    {
                        if (units.ToLower() == "centi-degrees")
                        {
                            units = "Degrees";
                            incrementRaw = "0.1";
                            string[] rangeParts = rangeRaw.Split(new[] { ' ' });
                            if (rangeParts.Count() == 2)
                            {
                                float lowerRange;
                                float.TryParse(rangeParts[0], out lowerRange);
                                float upperRange;
                                float.TryParse(rangeParts[1], out upperRange);

                                rangeRaw = (lowerRange / 100) + " " + (upperRange / 100);
                            }
                        }
                        else if (units.ToLower() == "centimeters")
                        {
                            units = "Meters";
                            incrementRaw = "0.1";
                            string[] rangeParts = rangeRaw.Split(new[] { ' ' });
                            if (rangeParts.Count() == 2)
                            {
                                float lowerRange;
                                float.TryParse(rangeParts[0], out lowerRange);
                                float upperRange;
                                float.TryParse(rangeParts[1], out upperRange);

                                rangeRaw = (lowerRange / 100) + " " + (upperRange / 100);
                            }
                        }
                        else
                        {
                            units += " / " + (int)(1 / test);
                        }
                    }

                    if (!String.IsNullOrEmpty(rangeRaw) && !String.IsNullOrEmpty(incrementRaw))
                    {
                        float increment, intValue;
                        float.TryParse(incrementRaw, out increment);
                        float.TryParse(value, out intValue);

                        string[] rangeParts = rangeRaw.Split(new[] { ' ' });
                        if (rangeParts.Count() == 2 && increment > 0)
                        {
                            float lowerRange;
                            float.TryParse(rangeParts[0], out lowerRange);
                            float upperRange;
                            float.TryParse(rangeParts[1], out upperRange);

                            int scaler = (int)float.Parse((1 / increment).ToString(CultureInfo.InvariantCulture));
                            int scaledLowerRange = 0, scaledUpperRange = 0;
                            int scaledIncrement = (int)increment;
                            if (scaler > 0)
                            {
                                scaledLowerRange = (int)(lowerRange * scaler);
                                scaledUpperRange = (int)(upperRange * scaler);
                                scaledIncrement = (int)float.Parse((increment * scaler).ToString(CultureInfo.InvariantCulture));
                                intValue *= scaler;
                            }

                            var rangeControl = new RangeControl();
                            rangeControl.Name = x.Key;
                            rangeControl.Scaler = scaler;
                            rangeControl.DescriptionText = FitDescriptionText(units, description);
                            rangeControl.LabelText = displayName;
                            rangeControl.TrackBarControl.Minimum = Math.Min(scaledLowerRange,(int)intValue);
                            rangeControl.TrackBarControl.Maximum = Math.Max(scaledUpperRange, (int)intValue);
                            rangeControl.TrackBarControl.TickFrequency = scaledIncrement;
                            rangeControl.TrackBarControl.Value = (int)intValue;

                            rangeControl.NumericUpDownControl.Increment = (decimal)increment;
                            rangeControl.NumericUpDownControl.DecimalPlaces = scaler.ToString(CultureInfo.InvariantCulture).Length - 1;
                            rangeControl.NumericUpDownControl.Minimum = (decimal)Math.Min(lowerRange, ((float)MainV2.comPort.param[x.Key]));
                            rangeControl.NumericUpDownControl.Maximum = (decimal)Math.Max(upperRange, ((float)MainV2.comPort.param[x.Key]));
                            rangeControl.NumericUpDownControl.Value = (decimal)((float)MainV2.comPort.param[x.Key]);

                            rangeControl.AttachEvents();

                            tableLayoutPanel1.Controls.Add(rangeControl);

                            controlAdded = true;
                        }
                    }

                    if (!controlAdded)
                    {
                        // If this is a subset of values
                        string availableValuesRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values);
                        if (!String.IsNullOrEmpty(availableValuesRaw))
                        {
                            string[] availableValues = availableValuesRaw.Split(new[] { ',' });
                            if (availableValues.Any())
                            {
                                var valueControl = new ValuesControl();
                                valueControl.Name = x.Key;
                                valueControl.DescriptionText = FitDescriptionText(units, description);
                                valueControl.LabelText = displayName;

                                var splitValues = new List<KeyValuePair<string, string>>();
                                // Add the values to the ddl
                                availableValues.ForEach(val =>
                                {
                                    string[] valParts = val.Split(new[] { ':' });
                                    splitValues.Add(new KeyValuePair<string, string>(valParts[0], (valParts.Length > 1) ? valParts[1] : valParts[0]));
                                });
                                valueControl.ComboBoxControl.DisplayMember = "Value";
                                valueControl.ComboBoxControl.ValueMember = "Key";
                                valueControl.ComboBoxControl.DataSource = splitValues;
                                valueControl.ComboBoxControl.SelectedValue = value;

                                tableLayoutPanel1.Controls.Add(valueControl);
                            }
                        }
                    }
                } // if there is an error simply dont show it, ie bad pde file, bad scale etc
                catch (Exception ex) { log.Error(ex); }
            }
         });

            ThemeManager.ApplyThemeTo(this);

            this.ResumeLayout();
        }