优化逻辑

This commit is contained in:
zhangsheng 2025-04-17 14:06:21 +08:00
parent 64f60fe3af
commit 4b28af5a4e
15 changed files with 1155 additions and 29 deletions

View File

@ -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 \

View File

@ -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<RadialVariable> radial_ptr = std::dynamic_pointer_cast<RadialVariable>(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<CardBase> 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<CardType>(card_type_[i]);
vib_data->slot_ = slot;
for (int j = 0; j < CHANNEL_COUNT; ++j) {
std::shared_ptr<VariableBase> 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<AccVelVariable> variable = std::make_shared<AccVelVariable>();
// 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();

View File

@ -21,7 +21,7 @@ class ConfigMgr {
return instance;
}
~ConfigMgr();
void Save();
void Save(QString & file_path);
void Load(QString filename);
std::shared_ptr<CardBase> GetSlotPtr(int slot);
void AddCard(std::shared_ptr<CardBase> ptr);

31
connect.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "connect.h"
#include "ui_connect.h"
#include <QRegExpValidator>
#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);
}

28
connect.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef CONNECT_H
#define CONNECT_H
#include <QWidget>
#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

58
connect.ui Normal file
View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Connect</class>
<widget class="QWidget" name="Connect">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>连接</string>
</property>
<widget class="QPushButton" name="pushButton_connect">
<property name="geometry">
<rect>
<x>130</x>
<y>190</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>连接</string>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>80</x>
<y>80</y>
<width>221</width>
<height>22</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>CPU IP:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_IP">
<property name="text">
<string>192.168.0.100</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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<QAbstractButton *> 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();
}

View File

@ -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();

View File

@ -1124,9 +1124,9 @@
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu">
<widget class="QMenu" name="menu_start">
<property name="title">
<string>文件</string>
<string>开始</string>
</property>
<addaction name="action_new"/>
<addaction name="action_open"/>
@ -1146,7 +1146,7 @@
<addaction name="action_realy"/>
<addaction name="action_time"/>
</widget>
<addaction name="menu"/>
<addaction name="menu_start"/>
<addaction name="menu_2"/>
<addaction name="menu_tool"/>
</widget>

138
rangeslider.cpp Normal file
View File

@ -0,0 +1,138 @@
#include "rangeslider.h"
#include <QPainter>
#include <QMouseEvent>
#include <QDebug>
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));
}
}

47
rangeslider.h Normal file
View File

@ -0,0 +1,47 @@
#ifndef RANGESLIDER_H
#define RANGESLIDER_H
#include <QWidget>
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

152
setpoint.cpp Normal file
View File

@ -0,0 +1,152 @@
#include "setpoint.h"
#include "ui_setpoint.h"
#include "config_mgr.h"
#include <QDebug>
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>(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<CardBase> 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<VibrationData> setpoint_data = std::dynamic_pointer_cast<VibrationData>(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<CardBase> 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<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(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()
{
}

38
setpoint.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef SETPOINT_H
#define SETPOINT_H
#include <QWidget>
#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

576
setpoint.ui Normal file
View File

@ -0,0 +1,576 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Setpoint</class>
<widget class="QWidget" name="Setpoint">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>734</width>
<height>528</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>540</x>
<y>10</y>
<width>161</width>
<height>451</height>
</rect>
</property>
<property name="title">
<string>危险 / 警报 2</string>
</property>
<widget class="QComboBox" name="comboBox_danger">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>69</width>
<height>22</height>
</rect>
</property>
<item>
<property name="text">
<string>直接值</string>
</property>
</item>
<item>
<property name="text">
<string>1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>2倍频幅值</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="comboBox_5">
<property name="geometry">
<rect>
<x>80</x>
<y>30</y>
<width>69</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_19">
<property name="geometry">
<rect>
<x>20</x>
<y>72</y>
<width>36</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>mil pp</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_danger">
<property name="geometry">
<rect>
<x>20</x>
<y>415</y>
<width>47</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>启用</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_danger_upper">
<property name="geometry">
<rect>
<x>12</x>
<y>90</y>
<width>50</width>
<height>20</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
<widget class="QWidget" name="widget_danger" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>116</y>
<width>80</width>
<height>260</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>260</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>260</height>
</size>
</property>
</widget>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>480</y>
<width>666</width>
<height>37</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_20">
<property name="text">
<string>槽位号</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_slot">
<property name="text">
<string>slot</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_chan">
<item>
<property name="text">
<string>通道 1</string>
</property>
</item>
<item>
<property name="text">
<string>通道 2</string>
</property>
</item>
<item>
<property name="text">
<string>通道 3</string>
</property>
</item>
<item>
<property name="text">
<string>通道 4</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_confirm">
<property name="minimumSize">
<size>
<width>100</width>
<height>35</height>
</size>
</property>
<property name="text">
<string>确定</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_set_default">
<property name="minimumSize">
<size>
<width>100</width>
<height>35</height>
</size>
</property>
<property name="text">
<string>设置为默认值</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_cancel">
<property name="minimumSize">
<size>
<width>100</width>
<height>35</height>
</size>
</property>
<property name="text">
<string>取消</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_print">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>35</height>
</size>
</property>
<property name="text">
<string>打印</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_help">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>35</height>
</size>
</property>
<property name="text">
<string>帮助</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>521</width>
<height>451</height>
</rect>
</property>
<property name="title">
<string>告警 / 警报 1</string>
</property>
<widget class="QWidget" name="widget_1x_ampl" native="true">
<property name="geometry">
<rect>
<x>100</x>
<y>110</y>
<width>100</width>
<height>260</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>260</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>260</height>
</size>
</property>
</widget>
<widget class="QLabel" name="label_27">
<property name="geometry">
<rect>
<x>121</x>
<y>41</y>
<width>54</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>1倍频幅值</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_1x_ampl_upper">
<property name="geometry">
<rect>
<x>121</x>
<y>77</y>
<width>50</width>
<height>20</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
<widget class="QLabel" name="label_25">
<property name="geometry">
<rect>
<x>130</x>
<y>59</y>
<width>36</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>mil pp</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_1x_ampl_lower">
<property name="geometry">
<rect>
<x>120</x>
<y>380</y>
<width>50</width>
<height>20</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_1x_ampl">
<property name="geometry">
<rect>
<x>121</x>
<y>420</y>
<width>47</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>启用</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_2x_ampl">
<property name="geometry">
<rect>
<x>221</x>
<y>420</y>
<width>47</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>启用</string>
</property>
</widget>
<widget class="QLabel" name="label_32">
<property name="geometry">
<rect>
<x>221</x>
<y>41</y>
<width>54</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>2倍频幅值</string>
</property>
</widget>
<widget class="QLabel" name="label_31">
<property name="geometry">
<rect>
<x>230</x>
<y>59</y>
<width>36</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>mil pp</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2x_ampl_upper">
<property name="geometry">
<rect>
<x>221</x>
<y>77</y>
<width>50</width>
<height>20</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
<widget class="QWidget" name="widget_2x_ampl" native="true">
<property name="geometry">
<rect>
<x>200</x>
<y>110</y>
<width>100</width>
<height>260</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>260</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>260</height>
</size>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2x_ampl_lower">
<property name="geometry">
<rect>
<x>220</x>
<y>380</y>
<width>50</width>
<height>20</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_direct_upper">
<property name="geometry">
<rect>
<x>30</x>
<y>80</y>
<width>50</width>
<height>20</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QWidget" name="widget_direct" native="true">
<property name="geometry">
<rect>
<x>10</x>
<y>107</y>
<width>100</width>
<height>260</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>260</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>260</height>
</size>
</property>
</widget>
<widget class="QLabel" name="label_21">
<property name="geometry">
<rect>
<x>40</x>
<y>40</y>
<width>36</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>直接值</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_22">
<property name="geometry">
<rect>
<x>40</x>
<y>60</y>
<width>36</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>mil pp</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_direct">
<property name="geometry">
<rect>
<x>30</x>
<y>420</y>
<width>65</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>启用</string>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -83,7 +83,11 @@ void Tachometer::UpdateData(std::shared_ptr<TachometerData> &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<TachometerData> &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<TachometerData> &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<TachometerData> &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();