Esempio n. 1
0
        private void btnSaveLog_Click(object sender, EventArgs e)
        {
            var err = "";

            foreach (var item in lstRaw.Items)
            {
                JoyStickDataReader.WriteLog(item.ToString() + "\r\n", true, ref err);
            }
            lstRaw.Items.Clear();
        }
Esempio n. 2
0
        private void Start()
        {
            InitThread();
            var err = "";

            while (true)
            {
                var isportnamechanged = false;

                Invoke(new MethodInvoker(delegate { isportnamechanged = serialPort1.PortName != cmbPort.Text; }));
                if (!serialPort1.IsOpen || isportnamechanged)
                {
                    Invoke(new MethodInvoker(OpenCom));
                }
                if (serialPort1.IsOpen)
                {
                    var data = JoyStickDataReader.GetValues(serialPort1, ref err);
                    if (string.IsNullOrEmpty(data.Sign))
                    {
                        continue;
                    }
                    Invoke(new MethodInvoker(delegate
                    {
                        var dataItem = _joyStickDataReader.CalculateData(data.Sign);
                        if (dataItem == null)
                        {
                            return;
                        }
                        var caption = dataItem.Title + "=" +
                                      _joyStickDataReader.GetHexString(data.SpeedHighSide, dataItem) + ":" +
                                      _joyStickDataReader.GetHexString(data.SpeedLowSide, dataItem);

                        lstRaw.Items.Add(caption);
                        lstRaw.TopIndex = lstRaw.Items.Count - 1;
                        var listData    = (ListBox)null;
                        switch (dataItem.Sign)
                        {
                        case Sign.Ln:
                            listData = lstLD;
                            break;

                        case Sign.Lp:
                            listData = lstRU;
                            break;

                        case Sign.Rn:
                            listData = lstRD;
                            break;

                        case Sign.Rp:
                            listData = lstLU;
                            break;

                        case Sign.Separator:
                            listData = lstSep;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                        if (dataItem.Sign != Sign.Separator)
                        {
                            CleanLabel(caption, dataItem);
                            var speed = JoyStickDataReader.ClampToSbyte(_joyStickDataReader.GetSpeed(
                                                                            _joyStickDataReader.GetIntString(data.SpeedHighSide + data.SpeedLowSide,
                                                                                                             dataItem)), dataItem.Sign == Sign.Rp | dataItem.Sign == Sign.Lp);

                            (dataItem.Sign == Sign.Ln | dataItem.Sign == Sign.Lp ? lblSpeedL : lblSpeedR).Text = speed.ToString();
                        }

                        if (listData != null)
                        {
                            if (listData.Items.Count > 0 &&
                                (string)listData.Items[listData.Items.Count - 1] == caption)
                            {
                                return;
                            }
                            listData.Items.Add(caption);
                            listData.TopIndex = listData.Items.Count - 1;
                        }
                        else
                        {
                            listData = null;
                        }
                    }));
                }
                Thread.Sleep(1);
            }
        }
Esempio n. 3
0
 private void InitThread()
 {
     _joyStickDataReader = new JoyStickDataReader();
 }