/*
    Original copyright 2018 Benjamin Vedder benjamin@vedder.se and the VESC Tool project ( https://github.com/vedderb/vesc_tool )

    Forked to:
    Copyright 2018 Danny Bokma github@diebie.nl (https://github.com/DieBieEngineering/DieBieMS-Tool)

    Now forked to:
    Copyright 2019 - 2020 Kevin Dionne kevin.dionne@ennoid.me (https://github.com/EnnoidMe/ENNOID-BMS-Tool)

    This file is part of ENNOID-BMS Tool.

    ENNOID-BMS Tool is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ENNOID-BMS Tool is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "pagemastersettings.h"
#include "ui_pagemastersettings.h"

PageMasterSettings::PageMasterSettings(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageMasterSettings)
{
    ui->setupUi(this);
    layout()->setContentsMargins(0, 0, 0, 0);
    mDieBieMS = 0;
}

PageMasterSettings::~PageMasterSettings()
{
    delete ui;
}

BMSInterface *PageMasterSettings::bms() const
{
    return mDieBieMS;
}

void PageMasterSettings::setDieBieMS(BMSInterface *dieBieMS)
{
    mDieBieMS = dieBieMS;

    if (mDieBieMS) {
#if 0
        ConfigParam *p = mDieBieMS->infoConfig()->getParam("master_setting_description");
        if (p != 0) {
            ui->textEdit->setHtml(p->description);
        } else {
            ui->textEdit->setText("Master Setting Description not found.");
        }
#endif
        ConfigParams *const conf = mDieBieMS->bmsConfig();
        ParamTable *const pt = ui->masterStateTab;
        pt->addRowSeparator(tr("Current"));
        pt->addParamRow(conf, "shuntLCFactor");
        pt->addParamRow(conf, "shuntOffset");

        pt->addRowSeparator(tr("Pack configuration"));
#if 0  // disable
        pt->addParamRow(conf, "cellMonitorICType");
#endif
        pt->addParamRow(conf, "cellMonitorICCount");
        pt->addParamRow(conf, "noOfParallelModules");
        pt->addParamRow(conf, "noOfCellsSeries");

        pt->addRowSeparator(tr("SOC - Pack capacity"));
        pt->addParamRow(conf, "noOfCellsParallel");
        pt->addParamRow(conf, "batteryCapacity");

        pt->addRowSeparator(tr("Cell specifications"));
        pt->addParamRow(conf, "cellHardUnderVoltage");
        pt->addParamRow(conf, "cellHardOverVoltage");
        pt->addParamRow(conf, "cellLCSoftUnderVoltage");
        pt->addParamRow(conf, "cellSoftOverVoltage");

        pt->addRowSeparator(tr("Balancing configuration"));
        pt->addParamRow(conf, "cellBalanceStart");
        pt->addParamRow(conf, "cellBalanceDifferenceThreshold");
        pt->addParamRow(conf, "cellBalanceUpdateInterval");

        pt->addRowSeparator(tr("SoC general"));
#if 0 // disable
        pt->addParamRow(conf, "stateOfChargeStoreInterval");
        pt->addParamRow(conf, "timeoutChargeCompleted");
        pt->addParamRow(conf, "timeoutChargingCompletedMinimalMismatch");
#endif
        pt->addParamRow(conf, "minimalPrechargePercentage"); // from pagemastersettings.cpp
        pt->addParamRow(conf, "timeoutLCPreCharge"); // from pagemastersettings.cpp

        pt->addRowSeparator(tr("Limits"));
        pt->addParamRow(conf, "maxMismatchThreshold");
        pt->addParamRow(conf, "maxAllowedCurrent");
#if 0
        pt->addParamRow(conf, "allowedTempBattDischargingMax");
        pt->addParamRow(conf, "allowedTempBattDischargingMin");
#endif
        pt->addParamRow(conf, "allowedTempBattChargingMax");
        pt->addParamRow(conf, "allowedTempBattChargingMin");

#if 0 // disable
        pt->addRowSeparator(tr("NTC specifications battery"));
        pt->addParamRow(mDieBieMS->bmsConfig(), "noOfTempSensorPerModule");
        pt->addParamRow(mDieBieMS->bmsConfig(), "NTCLTC25Deg");
        pt->addRowSeparator(tr("NTC specifications expansion Board"));
        pt->addParamRow(mDieBieMS->bmsConfig(), "noOfExpansionBoard");
        pt->addParamRow(mDieBieMS->bmsConfig(), "noOfTempSensorPerExpansionBoard");
#endif
    }
}
