private void executeCommand() { camBusy = true; if (newFocusCommand) { BeginInvoke((Action)(() => textBoxArduino.AppendText("Focus : " + focusCommand.ToString() + Environment.NewLine))); cam.RemoteControl.Focus.Mode((FocusMode)((int)focusCommand - 1)); Thread.Sleep(350); BeginInvoke((Action)(() => focusStatus.Text = focusCommand.ToString())); newFocusCommand = false; } if (newHsmCommand) { BeginInvoke((Action)(() => textBoxArduino.AppendText("Hsm : " + hsmCommand.ToString() + Environment.NewLine))); if (hsmCommand == hsmCommands.Disable) { cam.RemoteControl.CameraSettings.SetHighSensitivityModeEnabled(false); } else if (hsmCommand == hsmCommands.Enable) { cam.RemoteControl.CameraSettings.SetHighSensitivityModeEnabled(true); } Thread.Sleep(350); newHsmCommand = false; } if (newRecCommand) { BeginInvoke((Action)(() => textBoxArduino.AppendText("Record : " + recCommand.ToString() + Environment.NewLine))); if (recCommand == recCommands.Stop) { if (cam.Recorder.Status == RecorderState.Paused || cam.Recorder.Status == RecorderState.Recording) { cam.Recorder.Stop(); BeginInvoke((Action)(() => buttonRec.Text = "RECORD")); } } else if (recCommand == recCommands.Record) { if (cam.Recorder.Status == RecorderState.Stopped || cam.Recorder.Status == RecorderState.PreRecording) { // start recording BeginInvoke((Action)(() => buttonRec.Text = "STOP")); cam.Recorder.Start(GetNextFileName()); } else if (cam.Recorder.Status == RecorderState.Paused) { cam.Recorder.Continue(); BeginInvoke((Action)(() => buttonPause.Text = "PAUSE")); } } else if (recCommand == recCommands.Pause) { if (cam.Recorder.Status == RecorderState.Recording) { cam.Recorder.Pause(); BeginInvoke((Action)(() => buttonPause.Text = "CONTINUE")); } } Thread.Sleep(350); newRecCommand = false; } if (newPaletCommand) { BeginInvoke((Action)(() => textBoxArduino.AppendText("Palet : " + paletCommand.ToString() + Environment.NewLine))); cam.ThermalImage.EnterLock(); cam.ThermalImage.Palette = palletes[(int)paletCommand - 1]; string palet = cam.ThermalImage.Palette.Name; BeginInvoke((Action)(() => paletStatus.Text = palet)); cam.ThermalImage.ExitLock(); Thread.Sleep(50); newPaletCommand = false; } bool hsm = cam.RemoteControl.CameraSettings.IsHighSensitivityModeEnabled(); if (hsm) { BeginInvoke((Action)(() => hsmStatus.Text = "Enabled")); } else { BeginInvoke((Action)(() => hsmStatus.Text = "Disabled")); } RecorderState rec = cam.Recorder.Status; string recState = ""; if (rec == RecorderState.Stopped) { recState = "Stop"; } else if (rec == RecorderState.Recording) { recState = "Recording"; } else if (rec == RecorderState.Paused) { recState = "Paused"; } BeginInvoke((Action)(() => recordStatus.Text = recState)); camBusy = false; }
private async void ParseExecuteCommand(string message) { commandTypes type = (commandTypes)Int16.Parse(message.Substring(0, 1)); int command = Int16.Parse(message.Substring(1, 2)); switch (type) { case commandTypes.Range: if (command <= System.Enum.GetValues(typeof(rangeCommands)).Length) { rangeCommands rangeCommand = (rangeCommands)command; string rangeText = comboBoxRange.Items[(int)rangeCommand - 1].ToString(); BeginInvoke((Action)(() => textBoxArduino.AppendText("Range : " + rangeText + Environment.NewLine))); cam.ThermalImage.EnterLock(); switch (rangeCommand) { case rangeCommands.Auto: cam.ThermalImage.Scale.IsAutoAdjustEnabled = true; break; case rangeCommands.Range1: cam.ThermalImage.Scale.Range = new Range <double>(-4.0, 50.0); break; case rangeCommands.Range2: cam.ThermalImage.Scale.Range = new Range <double>(14.0, 77.0); break; case rangeCommands.Range3: cam.ThermalImage.Scale.Range = new Range <double>(50.0, 122.0); break; case rangeCommands.Range4: cam.ThermalImage.Scale.Range = new Range <double>(104.0, 185.0); break; case rangeCommands.Range5: cam.ThermalImage.Scale.Range = new Range <double>(158.0, 248.0); break; case rangeCommands.Range6: cam.ThermalImage.Scale.Range = new Range <double>(212.0, 320.0); break; default: break; } cam.ThermalImage.ExitLock(); BeginInvoke((Action)(() => rangeStatus.Text = rangeText)); } break; //function to enable/disable HSM from the arduino signal case commandTypes.Hsm: if (command == (int)hsmCommands.Disable || command == (int)hsmCommands.Enable) { hsmCommands hsmCommand = (hsmCommands)command; BeginInvoke((Action)(() => textBoxArduino.AppendText("Hsm : " + hsmCommand.ToString() + Environment.NewLine))); if (hsmCommand == hsmCommands.Disable) { Command(() => cam.RemoteControl.CameraSettings.SetHighSensitivityModeEnabled(false), false); // just added 3 lines below but havent tested it yet 01/02/19 cam.ThermalImage.EnterLock(); cam.ThermalImage.ThermalPipeline.Add(hsmFilter); cam.ThermalImage.ExitLock(); } else if (hsmCommand == hsmCommands.Enable) { Command(() => cam.RemoteControl.CameraSettings.SetHighSensitivityModeEnabled(true), false); // just added 3 lines below but havent tested it yet 01/02/19 cam.ThermalImage.EnterLock(); cam.ThermalImage.ThermalPipeline.Clear(); cam.ThermalImage.ExitLock(); } await camLock.WaitAsync(); bool hsm = cam.RemoteControl.CameraSettings.IsHighSensitivityModeEnabled(); if (camLock.CurrentCount == 0) { camLock.Release(); } if (hsm) { BeginInvoke((Action)(() => hsmStatus.Text = "Enabled")); } else { BeginInvoke((Action)(() => hsmStatus.Text = "Disabled")); } } break; case commandTypes.Palet: if (command <= System.Enum.GetValues(typeof(paletCommands)).Length) { paletCommands paletCommand = (paletCommands)command; BeginInvoke((Action)(() => textBoxArduino.AppendText("Palet : " + paletCommand.ToString() + Environment.NewLine))); cam.ThermalImage.EnterLock(); cam.ThermalImage.Palette = palletes[command - 1]; string palet = cam.ThermalImage.Palette.Name; cam.ThermalImage.ExitLock(); BeginInvoke((Action)(() => paletStatus.Text = palet)); } break; case commandTypes.Rec: if (command == (int)recCommands.Stop || command == (int)recCommands.Record || command == (int)recCommands.Pause) { recCommands recCommand = (recCommands)command; BeginInvoke((Action)(() => textBoxArduino.AppendText("Record : " + recCommand.ToString() + Environment.NewLine))); await camLock.WaitAsync(); RecorderState status = cam.Recorder.Status; if (camLock.CurrentCount == 0) { camLock.Release(); } if (recCommand == recCommands.Stop) { if (status == RecorderState.Paused || status == RecorderState.Recording) { Command(() => cam.Recorder.Stop(), true); BeginInvoke((Action)(() => buttonRec.Text = "RECORD")); } } else if (recCommand == recCommands.Record) { if (status == RecorderState.Stopped || status == RecorderState.PreRecording) { // start recording Command(() => cam.Recorder.Start(GetNextFileName()), true); BeginInvoke((Action)(() => buttonRec.Text = "STOP")); } else if (status == RecorderState.Paused) { Command(() => cam.Recorder.Continue(), true); BeginInvoke((Action)(() => buttonPause.Text = "PAUSE")); } } else if (recCommand == recCommands.Pause) { if (status == RecorderState.Recording) { Command(() => cam.Recorder.Pause(), true); BeginInvoke((Action)(() => buttonPause.Text = "CONTINUE")); } } } break; case commandTypes.Focus: if (command == (int)focusCommands.Auto || command == (int)focusCommands.Off) { focusCommands focusCommand = (focusCommands)command; BeginInvoke((Action)(() => textBoxArduino.AppendText("Focus : " + focusCommand.ToString() + Environment.NewLine))); if (command == (int)focusCommands.Auto) { Command(() => cam.RemoteControl.Focus.Mode(FocusMode.Auto), false); } else if (command == (int)focusCommands.Off) { Command(() => cam.RemoteControl.Focus.Mode(FocusMode.Stop), false); } await camLock.WaitAsync(); if (camLock.CurrentCount == 0) { camLock.Release(); } BeginInvoke((Action)(() => focusStatus.Text = focusCommand.ToString())); } break; default: break; } }