74 lines
1.6 KiB
C++
74 lines
1.6 KiB
C++
#ifndef WIDGET_H
|
|
#define WIDGET_H
|
|
|
|
#include <QWidget>
|
|
#include <QSerialPort>
|
|
#include <QTimer>
|
|
#include <QVector>
|
|
#include <QPushButton>
|
|
#include <QLineEdit>
|
|
#include <QComboBox>
|
|
#include <QTextEdit>
|
|
#include <QLabel>
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
namespace Ui { class Widget; }
|
|
QT_END_NAMESPACE
|
|
|
|
class Widget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
Widget(QWidget *parent = nullptr);
|
|
~Widget();
|
|
|
|
private slots:
|
|
void openPort();
|
|
void closePort();
|
|
void sendData();
|
|
void autoSendData();
|
|
void handleReadyRead();
|
|
void clearStatus();
|
|
|
|
private:
|
|
// UI 控件
|
|
QPushButton *openButton;
|
|
QPushButton *closeButton;
|
|
QPushButton *sendButton;
|
|
QPushButton *autoSendButton;
|
|
QLineEdit *autoIntervalEdit;
|
|
QComboBox *portComboBox;
|
|
QComboBox *baudRateComboBox;
|
|
QLineEdit *sendLineEdit;
|
|
QTextEdit *receiveTextEdit;
|
|
QLabel *statusLabel;
|
|
QLabel *minWindDirectionLabel;
|
|
QLabel *avgWindDirectionLabel;
|
|
QLabel *maxWindDirectionLabel;
|
|
QLabel *minWindSpeedLabel;
|
|
QLabel *avgWindSpeedLabel;
|
|
QLabel *maxWindSpeedLabel;
|
|
QLabel *temperatureLabel;
|
|
QLabel *humidityLabel;
|
|
QLabel *pressureLabel;
|
|
|
|
// 串口和定时器
|
|
QSerialPort *serialPort;
|
|
QTimer *autoSendTimer;
|
|
QTimer *statusTimer;
|
|
|
|
// 状态标志和缓冲区
|
|
bool isAutoSending;
|
|
QByteArray receiveBuffer;
|
|
|
|
// 数据记录
|
|
QString csvFileName = "weather_data.csv";
|
|
int dataCount = 1;
|
|
|
|
// 辅助函数
|
|
quint16 calculateCRC(const QByteArray &data);
|
|
void saveToCSV(const QVector<quint16>& values);
|
|
};
|
|
#endif // WIDGET_H
|