コード例 #1
0
ファイル: Form1.cs プロジェクト: mvlese/AwsLese
 private void AverageHandler(TPAverage value)
 {
     lock (_lockObject)
     {
         _dataQueueAvg.Enqueue(value);
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: mvlese/AwsLese
        private void UpdateChart()
        {
            while (IsReading)
            {
                BindingList <double> list = null;
                bool hasData = false;
                Thread.Sleep(1);
                if (_dataQueue.Count > 0)
                {
                    list = null;
                    TPCorrelation tpCorrelation = null;
                    lock (_lockObject)
                    {
                        tpCorrelation = _dataQueue.Dequeue();
                    }
                    if (tpCorrelation.correlation_coefficient.HasValue)
                    {
                        if (string.Compare(tpCorrelation.kind.Trim(), "temperature-lux", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            list = values1;
                        }
                        else if (string.Compare(tpCorrelation.kind.Trim(), "temperature-pressure", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            list = values2;
                        }
                        else if (string.Compare(tpCorrelation.kind.Trim(), "temperature-humidity", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            list = values3;
                        }
                    }

                    if (tpCorrelation.ts.HasValue && tpCorrelation.ts.Value > _mostRecentTimestamp)
                    {
                        _mostRecentTimestamp = tpCorrelation.ts.Value;
                    }

                    if (list != null)
                    {
                        if (list.Count >= MaxChartItems)
                        {
                            list.RemoveAt(0);
                        }
                        list.Add(tpCorrelation.correlation_coefficient.Value);
                        hasData = true;
                    }
                }

                if (_dataQueueAvg.Count > 0)
                {
                    list = null;
                    TPAverage tpAverage = null;
                    lock (_lockObject)
                    {
                        tpAverage = _dataQueueAvg.Dequeue();
                    }
                    if (tpAverage.kind.Trim().CompareTo("temperature") == 0)
                    {
                        list = valuesAvg1;
                    }
                    else if (tpAverage.kind.Trim().CompareTo("pressure") == 0)
                    {
                        list = valuesAvg2;
                    }
                    else if (tpAverage.kind.Trim().CompareTo("humidity") == 0)
                    {
                        list = valuesAvg3;
                    }
                    else if (tpAverage.kind.Trim().CompareTo("lux") == 0)
                    {
                        list = valuesAvg4;
                    }

                    if (tpAverage.ts.HasValue && tpAverage.ts.Value > _mostRecentTimestamp)
                    {
                        _mostRecentTimestamp = tpAverage.ts.Value;
                    }

                    if (list != null)
                    {
                        if (list.Count >= MaxChartItems)
                        {
                            list.RemoveAt(0);
                        }
                        list.Add(tpAverage.average.Value);
                        hasData = true;
                    }

                    if (hasData)
                    {
                        if (rbStartOfStream.Checked && updownFrequency.Value > 0)
                        {
                            if (_nextUpdateTimestamp == DateTime.MinValue)
                            {
                                _nextUpdateTimestamp = _mostRecentTimestamp.AddMinutes((int)updownFrequency.Value);
                                handleValuesChanged();
                            }
                            else if (_mostRecentTimestamp > _nextUpdateTimestamp)
                            {
                                _nextUpdateTimestamp = _nextUpdateTimestamp.AddMinutes((int)updownFrequency.Value);
                                handleValuesChanged();
                            }
                        }
                        else
                        {
                            handleValuesChanged();
                        }
                    }
                }
            }
        }