2024-12-17 18:53:41 +08:00
|
|
|
#include "tachometer.h"
|
|
|
|
#include "ui_tachometer.h"
|
2025-03-21 10:42:24 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonParseError>
|
|
|
|
#include <QJsonArray>
|
2024-12-17 18:53:41 +08:00
|
|
|
|
2025-03-27 10:16:01 +08:00
|
|
|
Tachometer::Tachometer(int slot_no_, QWidget *parent)
|
2024-12-17 18:53:41 +08:00
|
|
|
: QDialog(parent)
|
2025-03-27 10:16:01 +08:00
|
|
|
, ui(new Ui::Tachometer) {
|
2024-12-17 18:53:41 +08:00
|
|
|
ui->setupUi(this);
|
2025-03-11 16:42:00 +08:00
|
|
|
ui->widget_body->setProperty("flag", "body");
|
2025-03-27 10:16:01 +08:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2025-03-21 10:42:24 +08:00
|
|
|
slot_no = slot_no_;
|
|
|
|
QString slot = QString("%1").arg(slot_no);
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->label_slot->setText(slot);
|
2025-03-21 10:42:24 +08:00
|
|
|
QString filePath_tachometer = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\tachometer.json").arg(slot_no);
|
|
|
|
readJsonFile(filePath_tachometer);
|
|
|
|
Init();
|
2025-03-28 10:17:18 +08:00
|
|
|
connect(ui->radioButton_manual_threshold_1, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_1_clicked);
|
|
|
|
connect(ui->radioButton_manual_threshold_2, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_2_clicked);
|
|
|
|
connect(ui->radioButton_manual_threshold_3, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_3_clicked);
|
|
|
|
connect(ui->radioButton_manual_threshold_4, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_4_clicked);
|
2024-12-17 18:53:41 +08:00
|
|
|
}
|
|
|
|
|
2025-03-27 10:16:01 +08:00
|
|
|
Tachometer::~Tachometer() {
|
2024-12-17 18:53:41 +08:00
|
|
|
delete ui;
|
|
|
|
}
|
2025-03-28 10:17:18 +08:00
|
|
|
|
|
|
|
void Tachometer::on_manual_threshold_1_clicked(bool checked) {
|
|
|
|
if (checked) {
|
|
|
|
ui->doubleSpinBox_threshold_1->setEnabled(true);
|
|
|
|
ui->doubleSpinBox_hysteresis_1->setEnabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui->doubleSpinBox_threshold_1->setEnabled(false);
|
|
|
|
ui->doubleSpinBox_hysteresis_1->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tachometer::on_manual_threshold_2_clicked(bool checked) {
|
|
|
|
if (checked) {
|
|
|
|
ui->doubleSpinBox_threshold_2->setEnabled(true);
|
|
|
|
ui->doubleSpinBox_hysteresis_2->setEnabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui->doubleSpinBox_threshold_2->setEnabled(false);
|
|
|
|
ui->doubleSpinBox_hysteresis_2->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tachometer::on_manual_threshold_3_clicked(bool checked) {
|
|
|
|
if (checked) {
|
|
|
|
ui->doubleSpinBox_threshold_3->setEnabled(true);
|
|
|
|
ui->doubleSpinBox_hysteresis_3->setEnabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui->doubleSpinBox_threshold_3->setEnabled(false);
|
|
|
|
ui->doubleSpinBox_hysteresis_3->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tachometer::on_manual_threshold_4_clicked(bool checked) {
|
|
|
|
if (checked) {
|
|
|
|
ui->doubleSpinBox_threshold_4->setEnabled(true);
|
|
|
|
ui->doubleSpinBox_hysteresis_4->setEnabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui->doubleSpinBox_threshold_4->setEnabled(false);
|
|
|
|
ui->doubleSpinBox_hysteresis_4->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2025-03-27 10:16:01 +08:00
|
|
|
void Tachometer::readJsonFile(const QString &filePath) {
|
2025-03-21 10:42:24 +08:00
|
|
|
QFile file(filePath);
|
2025-03-23 14:03:48 +08:00
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
qDebug() << "Cannot open file for reading:" << filePath;
|
2025-03-21 10:42:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
QString content = file.readAll();
|
|
|
|
file.close();
|
|
|
|
QByteArray jsonData = content.toUtf8();
|
|
|
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
|
|
|
if (jsonDoc.isNull()) {
|
|
|
|
qDebug() << "Cannot parse JSON document";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
|
|
|
|
qDebug() << "JSON document is not an object or an array";
|
2025-03-21 10:42:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
QJsonObject json_obj = jsonDoc.object();
|
2025-03-21 10:42:24 +08:00
|
|
|
QJsonArray chan_array = json_obj["chan"].toArray();
|
2025-03-27 10:16:01 +08:00
|
|
|
for (int i = 0; i < chan_array.size(); i++) {
|
2025-03-21 10:42:24 +08:00
|
|
|
QJsonObject temp_obj = chan_array[i].toObject();
|
|
|
|
tachometer_variables[i].id = temp_obj["id"].toInt();
|
|
|
|
tachometer_variables[i].active = temp_obj["active"].toBool();
|
|
|
|
QJsonArray voltage_range_array = temp_obj["normal_voltage_range"].toArray();
|
|
|
|
tachometer_variables[i].normal_voltage_high = voltage_range_array[1].toDouble();
|
|
|
|
tachometer_variables[i].normal_voltage_low = voltage_range_array[0].toDouble();
|
|
|
|
tachometer_variables[i].threshold = temp_obj["threshold"].toDouble();
|
|
|
|
tachometer_variables[i].hysteresis = temp_obj["hysteresis"].toDouble();
|
|
|
|
tachometer_variables[i].events_per_revolution = temp_obj["events_per_revolution"].toInt();
|
|
|
|
tachometer_variables[i].record_output = temp_obj["record_output"].toString();
|
|
|
|
tachometer_variables[i].two_ma_clamp = temp_obj["two_ma_clamp"].toBool();
|
|
|
|
tachometer_variables[i].alert_latching = temp_obj["alert_latching"].toBool();
|
|
|
|
tachometer_variables[i].overspeed_latching = temp_obj["overspeed_latching"].toBool();
|
|
|
|
tachometer_variables[i].normal_latching = temp_obj["normal_latching"].toBool();
|
|
|
|
tachometer_variables[i].alert_response_time = temp_obj["alert_response_time"].toInt();
|
|
|
|
tachometer_variables[i].danger_response_time = temp_obj["danger_response_time"].toInt();
|
|
|
|
}
|
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
void Tachometer::Init() {
|
2025-04-02 09:59:55 +08:00
|
|
|
for (int i = 0; i < CHANNEL_COUNT; i++) {
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].id == 1) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->checkBox_chan_1->setChecked(tachometer_variables[i].active);
|
|
|
|
ui->doubleSpinBox_high_1->setValue(tachometer_variables[i].normal_voltage_high);
|
|
|
|
ui->doubleSpinBox_low_1->setValue(tachometer_variables[i].normal_voltage_low);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].automatic_threshold) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_automatic_threshold_1->setChecked(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_manual_threshold_1->setChecked(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->doubleSpinBox_threshold_1->setValue(tachometer_variables[i].threshold);
|
|
|
|
ui->doubleSpinBox_hysteresis_1->setValue(tachometer_variables[i].hysteresis);
|
|
|
|
ui->spinBox_events_per_revolution_1->setValue(tachometer_variables[i].events_per_revolution);
|
|
|
|
ui->comboBox_record_output_1->setCurrentText(tachometer_variables[i].record_output);
|
|
|
|
ui->checkBox_two_ma_clamp_1->setChecked(tachometer_variables[i].two_ma_clamp);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].alert_latching) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_alert_latching_1->setCheckable(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_alert_latching_1->setCheckable(false);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
|
|
|
if (tachometer_variables[i].overspeed_latching) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_overspeed_latching_1->setCheckable(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_overspeed_latching_1->setCheckable(false);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].id == 2) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->checkBox_chan_2->setChecked(tachometer_variables[i].active);
|
|
|
|
ui->doubleSpinBox_high_2->setValue(tachometer_variables[i].normal_voltage_high);
|
|
|
|
ui->doubleSpinBox_low_2->setValue(tachometer_variables[i].normal_voltage_low);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].automatic_threshold) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_automatic_threshold_2->setChecked(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_manual_threshold_2->setChecked(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->doubleSpinBox_threshold_2->setValue(tachometer_variables[i].threshold);
|
|
|
|
ui->doubleSpinBox_hysteresis_2->setValue(tachometer_variables[i].hysteresis);
|
|
|
|
ui->spinBox_events_per_revolution_2->setValue(tachometer_variables[i].events_per_revolution);
|
|
|
|
ui->comboBox_record_output_2->setCurrentText(tachometer_variables[i].record_output);
|
|
|
|
ui->checkBox_two_ma_clamp_2->setChecked(tachometer_variables[i].two_ma_clamp);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].alert_latching) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_alert_latching_2->setCheckable(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_alert_latching_2->setCheckable(false);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
|
|
|
if (tachometer_variables[i].overspeed_latching) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_overspeed_latching_2->setCheckable(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_overspeed_latching_2->setCheckable(false);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].id == 3) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->checkBox_chan_3->setChecked(tachometer_variables[i].active);
|
|
|
|
ui->doubleSpinBox_high_3->setValue(tachometer_variables[i].normal_voltage_high);
|
|
|
|
ui->doubleSpinBox_low_3->setValue(tachometer_variables[i].normal_voltage_low);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].automatic_threshold) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_automatic_threshold_3->setChecked(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_manual_threshold_3->setChecked(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->doubleSpinBox_threshold_3->setValue(tachometer_variables[i].threshold);
|
|
|
|
ui->doubleSpinBox_hysteresis_3->setValue(tachometer_variables[i].hysteresis);
|
|
|
|
ui->spinBox_events_per_revolution_3->setValue(tachometer_variables[i].events_per_revolution);
|
|
|
|
ui->comboBox_record_output_3->setCurrentText(tachometer_variables[i].record_output);
|
|
|
|
ui->checkBox_two_ma_clamp_3->setChecked(tachometer_variables[i].two_ma_clamp);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].alert_latching) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_alert_latching_3->setCheckable(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_alert_latching_3->setCheckable(false);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
|
|
|
if (tachometer_variables[i].overspeed_latching) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_overspeed_latching_3->setCheckable(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_overspeed_latching_3->setCheckable(false);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].id == 4) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->checkBox_chan_4->setChecked(tachometer_variables[i].active);
|
|
|
|
ui->doubleSpinBox_high_4->setValue(tachometer_variables[i].normal_voltage_high);
|
|
|
|
ui->doubleSpinBox_low_4->setValue(tachometer_variables[i].normal_voltage_low);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].automatic_threshold) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_automatic_threshold_4->setChecked(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_manual_threshold_4->setChecked(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->doubleSpinBox_threshold_4->setValue(tachometer_variables[i].threshold);
|
|
|
|
ui->doubleSpinBox_hysteresis_4->setValue(tachometer_variables[i].hysteresis);
|
|
|
|
ui->spinBox_events_per_revolution_4->setValue(tachometer_variables[i].events_per_revolution);
|
|
|
|
ui->comboBox_record_output_4->setCurrentText(tachometer_variables[i].record_output);
|
|
|
|
ui->checkBox_two_ma_clamp_4->setChecked(tachometer_variables[i].two_ma_clamp);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].alert_latching) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_alert_latching_4->setCheckable(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_alert_latching_4->setCheckable(false);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
|
|
|
if (tachometer_variables[i].overspeed_latching) {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_overspeed_latching_4->setCheckable(true);
|
2025-03-27 10:16:01 +08:00
|
|
|
} else {
|
2025-03-23 14:03:48 +08:00
|
|
|
ui->radioButton_overspeed_latching_4->setCheckable(false);
|
2025-03-27 10:16:01 +08:00
|
|
|
}
|
2025-03-23 14:03:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
void Tachometer::on_pushButton_confirm_clicked() {
|
2025-04-02 09:59:55 +08:00
|
|
|
for (int i = 0; i < CHANNEL_COUNT; i++) {
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].id == 1) {
|
2025-03-23 14:03:48 +08:00
|
|
|
tachometer_variables[i].active = ui->checkBox_chan_1->isChecked();
|
|
|
|
tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_1->value();
|
|
|
|
tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_1->value();
|
|
|
|
tachometer_variables[i].automatic_threshold = ui->radioButton_automatic_threshold_1->isChecked();
|
|
|
|
tachometer_variables[i].threshold = ui->doubleSpinBox_threshold_1->value();
|
|
|
|
tachometer_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_1->value();
|
|
|
|
tachometer_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_1->value();
|
|
|
|
tachometer_variables[i].record_output = ui->comboBox_record_output_1->currentText();
|
|
|
|
tachometer_variables[i].two_ma_clamp = ui->checkBox_two_ma_clamp_1->isChecked();
|
|
|
|
tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_1->isChecked();
|
|
|
|
tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_1->isChecked();
|
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].id == 2) {
|
2025-03-23 14:03:48 +08:00
|
|
|
tachometer_variables[i].active = ui->checkBox_chan_2->isChecked();
|
|
|
|
tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_2->value();
|
|
|
|
tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_2->value();
|
|
|
|
tachometer_variables[i].automatic_threshold = ui->radioButton_automatic_threshold_2->isChecked();
|
|
|
|
tachometer_variables[i].threshold = ui->doubleSpinBox_threshold_2->value();
|
|
|
|
tachometer_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_2->value();
|
|
|
|
tachometer_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_2->value();
|
|
|
|
tachometer_variables[i].record_output = ui->comboBox_record_output_2->currentText();
|
|
|
|
tachometer_variables[i].two_ma_clamp = ui->checkBox_two_ma_clamp_2->isChecked();
|
|
|
|
tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_2->isChecked();
|
|
|
|
tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_2->isChecked();
|
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].id == 3) {
|
2025-03-23 14:03:48 +08:00
|
|
|
tachometer_variables[i].active = ui->checkBox_chan_3->isChecked();
|
|
|
|
tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_3->value();
|
|
|
|
tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_3->value();
|
|
|
|
tachometer_variables[i].automatic_threshold = ui->radioButton_automatic_threshold_3->isChecked();
|
|
|
|
tachometer_variables[i].threshold = ui->doubleSpinBox_threshold_3->value();
|
|
|
|
tachometer_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_3->value();
|
|
|
|
tachometer_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_3->value();
|
|
|
|
tachometer_variables[i].record_output = ui->comboBox_record_output_3->currentText();
|
|
|
|
tachometer_variables[i].two_ma_clamp = ui->checkBox_two_ma_clamp_3->isChecked();
|
|
|
|
tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_3->isChecked();
|
|
|
|
tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_3->isChecked();
|
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
if (tachometer_variables[i].id == 4) {
|
2025-03-23 14:03:48 +08:00
|
|
|
tachometer_variables[i].active = ui->checkBox_chan_4->isChecked();
|
|
|
|
tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_4->value();
|
|
|
|
tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_4->value();
|
|
|
|
tachometer_variables[i].automatic_threshold = ui->radioButton_automatic_threshold_4->isChecked();
|
|
|
|
tachometer_variables[i].threshold = ui->doubleSpinBox_threshold_4->value();
|
|
|
|
tachometer_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_4->value();
|
|
|
|
tachometer_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_4->value();
|
|
|
|
tachometer_variables[i].record_output = ui->comboBox_record_output_4->currentText();
|
|
|
|
tachometer_variables[i].two_ma_clamp = ui->checkBox_two_ma_clamp_4->isChecked();
|
|
|
|
tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_4->isChecked();
|
|
|
|
tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_4->isChecked();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QString slot = QString("%1").arg(slot_no);
|
|
|
|
QString filePath_tachometer = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\tachometer.json").arg(slot_no);
|
|
|
|
QFile file(filePath_tachometer);
|
2025-03-27 10:16:01 +08:00
|
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
2025-03-23 14:03:48 +08:00
|
|
|
qDebug() << "Could not open file for writing";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QJsonObject json_obj;
|
|
|
|
QJsonArray chan_array;
|
2025-04-02 09:59:55 +08:00
|
|
|
for (int i = 0; i < CHANNEL_COUNT; i++) {
|
2025-03-23 14:03:48 +08:00
|
|
|
QJsonObject temp_obj;
|
|
|
|
temp_obj.insert("id", tachometer_variables[i].id);
|
|
|
|
temp_obj.insert("active", tachometer_variables[i].active);
|
|
|
|
QJsonArray voltage_range_array;
|
|
|
|
voltage_range_array.append(tachometer_variables[i].normal_voltage_low);
|
|
|
|
voltage_range_array.append(tachometer_variables[i].normal_voltage_high);
|
|
|
|
temp_obj.insert("normal_voltage_range", voltage_range_array);
|
|
|
|
temp_obj.insert("threshold", tachometer_variables[i].threshold);
|
|
|
|
temp_obj.insert("hysteresis", tachometer_variables[i].hysteresis);
|
|
|
|
temp_obj.insert("events_per_revolution", tachometer_variables[i].events_per_revolution);
|
|
|
|
temp_obj.insert("record_output", tachometer_variables[i].record_output);
|
|
|
|
temp_obj.insert("two_ma_clamp", tachometer_variables[i].two_ma_clamp);
|
|
|
|
temp_obj.insert("alert_latching", tachometer_variables[i].alert_latching);
|
|
|
|
temp_obj.insert("overspeed_latching", tachometer_variables[i].overspeed_latching);
|
|
|
|
temp_obj.insert("normal_latching", tachometer_variables[i].normal_latching);
|
|
|
|
temp_obj.insert("alert_response_time", tachometer_variables[i].alert_response_time);
|
|
|
|
temp_obj.insert("danger_response_time", tachometer_variables[i].danger_response_time);
|
|
|
|
chan_array.append(temp_obj);
|
|
|
|
}
|
|
|
|
json_obj.insert("chan", chan_array);
|
2025-03-27 10:16:01 +08:00
|
|
|
json_obj.insert("version", 1);
|
|
|
|
json_obj.insert("slot", slot_no);
|
|
|
|
json_obj.insert("card_type", 2);
|
2025-03-23 14:03:48 +08:00
|
|
|
QJsonDocument json_doc;
|
|
|
|
json_doc.setObject(json_obj);
|
|
|
|
QByteArray byte_array = json_doc.toJson();
|
|
|
|
file.write(byte_array);
|
|
|
|
file.close();
|
2025-03-21 10:42:24 +08:00
|
|
|
}
|
2025-03-27 10:16:01 +08:00
|
|
|
void Tachometer::on_pushButton_cancel_clicked() {
|
|
|
|
this->close();
|
|
|
|
}
|