Ejemplo n.º 1
0
        public bool Parse(string data, bool updating)
        {
            string[] colors;
            bool     success = true;

            data = data.Replace("\r", "");
            if (data.Contains('\n'))
            {
                colors = data.Split('\n');
            }
            else
            {
                colors = new string[] { data }
            };
            for (int count = 0; count < colors.Length; count++)
            {
                if (colors[count].Contains("color ") && colors[count].Contains(","))
                {
                    bool     colorOK = false;
                    string[] line = colors[count].Split(' ');
                    int      index, h, s, v;
                    if (line.Length == 3 && int.TryParse(line[1], out index))
                    {
                        string[] parms = line[2].Split(',');
                        if (parms.Length == 3)
                        {
                            if (int.TryParse(parms[0], out h) &&
                                int.TryParse(parms[1], out s) &&
                                int.TryParse(parms[2], out v))
                            {
                                if (h >= 0 && h < 360 && s >= 0 && s < 256 && v >= 0 && v < 256)
                                {
                                    if (updating)
                                    {
                                        HsvColor hsv = new HsvColor(h, s, v);
                                        if (!storedColors[index].compare(hsv))
                                        {
                                            storedColors[index].set(hsv);
                                            storedColors[index].fetched = true;
                                            storedColors[index].changed = true;
                                        }
                                    }
                                    else
                                    {
                                        storedColors[index] = new ColorStore(h, s, v, true);
                                    }
                                    colorOK = true;
                                }
                            }
                        }
                    }
                    if (!colorOK)
                    {
                        success = false;
                    }
                }
            }
            return(success);
        }
Ejemplo n.º 2
0
 public void MavlinkParameter(int index, float value)
 {
     index -= Form1.MAV_COLOR_START;
     byte[] bytes = BitConverter.GetBytes(value);
     storedColors[index] = new ColorStore(bytes[1] * 256 + bytes[0], bytes[2], bytes[3], true);
     updateButtonState(colorButtons[index], solidColorStates[index], storedColors[index].get());
     if (index == 15)
     {
         MavlinkCompleted();
     }
 }
Ejemplo n.º 3
0
        private MAVLink.mavlink_param_set_t comms_WriteMavlink(object sender, CommandEventArgs e)
        {
            MAVLink.mavlink_param_set_t param = new MAVLink.mavlink_param_set_t();
            if (!storedColors[e.Index].changed)
            {
                return(param);
            }
            param.target_system    = comms.sysid;
            param.target_component = comms.compid;
            form1.SetIdString(ref param.param_id, "color_" + e.Index.ToString());
            param.param_type = (byte)MAVLink.MAV_PARAM_TYPE.UINT32;
            ColorStore color = storedColors[e.Index];

            param.param_value = BitConverter.ToSingle(new byte[] {
                (byte)(color.hsv.hue & 0xff),
                (byte)((color.hsv.hue >> 8) & 0xff),
                (byte)(color.hsv.sat),
                (byte)(color.hsv.val)
            }, 0);
            return(param);
        }