private void PersoonSelecteren_Click(object sender, EventArgs e) { if (personsBox.SelectedItem == null) { PersoonToevoegen.Focus(); return; } PPGLogger.log("Selected person: " + personsBox.SelectedValue.ToString()); chartingSpace.ChartAreas[0].BackColor = Color.White; string currentTime = DateTime.Now.ToString().Replace('/', '-').Replace(':', '꞉'); string filePath = "Profiles\\" + personsBox.SelectedValue.ToString() + "\\" + currentTime + ".csv"; PPGLogger.log("Person filepath: " + filePath); if (File.Exists(filePath)) { MessageBox.Show("File error", "File already exists, please wait a couple of seconds and try again."); } else { File.CreateText(filePath).Close(); } try { file.Close(); } catch { } file = File.AppendText(filePath); file.WriteLine("sep=,\nTime since start(s),Thumb 1,Index 1,Middle 1,Ring 1,Thumb 2,Index 2,Middle 2,Ring 2,Sine Wave,Computer Time"); running = true; chartTimer.Enabled = true; clockTimer.Enabled = true; PPGLogger.log("Timer is enabled."); //chartingSpace.ChartAreas[0].AxisX.Minimum = 0; //chartingSpace.ChartAreas[0].AxisX.Maximum = 5 + DomeinScrollBar.Value; }
private void pauzeBtn_Click(object sender, EventArgs e) { PPGLogger.log("Pausing / resuming..."); if (running) { if (PauzeKnop.Text == "Pauze (Shift)" || PauzeKnop.Text == "Pause") { PauzeKnop.Text = "Start (Shift)"; chartTimer.Enabled = false; clockTimer.Enabled = false; chartManager.soundPlayer.Stop(); } else { if (english) { PauzeKnop.Text = "Pause"; } else { PauzeKnop.Text = "Pauze (Shift)"; } chartTimer.Enabled = true; clockTimer.Enabled = true; } } }
private void initialize_timer(bool timerToggle) { if (!timerToggle) { return; } PPGLogger.log("Initializing timer1"); timerTime = timerTotalTime; int minutes = (int)Math.Floor(timerTime / 60m); int seconds = timerTime - minutes * 60; int minutesTime = timerCounter / 60; int secondsTime = timerCounter - minutes * 60; if (english) { label18.Text = String.Format("Time: {0,2:D2}:{1,2:D2} Timer: {2,2:D2}:{3,2:D2}", minutesTime, secondsTime, minutes, seconds); } else { label18.Text = String.Format("Tijd: {0,2:D2}:{1,2:D2} Timer: {2,2:D2}:{3,2:D2}", minutesTime, secondsTime, minutes, seconds); } timerResetButton.Visible = true; timerPauseButton.Visible = true; }
private void colorButton(Button button, string vinger) { PPGLogger.log("Changing color: " + vinger); if (colorDialog1.ShowDialog() == DialogResult.OK) { button.BackColor = colorDialog1.Color; chartingSpace.Series[vinger].Color = colorDialog1.Color; } }
private void save_line_to_file() { try { DataHandler.saveLine(file, chartManager.sineWaveValue); } catch { PPGLogger.log("File Writing Error in timer1."); } }
private void IjkpuntKnop_Click(object sender, EventArgs e) { PPGLogger.log("Adding IJkpunt..."); try { add_eikpoint(DataHandler.chartData1.Count); } catch { PPGLogger.log("IJkpunt error"); } }
public void NewDataGloveOne(string input) { input = Regex.Replace(input, @"\r\n?|\n", ""); currentData1 += input; if (IsDone(currentData1)) { prepairedLine1 = ""; if (GetNthIndex(currentData1, '#', 2) == -1) { prepairedLine1 = currentData1; currentData1 = ""; } else { prepairedLine1 = currentData1.Substring(0, GetNthIndex(currentData1, '#', 2)); currentData1 = currentData1.Substring(GetNthIndex(currentData1, '#', 2)); } prepairedLine1 = prepairedLine1.Substring(1); //Console.WriteLine(prepairedLine1); var prepairedLine1Splitted = prepairedLine1.Split(); try { Thumb1Value = Math.Round(specializedCalibration(Decimal.Parse(prepairedLine1Splitted[0], new CultureInfo("en-US")), 0), 2); Index1Value = Math.Round(specializedCalibration(Decimal.Parse(prepairedLine1Splitted[1], new CultureInfo("en-US")), 1), 2); Middle1Value = Math.Round(specializedCalibration(Decimal.Parse(prepairedLine1Splitted[2], new CultureInfo("en-US")), 2), 2); Ring1Value = Math.Round(specializedCalibration(Decimal.Parse(prepairedLine1Splitted[3], new CultureInfo("en-US")), 3), 2); voltageHistoryPPG1.Add(Math.Round(Decimal.Parse(prepairedLine1Splitted[4], new CultureInfo("en-US")), 2)); if (voltageHistoryPPG1.Count > 300) { voltageHistoryPPG1.RemoveAt(0); } voltagePPG1 = voltageHistoryPPG1.Average(); if (monitorEnabled) { PPGLogger.log("Data collecting finished (PPG1)\nTime: " + instance.generalCounter.ToString() + "\n" + String.Format("{0:0000.0}", Thumb1Value) + " " + String.Format("{0:0000.0}", Index1Value) + " " + String.Format("{0:0000.0}", Middle1Value) + " " + String.Format("{0:0000.0}", Ring1Value) + " " + voltagePPG1.ToString()); } } catch (Exception e) { PPGLogger.log("Format error in processing of data from glove 1\n" + e.StackTrace); } } }
public void NewDataGloveTwo(string input) { input = Regex.Replace(input, @"\r\n?|\n", ""); currentData2 += input; if (IsDone(currentData2)) { prepairedLine2 = ""; if (GetNthIndex(currentData2, '#', 2) == -1) { prepairedLine2 = currentData2; currentData2 = ""; } else { prepairedLine2 = currentData2.Substring(0, GetNthIndex(currentData2, '#', 2)); currentData2 = currentData2.Substring(GetNthIndex(currentData2, '#', 2)); } prepairedLine2 = prepairedLine2.Substring(1); var prepairedLine2Splitted = prepairedLine2.Split(); try { Thumb2Value = Math.Round(specializedCalibration(Decimal.Parse(prepairedLine2Splitted[0], new CultureInfo("en-US")), 4), 2); Index2Value = Math.Round(specializedCalibration(Decimal.Parse(prepairedLine2Splitted[1], new CultureInfo("en-US")), 5), 2); Middle2Value = Math.Round(specializedCalibration(Decimal.Parse(prepairedLine2Splitted[2], new CultureInfo("en-US")), 6), 2); Ring2Value = Math.Round(specializedCalibration(Decimal.Parse(prepairedLine2Splitted[3], new CultureInfo("en-US")), 7), 2); voltageHistoryPPG2.Add(Math.Round(Decimal.Parse(prepairedLine2Splitted[4], new CultureInfo("en-US")), 2)); if (voltageHistoryPPG2.Count > 300) { voltageHistoryPPG2.RemoveAt(0); } voltagePPG2 = voltageHistoryPPG2.Average(); if (monitorEnabled) { PPGLogger.log("Data collecting finished (PPG2)\nTime: " + instance.generalCounter.ToString() + "\n" + String.Format("{0:0000.0}", Thumb1Value) + " " + String.Format("{0:0000.0}", Index1Value) + " " + String.Format("{0:0000.0}", Middle1Value) + " " + String.Format("{0:0000.0}", Ring1Value) + " " + voltagePPG1.ToString()); } } catch { PPGLogger.log("Format error in processing of data from glove 2"); } } }
private void resize() { PPGLogger.log("Resizing..."); try { label1.Font = new Font(label1.Font.FontFamily.Name, 12 * this.Size.Height / 768); label2.Font = new Font(label2.Font.FontFamily.Name, 12 * this.Size.Height / 768); label3.Font = new Font(label3.Font.FontFamily.Name, 12 * this.Size.Height / 768); label4.Font = new Font(label4.Font.FontFamily.Name, 12 * this.Size.Height / 768); Duim1Huidig.Font = new Font(Duim1Huidig.Font.FontFamily.Name, 12 * this.Size.Height / 768); Wijs1Huidig.Font = new Font(Wijs1Huidig.Font.FontFamily.Name, 12 * this.Size.Height / 768); Middel1Huidig.Font = new Font(Middel1Huidig.Font.FontFamily.Name, 12 * this.Size.Height / 768); Ring1Huidig.Font = new Font(Ring1Huidig.Font.FontFamily.Name, 12 * this.Size.Height / 768); label9.Font = new Font(label9.Font.FontFamily.Name, 12 * this.Size.Height / 768); label10.Font = new Font(label10.Font.FontFamily.Name, 12 * this.Size.Height / 768); Duim1Hoogst.Font = new Font(Duim1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Wijs1Hoogst.Font = new Font(Wijs1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Middel1Hoogst.Font = new Font(Middel1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Ring1Hoogst.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); label15.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); label19.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); label20.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Duim2Huidig.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Wijs2Huidig.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Middel2Huidig.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Ring2Huidig.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Duim2Hoogst.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Wijs2Hoogst.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Middel2Hoogst.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); Ring2Hoogst.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); ResetGrafiekKnop.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); ResetHoogstKnop.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); PauzeKnop.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); IjkpuntKnop.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); button1.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); label16.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); PPG1BatteryLvl.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); PPG2BatteryLvl.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); batteryLbl.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); rangeLabel.Font = new Font(Ring1Hoogst.Font.FontFamily.Name, 12 * this.Size.Height / 768); chartingSpace.Legends["Legend1"].Font = new Font(chartingSpace.Legends["Legend1"].Font.FontFamily, 12 * this.Size.Height / 768); chartingSpace.ChartAreas[0].AxisX.LabelAutoFitMaxFontSize = 12 * this.Size.Height / 768; chartingSpace.ChartAreas[0].AxisY.LabelAutoFitMaxFontSize = 12 * this.Size.Height / 768; } catch (Exception e) { PPGLogger.log("Resizing error: " + e.StackTrace); } }
private void AddPersonBtn_Click(object sender, EventArgs e) { if (!Directory.Exists("Profiles\\" + PersoonTextBox.Text)) { PPGLogger.log("Creating dir at: Profiles\\" + PersoonTextBox.Text); Directory.CreateDirectory("Profiles\\" + PersoonTextBox.Text); } else { PPGLogger.log("Invalid profile name: " + PersoonTextBox.Text); MessageBox.Show("Invalid profile name. Please try something else.", "Error"); } update_ComboBox(); }
public void resetHighestValues() { PPG1HighestValues = new decimal[8] { 0.00m, 0.00m, 0.00m, 0.00m, 0.00m, 0.00m, 0.00m, 0.00m, }; PPG2HighestValues = new decimal[8] { 0.00m, 0.00m, 0.00m, 0.00m, 0.00m, 0.00m, 0.00m, 0.00m, }; foreach (var label in PPG1Labels) { label.Text = "0.00"; } foreach (var label in PPG2Labels) { label.Text = "0.00"; } PPGLogger.log("Highs have been reset"); }
public Monitor(string comName, string comName2, bool english, bool showingLog, bool calibrationEnabled, decimal timerDelay, bool timerToggle, int timerTime) { InitializeComponent(); this.DataHandler = new PPG_Data_Handler(this, calibrationEnabled, timerDelay); this.timerEnabled = timerToggle; this.timerTotalTime = timerTime; this.english = english; chartTimer.Interval = (int)(timerDelay); PPG1.PortName = comName; PPG2.PortName = comName2; initialize_chart_manager(); initialize_English(english); initialize_buttons(); initialize_timer(timerToggle); update_ComboBox(); resize(); if (showingLog) { PPGLogger.setOutputTextBox(ref debuggingTextBox); PPGLogger.log("PPGLogger to textbox enabled."); } try { initialize_com_ports(); } catch (Exception e1) { MessageBox.Show("Could not connect with glove, please try again. If the problem stays, please reset the device.", "Connection error", MessageBoxButtons.OK, MessageBoxIcon.Error); PPGLogger.log("Opening port error " + e1.StackTrace); this.Dispose(); return; } if (!showingLog) { disable_debug_textbox(); } }
private void initialize_English(bool englishMode) { if (!englishMode) { return; } PPGLogger.log("Enableing english mode..."); PersoonLabel1.Text = "Open person:"; PersoonLabel2.Text = "Add person:"; PersoonSelecteren.Text = "Select"; PersoonToevoegen.Text = "Add"; batteryLbl.Text = "Battery"; label1.Text = "Thumb"; label2.Text = "Index finger"; label3.Text = "Middle finger"; label4.Text = "Ring finger"; label9.Text = "Current"; label10.Text = "Max"; label19.Text = "Current"; label20.Text = "Max"; label15.Text = "Window size:"; label16.Text = "Limit line:"; label17.Text = "Transition (%):"; label18.Text = "Time: 00:00"; label8.Text = "Sine wave:"; label6.Text = "Middle:"; label7.Text = "Frequency:"; PauzeKnop.Text = "Pause"; ResetGrafiekKnop.Text = "Clear chart"; ResetHoogstKnop.Text = "Reset maximums"; IjkpuntKnop.Text = "Highlight"; rangeLabel.Text = "Range:"; chartManager.english(); PPGLogger.log("English: " + english); }
public void resetChart(Monitor monitor) { PPGLogger.log("Resetting chart..."); resetHighestValues(); foreach (var series in chartingSpace.Series) { series.Points.Clear(); } PPGLogger.log("Emptied chart"); chartingSpace.ChartAreas[0].BackColor = Color.White; chartingSpace.Series[duim2].Points.AddXY(0, 0); chartingSpace.Series[wijsvinger2].Points.AddXY(0, 0); chartingSpace.Series[middelvinger2].Points.AddXY(0, 0); chartingSpace.Series[ringvinger2].Points.AddXY(0, 0); chartingSpace.Series[ringvinger2].Points.AddXY(1, 0); chartingSpace.Series["Series2"].Points.AddXY(5, 5); dataHandler.chartData1 = new List <decimal[]>(); dataHandler.chartData2 = new List <decimal[]>(); monitor.generalCounter = 0; PPGLogger.log("Timer has been reset"); }
public void initialize_chart() { chartingSpace.Series.Remove(chartingSpace.Series["Series1"]); chartingSpace.Series.Add(duim2); chartingSpace.Series.Add(wijsvinger2); chartingSpace.Series.Add(middelvinger2); chartingSpace.Series.Add(ringvinger2); chartingSpace.Series.Add(duim1); chartingSpace.Series.Add(wijsvinger1); chartingSpace.Series.Add(middelvinger1); chartingSpace.Series.Add(ringvinger1); chartingSpace.Series.Add("Maximum"); chartingSpace.Series[duim2].BorderWidth = 3; chartingSpace.Series[wijsvinger2].BorderWidth = 3; chartingSpace.Series[middelvinger2].BorderWidth = 3; chartingSpace.Series[ringvinger2].BorderWidth = 3; chartingSpace.Series[duim1].BorderWidth = 3; chartingSpace.Series[wijsvinger1].BorderWidth = 3; chartingSpace.Series[middelvinger1].BorderWidth = 3; chartingSpace.Series[ringvinger1].BorderWidth = 3; chartingSpace.Series["Maximum"].BorderWidth = 3; chartingSpace.Series["Maximum"].Color = Color.Black; chartingSpace.Series[duim2].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series[wijsvinger2].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series[middelvinger2].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series[ringvinger2].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series[duim1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series[wijsvinger1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series[middelvinger1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series[ringvinger1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series["Maximum"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; chartingSpace.Series[duim1].Color = Color.Blue; chartingSpace.Series[wijsvinger1].Color = Color.Red; chartingSpace.Series[middelvinger1].Color = Color.Black; chartingSpace.Series[ringvinger1].Color = Color.Green; chartingSpace.Series[duim2].Points.AddXY(0, 0); chartingSpace.Series[wijsvinger2].Points.AddXY(0, 0); chartingSpace.Series[middelvinger2].Points.AddXY(0, 0); chartingSpace.Series[ringvinger2].Points.AddXY(0, 0); chartingSpace.Series[duim2].Color = Color.Orange; chartingSpace.Series[wijsvinger2].Color = Color.Gray; chartingSpace.Series[middelvinger2].Color = Color.Pink; chartingSpace.Series[ringvinger2].Color = Color.Purple; chartingSpace.Series[duim1].Points.AddXY(0, 0); chartingSpace.Series[wijsvinger1].Points.AddXY(0, 0); chartingSpace.Series[middelvinger1].Points.AddXY(0, 0); chartingSpace.Series[ringvinger1].Points.AddXY(0, 0); chartingSpace.ChartAreas[0].AxisX.Minimum = 0; chartingSpace.ChartAreas[0].AxisX.Maximum = minimalDomain; chartingSpace.ChartAreas[0].AxisY.Minimum = 0; chartingSpace.ChartAreas[0].AxisY.Maximum = minimalDomain; chartingSpace.Series["Maximum"].Enabled = false; chartingSpace.Series.Add("Sine"); chartingSpace.Series["Sine"].BorderWidth = 3; chartingSpace.Series["Sine"].Color = Color.Black; chartingSpace.Series["Sine"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chartingSpace.Series["Sine"].Enabled = sineWaveEnabled; PPGLogger.log("Prepairing chart..."); }