diff options
author | Joshua Drake <joshua.drake@ditchwitch.com> | 2022-11-21 16:34:17 -0600 |
---|---|---|
committer | Joshua Drake <joshua.drake@ditchwitch.com> | 2022-11-21 16:34:17 -0600 |
commit | 179ed918aed1c9f190ae6846ea4bcccccbeab18f (patch) | |
tree | 1fabd0bbc20e102097eeecf18e2238f121629d0f /mainwindow.cpp | |
parent | 341e61f7a6f9deebf086a2b8147e252be6d45f33 (diff) |
Added Pre-Charge functionality and made thing prettier.
Diffstat (limited to 'mainwindow.cpp')
-rw-r--r-- | mainwindow.cpp | 233 |
1 files changed, 232 insertions, 1 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp index 62702cd..8559778 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,6 +6,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { + /*TODO fix crash after changing Voltage!!!! */ ui->setupUi(this); initializeGraphics(); @@ -19,6 +20,146 @@ MainWindow::MainWindow(QWidget *parent) ui->lineEditVoltageRange->setText(QString::number(m_battery.minimumPackVoltage())+" - "+QString::number(m_battery.maximumPackVoltage())); ui->lineEditPeakCurrent->setText(QString::number(m_battery.peakCurrent())); }); + + connect(&m_generator,&Generator::calculation, [&]() { + ui->lineEditGeneratorKV->setText(QString::number(m_generator.generatorKV())); + }); + + connect(&m_precharge,&Precharge::calculation, [&]() { + ui->lineEditMaximumPrechargeResistance->setText(QString::number(m_precharge.maximumResistance())); + ui->lineEditActualPreChargeTime->setText(QString::number(m_precharge.actualPreChargeTime())); + ui->lineEditPeakInRushCurrent->setText(QString::number(m_precharge.peakInRushCurrent())); + ui->lineEditAveragePreChargePower->setText(QString::number(m_precharge.averagePower())); + }); + + connect(ui->doubleSpinBoxPreChargePercentageDesired,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { + ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);"); + + }); + + connect(ui->doubleSpinBoxSystemCapacitance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { + ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);"); + + }); + + connect(ui->doubleSpinBoxPreChargeTime,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { + ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);"); + + }); + + connect(ui->doubleSpinBoxChosenResistance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { + ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);"); + + }); } MainWindow::~MainWindow() @@ -65,6 +206,8 @@ void MainWindow::on_doubleSpinBoxSystemVoltage_valueChanged(double arg1) //m_wire.calculate(); m_battery.setSystemVoltage(arg1); m_battery.calculate(); + m_generator.setSystemVoltage(arg1); + m_generator.calculate(); } @@ -77,7 +220,95 @@ void MainWindow::on_doubleSpinBoxEstimatedWireLength_valueChanged(double arg1) void MainWindow::on_lineEditVoltageRange_textChanged(const QString &arg1) { - m_wire.setSystemVoltage((arg1.split(" -")[0]).toDouble()); + double min = arg1.split(" - ")[0].toDouble(); + double max = arg1.split(" - ")[1].toDouble(); + + m_wire.setSystemVoltage(min); m_wire.calculate(); + + m_precharge.setMaximumVoltage(max); + m_precharge.calculate(); +} + + +void MainWindow::on_doubleSpinBoxMinimumAllowableSOC_valueChanged(double arg1) +{ + m_battery.setMinimumSOC(arg1); + m_battery.calculate(); + if (arg1 > 0) + { + ui->doubleSpinBoxMinimumAllowableSOC->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->labelMinimumAllowableSOC->setStyleSheet("color: rgb(0, 0, 0);"); + } + else + { + ui->doubleSpinBoxMinimumAllowableSOC->setStyleSheet("background-color: rgba(255, 255, 255, 80);" + "color: rgba(0, 0, 0, 80);"); + ui->labelMinimumAllowableSOC->setStyleSheet("color: rgba(0, 0, 0, 120);"); + } +} + + +void MainWindow::on_doubleSpinBoxGeneratorRPM_valueChanged(double arg1) +{ + m_generator.setRPM(arg1); + m_generator.calculate(); + if (arg1 > 0) + { + ui->doubleSpinBoxGeneratorRPM->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->labelGeneratorRPM->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->lineEditGeneratorKV->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->labelGeneratorKV->setStyleSheet("color: rgb(0, 0, 0);"); + } + else + { + ui->doubleSpinBoxGeneratorRPM->setStyleSheet("background-color: rgba(255, 255, 255, 80);" + "color: rgba(0, 0, 0, 80);"); + ui->labelGeneratorRPM->setStyleSheet("color: rgba(0, 0, 0, 120);"); + + ui->lineEditGeneratorKV->setStyleSheet("background-color: rgba(255, 255, 255, 80);" + "color: rgba(0, 0, 0, 80);"); + ui->labelGeneratorKV->setStyleSheet("color: rgba(0, 0, 0, 120);"); + ui->lineEditGeneratorKV->setText("--"); + } +} + + +void MainWindow::on_doubleSpinBoxPreChargeTime_valueChanged(double arg1) +{ + m_precharge.setPreChargeTime(arg1); + m_precharge.calculate(); +} + + +void MainWindow::on_doubleSpinBoxSystemCapacitance_valueChanged(double arg1) +{ + m_precharge.setSystemCapacitance(arg1); + m_precharge.calculate(); +} + + +void MainWindow::on_doubleSpinBoxPreChargePercentageDesired_valueChanged(double arg1) +{ + m_precharge.setPreChargePercentage(arg1); + m_precharge.calculate(); +} + + +void MainWindow::on_doubleSpinBoxChosenResistance_valueChanged(double arg1) +{ + m_precharge.setChosenResistance(arg1); + m_precharge.calculate(); +} + + +void MainWindow::on_lineEditMaximumPrechargeResistance_textChanged(const QString &arg1) +{ + ui->doubleSpinBoxChosenResistance->setMaximum(arg1.toDouble()); + if(ui->doubleSpinBoxChosenResistance->value() > arg1.toDouble()) ui->doubleSpinBoxChosenResistance->setValue(arg1.toDouble()); } |