private void beginControllingHandButton_Click(object sender, EventArgs e) { int desiredMillisecondDelay = controls.timeNeededForChange; int arraySize = (desiredMillisecondDelay / 1000) * rate; reader.Read(); rate = reader.getRate(); double lowConcentration = 0; double highConcentration = 0; //first get threshholds bool done = false; while (!done) { int reads = 0; decimal allReads = 0; MessageBox.Show("First try to let your mind wander until the next popup appears. Hit OK when ready.", string.Empty, MessageBoxButtons.OK); timer.Start(); while (timer.ElapsedMilliseconds < Globals.threshholdAquisitionTime) { decimal currentIn = (decimal)Math.Abs(reader.GetData()[Globals.inputNode]); allReads += currentIn; reads++; currentAverageBox.Text = (allReads / reads).ToString(); currentInputBox.Text = currentIn.ToString(); } timer.Reset(); lowConcentration = (double)(allReads / reads); midpointTextBox.Text = lowConcentration.ToString(); Console.WriteLine("Low concentration was: " + lowConcentration); reads = 0; allReads = 0; MessageBox.Show("Next try to focus as hard as possible something. Hit OK when ready.", string.Empty, MessageBoxButtons.OK); timer.Start(); while (timer.ElapsedMilliseconds < Globals.threshholdAquisitionTime) { decimal currentIn = (decimal)Math.Abs(reader.GetData()[Globals.inputNode]); allReads += currentIn; reads++; currentAverageBox.Text = (allReads / reads).ToString(); currentInputBox.Text = currentIn.ToString(); } timer.Reset(); highConcentration = (double)(allReads / reads); configuredMidPoint = ((highConcentration + lowConcentration) / 2); midpointTextBox.Text = configuredMidPoint.ToString(); Console.WriteLine("High concentration was: " + highConcentration); if (highConcentration > lowConcentration) { done = true; } } MessageBox.Show("Ready to control hand. Press OK when ready.", string.Empty, MessageBoxButtons.OK); }
private void FocusButton_Click(object sender, EventArgs e) { int desiredMillisecondDelay = controls.timeNeededForChange; int arraySize = (desiredMillisecondDelay / 1000) * rate; serial.Read(); rate = serial.getRate(); double lowConcentration = 0; double highConcentration = 0; //first get threshholds bool done = false; while (!done) { int reads = 0; decimal allReads = 0; MessageBox.Show("First try to let your mind wander until the next popup appears. Hit OK when ready.", string.Empty, MessageBoxButtons.OK); timer.Start(); while (timer.ElapsedMilliseconds < Globals.threshholdAquisitionTime) { decimal currentIn = (decimal)Math.Abs(serial.GetData()[Globals.inputNode]); allReads += currentIn; reads++; } timer.Reset(); lowConcentration = (double)(allReads / reads); Console.WriteLine("Low concentration was: " + lowConcentration); reads = 0; allReads = 0; MessageBox.Show("Next try to focus as hard as possible something. Hit OK when ready.", string.Empty, MessageBoxButtons.OK); timer.Start(); while (timer.ElapsedMilliseconds < Globals.threshholdAquisitionTime) { decimal currentIn = (decimal)Math.Abs(serial.GetData()[Globals.inputNode]); allReads += currentIn; reads++; } timer.Reset(); highConcentration = (double)(allReads / reads); Console.WriteLine("High concentration was: " + highConcentration); if (highConcentration > lowConcentration) { done = true; } } double differenceInConcentrations = highConcentration - lowConcentration; double deltaBetweenThreshholds = differenceInConcentrations / 2; //make ranges for this run ranges = new List <Threshhold>(2); //make sure all reads work for it ranges.Add(new Threshhold(Double.MinValue, lowConcentration + (deltaBetweenThreshholds))); ranges.Add(new Threshhold(lowConcentration + (deltaBetweenThreshholds), Double.MaxValue)); MessageBox.Show("Ready to control hand. Press OK when ready.", string.Empty, MessageBoxButtons.OK); }