Example #1
0
        private void button_Done_Click(object sender, EventArgs e)
        {
            Variables.cumul_data.ForEach(Console.WriteLine);
            File.WriteAllLines(Constants.DATA_PATH, Variables.cumul_data);
            File.WriteAllLines(Constants.RAND_PATH, Variables.cumul_rand);

            Variables.training = false;
            progressWorker.RunWorkerAsync();
            Thread.Sleep(100);
            bool trained = SVMClass.trainProblem();

            Thread.Sleep(300);
            if (trained)
            {
                cntrlForm.holdCommandListener = false;
                //cntrlForm.stopWatch.Restart();
                Console.WriteLine("Port is open: {0}", cntrlForm.port.IsOpen);
                cntrlForm.trained = true;
            }
            else
            {
                MessageBox.Show("Training failed, please restart the program.");
            }
            this.Close();
        }
Example #2
0
        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Console.WriteLine("Training: " + Variables.training.ToString());
            if (!Variables.training)
            {
                Thread.Sleep(33);
                //Console.Write(port.BytesToRead);

                string dataline = port.ReadExisting();
                //Console.Write(dataline);
                Variables.processedline = SVMClass.processData(dataline);
                //Console.WriteLine(Variables.dataline);
                if (Variables.processedline[0] != null)
                {
                    Variables.newdata = "0 " + Variables.processedline[0];
                }
                else
                {
                    Variables.newdata = "0 null";
                }
                File.WriteAllText(Constants.NEWDATA_PATH, Variables.newdata);

                Thread.Sleep(67);
                if (SVMClass.checkExistingModel())
                {
                    doAction();
                }
                else
                {
                    Console.WriteLine("No model!");
                }
            }
            else if (Variables.training)
            {
                Thread.Sleep(33);
                //Console.Write(port.BytesToRead);

                string dataline = port.ReadExisting();
                Console.WriteLine(dataline);
                Variables.processedline = SVMClass.processData(dataline);
                string fulldataline = Variables.selectedCode.ToString() + " " + Variables.processedline[0];
                string randdataline = Variables.selectedCode.ToString() + " " + Variables.processedline[1];
                if (!fulldataline.Contains("null"))
                {
                    Variables.dataset.Add(fulldataline);
                    Variables.randomized.Add(randdataline);
                }
            }
        }
Example #3
0
        private void doAction()
        {
            int      command = SVMClass.predictSVM();
            TimeSpan ts      = stopWatch.Elapsed;

            Console.WriteLine("Stopwatch ms: " + ts.Milliseconds.ToString());
            if (ts.Milliseconds > 750)
            {
                if (command == 1 && checkBox_ClickDrag.Checked)
                {
                    if (clickedDown)
                    {
                        ClickFunctions.leftUP();
                        clickedDown = false;
                    }

                    else
                    {
                        ClickFunctions.leftDOWN();
                        clickedDown = true;
                    }
                    stopWatch.Restart();
                }
                else if (command == 2 && checkBox_DoubleClick.Checked)
                {
                    ClickFunctions.doubleCLICK();
                    stopWatch.Restart();
                }

                else if (command == 3 && checkBox_RightClick.Checked)
                {
                    ClickFunctions.rightCLICK();
                    stopWatch.Restart();
                }
                else
                {
                    //
                }
            }
        }