public static void AddSensors(List <SensorItem> sensors) { foreach (SensorItem sensor in sensors) { SensorButton btn = new SensorButton(); btn.SensorId = sensor.Id; btn.Name = sensor.Id.ToString(); btn.Text = sensor.Name; Instances.Add(btn); } }
void Logger_OnConnectionChanged(object sender, EventArgs e) { if (DataLogger.Instance.IsConnected) { SensorButton.AddSensors(DataLogger.Sensors); } else { SensorButton.Clear(); } updateUi(); }
public override void OnDeactivate() { RefreshButton.Instance.RemoveFrom(Main.Instance.ToolStrip); RefreshButton.Instance.Refresh -= refresh; ClearButton.Instance.RemoveFrom(Main.Instance.ToolStrip); ClearButton.Instance.Click -= clear; SensorButton.RemoveFrom(Main.Instance.ToolStrip); SaveFileButton.Instance.RemoveFrom(Main.Instance.ToolStrip); base.OnDeactivate(); }
public override void OnActivate() { RefreshButton.Instance.AddTo(Main.Instance.ToolStrip); RefreshButton.Instance.Refresh += refresh; ClearButton.Instance.AddTo(Main.Instance.ToolStrip); ClearButton.Instance.Click += clear; SensorButton.AddTo(Main.Instance.ToolStrip); SaveFileButton.Instance.AddTo(Main.Instance.ToolStrip); SaveFileButton.Instance.Click += save; updateUi(); base.OnActivate(); }
public override void OnActivate() { RefreshButton.Instance.TimerButtonEnabled = false; RefreshButton.Instance.AddTo(Main.Instance.ToolStrip); RefreshButton.Instance.Refresh += refresh; ClearButton.Instance.AddTo(Main.Instance.ToolStrip); ClearButton.Instance.Click += clear; SensorButton.AddTo(Main.Instance.ToolStrip); SaveFileButton.Instance.AddTo(Main.Instance.ToolStrip); SaveFileButton.Instance.Click += save; PrintButton.Instance.AddTo(Main.Instance.ToolStrip); PrintButton.Instance.Click += printChart; updateUi(); base.OnActivate(); }
public static void AddSensors(List<SensorItem> sensors) { foreach (SensorItem sensor in sensors) { SensorButton btn = new SensorButton(); btn.SensorId = sensor.Id; btn.Name = sensor.Id.ToString(); btn.Text = sensor.Name; Instances.Add(btn); } }
private void refresh(object sender, EventArgs e) { chart.SuspendLayout(); for (int i = 0; i < SensorButton.Instances.Count; i++) { SensorButton sensorButton = SensorButton.Instances[i]; if (sensorButton.Checked) { List <TemperatureItem> temperaturItems; if (DataLogger.Instance.TryGetDayLog(sensorButton.SensorId, out temperaturItems)) { Series series = chart.Series[i]; series.Enabled = true; series.Points.Clear(); for (int n = 0; n < 24; n++) { series.Points.AddXY(23 - n, (double)temperaturItems[n].Temperature); } } } else { chart.Series[i].Enabled = false; } } ChartArea chartArea = chart.ChartAreas[0]; chartArea.RecalculateAxesScale(); double[] scale = { 5, 10, 25, 50, 75, 150 }; double max1 = chart.Series[0].Points.FindMaxByValue().YValues[0]; double max2 = chart.Series[1].Points.FindMaxByValue().YValues[0]; double min1 = chart.Series[0].Points.FindMinByValue().YValues[0]; double min2 = chart.Series[1].Points.FindMinByValue().YValues[0]; double m1 = System.Math.Max(System.Math.Abs(min1), max1); double m2 = System.Math.Max(System.Math.Abs(min2), max2); bool isNeg = min1 < 0 || min2 < 0; for (int i = 0; i < scale.Length; i++) { if (scale[i] > m1) { chartArea.AxisY.Maximum = scale[i]; if (isNeg) { chartArea.AxisY.Minimum = -scale[i]; } break; } } for (int i = 0; i < scale.Length; i++) { if (scale[i] > m2) { chartArea.AxisY2.Maximum = scale[i]; if (isNeg) { chartArea.AxisY2.Minimum = -scale[i]; } break; } } updateUi(); chart.ResumeLayout(); }