SignalMonitorUI.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using ScottPlot;
  2. using ScottPlot.Plottable;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Diagnostics;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace ProjectManagementSystem.UI
  14. {
  15. public partial class SignalMonitorUI : UserControl, IDisplayUI
  16. {
  17. readonly double[] signalValues = new double[60];
  18. private FormsPlot formsPlot1 = new FormsPlot();
  19. private SignalPlot signalPlot;
  20. public string PlotTitle { get; set; }
  21. public SignalMonitorUI()
  22. {
  23. InitializeComponent();
  24. }
  25. public bool Init()
  26. {
  27. formsPlot1.Dock = DockStyle.Fill;
  28. this.panel1.Controls.Add(formsPlot1);
  29. formsPlot1.Plot.Title(PlotTitle);
  30. signalPlot = formsPlot1.Plot.AddSignal(signalValues);
  31. signalPlot.StepDisplay = true;
  32. signalPlot.MarkerSize = 0;
  33. return true;
  34. }
  35. public void ClearSignal()
  36. {
  37. for (int i = 0; i < signalValues.Length; i++)
  38. {
  39. signalValues[i] = signalValues[i + 1];
  40. }
  41. }
  42. public void AddSignal(bool value)
  43. {
  44. AddSignal(value ? 1 : 0);
  45. }
  46. public void AddSignal(double value)
  47. {
  48. int maxIndex = signalValues.Length - 1;
  49. for (int i = 0; i < maxIndex; i++)
  50. {
  51. signalValues[i] = signalValues[i + 1];
  52. }
  53. signalValues[maxIndex] = value;
  54. }
  55. public void UpdateDisplay()
  56. {
  57. formsPlot1.Render();
  58. formsPlot1.Plot.AxisAuto();
  59. }
  60. }
  61. }