diff --git a/ISCamRecorder/ISCamRecorder.csproj b/ISCamRecorder/ISCamRecorder.csproj index f5b536f..2ce2726 100644 --- a/ISCamRecorder/ISCamRecorder.csproj +++ b/ISCamRecorder/ISCamRecorder.csproj @@ -155,9 +155,6 @@ - - - diff --git a/ISCamRecorder/MainForm.Designer.cs b/ISCamRecorder/MainForm.Designer.cs index 9a6c6b7..242f13a 100644 --- a/ISCamRecorder/MainForm.Designer.cs +++ b/ISCamRecorder/MainForm.Designer.cs @@ -61,6 +61,7 @@ this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.CboImageType = new System.Windows.Forms.ComboBox(); + this.ChkStartSW = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -239,8 +240,8 @@ chartArea1.AxisX.LabelStyle.Format = "HH:mm:ss"; chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.Gray; chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.Gray; - chartArea1.AxisY.Maximum = 700D; - chartArea1.AxisY.Minimum = 550D; + chartArea1.AxisY.Maximum = 800D; + chartArea1.AxisY.Minimum = 500D; chartArea1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); chartArea1.Name = "ChartArea1"; chartArea1.Position.Auto = false; @@ -445,9 +446,9 @@ // // BtnRecodeMovie // - this.BtnRecodeMovie.Location = new System.Drawing.Point(393, 12); + this.BtnRecodeMovie.Location = new System.Drawing.Point(383, 8); this.BtnRecodeMovie.Name = "BtnRecodeMovie"; - this.BtnRecodeMovie.Size = new System.Drawing.Size(74, 34); + this.BtnRecodeMovie.Size = new System.Drawing.Size(74, 27); this.BtnRecodeMovie.TabIndex = 15; this.BtnRecodeMovie.Text = "動画撮影"; this.BtnRecodeMovie.UseVisualStyleBackColor = true; @@ -474,12 +475,13 @@ // // BtnSnapImage // - this.BtnSnapImage.Location = new System.Drawing.Point(473, 12); + this.BtnSnapImage.Location = new System.Drawing.Point(463, 8); this.BtnSnapImage.Name = "BtnSnapImage"; - this.BtnSnapImage.Size = new System.Drawing.Size(74, 34); + this.BtnSnapImage.Size = new System.Drawing.Size(74, 27); this.BtnSnapImage.TabIndex = 18; this.BtnSnapImage.Text = "静止画撮影"; this.BtnSnapImage.UseVisualStyleBackColor = true; + this.BtnSnapImage.Click += new System.EventHandler(this.BtnSnapImage_Click); // // label5 // @@ -531,11 +533,24 @@ this.CboImageType.TabIndex = 21; this.CboImageType.Text = "JPG"; // + // 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; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(892, 555); + this.Controls.Add(this.ChkStartSW); this.Controls.Add(this.CboImageType); this.Controls.Add(this.TxtMovieRate); this.Controls.Add(this.label7); @@ -635,6 +650,7 @@ private System.Windows.Forms.TextBox TxtSensor; private System.Windows.Forms.PictureBox PicCvCamera; private System.Windows.Forms.TextBox TxtCvCamera; + private System.Windows.Forms.CheckBox ChkStartSW; } } diff --git a/ISCamRecorder/MainForm.cs b/ISCamRecorder/MainForm.cs index 68cf5f5..67450d6 100644 --- a/ISCamRecorder/MainForm.cs +++ b/ISCamRecorder/MainForm.cs @@ -13,12 +13,12 @@ using NAudio.MediaFoundation; using System.Windows.Forms.DataVisualization.Charting; using System.Threading; +using System.Media; namespace ISCamRecorder { public partial class MainForm : Form { readonly int PLOT_LENGTH = 200; // センサー値表示サンプル数 - readonly int PLOT_YAXIS_MIN = 800; // センサー値縦軸仮最小値 readonly int PLOT_UPDATE_INTERVAL = 30; // グラフ更新時間 readonly int UI_UPDATE_INTERVAL = 2000; // UI更新時間 readonly int CVCAMERA_ID = 0; // 追加カメラのID @@ -114,8 +114,6 @@ //chart1.ChartAreas[0].AxisY.Minimum = // minValue < PLOT_YAXIS_MIN ? minValue : PLOT_YAXIS_MIN; } - - PicCvCamera.Image = _CvCamera.GetImage(); } /// @@ -124,12 +122,17 @@ /// static void UITimerCB(object obj) { ((MainForm)obj).Invalidate(); + //((MainForm)obj).UpdateForm(); } /// /// UI更新 /// public void UpdateForm() { + //if (this.InvokeRequired) { + // this.Invoke((MethodInvoker)delegate { UpdateForm(); }); + // return; + //} var now = DateTime.Now; var elapsed = now - _LastUpdate; if (elapsed.TotalMilliseconds > UI_UPDATE_INTERVAL) { @@ -145,6 +148,12 @@ _TriggerFrameRate = float.Parse(TxtTriggerFPS.Text); } Plot(); + PicCvCamera.Image = _CvCamera.GetImage(); // 追加カメラ表示 + if (ChkStartSW.Checked && _Sensor.IsStartButtonPressed) StartRecoding(); + if (_RecodingThread != null && _RecodingThread.IsCompleted) { + _RecodingThread.Dispose(); + _RecodingThread = null; + } } /// @@ -249,17 +258,15 @@ /// /// private void BtnRecodeMovie_Click(object sender, EventArgs e) { + StartRecoding(); + } + + public void StartRecoding() { if (_RecodingThread != null) { // 中断 //_Cameras.ForEach(c => c.StopRecoding()); Debug.WriteLine("recoding"); } else { - BtnRecodeMovie.Enabled = false; - BtnSetProperty.Enabled = false; - BtnRecodeMovie.Text = "撮影中"; - var originalColor = BtnRecodeMovie.BackColor; - BtnRecodeMovie.BackColor = Color.Orange; - _RecodingThread = Task.Run(RecodingThread); } } @@ -272,10 +279,17 @@ string recodingDulationTxt = ""; string movieRateTxt = ""; string imageTypeTxt = ""; + Color originalButtonColor = Color.Gray; // 録画モードへ変更 this.Invoke((MethodInvoker)delegate { _Cameras.ForEach(c => c.ChangeSink(true)); + BtnRecodeMovie.Enabled = false; + BtnSetProperty.Enabled = false; + BtnRecodeMovie.Text = "撮影中"; + originalButtonColor = BtnRecodeMovie.BackColor; + BtnRecodeMovie.BackColor = Color.Orange; + recodingDulationTxt = TxtRecodingDulation.Text; movieRateTxt = TxtMovieRate.Text; imageTypeTxt = CboImageType.Text; @@ -318,7 +332,7 @@ this.Invoke((MethodInvoker)delegate { _Cameras.ForEach(c => c.ChangeSink(false)); BtnRecodeMovie.Text = "動画撮影"; - BtnRecodeMovie.BackColor = Color.Gray; + BtnRecodeMovie.BackColor = originalButtonColor; BtnRecodeMovie.Enabled = true; BtnSetProperty.Enabled = true; }); @@ -332,5 +346,15 @@ private void MainForm_Paint(object sender, PaintEventArgs e) { UpdateForm(); } + + /// + /// 静止画撮影ボタン + /// + /// + /// + private void BtnSnapImage_Click(object sender, EventArgs e) { + var player = new SoundPlayer(@"D:\prog\ISCamRecorder\ISCamRecorder\media\start.wav"); + player.Play(); + } } } diff --git a/ISCamRecorder/SensorData.cs b/ISCamRecorder/SensorData.cs index 7f154ee..43e4b87 100644 --- a/ISCamRecorder/SensorData.cs +++ b/ISCamRecorder/SensorData.cs @@ -17,6 +17,7 @@ // サンプル時間 public Queue Times { get; private set; } = new Queue(); public float FrameRate { get { return _Fps.FrameRate; } } + public bool IsStartButtonPressed { get { return _StartButtonState; } } SerialPort _Serial = null; // シリアル通信オブジェクト bool _ExitSignal = false; // 終了シグナル @@ -26,6 +27,7 @@ StreamWriter _CsvWriter = null; // ファイル保存オブジェクト DateTime _RecordBeginTime; // 記録開始時間 FrameRateCounter _Fps = new FrameRateCounter(10); + bool _StartButtonState = false; // スタートボタンの状態 /// /// 接続 @@ -71,6 +73,8 @@ var str = _Serial.ReadLine(); var values = str.Split(','); if (values.Length < 2) continue; + + _StartButtonState = values[0].Equals("0"); var photoSensor = int.Parse(values[1]); var dt = DateTime.Now; var elapsed = (dt - _RecordBeginTime).TotalMilliseconds; diff --git a/ISCamRecorder/media/end.wav b/ISCamRecorder/media/end.wav new file mode 100644 index 0000000..cab656c --- /dev/null +++ b/ISCamRecorder/media/end.wav Binary files differ diff --git a/ISCamRecorder/media/start.wav b/ISCamRecorder/media/start.wav new file mode 100644 index 0000000..26e8d05 --- /dev/null +++ b/ISCamRecorder/media/start.wav Binary files differ diff --git a/PhotoReflectorIF/PhotoReflectorIF.ino b/PhotoReflectorIF/PhotoReflectorIF.ino index 0ab907b..120f79b 100644 --- a/PhotoReflectorIF/PhotoReflectorIF.ino +++ b/PhotoReflectorIF/PhotoReflectorIF.ino @@ -10,7 +10,7 @@ const int SW_PIN = 6; // 開始スイッチ入力ピン const int SPEAKER_PIN = 4; // スピーカー出力 const int LOOP_WAIT = 30; // ループ毎のウェイト(ms) -const unsigned long BUZZER_LENGTH = 2000; // 開始ブザー音の長さ(ms) +const unsigned long BUZZER_LENGTH = 500; // 開始ブザー音の長さ(ms) unsigned long gBuzzerEnd = 0; // 初期化