Skip to content

Commit

Permalink
Merge pull request #53 from Northeastern-Electric-Racing/#46-Update-C…
Browse files Browse the repository at this point in the history
…ontroller

#46-Update-Controller
  • Loading branch information
Peyton-McKee authored Feb 2, 2024
2 parents 693dc24 + 47e5b0d commit d86f63f
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
53 changes: 53 additions & 0 deletions NERODevelopment/src/controllers/offviewcontroller.cpp
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);
}
}
50 changes: 50 additions & 0 deletions NERODevelopment/src/controllers/offviewcontroller.h
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
10 changes: 10 additions & 0 deletions NERODevelopment/src/utils/attributestatus.h
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
10 changes: 10 additions & 0 deletions NERODevelopment/src/utils/data_type_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d86f63f

Please sign in to comment.