From 4b28af5a4e70c94d3f1175e49c7a4f97130d33b5 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Thu, 17 Apr 2025 14:06:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TSI_Config.pro | 3 + config_mgr.cpp | 25 ++- config_mgr.h | 2 +- connect.cpp | 31 +++ connect.h | 28 +++ connect.ui | 58 +++++ mainwindow.cpp | 53 ++++- mainwindow.h | 3 + mainwindow.ui | 6 +- rangeslider.cpp | 138 ++++++++++++ rangeslider.h | 47 ++++ setpoint.cpp | 152 +++++++++++++ setpoint.h | 38 ++++ setpoint.ui | 576 ++++++++++++++++++++++++++++++++++++++++++++++++ tachometer.cpp | 24 +- 15 files changed, 1155 insertions(+), 29 deletions(-) create mode 100644 connect.cpp create mode 100644 connect.h create mode 100644 connect.ui create mode 100644 rangeslider.cpp create mode 100644 rangeslider.h create mode 100644 setpoint.cpp create mode 100644 setpoint.h create mode 100644 setpoint.ui diff --git a/TSI_Config.pro b/TSI_Config.pro index ef70588..2fb7fb1 100644 --- a/TSI_Config.pro +++ b/TSI_Config.pro @@ -14,6 +14,7 @@ SOURCES += \ cardbase.cpp \ common.cpp \ config_mgr.cpp \ + connect.cpp \ keyphase.cpp \ keyphase_data.cpp \ main.cpp \ @@ -36,6 +37,7 @@ HEADERS += \ cardbase.h \ common.h \ config_mgr.h \ + connect.h \ data_config.h \ displacement_ds.h \ keyphase.h \ @@ -55,6 +57,7 @@ HEADERS += \ FORMS += \ acceleration.ui \ + connect.ui \ keyphase.ui \ mainwindow.ui \ radial_vibration.ui \ diff --git a/config_mgr.cpp b/config_mgr.cpp index 2324bad..2f23741 100644 --- a/config_mgr.cpp +++ b/config_mgr.cpp @@ -16,9 +16,8 @@ ConfigMgr *ConfigMgr::instance = nullptr; ConfigMgr::~ConfigMgr() { } -void ConfigMgr::Save() { +void ConfigMgr::Save(QString & file_path) { QJsonObject doc_obj; - doc_obj["version"] = 1; int slot = 0; QJsonArray card_type; for (int i = 0; i < SLOT_NUM; ++i) { @@ -65,16 +64,16 @@ void ConfigMgr::Save() { voltage_range.append(ptr->base_config_[cid].normal_voltage_high); channel_item["normal_voltage_range"] = voltage_range; QJsonObject setpoint_data; - setpoint_data["direct_upper"] = ptr->vib_alert_danger[cid].direct_upper; + setpoint_data["direct_upper"] = qRound(ptr->vib_alert_danger[cid].direct_upper * 10)/10.0; setpoint_data["direct_enable"] = ptr->vib_alert_danger[cid].direct_enable; - setpoint_data["1x_ampl_upper"] = ptr->vib_alert_danger[cid].x1_ampl_upper; - setpoint_data["1x_ampl_lower"] = ptr->vib_alert_danger[cid].x1_ampl_lower; + setpoint_data["1x_ampl_upper"] = qRound(ptr->vib_alert_danger[cid].x1_ampl_upper * 10)/10.0; + setpoint_data["1x_ampl_lower"] = qRound(ptr->vib_alert_danger[cid].x1_ampl_lower * 10)/10.0; setpoint_data["1x_ampl_enable"] = ptr->vib_alert_danger[cid].x1_ampl_enable; - setpoint_data["2x_ampl_upper"] = ptr->vib_alert_danger[cid].x2_ampl_upper; - setpoint_data["2x_ampl_lower"] = ptr->vib_alert_danger[cid].x2_ampl_lower; + setpoint_data["2x_ampl_upper"] = qRound(ptr->vib_alert_danger[cid].x2_ampl_upper * 10)/10.0; + setpoint_data["2x_ampl_lower"] = qRound(ptr->vib_alert_danger[cid].x2_ampl_lower * 10)/10.0; setpoint_data["2x_ampl_enable"] = ptr->vib_alert_danger[cid].x2_ampl_enable; setpoint_data["danger_param"] = ptr->vib_alert_danger[cid].danger_param; - setpoint_data["danger_upper"] = ptr->vib_alert_danger[cid].danger_upper; + setpoint_data["danger_upper"] = qRound(ptr->vib_alert_danger[cid].danger_upper * 10)/10.0; setpoint_data["danger_enable"] = ptr->vib_alert_danger[cid].danger_enable; channel_item["setpoint"] = setpoint_data; // variables @@ -83,7 +82,7 @@ void ConfigMgr::Save() { if (base_channel_ptr == nullptr) { continue; } - if (base_channel_ptr->type_ == kVibRadial) { + if (ptr->base_config_[cid].channel_type == kVibRadial) { std::shared_ptr radial_ptr = std::dynamic_pointer_cast(base_channel_ptr); if(radial_ptr == nullptr){ continue; @@ -239,6 +238,7 @@ void ConfigMgr::Save() { channel_item.insert("normal_latching", ptr->variables_[cid].normal_latching); channel_item.insert("speed_peak", ptr->variables_[cid].speed_peek); channel_item.insert("default_speed", ptr->variables_[cid].default_speed); + channel_item.insert("automatic_threshold",ptr->variables_[cid].automatic_threshold); } else if (card_type_[i] == kCardKeyphaseSingle) { std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot); @@ -257,6 +257,7 @@ void ConfigMgr::Save() { } slot_item[QString::number(cid + 1)] = channel_item; } + slot_item["version"] = 1; }else{ // TODO: save relay data } @@ -266,8 +267,7 @@ void ConfigMgr::Save() { // TODO: show success message box QJsonDocument jsonDoc; jsonDoc.setObject(doc_obj); - filename_ = QCoreApplication::applicationDirPath() + "\\config\\tsi_config_file.json"; - QFile file(filename_); + QFile file(file_path); file.open(QIODevice::WriteOnly); file.write(jsonDoc.toJson()); file.close(); @@ -322,6 +322,7 @@ void ConfigMgr::Load(QString filename) { vib_data->card_type_ = static_cast(card_type_[i]); vib_data->slot_ = slot; for (int j = 0; j < CHANNEL_COUNT; ++j) { + std::shared_ptr base_channel_ptr = vib_data->GetChannelPtr(j + 1); channel = temp_obj[QString::number(j + 1)].toObject(); if(channel.isEmpty()) continue; @@ -411,7 +412,7 @@ void ConfigMgr::Load(QString filename) { case kVibAcc: { std::shared_ptr variable = std::make_shared(); // filter - QJsonArray filter_array = channel["filter"].toArray(); + QJsonArray filter_array = tmp_variable["filter"].toArray(); for (int k = 0; k < filter_array.size(); k++) { QJsonObject filter_ele = filter_array[i].toObject(); variable->filter_[k].low = filter_ele["low"].toInt(); diff --git a/config_mgr.h b/config_mgr.h index 392e1c4..b42bbcc 100644 --- a/config_mgr.h +++ b/config_mgr.h @@ -21,7 +21,7 @@ class ConfigMgr { return instance; } ~ConfigMgr(); - void Save(); + void Save(QString & file_path); void Load(QString filename); std::shared_ptr GetSlotPtr(int slot); void AddCard(std::shared_ptr ptr); diff --git a/connect.cpp b/connect.cpp new file mode 100644 index 0000000..54522a9 --- /dev/null +++ b/connect.cpp @@ -0,0 +1,31 @@ +#include "connect.h" +#include "ui_connect.h" +#include +#include "data_config.h" + +Connect::Connect(QWidget *parent) : + QWidget(parent), + ui(new Ui::Connect) +{ + ui->setupUi(this); + + QString exp = "\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.)" + "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"; + QRegExp rege(exp); + QValidator *Validator = new QRegExpValidator(rege); + ui->lineEdit_IP->setValidator(Validator); +} + +Connect::~Connect() +{ + delete ui; +} + +void Connect::on_pushButton_connect_clicked() +{ + g_strServerIp = ui->lineEdit_IP->text(); + m_tcpClient = MyTcpClient::instance(); + // 连接服务器 + m_tcpClient->connectToServer(g_strServerIp, 10000); +} + diff --git a/connect.h b/connect.h new file mode 100644 index 0000000..e2dbda1 --- /dev/null +++ b/connect.h @@ -0,0 +1,28 @@ +#ifndef CONNECT_H +#define CONNECT_H + +#include +#include "MyTcpClient.h" + +namespace Ui { +class Connect; +} + +class Connect : public QWidget +{ + Q_OBJECT + +public: + explicit Connect(QWidget *parent = nullptr); + ~Connect(); + +private slots: + void on_pushButton_connect_clicked(); + +private: + Ui::Connect *ui; + MyTcpClient* m_tcpClient; + +}; + +#endif // CONNECT_H diff --git a/connect.ui b/connect.ui new file mode 100644 index 0000000..92eecb9 --- /dev/null +++ b/connect.ui @@ -0,0 +1,58 @@ + + + Connect + + + + 0 + 0 + 550 + 300 + + + + 连接 + + + + + 130 + 190 + 75 + 23 + + + + 连接 + + + + + + 80 + 80 + 221 + 22 + + + + + + + CPU IP: + + + + + + + 192.168.0.100 + + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 0a284de..2ce5884 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,6 +20,7 @@ #include "relaysetting.h" #include "config_mgr.h" #include "vibrationdata.h" +#include "connect.h" QString g_strServerIp; @@ -27,9 +28,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); - QMenuBar *menuBar = this->menuBar(); - this->setMenuBar(menuBar); //添加到对象树 - menuBar->addMenu(ui->menu_tool); +// QMenuBar *menuBar = this->menuBar(); +// this->setMenuBar(menuBar); //添加到对象树 +// menuBar->addMenu(ui->menu_start); ui->widget_body->setProperty("flag", "title"); ui->menuBar->setProperty("flag", "menuBar"); //关联事件过滤器用于双击放大 @@ -85,6 +86,9 @@ MainWindow::MainWindow(QWidget *parent) ui->pushButton_slot->setChecked(true); createMenu(); connect(btnGroup_slot, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(OnButtonGroup(QAbstractButton *))); + QObject::connect(ui->action_connect, &QAction::triggered, this, &MainWindow::onConnect); + QObject::connect(ui->action_disconnect, &QAction::triggered, this, &MainWindow::onConnect); + QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat); g_strServerIp = settingsread.value("Server/IP").toString(); //connectServer(); @@ -103,17 +107,20 @@ void MainWindow::onDisConnected() { } void MainWindow::onConnected() { - statusBar()->showMessage("连接成功!", 3000); // 显示3秒 + statusBar()->showMessage("连接成功!", 3000); +} +void MainWindow::onerrorOccurred(const QString &errorMsg) { + statusBar()->showMessage(errorMsg, 3000); } - void MainWindow::connectServer() { m_tcpClient = MyTcpClient::instance(); // 监听信号 connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray &)), this, SLOT(readData(const QByteArray &))); connect(m_tcpClient, SIGNAL(disconnected()), this, SLOT(onDisConnected())); connect(m_tcpClient, SIGNAL(connected()), this, SLOT(onConnected())); + connect(m_tcpClient, SIGNAL(errorOccurred(const QString &)), this, SLOT(onerrorOccurred(const QString &))); // 连接服务器 - m_tcpClient->connectToServer(g_strServerIp, 10000); + //m_tcpClient->connectToServer(g_strServerIp, 10000); } void MainWindow::initStyle() { @@ -503,9 +510,14 @@ uint8_t calculate_crc(uint8_t c, const QByteArray &data) { return crc; } void MainWindow::on_pushButton_save_clicked() { - ConfigMgr::Instance()->Save(); + + QString filepath = QFileDialog::getExistingDirectory(this, tr("选择文件夹"), tr("")); + if(filepath == "") + return; + QString file_name = filepath + "\\tsi_config_file.json"; + ConfigMgr::Instance()->Save(file_name); // 读取文件内容 - QFile file(QCoreApplication::applicationDirPath() + "\\config\\tsi_config_file.json"); + QFile file(file_name); if (!file.open(QIODevice::ReadOnly)) { qWarning() << "Failed to open update file."; return; @@ -556,7 +568,22 @@ void MainWindow::on_pushButton_save_clicked() { } void MainWindow::on_pushButton_open_clicked() { - ConfigMgr::Instance()->Load(QCoreApplication::applicationDirPath() + "\\config\\tsi_config_file.json"); + + QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*.json")); + QFileInfo fileinfo; + fileinfo = QFileInfo(filepath); + QString file_suffix = fileinfo.suffix(); + QString FileName = fileinfo.fileName(); + if (FileName.isEmpty()) { + return; + } + QFile file(filepath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "Failed to open update file."; + return; + } + + ConfigMgr::Instance()->Load(filepath); QList buttonList = btnGroup_slot->buttons(); for (int i = 0; i < buttonList.count(); i++) { @@ -746,3 +773,11 @@ void MainWindow::on_pushButton_download_clicked() qDebug() << "bytesWritten: " << bytesWritten; } +void MainWindow::onConnect(){ + Connect *connect_config = new Connect(); + connect_config->setWindowModality(Qt::ApplicationModal); + connect_config->show(); +} +void MainWindow::onDisconnect(){ + m_tcpClient->disconnectFromServer(); +} diff --git a/mainwindow.h b/mainwindow.h index 5d7e69d..022fd31 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -57,6 +57,7 @@ private: void getVersion(int slot); void initStyle(); void connectServer(); + void onerrorOccurred(const QString &errorMsg); private slots: void onDisConnected(); @@ -64,6 +65,8 @@ private slots: void readData(const QByteArray&); void onMenuAction_relay(); void OnButtonGroup(QAbstractButton *); + void onConnect(); + void onDisconnect(); void onMenuActionTriggered(); void on_pushButton_slot_clicked(); diff --git a/mainwindow.ui b/mainwindow.ui index 1e5dcef..ac5106c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1124,9 +1124,9 @@ 23 - + - 文件 + 开始 @@ -1146,7 +1146,7 @@ - + diff --git a/rangeslider.cpp b/rangeslider.cpp new file mode 100644 index 0000000..7209503 --- /dev/null +++ b/rangeslider.cpp @@ -0,0 +1,138 @@ +#include "rangeslider.h" +#include +#include +#include + +RangeSlider::RangeSlider(int style,QWidget *parent) + : QWidget(parent) { + setMinimumSize(20, 240); +} + +void RangeSlider::setRange(int min, int max) { + m_min = min; + m_max = max; + m_lower = qBound(m_min, m_lower, m_max); + m_upper = qBound(m_lower, m_upper, m_max); + update(); +} + +void RangeSlider::setSliderWidth(int width) { + sliderWidth = width; + update(); // 更新界面 +} + +float RangeSlider::lowerValue() const { return m_lower; } +float RangeSlider::upperValue() const { return m_upper; } + +float RangeSlider::valueToY(float value) const { + double ratio = (value - m_min) / double(m_max - m_min); + return height() - handleRadius - ratio * (height() - 2 * handleRadius); +} + +float RangeSlider::yToValue(float y) const { + double ratio = (height() - handleRadius - y) / double(height() - 2 * handleRadius); + ratio = qBound(0.0, ratio, 1.0); + float rawValue = m_min + ratio * (m_max - m_min); + float steppedValue = qRound(rawValue * 10) / 10.0f; + return qBound(m_min, steppedValue, m_max); +} + +RangeSlider::HandleType RangeSlider::handleHitTest(float y) const { + int yLower = valueToY(m_lower); + int yUpper = valueToY(m_upper); + if (qAbs(y - yLower) <= handleRadius + 2) return LowerHandle; + if (qAbs(y - yUpper) <= handleRadius + 2) return UpperHandle; + return NoHandle; +} + +void RangeSlider::mousePressEvent(QMouseEvent *event) { + currentHandle = handleHitTest(event->pos().y()); +} + +void RangeSlider::mouseMoveEvent(QMouseEvent *event) { + if (currentHandle == NoHandle) return; + + float val = yToValue(event->pos().y()); + if (currentHandle == LowerHandle) { + m_lower = qBound(m_min, val, m_upper); + } else if (currentHandle == UpperHandle) { + m_upper = qBound(m_lower, val, m_max); + } + update(); + emit rangeChanged(m_lower, m_upper); +} + +void RangeSlider::mouseReleaseEvent(QMouseEvent *) { + currentHandle = NoHandle; +} + +void RangeSlider::paintEvent(QPaintEvent *) { + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); + + int x = width() / 2; + int yLower = valueToY(m_lower); + int yUpper = valueToY(m_upper); + + // Draw Temperature-style background (gradient) + drawTemperatureStyle(&p); + + // Draw selected range (green) + // Draw selected range (green) + p.setPen(Qt::NoPen); + p.setBrush(Qt::green); + p.drawRect(x - sliderWidth / 2, yUpper, sliderWidth, yLower - yUpper); + + // Draw simple red handles (circles) + p.setPen(Qt::NoPen); + p.setBrush(Qt::red); + p.drawEllipse(QPointF(x, yLower), handleRadius, handleRadius); + p.drawEllipse(QPointF(x, yUpper), handleRadius, handleRadius); + + // Draw ticks + drawTicks(&p); +} +void RangeSlider::setLowerValue(float val) { + m_lower = qBound(m_min, val, m_upper); + update(); + emit rangeChanged(m_lower, m_upper); +} + +void RangeSlider::setUpperValue(float val) { + m_upper = qBound(m_lower, val, m_max); + update(); + emit rangeChanged(m_lower, m_upper); +} +void RangeSlider::drawTemperatureStyle(QPainter *p) { + int x = width() / 2; + int yTop = handleRadius; + int yBottom = height() - handleRadius; + + // Draw border (black) + p->setPen(Qt::black); + p->setBrush(Qt::NoBrush); + p->drawRect(x - sliderWidth / 2, yTop, sliderWidth, yBottom - yTop); + + // Draw yellow outside the range + p->setBrush(Qt::yellow); + p->drawRect(x - sliderWidth / 2, yTop, sliderWidth, valueToY(m_lower) - yTop); // Above lower range + p->drawRect(x - sliderWidth / 2, valueToY(m_upper), sliderWidth, yBottom - valueToY(m_upper)); // Below upper range + + // Draw green inside the range + p->setBrush(Qt::green); + p->drawRect(x - sliderWidth / 2, valueToY(m_upper), sliderWidth, valueToY(m_lower) - valueToY(m_upper)); // Green area +} + +void RangeSlider::drawTicks(QPainter *p) { + int tickCount = 11; + p->setPen(Qt::black); + p->setFont(QFont("Arial", 8)); + int x = width() / 2 + handleRadius + 4; + + for (int i = 0; i < tickCount; ++i) { + int val = m_min + i * (m_max - m_min) / (tickCount - 1); + int y = valueToY(val); + p->drawLine(x, y, x + 3, y); // 刻度宽度 + p->drawText(x + 8, y + 4, QString::number(val)); + } +} diff --git a/rangeslider.h b/rangeslider.h new file mode 100644 index 0000000..4530c1d --- /dev/null +++ b/rangeslider.h @@ -0,0 +1,47 @@ +#ifndef RANGESLIDER_H +#define RANGESLIDER_H + +#include + +class RangeSlider : public QWidget { + Q_OBJECT + +public: + explicit RangeSlider(int style = 0,QWidget *parent = nullptr); + + void setRange(int min, int max); + void setSliderWidth(int width); // 新增方法:设置宽度 + float lowerValue() const; + float upperValue() const; + void setLowerValue(float val); + void setUpperValue(float val); + float m_lower = 3.5; + float m_upper = 6.5; +signals: + void rangeChanged(float lower, float upper); + +protected: + void paintEvent(QPaintEvent *) override; + void mousePressEvent(QMouseEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; + void mouseReleaseEvent(QMouseEvent *) override; + +private: + float m_min = 0; + float m_max = 10; + + int sliderWidth = 15; // 默认宽度(可以根据需求调整) + + int handleRadius = 8; + enum HandleType { NoHandle, LowerHandle, UpperHandle }; + HandleType currentHandle = NoHandle; + + float valueToY(float value) const; + float yToValue(float y) const; + HandleType handleHitTest(float y) const; + + void drawTicks(QPainter *p); + void drawTemperatureStyle(QPainter *p); +}; + +#endif // RANGESLIDER_H diff --git a/setpoint.cpp b/setpoint.cpp new file mode 100644 index 0000000..25d890e --- /dev/null +++ b/setpoint.cpp @@ -0,0 +1,152 @@ +#include "setpoint.h" +#include "ui_setpoint.h" +#include "config_mgr.h" +#include + +Setpoint::Setpoint(int slot_no_,int cardtype,QWidget *parent) : + QWidget(parent), + ui(new Ui::Setpoint) +{ + ui->setupUi(this); + slot_no = slot_no_; + car_type = static_cast(cardtype); + ui->label_slot->setText(QString::number(slot_no)); + + Init(); +} + +Setpoint::~Setpoint() +{ + if(slider_direct != nullptr) + delete slider_direct; + if(slider_1x_ampl != nullptr) + delete slider_1x_ampl; + if(slider_2x_ampl != nullptr) + delete slider_2x_ampl; + if(slider_danger != nullptr) + delete slider_danger; + delete ui; +} +void Setpoint::Init(){ + + QVBoxLayout *layout_direct = new QVBoxLayout(ui->widget_direct); + slider_direct = new RangeSlider; + layout_direct->addWidget(slider_direct); + + QVBoxLayout *layout_1x_ampl = new QVBoxLayout(ui->widget_1x_ampl); + slider_1x_ampl = new RangeSlider; + layout_1x_ampl->addWidget(slider_1x_ampl); + + QVBoxLayout *layout_2x_ampl = new QVBoxLayout(ui->widget_2x_ampl); + slider_2x_ampl = new RangeSlider; + layout_2x_ampl->addWidget(slider_2x_ampl); + + QVBoxLayout *layout_danger = new QVBoxLayout(ui->widget_danger); + slider_danger = new RangeSlider; + layout_danger->addWidget(slider_danger); + + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + + + switch (car_type) { + case kCardVibSingle:{ + slider_direct->setRange(0,20); + slider_1x_ampl->setRange(0,20); + slider_2x_ampl->setRange(0,20); + slider_danger->setRange(0,20); + int chan = ui->comboBox_chan->currentIndex(); + std::shared_ptr setpoint_data = std::dynamic_pointer_cast(base_ptr); + ui->lineEdit_direct_upper->setText(QString::number(setpoint_data->vib_alert_danger[chan].direct_upper)); + ui->checkBox_direct->setChecked(setpoint_data->vib_alert_danger[chan].direct_enable); + slider_direct->m_upper = setpoint_data->vib_alert_danger[chan].direct_upper; + ui->lineEdit_1x_ampl_upper->setText(QString::number(setpoint_data->vib_alert_danger[chan].x1_ampl_upper)); + ui->lineEdit_1x_ampl_lower->setText(QString::number(setpoint_data->vib_alert_danger[chan].x1_ampl_lower)); + ui->checkBox_1x_ampl->setChecked(setpoint_data->vib_alert_danger[chan].x1_ampl_enable); + slider_1x_ampl->m_upper = setpoint_data->vib_alert_danger[chan].x1_ampl_upper; + slider_1x_ampl->m_lower = setpoint_data->vib_alert_danger[chan].x1_ampl_lower; + ui->lineEdit_2x_ampl_upper->setText(QString::number(setpoint_data->vib_alert_danger[chan].x2_ampl_upper)); + ui->lineEdit_2x_ampl_lower->setText(QString::number(setpoint_data->vib_alert_danger[chan].x2_ampl_lower)); + ui->checkBox_2x_ampl->setChecked(setpoint_data->vib_alert_danger[chan].x2_ampl_enable); + slider_2x_ampl->m_upper = setpoint_data->vib_alert_danger[chan].x2_ampl_upper; + slider_2x_ampl->m_lower = setpoint_data->vib_alert_danger[chan].x2_ampl_lower; + ui->lineEdit_danger_upper->setText(QString::number(setpoint_data->vib_alert_danger[chan].danger_upper)); + ui->checkBox_danger->setChecked(setpoint_data->vib_alert_danger[chan].danger_enable); + slider_danger->m_upper = setpoint_data->vib_alert_danger[chan].danger_upper; + }break; + case kCardSpeedSingle:{ + slider_direct->setRange(0,5000); + + }break; + } + QObject::connect(ui->lineEdit_direct_upper, &QLineEdit::editingFinished, [&]() { + slider_direct->setUpperValue(ui->lineEdit_direct_upper->text().toFloat()); + }); + QObject::connect(slider_direct, &RangeSlider::rangeChanged, [&](float low,float high) { + ui->lineEdit_direct_upper->setText(QString::number(high)); + }); + + QObject::connect(slider_1x_ampl, &RangeSlider::rangeChanged, [&](float low, float high) { + ui->lineEdit_1x_ampl_upper->setText(QString::number(high)); + ui->lineEdit_1x_ampl_lower->setText(QString::number(low)); + }); + QObject::connect(ui->lineEdit_1x_ampl_upper, &QLineEdit::editingFinished, [&]() { + slider_1x_ampl->setUpperValue(ui->lineEdit_1x_ampl_upper->text().toFloat()); + }); + QObject::connect(ui->lineEdit_1x_ampl_lower, &QLineEdit::editingFinished, [&]() { + slider_1x_ampl->setLowerValue(ui->lineEdit_1x_ampl_lower->text().toFloat()); + }); + + QObject::connect(slider_2x_ampl, &RangeSlider::rangeChanged, [&](float low, float high) { + ui->lineEdit_2x_ampl_upper->setText(QString::number(high)); + ui->lineEdit_2x_ampl_lower->setText(QString::number(low)); + }); + QObject::connect(ui->lineEdit_2x_ampl_upper, &QLineEdit::editingFinished, [&]() { + slider_1x_ampl->setUpperValue(ui->lineEdit_2x_ampl_upper->text().toFloat()); + }); + QObject::connect(ui->lineEdit_2x_ampl_lower, &QLineEdit::editingFinished, [&]() { + slider_1x_ampl->setLowerValue(ui->lineEdit_2x_ampl_lower->text().toFloat()); + }); + + QObject::connect(slider_danger, &RangeSlider::rangeChanged, [&](float low,float high) { + ui->lineEdit_danger_upper->setText(QString::number(high)); + }); + QObject::connect(ui->lineEdit_danger_upper, &QLineEdit::editingFinished, [&]() { + slider_danger->setUpperValue(ui->lineEdit_danger_upper->text().toFloat()); + }); +} + +void Setpoint::on_pushButton_confirm_clicked() +{ + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + if (base_ptr == nullptr) { + qCritical() << "[Setpoint::confirm] should not be here"; + return; + } + int chan = ui->comboBox_chan->currentIndex(); + std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); + ptr->vib_alert_danger[chan].direct_upper = ui->lineEdit_direct_upper->text().toFloat(); + ptr->vib_alert_danger[chan].direct_enable = ui->checkBox_direct->checkState(); + ptr->vib_alert_danger[chan].x1_ampl_upper = ui->lineEdit_1x_ampl_upper->text().toFloat(); + ptr->vib_alert_danger[chan].x1_ampl_lower = ui->lineEdit_1x_ampl_lower->text().toFloat(); + ptr->vib_alert_danger[chan].x1_ampl_enable = ui->checkBox_1x_ampl->checkState(); + ptr->vib_alert_danger[chan].x2_ampl_upper = ui->lineEdit_2x_ampl_upper->text().toFloat(); + ptr->vib_alert_danger[chan].x2_ampl_lower = ui->lineEdit_2x_ampl_lower->text().toFloat(); + ptr->vib_alert_danger[chan].x2_ampl_enable = ui->checkBox_2x_ampl->checkState(); + ptr->vib_alert_danger[chan].danger_param = ui->comboBox_danger->currentIndex(); + ptr->vib_alert_danger[chan].danger_upper = ui->lineEdit_danger_upper->text().toFloat(); + ptr->vib_alert_danger[chan].danger_enable = ui->checkBox_danger->checkState(); + this->close(); +} + + +void Setpoint::on_pushButton_cancel_clicked() +{ + this->close(); +} + + +void Setpoint::on_pushButton_set_default_clicked() +{ + +} + diff --git a/setpoint.h b/setpoint.h new file mode 100644 index 0000000..b59bd15 --- /dev/null +++ b/setpoint.h @@ -0,0 +1,38 @@ +#ifndef SETPOINT_H +#define SETPOINT_H + +#include +#include "data_config.h" +#include "rangeslider.h" +#include "vibrationdata.h" + +namespace Ui { +class Setpoint; +} + +class Setpoint : public QWidget +{ + Q_OBJECT + +public: + explicit Setpoint(int slot_no_,int cardtype,QWidget *parent = nullptr); + ~Setpoint(); + int slot_no; + CardType car_type; +private slots: + void on_pushButton_confirm_clicked(); + + void on_pushButton_cancel_clicked(); + + void on_pushButton_set_default_clicked(); + +private: + Ui::Setpoint *ui; + RangeSlider *slider_direct; + RangeSlider *slider_1x_ampl; + RangeSlider *slider_2x_ampl; + RangeSlider *slider_danger; + void Init(); +}; + +#endif // SETPOINT_H diff --git a/setpoint.ui b/setpoint.ui new file mode 100644 index 0000000..1376538 --- /dev/null +++ b/setpoint.ui @@ -0,0 +1,576 @@ + + + Setpoint + + + + 0 + 0 + 734 + 528 + + + + Form + + + + + 540 + 10 + 161 + 451 + + + + 危险 / 警报 2 + + + + + 10 + 30 + 69 + 22 + + + + + 直接值 + + + + + 1倍频幅值 + + + + + 2倍频幅值 + + + + + + + 80 + 30 + 69 + 22 + + + + + + + 20 + 72 + 36 + 16 + + + + mil pp + + + + + + 20 + 415 + 47 + 16 + + + + 启用 + + + false + + + + + + 12 + 90 + 50 + 20 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + + + + 0 + 116 + 80 + 260 + + + + + 80 + 260 + + + + + 80 + 260 + + + + + + + + 20 + 480 + 666 + 37 + + + + + + + 槽位号 + + + + + + + slot + + + + + + + + 通道 1 + + + + + 通道 2 + + + + + 通道 3 + + + + + 通道 4 + + + + + + + + + 100 + 35 + + + + 确定 + + + + + + + + 100 + 35 + + + + 设置为默认值 + + + + + + + + 100 + 35 + + + + 取消 + + + + + + + false + + + + 100 + 35 + + + + 打印 + + + + + + + false + + + + 100 + 35 + + + + 帮助 + + + + + + + + + 10 + 10 + 521 + 451 + + + + 告警 / 警报 1 + + + + + 100 + 110 + 100 + 260 + + + + + 100 + 260 + + + + + 100 + 260 + + + + + + + 121 + 41 + 54 + 16 + + + + 1倍频幅值 + + + + + + 121 + 77 + 50 + 20 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + + + + 130 + 59 + 36 + 16 + + + + mil pp + + + + + + 120 + 380 + 50 + 20 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + + + + 121 + 420 + 47 + 16 + + + + 启用 + + + + + + 221 + 420 + 47 + 16 + + + + 启用 + + + + + + 221 + 41 + 54 + 16 + + + + 2倍频幅值 + + + + + + 230 + 59 + 36 + 16 + + + + mil pp + + + + + + 221 + 77 + 50 + 20 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + + + + 200 + 110 + 100 + 260 + + + + + 100 + 260 + + + + + 100 + 260 + + + + + + + 220 + 380 + 50 + 20 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + + + + 30 + 80 + 50 + 20 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + Qt::AlignCenter + + + + + + 10 + 107 + 100 + 260 + + + + + 100 + 260 + + + + + 100 + 260 + + + + + + + 40 + 40 + 36 + 16 + + + + 直接值 + + + Qt::AlignCenter + + + + + + 40 + 60 + 36 + 16 + + + + mil pp + + + Qt::AlignCenter + + + + + + 30 + 420 + 65 + 16 + + + + 启用 + + + + + + + diff --git a/tachometer.cpp b/tachometer.cpp index 3a882c8..cf0417b 100644 --- a/tachometer.cpp +++ b/tachometer.cpp @@ -83,7 +83,11 @@ void Tachometer::UpdateData(std::shared_ptr &speed_data) { speed_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_1->value(); speed_data->variables_[i].speed_peek = ui->full_scale_range_1->value(); speed_data->variables_[i].default_speed = ui->default_value_1->value(); - speed_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_1->isChecked(); + if(ui->radioButton_automatic_threshold_1->isChecked()){ + speed_data->variables_[i].automatic_threshold = true; + }else{ + speed_data->variables_[i].automatic_threshold = false; + } speed_data->variables_[i].threshold = ui->doubleSpinBox_threshold_1->value(); speed_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_1->value(); speed_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_1->value(); @@ -97,7 +101,11 @@ void Tachometer::UpdateData(std::shared_ptr &speed_data) { speed_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_2->value(); speed_data->variables_[i].speed_peek = ui->full_scale_range_2->value(); speed_data->variables_[i].default_speed = ui->default_value_2->value(); - speed_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_2->isChecked(); + if(ui->radioButton_automatic_threshold_2->isChecked()){ + speed_data->variables_[i].automatic_threshold = true; + }else{ + speed_data->variables_[i].automatic_threshold = false; + } speed_data->variables_[i].threshold = ui->doubleSpinBox_threshold_2->value(); speed_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_2->value(); speed_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_2->value(); @@ -111,7 +119,11 @@ void Tachometer::UpdateData(std::shared_ptr &speed_data) { speed_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_3->value(); speed_data->variables_[i].speed_peek = ui->full_scale_range_3->value(); speed_data->variables_[i].default_speed = ui->default_value_3->value(); - speed_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_3->isChecked(); + if(ui->radioButton_automatic_threshold_3->isChecked()){ + speed_data->variables_[i].automatic_threshold = true; + }else{ + speed_data->variables_[i].automatic_threshold = false; + } speed_data->variables_[i].threshold = ui->doubleSpinBox_threshold_3->value(); speed_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_3->value(); speed_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_3->value(); @@ -125,7 +137,11 @@ void Tachometer::UpdateData(std::shared_ptr &speed_data) { speed_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_4->value(); speed_data->variables_[i].speed_peek = ui->full_scale_range_4->value(); speed_data->variables_[i].default_speed = ui->default_value_4->value(); - speed_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_4->isChecked(); + if(ui->radioButton_automatic_threshold_4->isChecked()){ + speed_data->variables_[i].automatic_threshold = true; + }else{ + speed_data->variables_[i].automatic_threshold = false; + } speed_data->variables_[i].threshold = ui->doubleSpinBox_threshold_4->value(); speed_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_4->value(); speed_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_4->value();