Example #1
0
        public static void stopRecording(object source, System.Timers.ElapsedEventArgs e)   //stops the recording and checks & resets various values to normal
        {
            Console.Clear();
            endRecording = true;
            recording    = false;

            RecordData.stopArduino();
            RecordData.boxDataReady = false;
            if (COMManager.streamOpen)
            {
                COMManager.CloseCom();
            }
            if (RecordData.fs != null)
            {
                RecordData.fs.Close();
            }
            if (RecordData.file != null)
            {
                RecordData.file.Close();
            }
            startCode();
        }
Example #2
0
        public static void Main()   //primary program loop
        {
            while (true)
            {
                startCode();
                string res = getInput();

                if (res == "1")
                {
                    Console.Clear();
                    COMManager.OpenCom();
                    RecordData.startArduino();
                    if (RecordData.RecordingData && COMManager.streamOpen)
                    {
                        endRecording = false;
                        Console.WriteLine("Starting data recording, please wait " + RecordData.recordTime + "s.");
                        createThreadRecording();
                        startTimer();
                    }
                    else
                    {
                        Console.WriteLine("Failed to start recording. Were we unable to open a serial port?");
                    }
                }
                else if (res == "2")
                {
                    settingsMenu();
                    string newResult = getInput();
                    switch (newResult)  //contains various results for different inputs
                    {
                    case "1":
                        Console.WriteLine("How long would you like to record (seconds) | Default is 5 seconds:");
                        string period = getInput();
                        try {
                            RecordData.recordTime = int.Parse(period);
                            Console.WriteLine("Recording time set to " + period + " seconds.");
                        } catch (Exception e) {
                            Console.WriteLine("Failed to set recording time. Did you type an integer? Error: " + e);
                        }
                        //do recording
                        break;

                    case "2":
                        Console.WriteLine("Please enter the new COM port (default is /dev/ttymxc3 | Current COM: " + COMManager.comPort + "):");
                        string newCom = getInput();
                        COMManager.comPort = newCom;
                        Console.WriteLine("COM port is now set to: " + newCom);
                        break;

                    case "3":
                        Console.WriteLine("Please enter the new BAUD rate (default is 115200 | Current BAUD: " + COMManager.baudRate + "):");
                        string newBaud = getInput();
                        int    newFinalBaud;
                        try {
                            newFinalBaud        = int.Parse(newBaud);
                            COMManager.baudRate = newFinalBaud;
                            Console.WriteLine("BAUD rate is now set to: " + newFinalBaud);
                        } catch (Exception e) {
                            Console.WriteLine("Failed to set BAUD. Did you type an integer? Error: " + e);
                        }
                        break;

                    default:
                        Console.Clear();
                        break;
                    }
                }
                else if (res == "3")
                {
                    Console.Clear();
                    //return;
                }
                else if (res == "4")
                {
                    Console.Clear();
                    endRecording = true;
                    recording    = false;
                    RecordData.stopArduino();
                    RecordData.boxDataReady = false;
                    if (COMManager.streamOpen)
                    {
                        COMManager.CloseCom();
                    }
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Exiting...");
                    if (!endRecording)
                    {
                        endRecording = true;
                    }
                    if (recording)
                    {
                        recording = false;
                    }
                    if (COMManager.streamOpen)
                    {
                        COMManager.CloseCom();
                    }
                    break;
                }
            }
        }