diff --git a/ISCamRecorder/MainForm.Designer.cs b/ISCamRecorder/MainForm.Designer.cs index d077b6f..85330ad 100644 --- a/ISCamRecorder/MainForm.Designer.cs +++ b/ISCamRecorder/MainForm.Designer.cs @@ -48,7 +48,6 @@ this.icRight = new TIS.Imaging.ICImagingControl(); this.BtnRecodeMovie = new System.Windows.Forms.Button(); this.BtnSnapImage = new System.Windows.Forms.Button(); - this.ChkStartSW = new System.Windows.Forms.CheckBox(); this.label8 = new System.Windows.Forms.Label(); this.TxtSubjectName = new System.Windows.Forms.TextBox(); this.BtnOpenSubjList = new System.Windows.Forms.Button(); @@ -86,9 +85,9 @@ // // BtnSetProperty // - this.BtnSetProperty.Location = new System.Drawing.Point(12, 12); + this.BtnSetProperty.Location = new System.Drawing.Point(244, 12); this.BtnSetProperty.Name = "BtnSetProperty"; - this.BtnSetProperty.Size = new System.Drawing.Size(64, 34); + this.BtnSetProperty.Size = new System.Drawing.Size(75, 34); this.BtnSetProperty.TabIndex = 5; this.BtnSetProperty.Text = "設定"; this.BtnSetProperty.UseVisualStyleBackColor = true; @@ -382,9 +381,9 @@ // // BtnRecodeMovie // - this.BtnRecodeMovie.Location = new System.Drawing.Point(383, 8); + this.BtnRecodeMovie.Location = new System.Drawing.Point(82, 12); this.BtnRecodeMovie.Name = "BtnRecodeMovie"; - this.BtnRecodeMovie.Size = new System.Drawing.Size(74, 27); + this.BtnRecodeMovie.Size = new System.Drawing.Size(75, 34); this.BtnRecodeMovie.TabIndex = 15; this.BtnRecodeMovie.Text = "動画撮影"; this.BtnRecodeMovie.UseVisualStyleBackColor = true; @@ -392,27 +391,14 @@ // // BtnSnapImage // - this.BtnSnapImage.Location = new System.Drawing.Point(463, 8); + this.BtnSnapImage.Location = new System.Drawing.Point(163, 12); this.BtnSnapImage.Name = "BtnSnapImage"; - this.BtnSnapImage.Size = new System.Drawing.Size(74, 27); + this.BtnSnapImage.Size = new System.Drawing.Size(75, 34); this.BtnSnapImage.TabIndex = 18; this.BtnSnapImage.Text = "静止画撮影"; this.BtnSnapImage.UseVisualStyleBackColor = true; this.BtnSnapImage.Click += new System.EventHandler(this.BtnSnapImage_Click); // - // ChkStartSW - // - this.ChkStartSW.AutoSize = true; - this.ChkStartSW.Checked = true; - this.ChkStartSW.CheckState = System.Windows.Forms.CheckState.Checked; - this.ChkStartSW.Location = new System.Drawing.Point(393, 36); - this.ChkStartSW.Name = "ChkStartSW"; - this.ChkStartSW.Size = new System.Drawing.Size(64, 16); - this.ChkStartSW.TabIndex = 22; - this.ChkStartSW.Text = "SW連動"; - this.ChkStartSW.UseVisualStyleBackColor = true; - this.ChkStartSW.CheckedChanged += new System.EventHandler(this.ChkStartSW_CheckedChanged); - // // label8 // this.label8.AutoSize = true; @@ -486,16 +472,15 @@ this.ClientSize = new System.Drawing.Size(1016, 555); this.Controls.Add(this.label9); this.Controls.Add(this.TxtCounter); + this.Controls.Add(this.BtnSetProperty); this.Controls.Add(this.BtnPrevSubject); this.Controls.Add(this.BtnNextSubject); this.Controls.Add(this.BtnOpenSubjList); this.Controls.Add(this.TxtSubjectName); this.Controls.Add(this.label8); - this.Controls.Add(this.ChkStartSW); this.Controls.Add(this.BtnSnapImage); this.Controls.Add(this.BtnRecodeMovie); this.Controls.Add(this.splitContainer1); - this.Controls.Add(this.BtnSetProperty); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "MainForm"; this.Text = "マルチカメラ撮影ソフトウェア by 千葉大学フロンティア医工学センター"; @@ -560,7 +545,6 @@ private System.Windows.Forms.TextBox TxtSensor; private System.Windows.Forms.PictureBox PicCvCamera; private System.Windows.Forms.TextBox TxtCvCamera; - private System.Windows.Forms.CheckBox ChkStartSW; private System.Windows.Forms.Label label8; private System.Windows.Forms.TextBox TxtSubjectName; private System.Windows.Forms.Button BtnOpenSubjList; diff --git a/ISCamRecorder/MainForm.cs b/ISCamRecorder/MainForm.cs index 250967f..8eef749 100644 --- a/ISCamRecorder/MainForm.cs +++ b/ISCamRecorder/MainForm.cs @@ -12,7 +12,6 @@ using System.IO; using NAudio.MediaFoundation; using System.Windows.Forms.DataVisualization.Charting; -using System.Threading; using System.Media; namespace ISCamRecorder { @@ -56,7 +55,6 @@ public DateTime RecodingTime { get; private set; } = DateTime.Now; // 録画開始時間 public string RecodingTimeStr { get { return RecodingTime.ToString("yyyyMMdd_HHmmss"); } } // 録画開始時間文字列 public string OutputDir { get { return Path.Combine(Setting.SaveDir , $"rec{RecodingTimeStr}_{TxtSubjectName.Text}_{TxtCounter.Text}"); } } // データ保存フォルダ - public bool SwitchEnabled { get; private set; } /// /// コンストラクタ @@ -92,7 +90,6 @@ _CvCameraThread = Task.Run(CvCameraThread); // コントロール変数初期化 - SwitchEnabled = ChkStartSW.Checked; #if DEBUG TxtSubjectName.Text = "デバッグ"; #endif @@ -218,18 +215,9 @@ } /// - /// 動画撮影 - /// - /// - /// - private void BtnRecodeMovie_Click(object sender, EventArgs e) { - StartRecoding(); - } - - /// /// 録画開始・中断 /// - public void StartRecoding() { + private void StartRecoding() { if (State == STATE.Idle) { _RecodingThread = Task.Run(RecodingThread); } else if (State == STATE.Recoding) { @@ -304,11 +292,9 @@ } /// - /// 静止画撮影ボタン + /// 静止画撮影 /// - /// - /// - private void BtnSnapImage_Click(object sender, EventArgs e) { + private void SnapImage() { if (State != STATE.Idle) return; var player = new SoundPlayer(@"snap.wav"); @@ -316,11 +302,42 @@ var outDir = Path.Combine(Setting.SaveDir, "image"); Directory.CreateDirectory(outDir); - _Cameras.ForEach(c => c.SnapImage()); + this.Invoke((MethodInvoker)delegate { + _Cameras.ForEach(c => c.SnapImage()); + }); _CvCamera.Snap(); } /// + /// 動画撮影ボタン + /// + /// + /// + private void BtnRecodeMovie_Click(object sender, EventArgs e) { + StartRecoding(); + } + + /// + /// 静止画撮影ボタン + /// + /// + /// + private void BtnSnapImage_Click(object sender, EventArgs e) { + this.SnapImage(); + } + + /// + /// ハードウェアボタン押下時 + /// + public void HWButton() { + if (Setting.ButtonAction == Setting.ACTION.movie) { + StartRecoding(); + } else { + SnapImage(); + } + } + + /// /// プログラム終了 /// private void ExitProgram() { @@ -358,15 +375,6 @@ } /// - /// SW連動チェック変更 - /// - /// - /// - private void ChkStartSW_CheckedChanged(object sender, EventArgs e) { - SwitchEnabled = ChkStartSW.Checked; - } - - /// /// 非測定者の一覧を開く /// /// diff --git a/ISCamRecorder/SensorData.cs b/ISCamRecorder/SensorData.cs index 7be36f6..c73040c 100644 --- a/ISCamRecorder/SensorData.cs +++ b/ISCamRecorder/SensorData.cs @@ -88,13 +88,10 @@ // ボタン状態 var buttonState = (1 - values[4]); - if (_LastButtonState == 0 && buttonState == 1 && _MainForm.SwitchEnabled) { - _MainForm.StartRecoding(); - } + if (_LastButtonState == 0 && buttonState == 1) _MainForm.HWButton(); _LastButtonState = buttonState; // センサー値 - //var photoSensor = int.Parse(values[1]); var dt = DateTime.Now; var elapsed = (dt - _MainForm.RecodingTime).TotalMilliseconds; diff --git a/ISCamRecorder/Setting.Designer.cs b/ISCamRecorder/Setting.Designer.cs index 8080841..9cb3cb2 100644 --- a/ISCamRecorder/Setting.Designer.cs +++ b/ISCamRecorder/Setting.Designer.cs @@ -42,7 +42,12 @@ this.label4 = new System.Windows.Forms.Label(); this.TxtTriggerFPS = new System.Windows.Forms.TextBox(); this.ChkTrigger = new System.Windows.Forms.CheckBox(); + this.RadSwitchMovie = new System.Windows.Forms.RadioButton(); + this.RadSwitchImage = new System.Windows.Forms.RadioButton(); + this.panel1 = new System.Windows.Forms.Panel(); + this.label8 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); + this.panel1.SuspendLayout(); this.SuspendLayout(); // // label3 @@ -63,6 +68,7 @@ // // groupBox1 // + this.groupBox1.Controls.Add(this.panel1); this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.TxtTriggerFPS); this.groupBox1.Controls.Add(this.ChkTrigger); @@ -232,7 +238,47 @@ this.ChkTrigger.TabIndex = 32; this.ChkTrigger.Text = "ソフトウェアトリガー"; this.ChkTrigger.UseVisualStyleBackColor = true; - this.ChkTrigger.CheckedChanged += new System.EventHandler(this.ChkTrigger_CheckedChanged); + // + // RadSwitchMovie + // + this.RadSwitchMovie.AutoSize = true; + this.RadSwitchMovie.Checked = true; + this.RadSwitchMovie.Location = new System.Drawing.Point(65, 7); + this.RadSwitchMovie.Name = "RadSwitchMovie"; + this.RadSwitchMovie.Size = new System.Drawing.Size(71, 16); + this.RadSwitchMovie.TabIndex = 36; + this.RadSwitchMovie.TabStop = true; + this.RadSwitchMovie.Text = "動画撮影"; + this.RadSwitchMovie.UseVisualStyleBackColor = true; + // + // RadSwitchImage + // + this.RadSwitchImage.AutoSize = true; + this.RadSwitchImage.Location = new System.Drawing.Point(142, 7); + this.RadSwitchImage.Name = "RadSwitchImage"; + this.RadSwitchImage.Size = new System.Drawing.Size(83, 16); + this.RadSwitchImage.TabIndex = 37; + this.RadSwitchImage.Text = "静止画撮影"; + this.RadSwitchImage.UseVisualStyleBackColor = true; + // + // panel1 + // + this.panel1.Controls.Add(this.label8); + this.panel1.Controls.Add(this.RadSwitchImage); + this.panel1.Controls.Add(this.RadSwitchMovie); + this.panel1.Location = new System.Drawing.Point(8, 178); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(229, 30); + this.panel1.TabIndex = 20; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(3, 9); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(56, 12); + this.label8.TabIndex = 0; + this.label8.Text = "ボタン連動"; // // Setting // @@ -252,6 +298,8 @@ this.Activated += new System.EventHandler(this.Setting_Activated); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); this.ResumeLayout(false); } @@ -276,5 +324,9 @@ private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox TxtTriggerFPS; private System.Windows.Forms.CheckBox ChkTrigger; + private System.Windows.Forms.RadioButton RadSwitchMovie; + private System.Windows.Forms.RadioButton RadSwitchImage; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label label8; } } \ No newline at end of file diff --git a/ISCamRecorder/Setting.cs b/ISCamRecorder/Setting.cs index f493c83..e00167a 100644 --- a/ISCamRecorder/Setting.cs +++ b/ISCamRecorder/Setting.cs @@ -11,6 +11,7 @@ namespace ISCamRecorder { public partial class Setting : Form { + public enum ACTION { movie, image} public string SaveDir { get; private set; } public string ImageType { get; private set; } public string ImageTypeL { get { return ImageType.ToLower(); } } @@ -18,6 +19,7 @@ public float RecodingLimit { get; private set; } public bool SWTrigger { get; private set; } public float SWTriggerFPS { get; private set; } + public ACTION ButtonAction { get; private set; } public float TotalConsumedMemoryPerSecond { get; set; } /// @@ -28,6 +30,7 @@ ImageType = "JPG"; SWTrigger = false; SWTriggerFPS = 40F; + ButtonAction = ACTION.movie; #if DEBUG SaveDir = @"D:\DataDBG"; RecodingLimit = 3F; @@ -51,6 +54,8 @@ TxtRecodingDulation.Text = RecodingLimit.ToString("0.0"); ChkTrigger.Checked = SWTrigger; TxtTriggerFPS.Text = SWTriggerFPS.ToString("0.0"); + RadSwitchMovie.Checked = ButtonAction == ACTION.movie; + RadSwitchImage.Checked = ButtonAction == ACTION.image; this.UpdateMemoryInfo(); } @@ -66,6 +71,7 @@ RecodingLimit = float.Parse(TxtRecodingDulation.Text); SWTrigger = ChkTrigger.Checked; SWTriggerFPS = float.Parse(TxtTriggerFPS.Text); + ButtonAction = RadSwitchMovie.Checked ? ACTION.movie : ACTION.image; this.Close(); }