#include "tachometer.h" #include "ui_tachometer.h" #include #include #include #include #include #include #include "data_config.h" #include "config_mgr.h" #include "tachometer_data.h" Tachometer::Tachometer(int slot_no_, QWidget *parent) : QDialog(parent) , ui(new Ui::Tachometer) { 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); Init(); 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); } Tachometer::~Tachometer() { delete ui; } 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); } void Tachometer::UpdateData(std::shared_ptr &speed_data) { speed_data->card_type_ = kCardSpeedSingle; speed_data->slot_ = slot_no; speed_data->version_ = 1; for (int i = 0; i < CHANNEL_COUNT; i++) { if (i + 1 == 1) { speed_data->variables_[i].active = ui->checkBox_chan_1->isChecked(); speed_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_1->value(); 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(); 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(); speed_data->variables_[i].record_output = ui->comboBox_record_output_1->currentIndex(); speed_data->variables_[i].two_ma_clamp = ui->checkBox_two_ma_clamp_1->isChecked(); speed_data->variables_[i].alert_latching = ui->radioButton_alert_latching_1->isChecked(); speed_data->variables_[i].overspeed_latching = ui->radioButton_overspeed_latching_1->isChecked(); } else if (i + 1 == 2) { speed_data->variables_[i].active = ui->checkBox_chan_2->isChecked(); speed_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_2->value(); 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(); 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(); speed_data->variables_[i].record_output = ui->comboBox_record_output_2->currentIndex(); speed_data->variables_[i].two_ma_clamp = ui->checkBox_two_ma_clamp_2->isChecked(); speed_data->variables_[i].alert_latching = ui->radioButton_alert_latching_2->isChecked(); speed_data->variables_[i].overspeed_latching = ui->radioButton_overspeed_latching_2->isChecked(); } else if (i + 1 == 3) { speed_data->variables_[i].active = ui->checkBox_chan_3->isChecked(); speed_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_3->value(); 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(); 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(); speed_data->variables_[i].record_output = ui->comboBox_record_output_3->currentIndex(); speed_data->variables_[i].two_ma_clamp = ui->checkBox_two_ma_clamp_3->isChecked(); speed_data->variables_[i].alert_latching = ui->radioButton_alert_latching_3->isChecked(); speed_data->variables_[i].overspeed_latching = ui->radioButton_overspeed_latching_3->isChecked(); } else if (i + 1 == 4) { speed_data->variables_[i].active = ui->checkBox_chan_4->isChecked(); speed_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_4->value(); 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(); 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(); speed_data->variables_[i].record_output = ui->comboBox_record_output_4->currentIndex(); speed_data->variables_[i].two_ma_clamp = ui->checkBox_two_ma_clamp_4->isChecked(); speed_data->variables_[i].alert_latching = ui->radioButton_alert_latching_4->isChecked(); speed_data->variables_[i].overspeed_latching = ui->radioButton_overspeed_latching_4->isChecked(); } } } void Tachometer::Init() { std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); if (base_ptr == nullptr) { // do nothing or use template to init it. std::shared_ptr speed_data = std::make_shared(); ConfigMgr::Instance()->AddCard(speed_data); UpdateData(speed_data); return; } std::shared_ptr speed_data = std::dynamic_pointer_cast(base_ptr); for (int i = 0; i < CHANNEL_COUNT; i++) { if (i + 1 == 1) { ui->checkBox_chan_1->setChecked(speed_data->variables_[i].active); ui->doubleSpinBox_high_1->setValue(speed_data->variables_[i].normal_voltage_high); ui->doubleSpinBox_low_1->setValue(speed_data->variables_[i].normal_voltage_low); ui->full_scale_range_1->setValue(speed_data->variables_[i].speed_peek); ui->default_value_1->setValue(speed_data->variables_[i].default_speed); if (speed_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(speed_data->variables_[i].threshold); ui->doubleSpinBox_hysteresis_1->setValue(speed_data->variables_[i].hysteresis); ui->spinBox_events_per_revolution_1->setValue(speed_data->variables_[i].events_per_revolution); ui->comboBox_record_output_1->setCurrentIndex(speed_data->variables_[i].record_output); ui->checkBox_two_ma_clamp_1->setChecked(speed_data->variables_[i].two_ma_clamp); if (speed_data->variables_[i].alert_latching) { ui->radioButton_alert_latching_1->setCheckable(true); } else { ui->radioButton_alert_latching_1->setCheckable(false); } if (speed_data->variables_[i].overspeed_latching) { ui->radioButton_overspeed_latching_1->setCheckable(true); } else { ui->radioButton_overspeed_latching_1->setCheckable(false); } } else if (i + 1 == 2) { ui->checkBox_chan_2->setChecked(speed_data->variables_[i].active); ui->doubleSpinBox_high_2->setValue(speed_data->variables_[i].normal_voltage_high); ui->doubleSpinBox_low_2->setValue(speed_data->variables_[i].normal_voltage_low); ui->full_scale_range_2->setValue(speed_data->variables_[i].speed_peek); ui->default_value_2->setValue(speed_data->variables_[i].default_speed); if (speed_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(speed_data->variables_[i].threshold); ui->doubleSpinBox_hysteresis_2->setValue(speed_data->variables_[i].hysteresis); ui->spinBox_events_per_revolution_2->setValue(speed_data->variables_[i].events_per_revolution); ui->comboBox_record_output_2->setCurrentIndex(speed_data->variables_[i].record_output); ui->checkBox_two_ma_clamp_2->setChecked(speed_data->variables_[i].two_ma_clamp); if (speed_data->variables_[i].alert_latching) { ui->radioButton_alert_latching_2->setCheckable(true); } else { ui->radioButton_alert_latching_2->setCheckable(false); } if (speed_data->variables_[i].overspeed_latching) { ui->radioButton_overspeed_latching_2->setCheckable(true); } else { ui->radioButton_overspeed_latching_2->setCheckable(false); } } else if (i + 1 == 3) { ui->checkBox_chan_3->setChecked(speed_data->variables_[i].active); ui->doubleSpinBox_high_3->setValue(speed_data->variables_[i].normal_voltage_high); ui->doubleSpinBox_low_3->setValue(speed_data->variables_[i].normal_voltage_low); ui->full_scale_range_3->setValue(speed_data->variables_[i].speed_peek); ui->default_value_3->setValue(speed_data->variables_[i].default_speed); if (speed_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(speed_data->variables_[i].threshold); ui->doubleSpinBox_hysteresis_3->setValue(speed_data->variables_[i].hysteresis); ui->spinBox_events_per_revolution_3->setValue(speed_data->variables_[i].events_per_revolution); ui->comboBox_record_output_3->setCurrentIndex(speed_data->variables_[i].record_output); ui->checkBox_two_ma_clamp_3->setChecked(speed_data->variables_[i].two_ma_clamp); if (speed_data->variables_[i].alert_latching) { ui->radioButton_alert_latching_3->setCheckable(true); } else { ui->radioButton_alert_latching_3->setCheckable(false); } if (speed_data->variables_[i].overspeed_latching) { ui->radioButton_overspeed_latching_3->setCheckable(true); } else { ui->radioButton_overspeed_latching_3->setCheckable(false); } } else if (i + 1 == 4) { ui->checkBox_chan_4->setChecked(speed_data->variables_[i].active); ui->doubleSpinBox_high_4->setValue(speed_data->variables_[i].normal_voltage_high); ui->doubleSpinBox_low_4->setValue(speed_data->variables_[i].normal_voltage_low); ui->full_scale_range_4->setValue(speed_data->variables_[i].speed_peek); ui->default_value_4->setValue(speed_data->variables_[i].default_speed); if (speed_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(speed_data->variables_[i].threshold); ui->doubleSpinBox_hysteresis_4->setValue(speed_data->variables_[i].hysteresis); ui->spinBox_events_per_revolution_4->setValue(speed_data->variables_[i].events_per_revolution); ui->comboBox_record_output_4->setCurrentIndex(speed_data->variables_[i].record_output); ui->checkBox_two_ma_clamp_4->setChecked(speed_data->variables_[i].two_ma_clamp); if (speed_data->variables_[i].alert_latching) { ui->radioButton_alert_latching_4->setCheckable(true); } else { ui->radioButton_alert_latching_4->setCheckable(false); } if (speed_data->variables_[i].overspeed_latching) { ui->radioButton_overspeed_latching_4->setCheckable(true); } else { ui->radioButton_overspeed_latching_4->setCheckable(false); } } } } void Tachometer::on_pushButton_confirm_clicked() { std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); if (base_ptr == nullptr) { qCritical() << " should not be here"; return; } std::shared_ptr speed_data = std::dynamic_pointer_cast(base_ptr); UpdateData(speed_data); this->close(); } void Tachometer::on_pushButton_cancel_clicked() { this->close(); }