private void OnResizeForm1(object sender, EventArgs ee) { if ((this.form1.Width > Constants.FORM_MIN_WIDTH) && (this.form1.Height > Constants.FORM_MIN_HEIGHT)) { this.panel1.Width = this.form1.ClientSize.Width; this.panel1.Height = this.form1.ClientSize.Height; //Intialize Labels 40% of the screen int num_rows = (int)((this.sensors.Sensors.Count + 2) / 2); //additional row for HR and total sampling rate int textBoxHeight = ((int)(0.40 * this.panel1.ClientSize.Height) - ((this.sensors.Sensors.Count - 1) * Constants.WIDGET_SPACING)) / num_rows; int textBoxWidth = ((this.panel1.ClientSize.Width - (3 * Constants.WIDGET_SPACING)) / 2); int currentTextY = (int)(this.panel1.Height * 0.60); int leftTextX = Constants.WIDGET_SPACING; int rightTextX = (Constants.WIDGET_SPACING * 2) + textBoxWidth; int currentTextX = Constants.WIDGET_SPACING; //System.Windows.Forms.Label samplingLabel = (System.Windows.Forms.Label)this.textBoxes[0]; //samplingLabel.Width = textBoxWidth; //samplingLabel.Height = textBoxHeight; Form f = new Form(); f.Width = textBoxWidth; f.Height = textBoxHeight; Font textFont = GUI.CalculateBestFitFont(f.CreateGraphics(), Constants.MIN_FONT, Constants.MAX_FONT, f.ClientSize, "textBoxAC11", new Font(Constants.FONT_FAMILY, (float)32.0, FontStyle.Bold), (float)0.9, (float)0.9); System.Windows.Forms.Label t; foreach (Sensor sensor in this.sensors.Sensors) { string labelKey = "MITes" + sensor.ID; t = (System.Windows.Forms.Label)this.sensorLabels[labelKey]; t.Font = textFont; t.Size = new System.Drawing.Size(textBoxWidth, textBoxHeight); t.Location = new System.Drawing.Point(currentTextX, currentTextY); if (currentTextX == leftTextX) currentTextX = rightTextX; else { currentTextX = leftTextX; currentTextY += (textBoxHeight + Constants.WIDGET_SPACING); } } t = (System.Windows.Forms.Label)this.sensorLabels["SampRate"]; t.Font = textFont; t.Size = new System.Drawing.Size(textBoxWidth, textBoxHeight); t.Location = new System.Drawing.Point(currentTextX, currentTextY); if (currentTextX == leftTextX) currentTextX = rightTextX; else { currentTextX = leftTextX; currentTextY += (textBoxHeight + Constants.WIDGET_SPACING); } //adjust the size of the plotter aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, this.mitesDecoders[0], new Size(this.panel1.Width, (int)(0.60 * this.panel1.Height))); SetFormPositions(); this.isResized = true; } }
private void OnResize(object sender, EventArgs ee) { if ((this.Width > Constants.FORM_MIN_WIDTH) && (this.Height > Constants.FORM_MIN_HEIGHT)) { this.tabControl1.Width = this.ClientSize.Width; this.tabControl1.Height = this.ClientSize.Height; this.tabPage1.Width =this.panel1.Width = this.tabPage2.Width = this.tabPage3.Width = this.tabPage4.Width = this.tabControl1.ClientSize.Width; this.tabPage1.Height = this.panel1.Height = this.tabPage2.Height = this.tabPage3.Height = this.tabPage4.Height = this.tabControl1.ClientSize.Height; //Intialize Labels 40% of the screen int num_rows = (int)((this.sensors.Sensors.Count + 2) / 2); //additional row for HR and total sampling rate int textBoxHeight = ((int)(0.40 * this.tabPage1.ClientSize.Height) - ((this.sensors.Sensors.Count - 1) * Constants.WIDGET_SPACING)) / num_rows; int textBoxWidth = ((this.tabPage1.ClientSize.Width - (3 * Constants.WIDGET_SPACING)) / 2); int currentTextY = (int)(this.tabPage1.Height * 0.60); int leftTextX = Constants.WIDGET_SPACING; int rightTextX = (Constants.WIDGET_SPACING * 2) + textBoxWidth; int currentTextX = Constants.WIDGET_SPACING; //System.Windows.Forms.Label samplingLabel = (System.Windows.Forms.Label)this.textBoxes[0]; //samplingLabel.Width = textBoxWidth; //samplingLabel.Height = textBoxHeight; Form f = new Form(); f.Width = textBoxWidth; f.Height = textBoxHeight; Font textFont = GUI.CalculateBestFitFont(f.CreateGraphics(), Constants.MIN_FONT, Constants.MAX_FONT, f.ClientSize, "textBoxAC11", new Font(Constants.FONT_FAMILY, (float)32.0, FontStyle.Bold), (float)0.9, (float)0.9); System.Windows.Forms.Label t; foreach (Sensor sensor in this.sensors.Sensors) { string labelKey = "MITes" + sensor.ID; t=(System.Windows.Forms.Label)this.sensorLabels[labelKey]; t.Font = textFont; t.Size = new System.Drawing.Size(textBoxWidth, textBoxHeight); t.Location = new System.Drawing.Point(currentTextX, currentTextY); if (currentTextX == leftTextX) currentTextX = rightTextX; else { currentTextX = leftTextX; currentTextY += (textBoxHeight + Constants.WIDGET_SPACING); } } t = (System.Windows.Forms.Label)this.sensorLabels["SampRate"]; t.Font = textFont; t.Size = new System.Drawing.Size(textBoxWidth, textBoxHeight); t.Location = new System.Drawing.Point(currentTextX, currentTextY); if (currentTextX == leftTextX) currentTextX = rightTextX; else { currentTextX = leftTextX; currentTextY += (textBoxHeight + Constants.WIDGET_SPACING); } //foreach (System.Windows.Forms.Label t in this.sensorLabels) //{ // t.Font = textFont; // t.Size = new System.Drawing.Size(textBoxWidth, textBoxHeight); // t.Location = new System.Drawing.Point(currentTextX, currentTextY); // if (currentTextX == leftTextX) // currentTextX = rightTextX; // else // { // currentTextX = leftTextX; // currentTextY += (textBoxHeight + Constants.WIDGET_SPACING); // } //} //Initialize Buttons int button_width = this.tabPage2.ClientSize.Width - Constants.SCREEN_LEFT_MARGIN - Constants.SCREEN_RIGHT_MARGIN; int button_height = (this.tabPage2.ClientSize.Height - Constants.SCREEN_TOP_MARGIN - Constants.SCREEN_BOTTOM_MARGIN - (this.annotation.Categories.Count * Constants.WIDGET_SPACING)) / (this.annotation.Categories.Count + 1); int button_x = Constants.SCREEN_LEFT_MARGIN; int button_y = Constants.SCREEN_TOP_MARGIN * 2; int delta_y = button_height + Constants.WIDGET_SPACING; int button_id = 0; f.Size = new Size(button_width, button_height); Font buttonFont = GUI.CalculateBestFitFont(f.CreateGraphics(), Constants.MIN_FONT, Constants.MAX_FONT, f.ClientSize, longest_label, new Font(Constants.FONT_FAMILY, (float)32.0, FontStyle.Bold), (float)0.9, (float)0.9); foreach (System.Windows.Forms.Button button in categoryButtons) { button.Location = new System.Drawing.Point(button_x, button_y + button_id * delta_y); button.Font = buttonFont; button.Size = new System.Drawing.Size(button_width, button_height); button_id++; } //adjust round buttons start/stop -reset button_width = (this.Size.Width - Constants.SCREEN_LEFT_MARGIN - Constants.SCREEN_RIGHT_MARGIN - Constants.WIDGET_SPACING) / 2; this.startStopButton.Size = new System.Drawing.Size(button_width, button_height); this.resetButton.Size = new System.Drawing.Size(button_width, button_height); this.startStopButton.Location = new System.Drawing.Point(Constants.SCREEN_LEFT_MARGIN, button_y + button_id * delta_y); this.resetButton.Location = new System.Drawing.Point(this.startStopButton.Location.X + this.startStopButton.Size.Width + Constants.WIDGET_SPACING, button_y + button_id * delta_y); this.startStopButton.Font = buttonFont; this.resetButton.Font = buttonFont; //adjust the size of the plotter aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, this.mitesDecoders[0], new Size(this.panel1.Width, (int)(0.60 * this.panel1.Height))); SetFormPositions(); this.isResized = true; } }
//private MITesDataCollectionForm thisForm = null; private bool InitializeMITes(string dataDirectory) { // thisForm = this; SetFormPositions(); //depending on the number of receivers initialize mites objects int maxPortSearched = 1; for (int i = 0; (i < this.sensors.TotalReceivers); i++) { progressMessage += "Searching for receiver " +i +"...\r\n"; this.mitesControllers[i] = new MITesReceiverController(MITesReceiverController.FIND_PORT, BYTES_BUFFER_SIZE); int portNumber = MITesReceiverController.FIND_PORT; //#if (PocketPC) try { for (int j = maxPortSearched; (j < Constants.MAX_PORT); j++) { portNumber = maxPortSearched = j; progressMessage += "Testing COM Port " + portNumber; if (this.mitesControllers[i].TestPort(portNumber, BYTES_BUFFER_SIZE)) { progressMessage += "... Success\r\n"; break; } else progressMessage += "... Failed\r\n"; } } catch (Exception) { MessageBox.Show("Exiting: Could not find a valid COM port with a MITes receiver!"); #if (PocketPC) Application.Exit(); #else Environment.Exit(0); #endif } //#else //string[] portNames = SerialPort.GetPortNames(); //Regex comregex = new Regex("COM([0-9]+)"); //for (int j = 0; (j < portNames.Length); j++) //{ // Match m = comregex.Match(portNames[j]); // if (m.Success) // { // portNumber = Convert.ToInt32(m.Groups[1].Value); // progressMessage += "Testing COM Port " + portNumber; // if (this.mitesControllers[i].TestPort(portNumber, BYTES_BUFFER_SIZE)) // { // progressMessage += "... Success\r\n"; // break; // } // else // { // progressMessage += "... Failed\r\n"; // portNumber = MITesReceiverController.FIND_PORT; // } // } //} //#endif if (portNumber == MITesReceiverController.FIND_PORT) { progressMessage += "Could not find a valid COM port with a MITes receiver!"; MessageBox.Show("Exiting: Could not find a valid COM port with a MITes receiver!"); #if (PocketPC) Application.Exit(); #else Environment.Exit(0); #endif return false; } this.mitesControllers[i].InitializeController(portNumber, BYTES_BUFFER_SIZE, true, MITesReceiverController.USE_THREADS); this.mitesDecoders[i] = new MITesDecoder(); } aMITesActivityLogger = new MITesActivityLogger(dataDirectory + "\\data\\activity\\MITesActivityData"); aMITesActivityLogger.SetupDirectories(dataDirectory); //aMITesDecoder = new MITesDecoder(); aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, this.mitesDecoders[0], GetGraphSize(false)); //for each sensor created a counter for (int i = 0; (i < this.sensors.Sensors.Count); i++) { int sensor_id=Convert.ToInt32(((SXML.Sensor)this.sensors.Sensors[i]).ID); if (sensor_id!=0) aMITesActivityCounters.Add(sensor_id,new MITesActivityCounter(this.mitesDecoders[0],sensor_id)); } aMITesHRAnalyzer = new MITesHRAnalyzer(this.mitesDecoders[0]); aMITesDataFilterer = new MITesDataFilterer(this.mitesDecoders[0]); aMITesLogger = new MITesLoggerNew(this.mitesDecoders[0], dataDirectory + "\\data\\raw\\MITesAccelBytes", dataDirectory + "\\data\\log\\MITesLogFileBytes"); //aMITesLogger.SetActive(false); aMITesActivityLogger.WriteLogComment("Application started with command line: " + dataDirectory + " " + Constants.ACCEL_ID1 + " " + Constants.ACCEL_ID2 + " " + Constants.ACCEL_ID3 + " " );//+ //Constants.ACCEL_ID4 + " " + //Constants.ACCEL_ID5 + " " + //Constants.ACCEL_ID6 + " "); // Set the correct channels based on sannotation automatically for (int i = 0; (i < this.sensors.TotalReceivers); i++) { int[] channels = new int[6]; int channelCounter = 0; for (int j = 0; (j < this.sensors.Sensors.Count); j++) { if (Convert.ToInt32(((Sensor)this.sensors.Sensors[j]).Receiver) == i) { channels[channelCounter] = Convert.ToInt32(((Sensor)this.sensors.Sensors[j]).ID); channelCounter++; } } this.mitesControllers[i].SetChannels(this.sensors.GetNumberSensors(i), channels); } //isPlotting = true; return true; }
private void SetPlotterPartialScreen() { aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, this.mitesDecoders[0], GetGraphSize(false)); }
public MITesDataCollectionForm(string dataDirectory) { //where data is being stored this.dataDirectory = dataDirectory; //Initialize high resolution unix timer UnixTime.InitializeTime(); //Initialize and start GUI progress thread progressMessage = null; aProgressThread = new Thread(new ThreadStart(ProgressThread)); aProgressThread.Start(); #region Load Configuration files //load the activity and sensor configuration files progressMessage = "Loading XML protocol and sensors ..."; AXML.Reader reader = new AXML.Reader(Constants.MASTER_DIRECTORY, dataDirectory); #if (!PocketPC) if (reader.validate() == false) { throw new Exception("Error Code 0: XML format error - activities.xml does not match activities.xsd!"); } else { #endif this.annotation = reader.parse(); this.annotation.DataDirectory = dataDirectory; SXML.Reader sreader = new SXML.Reader(Constants.MASTER_DIRECTORY, dataDirectory); #if (!PocketPC) if (sreader.validate() == false) { throw new Exception("Error Code 0: XML format error - sensors.xml does not match sensors.xsd!"); } else { #endif this.sensors = sreader.parse(Constants.MAX_CONTROLLERS); progressMessage += " Completed\r\n"; //TODO: remove BT components progressMessage += "Loading configuration file ..."; MITesFeatures.core.conf.ConfigurationReader creader = new MITesFeatures.core.conf.ConfigurationReader(dataDirectory); this.configuration = creader.parse(); progressMessage += " Completed\r\n"; #if (!PocketPC) } } #endif #endregion Load Configuration files //Initialize 1 master decoder this.masterDecoder = new MITesDecoder(); #region Initialize External Data Reception Channels //Initialize Data reception for Bluetooth and USB if ((this.sensors.TotalReceivers > 0) && (this.sensors.TotalReceivers <= Constants.MAX_CONTROLLERS)) { //Initialize arrays to store USB and Bluetooth controllers this.mitesControllers = new MITesReceiverController[this.sensors.TotalWiredReceivers]; #if (PocketPC) this.bluetoothControllers = new BluetoothController[this.sensors.TotalBluetoothReceivers]; // this.ts = new Thread[this.sensors.TotalBluetoothReceivers]; #endif //Initialize array to store Bluetooth connection status //this.bluetoothConnectionStatus = new bool[this.sensors.TotalBluetoothReceivers]; //Initialize a decoder for each sensor this.mitesDecoders = new MITesDecoder[this.sensors.TotalReceivers]; this.aMITesActivityCounters = new Hashtable(); #if (PocketPC) #region Bluetooth reception channels initialization //Initialize and search for wockets connections progressMessage += "Initializing Bluetooth receivers ... searching " + this.sensors.TotalBluetoothReceivers+ " BT receivers\r\n"; //Try to initialize all Bluetooth receivers 10 times then exit int initializationAttempt = 0; while (initializationAttempt <= 10) { if (InitializeBluetoothReceivers() == false) { initializationAttempt++; if (initializationAttempt == 10) { MessageBox.Show("Exiting: Some Bluetooth receivers in your configuration were not initialized."); Application.Exit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } else progressMessage += "Failed to initialize all BT connections. Retrying (" + initializationAttempt + ")...\r\n"; } else break; Thread.Sleep(2000); } #endregion Bluetooth reception channels initialization #endif #region USB reception channels initialization if (InitializeUSBReceivers() == false) { MessageBox.Show("Exiting: Some USB receivers in your configuration were not initialized."); #if (PocketPC) Application.Exit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); #else Environment.Exit(0); #endif } #endregion USB reception channels initialization } #endregion Initialize External Data Reception Channels #if (PocketPC) #region Initialize Builtin Data Reception Channels if (InitializeBuiltinReceivers() == false) { MessageBox.Show("Exiting: A built in receiver channel was not found."); Application.Exit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } #endregion Initialize Builtin Data Reception Channels #endif #region Initialize GUI Components //initialize the interface components InitializeComponent(); //Initialize GUI timers progressMessage += "Initializing Timers ..."; InitializeTimers(); progressMessage += " Completed\r\n"; //Initialize different GUI components progressMessage += "Initializing GUI ..."; InitializeInterface(); progressMessage += " Completed\r\n"; this.isPlotting = true; //count the number of accelerometers if (this.sensors.IsHR) this.maxPlots = this.sensors.Sensors.Count - 1; else this.maxPlots = this.sensors.Sensors.Count; SetFormPositions(); if (this.sensors.TotalReceivers > 0) aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, this.masterDecoder, GetGraphSize(false)); else aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, this.masterDecoder, GetGraphSize(false)); //Override the resize event #if (PocketPC) this.Resize += new EventHandler(OnResize); #else this.form1.Resize += new EventHandler(OnResizeForm1); this.form1.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form2.Resize += new EventHandler(OnResizeForm2); this.form2.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form3.Resize += new EventHandler(OnResizeForm3); this.form3.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form4.Resize += new EventHandler(OnResizeForm4); this.form4.FormClosing += new FormClosingEventHandler(form_FormClosing); #endif //Initialize the quality interface progressMessage += "Initializing MITes Quality GUI ..."; InitializeQualityInterface(); progressMessage += " Completed\r\n"; //Remove classifier tabs #if (PocketPC) this.tabControl1.TabPages.RemoveAt(4); this.tabControl1.SelectedIndex = 0; #else this.ShowForms(); #endif #endregion Initialize GUI Components #region Initialize Feature Extraction this.isExtracting = false; if (this.sensors.TotalReceivers > 0) // if there is at least 1 MIT //Extractor.Initialize(this.mitesDecoders[0], dataDirectory, this.annotation, this.sensors, this.configuration); Extractor.Initialize(this.masterDecoder, dataDirectory, this.annotation, this.sensors, this.configuration); else if (this.sensors.Sensors.Count > 0) // only built in Extractor.Initialize(new MITesDecoder(), dataDirectory, this.annotation, this.sensors, this.configuration); #endregion Initialize Feature Extraction #region Initialize Quality Tracking variables InitializeQuality(); #endregion Initialize Quality Tracking variables #region Initialize Logging InitializeLogging(dataDirectory); #endregion Initialize Logging #region Initialize CSV Storage (PC Only) #if (!PocketPC) //create some counters for activity counts averageX = new int[this.sensors.MaximumSensorID + 1]; averageY = new int[this.sensors.MaximumSensorID + 1]; averageZ = new int[this.sensors.MaximumSensorID + 1]; averageRawX = new int[this.sensors.MaximumSensorID + 1]; averageRawY = new int[this.sensors.MaximumSensorID + 1]; averageRawZ = new int[this.sensors.MaximumSensorID + 1]; prevX = new int[this.sensors.MaximumSensorID + 1]; prevY = new int[this.sensors.MaximumSensorID + 1]; prevZ = new int[this.sensors.MaximumSensorID + 1]; acCounters = new int[this.sensors.MaximumSensorID + 1]; activityCountWindowSize = 0; activityCountCSVs = new StreamWriter[this.sensors.MaximumSensorID + 1]; samplingCSVs = new StreamWriter[this.sensors.MaximumSensorID + 1]; averagedRaw = new StreamWriter[this.sensors.MaximumSensorID + 1]; masterCSV = new StreamWriter(dataDirectory + "\\MITesSummaryData.csv"); hrCSV = new StreamWriter(dataDirectory + "\\HeartRate_MITes.csv"); string csv_line1 = "UnixTimeStamp,TimeStamp,X,Y,Z"; string csv_line2 = "UnixTimeStamp,TimeStamp,Sampling"; string hr_csv_header = "UnixTimeStamp,TimeStamp,HR"; string master_csv_header = "UnixTimeStamp,TimeStamp"; foreach (Category category in this.annotation.Categories) master_csv_header += "," + category.Name; foreach (Sensor sensor in this.sensors.Sensors) { int sensor_id = Convert.ToInt32(sensor.ID); string location = sensor.Location.Replace(' ', '-'); if (sensor_id > 0) //exclude HR { activityCountCSVs[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" + sensor_id.ToString("00") + "_ActivityCount_" + location + ".csv"); activityCountCSVs[sensor_id].WriteLine(csv_line1); averagedRaw[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" + sensor_id.ToString("00") + "_1s-RawMean_" + location + ".csv"); averagedRaw[sensor_id].WriteLine(csv_line1); samplingCSVs[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" + sensor_id.ToString("00") + "_SampleRate_" + location + ".csv"); samplingCSVs[sensor_id].WriteLine(csv_line2); master_csv_header += ",MITes" + sensor_id.ToString("00") + "_SR," + "MITes" + sensor_id.ToString("00") + "_AVRaw_X," + "MITes" + sensor_id.ToString("00") + "_AVRaw_Y," + "MITes" + sensor_id.ToString("00") + "_AVRaw_Z," + "MITes" + sensor_id.ToString("00") + "_AC_X," + "MITes" + sensor_id.ToString("00") + "_AC_Y," + "MITes" + sensor_id.ToString("00") + "_AC_Z"; } } master_csv_header += ",HR"; this.masterCSV.WriteLine(master_csv_header); this.hrCSV.WriteLine(hr_csv_header); #endif #endregion Initialize CSV Storage (PC Only) #region Start Collecting Data this.collectDataMode = true; #if (PocketPC) this.isCollectingDetailedData = false; #else this.isCollectingDetailedData = true; #endif //if (this.sensors.TotalReceivers > 0) // isStartedReceiver = true; //Start the built in polling thread #if (PocketPC) if (this.sensors.HasBuiltinSensors) { this.pollingThread = new Thread(new ThreadStart(this.pollingData)); this.pollingThread.Priority = ThreadPriority.Lowest; this.pollingThread.Start(); } #endif //Terminate the progress thread progressThreadQuit = true; //Enable all timer functions this.readDataTimer.Enabled = true; this.qualityTimer.Enabled = true; if (this.sensors.IsHR) this.HRTimer.Enabled = true; #endregion Start Collecting Data }
private void SetPlotterFullScreen() { aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, /*this.mitesDecoders[0]*/this.masterDecoder, GetGraphSize(true)); }