Ejemplo n.º 1
0
        public void Check_Grid()
        {
            double d = 0d;

            LBL = 0.0;


            if (double.TryParse(dgvRiver[2, 0].Value.ToString(), out LBL))
            {
                d = 0d;
            }


            for (int i = 0; i < dgvRiver.Rows.Count - 1; i++)
            {
                dgvRiver[0, i].Value = (i + 1);

                if (dgvRiver[1, i].Value != null)
                {
                    if (!double.TryParse(dgvRiver[1, i].Value.ToString(), out d))
                    {
                        d = 0;
                    }
                }
                else
                {
                    d = 0;
                }
                dgvRiver[1, i].Value = d.ToString("0.000");

                if (dgvRiver[2, i].Value != null)
                {
                    if (!double.TryParse(dgvRiver[2, i].Value.ToString(), out d))
                    {
                        d = 0;
                    }
                }
                else
                {
                    d = 0;
                }
                if (d < LBL)
                {
                    LBL = d;
                }

                txt_LBL.Text         = LBL.ToString("0.000");
                dgvRiver[2, i].Value = d.ToString("0.000");
            }

            int wid = dgvRiver.Width - dgvRiver.RowHeadersWidth - SL_N.Width;

            wid         -= 19;
            dist.Width   = wid / 2;
            reduce.Width = wid / 2;
        }
Ejemplo n.º 2
0
 void SendMessage(string msg)
 {
     Debug.Assert(msg == "R" || msg == "0" || msg == "1");
     LBL.Invoke(new Action(() => { LBL.Text = $"Score: {score}"; }));
     //this.Invoke(new Action(() => { this.Text = "Send:" + msg; }));
     writer.WriteLine(msg);
     writer.Flush();
     try
     {
         string[] s = reader.ReadLine().Split(' ');
         if (msg == "R")
         {
             score = 0;
         }
         else
         {
             score += Math.Max(int.Parse(s[s.Length - 2]), 0);
         }
     } catch (Exception error) { this.Invoke(new Action(() => { this.Text = error.ToString(); })); }
 }
Ejemplo n.º 3
0
        private void Comport_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Byte[] buffer = new Byte[1024];
            Int32  length = (sender as SerialPort).Read(buffer, 0, buffer.Length);

            Array.Resize(ref buffer, length);
            string s = BitConverter.ToString(buffer);

            if (!IsSerialFormatCorrect(s))
            {
                return;
            }
            LBL.Invoke(new Action(() =>
            {
                //LBL.Text = BitConverter.ToString(buffer);
                this.Text = s;
                for (int i = 0, j = 0; i < s.Length; i++)
                {
                    if (s[i] == '0' || s[i] == '1')
                    {
                        if (j == 3 && s[i] == '1')
                        {
                            ResetAll();
                        }
                        else if (j < socketCount)
                        {
                            if (s[i] == '1')
                            {
                                SetKeyState(j, 1);
                            }
                            else if (s[i] == '0')
                            {
                                SetKeyState(j, 0);
                            }
                        }
                        j++;
                    }
                }
            }));
        }
Ejemplo n.º 4
0
        private void Comport_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Byte[] buffer = new Byte[1024];
            Int32  length = (sender as SerialPort).Read(buffer, 0, buffer.Length);

            Array.Resize(ref buffer, length);
            LBL.Invoke(new Action(() =>
            {
                //LBL.Text = BitConverter.ToString(buffer);
                string s  = BitConverter.ToString(buffer);
                this.Text = s;
                for (int i = 0, j = 0; i < s.Length; i++)
                {
                    if (s[i] == '0' || s[i] == '1')
                    {
                        if (j == 3 && s[i] == '1')
                        {
                            SendMessage("R");
                            keyState = -1;
                        }
                        else if (j == 0)
                        {
                            if (s[i] == '1')
                            {
                                keyState = 1;
                            }
                            else if (s[i] == '0')
                            {
                                keyState = 0;
                            }
                        }
                        j++;
                    }
                }
            }));
        }
Ejemplo n.º 5
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            this.Size     = new Size(400, 800);
            this.Location = new Point(0, 0);
            InitializeControls();
            {
                Thread thread = new Thread(() =>
                {
                    while (true)
                    {
                        StringBuilder s = new StringBuilder();
                        foreach (var sh in socketHandlers)
                        {
                            s.AppendLine(sh.status);
                        }
                        s.AppendLine(status);
                        if (s.ToString() != LBL.Text)
                        {
                            LBL.Invoke(new Action(() => { LBL.Text = s.ToString(); }));
                        }
                        Thread.Sleep(10);
                    }
                });
                thread.IsBackground = true;
                thread.Start();
            }
            {
                Thread thread = new Thread(() =>
                {
                    while (true)
                    {
                        PBX.Invoke(new Action(() => { PBX.Image = (AIaction == '0' ? Properties.Resources.buttonLight : Properties.Resources.buttonDark); }));
                        TB.Invoke(new Action(() =>
                        {
                            int target = ((int)Math.Round(AIpressButtonPossibility * 1000.0) - TB.Value);
                            if (target > 0)
                            {
                                TB.Value += (int)Math.Ceiling(target * 0.2);
                            }
                            if (target < 0)
                            {
                                TB.Value += (int)Math.Floor(target * 0.2);
                            }
                            Application.DoEvents();
                        }));
                        Thread.Sleep(20);
                    }
                    ;
                });
                thread.IsBackground = true;
                thread.Start();
            }
            try
            {
                comport = new SerialPort("COM3", 115200, Parity.None, 8, StopBits.One);
                comport.DataReceived += Comport_DataReceived;
                if (!comport.IsOpen)
                {
                    comport.Open();
                }
            }
            catch (Exception error)
            {
                status += $"\r\nArduino doesn't connected, restart the program to try again\r\nError:\r\n{error}";
            }
            for (int i = 1; i <= socketCount; i++)
            {
                socketHandlers.Add(new MessageSender(port + i));
            }
            socketHandlers.Add(new MessageSender(port));
            MessageReceiver receiver = new MessageReceiver(aiPort);

            receiver.msgReceived += Receiver_msgReceived;
            receiver.Start();
        }