Example #1
0
        private void UpdateTimer_Tick(object sender, EventArgs e)
        {
            lock (chartLock)
            {
                if (motionLevel > motionTriggerThreshold)
                {
                    if (!playOnce && enableBeepOnTrigger)
                    {
                        playOnce = true;
                        PlayBeep();
                    }
                    if (!captureImageOnce && cbEnableSaveImg.IsChecked == true)
                    {
                        captureImageOnce = true;
                        CaptureAsImage();
                    }
                }

                // update data into collection
                DateTime currentTime = DateTime.Now;
                double   elapsedTime = (currentTime - startTime).TotalSeconds;
                motionLevelData = new MotionLevelData(elapsedTime, motionLevel, motionTriggerThreshold, startTime, currentTime, detectedObjectsCount);
                GraphDataCollection.Add(motionLevelData);
                if (GraphDataCollection.Count > 10000)
                {
                    GraphDataCollection.RemoveAt(0);
                }

                // update sensitivity bar
                UpdateSensivityBarUI();

                // update graph
                OxyGraph.InvalidatePlot(true);

                // autoscroll graph x-axis
                if ((elapsedTime + 0.001) >= xAxis.Maximum)
                {
                    double panStep = (xAxis.ActualMaximum - xAxis.DataMaximum) * xAxis.Scale;
                    xAxis.Pan(panStep);
                }

                // write to log file
                if (!customIntervalEnabled)
                {
                    LogData(motionLevelData);
                }
            }
        }
Example #2
0
 private void LogData(MotionLevelData data)
 {
     if (data == null)
     {
         return;
     }
     if (cbLimitDataLog.IsChecked == true && pointsLimitCounter > Convert.ToInt32(tbLimitDataLogPoint.Text))
     {
         canLogData = false;
         UpdateStatusOnUI();
         return;
     }
     if (cbLogGreaterThanThreshold.IsChecked == true && data.Value < data.ThresholdValue)
     {
         return;
     }
     if (canLogData)
     {
         try
         {
             if (!File.Exists(datalogFilePath))
             {
                 const string header = "Elapsed Time (s), Motion Level, Trigger Threshold, Blob Count, Start Time, Current Time";
                 File.WriteAllText(datalogFilePath, header + Environment.NewLine);
             }
             var sb = new StringBuilder();
             sb.Append(data.ElapsedTime);
             sb.Append("," + data.Value);
             sb.Append("," + data.ThresholdValue);
             sb.Append("," + data.BlobCount);
             sb.Append("," + data.StartTime.ToString("yyyy-MM-dd hh:mm:ss.fff"));
             sb.Append("," + data.CurrentTime.ToString("yyyy-MM-dd hh:mm:ss.fff"));
             sb.Append(Environment.NewLine);
             File.AppendAllText(datalogFilePath, sb.ToString());
             pointsLimitCounter++;
         }
         catch
         {
             // ignored
         }
     }
 }