-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ontroller #46-Update-Controller
- Loading branch information
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<QString, AttributeStatus> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef OFFVIEWCONTROLLER_H | ||
#define OFFVIEWCONTROLLER_H | ||
|
||
#include <QObject> | ||
#include <QMap> | ||
#include <QString> | ||
#include "../models/model.h" | ||
#include "../utils/data_type_names.h" | ||
#include "../utils/attributestatus.h" | ||
|
||
class OffViewController : public QObject { | ||
Q_OBJECT | ||
Q_PROPERTY(QMap<QString, AttributeStatus> 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<QString, AttributeStatus> getAttributeStatus() const; | ||
float packTemp() const; | ||
float motorTemp() const; | ||
float stateOfCharge() const; | ||
void updateAttributesFromModel(); | ||
|
||
signals: | ||
void attributeStatusChanged(const QMap<QString, AttributeStatus> &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<QString, AttributeStatus> m_attributeStatus; | ||
float m_packTemp; | ||
float m_motorTemp; | ||
float m_stateOfCharge; | ||
}; | ||
|
||
#endif // OFFVIEWCONTROLLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef ATTRIBUTESTATUS_H | ||
#define ATTRIBUTESTATUS_H | ||
|
||
enum class AttributeStatus : int { | ||
GOOD = 0, | ||
FAULTED = 1, | ||
OFF = 2 | ||
}; | ||
|
||
#endif // ATTRIBUTESTATUS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters