private void OkButton_Click(object sender, EventArgs e) { if (this.ValidateFields() == true) { ZeoSettings.Default.AlarmEnabled = this.enableAlarmCheckBox.Checked; ZeoSettings.Default.MP3FileName = this.mp3FileName; ZeoSettings.Default.AlarmDuration = this.durationTextBox.Text; ZeoSettings.Default.AlarmFadeIn = this.fadeInTextBox.Text; ZeoSettings.Default.AlarmFadeOut = this.fadeOutTextBox.Text; ZeoSettings.Default.MaxVolume = Convert.ToInt32(this.maxVolumeComboBox.Text); ZeoSettings.Default.AlarmFromTime = this.fromTimeTextBox.Text; ZeoSettings.Default.AlarmToTime = this.toTimeTextBox.Text; ZeoSettings.Default.AlarmSnooze = this.snoozeTextBox.Text; this.SaveAlarmCues(); ZeoSettings.Default.Save(); ZeoSettings.Default.Reload(); SoundAlarm.SetVolumes(ZeoSettings.Default.MaxVolume); this.Close(); } }
public void Initialize() { this.MinimumSize = new Size((int)(ZeoStream.SamplesPerSec * 2), 100); this.timer = new Stopwatch(); this.eegLevelToolStripComboBox.SelectedIndex = ZeoSettings.Default.EegLevelSelecteIndex; float eegLevel; float.TryParse(this.eegLevelToolStripComboBox.Text, out eegLevel); this.eegScopePanel.MaxValueDisplay = new float[] { eegLevel }; this.eegScopePanel.MinValueDisplay = new float[] { -eegLevel }; if (this.fileNameToolStripComboBox.Items.Count > 0) { this.fileNameToolStripComboBox.SelectedIndex = 0; } SoundAlarm.SetVolumes(ZeoSettings.Default.MaxVolume); this.freqScopePanel.SamplesPerSecond = 1.0; this.freqScopePanel.NumberOfChannels = ZeoMessage.FrequencyBinsLength + 2; // Include Impedance and Sound Alarm Volume this.freqScopePanel.MaxValueDisplay = new float[] { 50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 2.0f, 1500.0f, SoundAlarm.MaxVolume + 2000 }; this.freqScopePanel.MinValueDisplay = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, SoundAlarm.MinVolume - 200 }; this.freqScopePanel.GraphColors = new Color[] { Color.Red, Color.Green, Color.Blue, Color.Cyan, Color.Magenta, Color.Yellow, Color.Coral, Color.FromArgb(80, 80, 80), Color.Brown }; this.freqScopePanel.LabelFormatStrings = new string[] { "D: {0:0.00}", "T: {0:0.00}", "A: {0:0.00}", "B1: {0:0.00}", "B2: {0:0.00}", "B3: {0:0.00}", "G: {0:0.00}", "Im: {0:0.0}", "V: {0}" }; this.freqScopePanel.HorizontalLinesCount = 0; // Restore from ZeoSettings this.eegLevelToolStripComboBox.SelectedIndex = ZeoSettings.Default.EegLevelSelecteIndex; this.WindowState = ZeoSettings.Default.WindowMaximized == true ? FormWindowState.Maximized : FormWindowState.Normal; this.Height = ZeoSettings.Default.WindowHeight; this.Width = ZeoSettings.Default.WindowWidth; this.freqScopePanel.Height = ZeoSettings.Default.FreqPanelHeight; if (ZeoSettings.Default.AlarmEnabled == true) { this.alarmStateToolStripLabel.Text = this.alarmOnString; this.alarmStateToolStripLabel.ForeColor = Color.DarkGreen; } else { this.alarmStateToolStripLabel.Text = this.alarmOffString; this.alarmStateToolStripLabel.ForeColor = SystemColors.ControlText; } this.LoadFileNames(); Action <object> comPortsDetect = delegate(object obj) { Thread.Sleep(50); // sleep to make sure the form is created string[] comPorts = Ftdi.GetComPortList(); this.Invoke(new Action <string[]>(this.ComPortsComboBoxItemsAdd), new object[] { comPorts }); }; this.InitBluetoothSpeaker(); comPortsDetect.BeginInvoke(null, null, null); }
private void AlarmPreviewButton_Click(object sender, EventArgs e) { if (this.alarmPreviewStarted == false) { if (this.ValidateFields() == true) { SoundAlarm.SetVolumes(Convert.ToInt32(this.maxVolumeComboBox.Text)); this.alarmPreviewStarted = true; this.alarmPreviewButton.Text = "Stop"; this.soundAlarm = new SoundAlarm(this.mp3FileName, this.fadeInTextBox.Text, this.fadeOutTextBox.Text, this.durationTextBox.Text, string.Empty, string.Empty, string.Empty, "1A"); this.soundAlarm.AlarmStarted = true; this.alarmThread = new System.Threading.Timer(new TimerCallback(this.RunAlarm), null, 0, 1000); } } else { this.alarmPreviewStarted = false; this.alarmPreviewButton.Text = "Alarm Preview"; this.alarmThread.Dispose(); this.alarmThread = null; this.soundAlarm.AlarmStarted = false; this.soundAlarm.ProcessZeoMessage(new ZeoMessage()); this.soundAlarm.Dispose(); this.soundAlarm = null; } }
private void AlarmPreviewButton_Click(object sender, EventArgs e) { if (this.alarmPreviewStarted == false) { if (this.ValidateFields() == true) { SoundAlarm.SetVolumes(Convert.ToInt32(this.maxVolumeComboBox.Text)); this.alarmPreviewStarted = true; this.alarmPreviewButton.Text = "Stop"; this.soundAlarm = new SoundAlarm(this.mp3FileName, this.fadeInTextBox.Text, this.fadeOutTextBox.Text, this.durationTextBox.Text, string.Empty, string.Empty, string.Empty, "1A"); this.soundAlarm.AlarmStarted = true; this.alarmThread = new System.Threading.Timer(new TimerCallback(this.RunAlarm), null, 0, 1000); } } else { this.alarmPreviewStarted = false; this.alarmPreviewButton.Text = "Alarm Preview"; this.alarmThread.Dispose(); this.alarmThread = null; this.soundAlarm.AlarmStarted = false; this.soundAlarm.ProcessZeoMessage(new ZeoMessage()); this.soundAlarm.Dispose(); this.soundAlarm = null; } }
private void StartToolStripButton_Click(object sender, EventArgs e) { if (this.zeoStream != null) { this.zeoStream.Dispose(); this.zeoStream = null; this.exitEvent.Reset(); this.eegLastPosition = 0; this.eegScopePanel.ScrollBarMaximum = 0; this.eegScopePanel.ScrollBarValue = 0; } this.timer.Reset(); this.timer.Start(); this.zeoStream = new ZeoStream(this.exitEvent); this.zeoStream.HeadbandDocked += new EventHandler(this.ZeoStream_HeadbandDocked); if (ZeoSettings.Default.AlarmEnabled == true && File.Exists(ZeoSettings.Default.MP3FileName) == true) { this.soundAlarm = new SoundAlarm(ZeoSettings.Default.MP3FileName, ZeoSettings.Default.AlarmFadeIn, ZeoSettings.Default.AlarmFadeOut, ZeoSettings.Default.AlarmDuration, ZeoSettings.Default.AlarmFromTime, ZeoSettings.Default.AlarmToTime, ZeoSettings.Default.AlarmSnooze, ZeoSettings.Default.AlarmCue); // Add one more channel for Alarm sound volume this.freqScopePanel.NumberOfChannels = ZeoMessage.FrequencyBinsLength + 2; this.freqScopePanel.MaxValueDisplay[this.freqScopePanel.NumberOfChannels - 1] = SoundAlarm.MaxVolume + 2000; this.freqScopePanel.MinValueDisplay[this.freqScopePanel.NumberOfChannels - 1] = SoundAlarm.MinVolume - 200; this.stageScopePanel.MaxValueDisplay[this.stageScopePanel.NumberOfChannels - 1] = SoundAlarm.MaxVolume + 2000; this.stageScopePanel.MinValueDisplay[this.stageScopePanel.NumberOfChannels - 1] = SoundAlarm.MinVolume - 200; } else { this.freqScopePanel.NumberOfChannels = ZeoMessage.FrequencyBinsLength + 1; } this.zeoStream.OpenLiveStream(this.comPortToolStripComboBox.Text, this.fileNameToolStripComboBox.Text, this.soundAlarm); this.SetFormText(this.zeoStream.FileName); this.startToolStripButton.Enabled = false; this.settingsToolStripButton.Enabled = false; this.openToolStripButton.Enabled = false; this.stopToolStripButton.Enabled = true; this.SaveFileNames(); }
private void StopToolStripButton_Click(object sender, EventArgs e) { if (this.zeoStream.LiveStream == true) { this.exitEvent.Set(); this.startToolStripButton.Enabled = true; this.settingsToolStripButton.Enabled = true; this.openToolStripButton.Enabled = true; this.stopToolStripButton.Enabled = false; this.SetFormText(this.zeoStream.FileName); if (this.soundAlarm != null) { this.soundAlarm.Dispose(); this.soundAlarm = null; } return; } }
public void OpenLiveStream(string comPortName, string fileName, SoundAlarm soundAlarm) { Directory.CreateDirectory("ZeoData"); this.soundAlarm = soundAlarm; this.LiveStream = true; this.fileName = string.Format(@"ZeoData\{0}_{1}.zeo", fileName, DateTime.Now.ToString("yyyy-MM-dd_HHmmss")); this.binFile = new FileStream(this.fileName, FileMode.CreateNew); this.AddVersionString(); if (this.soundAlarm != null) { this.WriteZ9Message(new ZeoMessage(), Z9DataType.SoundAlarmEnabled); } this.serialPort = new SerialPort(comPortName, 38400, Parity.None, 8, StopBits.One); this.serialPort.Open(); this.serialPort.DiscardInBuffer(); this.readThread = new Thread(new ThreadStart(this.ReadSerialStream)); this.readThread.Start(); }
private void StopToolStripButton_Click(object sender, EventArgs e) { if (this.zeoStream.LiveStream == true) { this.exitEvent.Set(); this.startToolStripButton.Enabled = true; this.settingsToolStripButton.Enabled = true; this.openToolStripButton.Enabled = true; this.stopToolStripButton.Enabled = false; this.SetFormText(this.zeoStream.FileName); if (this.soundAlarm != null) { this.soundAlarm.Dispose(); this.soundAlarm = null; } return; } }
private void StartToolStripButton_Click(object sender, EventArgs e) { if (this.zeoStream != null) { this.zeoStream.Dispose(); this.zeoStream = null; this.exitEvent.Reset(); this.eegLastPosition = 0; this.eegScopePanel.ScrollBarMaximum = 0; this.eegScopePanel.ScrollBarValue = 0; } this.timer.Reset(); this.timer.Start(); this.zeoStream = new ZeoStream(this.exitEvent); this.zeoStream.HeadbandDocked += new EventHandler(this.ZeoStream_HeadbandDocked); if (ZeoSettings.Default.AlarmEnabled == true && File.Exists(ZeoSettings.Default.MP3FileName) == true) { this.soundAlarm = new SoundAlarm(ZeoSettings.Default.MP3FileName, ZeoSettings.Default.AlarmFadeIn, ZeoSettings.Default.AlarmFadeOut, ZeoSettings.Default.AlarmDuration, ZeoSettings.Default.AlarmFromTime, ZeoSettings.Default.AlarmToTime, ZeoSettings.Default.AlarmSnooze, ZeoSettings.Default.AlarmCue); // Add one more channel for Alarm sound volume this.freqScopePanel.NumberOfChannels = ZeoMessage.FrequencyBinsLength + 2; this.freqScopePanel.MaxValueDisplay[this.freqScopePanel.NumberOfChannels - 1] = SoundAlarm.MaxVolume + 2000; this.freqScopePanel.MinValueDisplay[this.freqScopePanel.NumberOfChannels - 1] = SoundAlarm.MinVolume - 200; this.stageScopePanel.MaxValueDisplay[this.stageScopePanel.NumberOfChannels - 1] = SoundAlarm.MaxVolume + 2000; this.stageScopePanel.MinValueDisplay[this.stageScopePanel.NumberOfChannels - 1] = SoundAlarm.MinVolume - 200; } else { this.freqScopePanel.NumberOfChannels = ZeoMessage.FrequencyBinsLength + 1; } this.zeoStream.OpenLiveStream(this.comPortToolStripComboBox.Text, this.fileNameToolStripComboBox.Text, this.soundAlarm); this.SetFormText(this.zeoStream.FileName); this.startToolStripButton.Enabled = false; this.settingsToolStripButton.Enabled = false; this.openToolStripButton.Enabled = false; this.stopToolStripButton.Enabled = true; this.SaveFileNames(); }
public void OpenLiveStream(string comPortName, string fileName, SoundAlarm soundAlarm) { Directory.CreateDirectory("ZeoData"); this.soundAlarm = soundAlarm; this.LiveStream = true; this.fileName = string.Format(@"ZeoData\{0}_{1}.zeo", fileName, DateTime.Now.ToString("yyyy-MM-dd_HHmmss")); this.binFile = new FileStream(this.fileName, FileMode.CreateNew); this.AddVersionString(); if (this.soundAlarm != null) { this.WriteZ9Message(new ZeoMessage(), Z9DataType.SoundAlarmEnabled); } this.serialPort = new SerialPort(comPortName, 38400, Parity.None, 8, StopBits.One); this.serialPort.Open(); this.serialPort.DiscardInBuffer(); this.readThread = new Thread(new ThreadStart(this.ReadSerialStream)); this.readThread.Start(); }
private bool ValidateFields() { bool validFields = true; Control[] requiredFields = new Control[] { this.durationTextBox, this.fadeInTextBox, this.fadeOutTextBox }; int errorProviderId = 0; foreach (Control control in requiredFields) { if (string.IsNullOrEmpty(control.Text) == true || Regex.Match(control.Text, SettingsForm.regexTime).Value != control.Text) { this.errorProviders[errorProviderId].SetError(control, "Invalid or empty time string (mm:ss)"); validFields = false; } else { this.errorProviders[errorProviderId].SetError(control, string.Empty); } errorProviderId++; } Control[] optionalFields = new Control[] { this.fromTimeTextBox, this.toTimeTextBox, this.snoozeTextBox }; foreach (Control control in optionalFields) { if (Regex.Match(control.Text, SettingsForm.regexTime).Value != control.Text) { this.errorProviders[errorProviderId].SetError(control, "Invalid time string (hh:mm)"); validFields = false; } else { this.errorProviders[errorProviderId].SetError(control, string.Empty); } errorProviderId++; } if (string.IsNullOrEmpty(this.alarmCueComboBox.Text) == true || SoundAlarm.ValidateAlarmCue(this.alarmCueComboBox.Text) == false) { this.errorProviders[errorProviderId].SetError(this.alarmCueComboBox, "Invalid or empty Alarm Cue"); validFields = false; } else { this.errorProviders[errorProviderId].SetError(this.alarmCueComboBox, string.Empty); } errorProviderId++; if (string.IsNullOrEmpty(this.mp3FileName) == true && this.enableAlarmCheckBox.Checked == true) { this.errorProviders[errorProviderId].SetError(this.mp3FileNameLabel, "Empty MP3 file name"); validFields = false; } else { this.errorProviders[errorProviderId].SetError(this.mp3FileNameLabel, string.Empty); } errorProviderId++; return(validFields); }