193 lines
10 KiB
C++
193 lines
10 KiB
C++
#include "keyphase.h"
|
|
#include "ui_keyphase.h"
|
|
#include <QDebug>
|
|
#include <QJsonDocument>
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
#include <QFile>
|
|
|
|
#include "data_config.h"
|
|
#include "config_mgr.h"
|
|
#include "keyphase_data.h"
|
|
|
|
KeyPhase::KeyPhase(int slot_no_, QWidget *parent)
|
|
: QDialog(parent)
|
|
, ui(new Ui::KeyPhase) {
|
|
ui->setupUi(this);
|
|
ui->widget_body->setProperty("flag", "body");
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
slot_no = slot_no_;
|
|
QString slot = QString("%1").arg(slot_no);
|
|
ui->label_slot->setText(slot);
|
|
// QString filePath_keyphase = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\keyphase.json").arg(slot_no);
|
|
// readJsonFile(filePath_keyphase);
|
|
Init();
|
|
connect(ui->radioButton_manual_threshold_1, &QRadioButton::toggled, this, &KeyPhase::on_manual_threshold_1_clicked);
|
|
connect(ui->radioButton_manual_threshold_2, &QRadioButton::toggled, this, &KeyPhase::on_manual_threshold_2_clicked);
|
|
connect(ui->radioButton_manual_threshold_3, &QRadioButton::toggled, this, &KeyPhase::on_manual_threshold_3_clicked);
|
|
connect(ui->radioButton_manual_threshold_4, &QRadioButton::toggled, this, &KeyPhase::on_manual_threshold_4_clicked);
|
|
}
|
|
|
|
KeyPhase::~KeyPhase() {
|
|
delete ui;
|
|
}
|
|
|
|
void KeyPhase::on_pushButton_cancel_clicked() {
|
|
this->close();
|
|
}
|
|
|
|
void KeyPhase::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 KeyPhase::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 KeyPhase::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 KeyPhase::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);
|
|
}
|
|
|
|
void KeyPhase::UpdateData(std::shared_ptr<KeyphaseData> &keyphase_data) {
|
|
keyphase_data->card_type_ = kCardKeyphase;
|
|
keyphase_data->slot_ = slot_no;
|
|
keyphase_data->version_ = 1;
|
|
for (int i = 0; i < CHANNEL_COUNT; i++) {
|
|
if (i + 1 == 1) {
|
|
keyphase_data->variables_[i].active = ui->checkBox_enable_1->isChecked();
|
|
keyphase_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_1->value();
|
|
keyphase_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_1->value();
|
|
keyphase_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_1->isChecked();
|
|
keyphase_data->variables_[i].threshold = ui->doubleSpinBox_threshold_1->value();
|
|
keyphase_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_1->value();
|
|
keyphase_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_1->value();
|
|
} else if (i + 1 == 2) {
|
|
keyphase_data->variables_[i].active = ui->checkBox_enable_2->isChecked();
|
|
keyphase_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_2->value();
|
|
keyphase_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_2->value();
|
|
keyphase_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_2->isChecked();
|
|
keyphase_data->variables_[i].threshold = ui->doubleSpinBox_threshold_2->value();
|
|
keyphase_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_2->value();
|
|
keyphase_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_2->value();
|
|
} else if (i + 1 == 3) {
|
|
keyphase_data->variables_[i].active = ui->checkBox_enable_3->isChecked();
|
|
keyphase_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_3->value();
|
|
keyphase_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_3->value();
|
|
keyphase_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_3->isChecked();
|
|
keyphase_data->variables_[i].threshold = ui->doubleSpinBox_threshold_3->value();
|
|
keyphase_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_3->value();
|
|
keyphase_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_3->value();
|
|
} else if (i + 1 == 4) {
|
|
keyphase_data->variables_[i].active = ui->checkBox_enable_4->isChecked();
|
|
keyphase_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_4->value();
|
|
keyphase_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_4->value();
|
|
keyphase_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_4->isChecked();
|
|
keyphase_data->variables_[i].threshold = ui->doubleSpinBox_threshold_4->value();
|
|
keyphase_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_4->value();
|
|
keyphase_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_4->value();
|
|
}
|
|
}
|
|
}
|
|
|
|
void KeyPhase::Init() {
|
|
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
|
|
if (base_ptr == nullptr) {
|
|
// do nothing or use template to init it.
|
|
std::shared_ptr<KeyphaseData> keyphase_data = std::make_shared<KeyphaseData>();
|
|
ConfigMgr::Instance()->AddCard(keyphase_data);
|
|
UpdateData(keyphase_data);
|
|
return;
|
|
}
|
|
std::shared_ptr<KeyphaseData> keyphase_data = std::dynamic_pointer_cast<KeyphaseData>(base_ptr);
|
|
for (int i = 0; i < CHANNEL_COUNT; i++) {
|
|
if (i + 1 == 1) {
|
|
ui->checkBox_enable_1->setChecked(keyphase_data->variables_[i].active);
|
|
ui->doubleSpinBox_high_1->setValue(keyphase_data->variables_[i].normal_voltage_high);
|
|
ui->doubleSpinBox_low_1->setValue(keyphase_data->variables_[i].normal_voltage_low);
|
|
if (keyphase_data->variables_[i].automatic_threshold) {
|
|
ui->radioButton_automatic_threshold_1->setChecked(true);
|
|
} else {
|
|
ui->radioButton_manual_threshold_1->setChecked(true);
|
|
}
|
|
ui->doubleSpinBox_threshold_1->setValue(keyphase_data->variables_[i].threshold);
|
|
ui->doubleSpinBox_hysteresis_1->setValue(keyphase_data->variables_[i].hysteresis);
|
|
ui->spinBox_events_per_revolution_1->setValue(keyphase_data->variables_[i].events_per_revolution);
|
|
} else if (i + 1 == 2) {
|
|
ui->checkBox_enable_2->setChecked(keyphase_data->variables_[i].active);
|
|
ui->doubleSpinBox_high_2->setValue(keyphase_data->variables_[i].normal_voltage_high);
|
|
ui->doubleSpinBox_low_2->setValue(keyphase_data->variables_[i].normal_voltage_low);
|
|
if (keyphase_data->variables_[i].automatic_threshold) {
|
|
ui->radioButton_automatic_threshold_2->setChecked(true);
|
|
} else {
|
|
ui->radioButton_manual_threshold_2->setChecked(true);
|
|
}
|
|
ui->doubleSpinBox_threshold_2->setValue(keyphase_data->variables_[i].threshold);
|
|
ui->doubleSpinBox_hysteresis_2->setValue(keyphase_data->variables_[i].hysteresis);
|
|
ui->spinBox_events_per_revolution_2->setValue(keyphase_data->variables_[i].events_per_revolution);
|
|
} else if (i + 1 == 3) {
|
|
ui->checkBox_enable_3->setChecked(keyphase_data->variables_[i].active);
|
|
ui->doubleSpinBox_high_3->setValue(keyphase_data->variables_[i].normal_voltage_high);
|
|
ui->doubleSpinBox_low_3->setValue(keyphase_data->variables_[i].normal_voltage_low);
|
|
if (keyphase_data->variables_[i].automatic_threshold) {
|
|
ui->radioButton_automatic_threshold_3->setChecked(true);
|
|
} else {
|
|
ui->radioButton_manual_threshold_3->setChecked(true);
|
|
}
|
|
ui->doubleSpinBox_threshold_3->setValue(keyphase_data->variables_[i].threshold);
|
|
ui->doubleSpinBox_hysteresis_3->setValue(keyphase_data->variables_[i].hysteresis);
|
|
ui->spinBox_events_per_revolution_3->setValue(keyphase_data->variables_[i].events_per_revolution);
|
|
} else if (i + 1 == 4) {
|
|
ui->checkBox_enable_4->setChecked(keyphase_data->variables_[i].active);
|
|
ui->doubleSpinBox_high_4->setValue(keyphase_data->variables_[i].normal_voltage_high);
|
|
ui->doubleSpinBox_low_4->setValue(keyphase_data->variables_[i].normal_voltage_low);
|
|
if (keyphase_data->variables_[i].automatic_threshold) {
|
|
ui->radioButton_automatic_threshold_4->setChecked(true);
|
|
} else {
|
|
ui->radioButton_manual_threshold_4->setChecked(true);
|
|
}
|
|
ui->doubleSpinBox_threshold_4->setValue(keyphase_data->variables_[i].threshold);
|
|
ui->doubleSpinBox_hysteresis_4->setValue(keyphase_data->variables_[i].hysteresis);
|
|
ui->spinBox_events_per_revolution_4->setValue(keyphase_data->variables_[i].events_per_revolution);
|
|
}
|
|
}
|
|
}
|
|
void KeyPhase::on_pushButton_confirm_clicked() {
|
|
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
|
|
if (base_ptr == nullptr) {
|
|
qCritical() << " should not be here";
|
|
return;
|
|
}
|
|
std::shared_ptr<KeyphaseData> keyphase_data = std::dynamic_pointer_cast<KeyphaseData>(base_ptr);
|
|
UpdateData(keyphase_data);
|
|
this->close();
|
|
}
|
|
|