mainwindow.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <QMainWindow>
  4. #include <QtSerialPort/QtSerialPort>
  5. #include <qwt_plot_curve.h>
  6. #define MOTORS 2
  7. #define ADCS 2
  8. #define POINTSPERSEC 100
  9. #define ADCDATALEN (60*POINTSPERSEC)
  10. namespace Ui {
  11. class MainWindow;
  12. }
  13. struct motor {
  14. char direction;
  15. u_int8_t speed;
  16. };
  17. typedef struct motor motor_t;
  18. struct adc {
  19. u_int16_t value;
  20. };
  21. typedef struct adc adc_t;
  22. struct state {
  23. motor_t m[MOTORS];
  24. adc_t adc[ADCS];
  25. };
  26. typedef struct state state_t;
  27. struct curpoint {
  28. double avg;
  29. qint64 times;
  30. qint64 ts;
  31. qint64 pointId;
  32. };
  33. typedef struct curpoint curpoint_t;
  34. struct point {
  35. float x;
  36. u_int16_t y;
  37. };
  38. typedef struct point point_t;
  39. enum m_state {
  40. M_DOWN = '1',
  41. M_UP = '2',
  42. M_STOP = '9',
  43. };
  44. class MainWindow : public QMainWindow
  45. {
  46. Q_OBJECT
  47. public:
  48. explicit MainWindow(QWidget *parent = 0);
  49. ~MainWindow();
  50. protected:
  51. bool eventFilter(QObject *obj, QEvent *event);
  52. private slots:
  53. void recvData();
  54. void reopenRemote();
  55. void on_speedM0Slider_valueChanged(int value);
  56. void on_speedM1Slider_valueChanged(int value);
  57. void on_downM0Radio_toggled(bool checked);
  58. void on_stopM0Radio_toggled(bool checked);
  59. void on_upM0Radio_toggled(bool checked);
  60. void on_downM1Radio_toggled(bool checked);
  61. void on_stopM1Radio_toggled(bool checked);
  62. void on_upM1Radio_toggled(bool checked);
  63. private:
  64. void on_resize_centralWidget(QResizeEvent *event);
  65. void on_resize_toolsWidget(QResizeEvent *event);
  66. void on_resize_plot(QResizeEvent *event, int adcId, QwtPlot *p);
  67. void openRemote();
  68. void closeRemote();
  69. void showCurState();
  70. void pushAdcValue(u_int8_t adcId, qint64 ts, u_int16_t value);
  71. void redrawGraphics();
  72. qint64 drawOldCurve(int adcId);
  73. void drawNewCurve(int adcId, qint64 startPointId);
  74. QwtPlot *getPlotByAdcId(int adcId);
  75. int fillPoints(QPolygonF &points, point_t *data, int startPointId, int endPointId, int skipBeforeTs);
  76. void sendDesiredState(int motorId);
  77. point_t ADCData[ADCS][ADCDATALEN];
  78. curpoint_t ADCCurPoint[ADCS];
  79. QwtPlotCurve ADCCurve[ADCS][2];
  80. state_t curState;
  81. state_t desiredState;
  82. u_int64_t xMax;
  83. QSerialPort *remote;
  84. Ui::MainWindow *ui;
  85. };
  86. #endif // MAINWINDOW_H