diff --git a/NERODevelopment/src/controllers/offviewcontroller.cpp b/NERODevelopment/src/controllers/offviewcontroller.cpp new file mode 100644 index 0000000..2fe8a1c --- /dev/null +++ b/NERODevelopment/src/controllers/offviewcontroller.cpp @@ -0,0 +1,53 @@ +#include "offviewcontroller.h" + +OffViewController::OffViewController(Model *model, QObject *parent) + : QObject{parent}, m_packTemp(0.0), m_motorTemp(0.0), m_stateOfCharge(0.0) { + this->m_model = model; + connect(m_model, &Model::onCurrentDataChange, this, + &OffViewController::currentDataDidChange); +} + +QMap OffViewController::getAttributeStatus() const { return m_attributeStatus; } +void OffViewController::setAttributeStatus(const QString &name, AttributeStatus status) +{ + if (m_attributeStatus.value(name) != status) + { + m_attributeStatus[name] = status; + emit attributeStatusChanged(m_attributeStatus); + } +} + +void OffViewController::updateAttributesFromModel() { + const auto attributeStatusMap = m_model->getAttributeStatus(); + for (const auto& attributeName : {SIDEBRBS, BMS, BSPD, MPU, BOTS, INERTIA, CPBRB, TSMS, HVDINTRLK, HVCNCTR}) { + AttributeStatus status = attributeStatusMap.value(attributeName); + setAttributeStatus(attributeName, status); + } + setPackTemp(*m_model->getPackTemp()); + setMotorTemp(*m_model->getMotorTemp()); + setStateOfCharge(*m_model->getStateOfCharge()); +} + +float OffViewController::packTemp() const { return m_packTemp; } +void OffViewController::setPackTemp(float degrees) { + if (degrees != m_packTemp) { + m_packTemp = degrees; + emit packTempChanged(degrees); + } +} + +float OffViewController::motorTemp() const { return m_motorTemp; } +void OffViewController::setMotorTemp(float temp) { + if (temp != m_motorTemp) { + m_motorTemp = temp; + emit motorTempChanged(temp); + } +} + +float OffViewController::stateOfCharge() const { return m_stateOfCharge; } +void OffViewController::setStateOfCharge(float charge) { + if (charge != m_stateOfCharge) { + m_stateOfCharge = charge; + emit stateOfChargeChanged(charge); + } +} diff --git a/NERODevelopment/src/controllers/offviewcontroller.h b/NERODevelopment/src/controllers/offviewcontroller.h new file mode 100644 index 0000000..2f9f67c --- /dev/null +++ b/NERODevelopment/src/controllers/offviewcontroller.h @@ -0,0 +1,50 @@ +#ifndef OFFVIEWCONTROLLER_H +#define OFFVIEWCONTROLLER_H + +#include +#include +#include +#include "../models/model.h" +#include "../utils/data_type_names.h" +#include "../utils/attributestatus.h" + +class OffViewController : public QObject { + Q_OBJECT + Q_PROPERTY(QMap attributeStatus READ getAttributeStatus NOTIFY attributeStatusChanged) + Q_PROPERTY( + float packTemp READ packTemp WRITE setPackTemp NOTIFY packTempChanged FINAL) + Q_PROPERTY(float motorTemp READ motorTemp WRITE setMotorTemp NOTIFY + motorTempChanged FINAL) + Q_PROPERTY(float stateOfCharge READ stateOfCharge WRITE setStateOfCharge NOTIFY + stateOfChargeChanged FINAL) + +public: + explicit OffViewController(Model *model, QObject *parent = nullptr); + + QMap getAttributeStatus() const; + float packTemp() const; + float motorTemp() const; + float stateOfCharge() const; + void updateAttributesFromModel(); + +signals: + void attributeStatusChanged(const QMap &attributeStatus); + void packTempChanged(float); + void motorTempChanged(float); + void stateOfChargeChanged(float); + +public slots: + void setAttributeStatus(const QString &name, AttributeStatus status); + void setPackTemp(float); + void setMotorTemp(float); + void setStateOfCharge(float); + +private: + Model *m_model; + QMap m_attributeStatus; + float m_packTemp; + float m_motorTemp; + float m_stateOfCharge; +}; + +#endif // OFFVIEWCONTROLLER_H diff --git a/NERODevelopment/src/utils/attributestatus.h b/NERODevelopment/src/utils/attributestatus.h new file mode 100644 index 0000000..855b965 --- /dev/null +++ b/NERODevelopment/src/utils/attributestatus.h @@ -0,0 +1,10 @@ +#ifndef ATTRIBUTESTATUS_H +#define ATTRIBUTESTATUS_H + +enum class AttributeStatus : int { + GOOD = 0, + FAULTED = 1, + OFF = 2 +}; + +#endif // ATTRIBUTESTATUS_H diff --git a/NERODevelopment/src/utils/data_type_names.h b/NERODevelopment/src/utils/data_type_names.h index 95ae6d5..d604833 100644 --- a/NERODevelopment/src/utils/data_type_names.h +++ b/NERODevelopment/src/utils/data_type_names.h @@ -52,5 +52,15 @@ #define SEGMENTTEMP3 "segmenttemp3" #define SEGMENTTEMP4 "segmenttemp4" #define TORQUEPOWER "torquepower" +#define SIDEBRBS "SIDEBRBS" +#define BMS "BMS" +#define BSPD "BSPD" +#define MPU "MPU" +#define BOTS "BOTS" +#define INERTIA "INERTIA" +#define CPBRB "CP BRB" +#define TSMS "TSMS" +#define HVDINTRLK "HVD INTRLK" +#define HVCNCTR "HV CNCTR" #endif // DATATYPENAMES_H