Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#36 refactor to mqtt #39

Merged
merged 10 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions NERODevelopment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,46 @@ project(NEROApp LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)

find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick)

if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3)
if (Qt6_VERSION VERSION_GREATER_EQUAL 6.5)
qt_standard_project_setup()
endif()

set(PROJECT_SOURCES
src/controllers/chargingcontroller.h
src/constants/fault_statuses.h

src/controllers/chargingcontroller.h
src/controllers/homecontroller.h
src/controllers/efficiencycontroller.h

src/models/mock_model.h
src/models/model.h
src/models/raspberry_model.h
src/models/mqtt_client.h

src/modes/debug_mode/debug_utils.h
src/views/thermometercomponent.h

src/utils/data_type_names.h
src/utils/server_data.h

src/controllers/efficiencycontroller.cpp
src/controllers/chargingcontroller.cpp
src/controllers/homecontroller.cpp
src/main.cpp

src/models/mock_model.cpp
src/models/model.cpp
src/models/raspberry_model.cpp
src/models/mqtt_client.cpp


src/modes/debug_mode/debug_utils.cpp
src/views/thermometercomponent.cpp)

src/utils/server_data.cpp

src/main.cpp
)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick Network Mqtt)

qt_add_executable(NEROApp ${PROJECT_SOURCES})

Expand All @@ -42,12 +57,15 @@ qt_add_resources(NEROApp "configuration"
)

target_include_directories(${PROJECT_NAME} PUBLIC include)
include_directories("src/models")
include_directories("src/**")


target_link_libraries(NEROApp PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Qml
Qt6::Network
Qt6::Mqtt
Qt6::Quick
)

Expand Down
20 changes: 8 additions & 12 deletions NERODevelopment/content/Pit.qml
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import HomeController 1.0
import NERO

Item {
id: pit

HomeController {
id: controller
}

width: 800
height: 480
property int stateOfChargePercentage: controller.stateOfCharge()
property int packTempValue: controller.packTemp()
property int motorTempValue: controller.motorTemp()
property int currentSpeed: controller.speed()
property bool forward: controller.status()
width: parent.width
height: parent.height
property int stateOfChargePercentage: homeController.stateOfCharge
property int packTempValue: homeController.packTemp
property int motorTempValue: homeController.motorTemp
property int currentSpeed: homeController.speed
property bool forward: homeController.status

property int maxSpeed: 5
property int horizontalMargin: 10
Expand Down
4 changes: 2 additions & 2 deletions NERODevelopment/content/Spedometer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ Item {
Canvas {
id: ring
x: shape.x
y: shape.y
y: shape.y - gauge.verticalPadding + (gauge.verticalPadding / 10)
width: parent.width
height: parent.height
antialiasing: true

property real centerX: ring.width / 2
property real centerY: ring.height - gauge.verticalPadding + (gauge.verticalPadding / 10)
property real centerY: ring.height
property real borderWidth: gauge.outerStrokeWidth
property real ringRadius: (ring.width - gauge.horizontalPadding * 2) / 2
property real pi: Math.PI
Expand Down
107 changes: 29 additions & 78 deletions NERODevelopment/src/controllers/chargingcontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,159 +1,110 @@
#include "chargingcontroller.h"

ChargingController::ChargingController(QObject *parent)
: QObject{parent}
, m_charge(0)
, m_burning(false)
, m_maxCellVoltage(0)
, m_maxCellVoltageChipNumber(0)
, m_maxCellVoltageCellNumber(0)
, m_minCellVoltage(0)
, m_minCellVoltageChipNumber(0)
, m_minCellVoltageCellNumber(0)
, m_cellDelta(0)
, m_packVoltage(0)
, m_current(0)
, m_packTemp(0)
{}
: QObject{parent}, m_charge(0), m_burning(false), m_maxCellVoltage(0),
m_maxCellVoltageChipNumber(0), m_maxCellVoltageCellNumber(0),
m_minCellVoltage(0), m_minCellVoltageChipNumber(0),
m_minCellVoltageCellNumber(0), m_cellDelta(0), m_packVoltage(0),
m_current(0), m_packTemp(0) {}

int ChargingController::charge() const
{
return m_charge;
}
void ChargingController::setCharge(int charge)
{
int ChargingController::charge() const { return m_charge; }
void ChargingController::setCharge(int charge) {
if (charge != m_charge) {
m_charge = charge;
emit chargeChanged(charge);
}
}

bool ChargingController::burning() const
{
return m_burning;
}
void ChargingController::setBurning(bool burning)
{
bool ChargingController::burning() const { return m_burning; }
void ChargingController::setBurning(bool burning) {
if (burning != m_burning) {
m_burning = burning;
emit burningChanged(burning);
}
}

int ChargingController::maxCellVoltage() const
{
return m_maxCellVoltage;
}
void ChargingController::setMaxCellVoltage(int volts)
{
int ChargingController::maxCellVoltage() const { return m_maxCellVoltage; }
void ChargingController::setMaxCellVoltage(int volts) {
if (volts != m_maxCellVoltage) {
m_maxCellVoltage = volts;
emit maxCellVoltageChanged(volts);
}
}

int ChargingController::maxCellVoltageChipNumber() const
{
int ChargingController::maxCellVoltageChipNumber() const {
return m_maxCellVoltageChipNumber;
}
void ChargingController::setMaxCellVoltageChipNumber(int num)
{
void ChargingController::setMaxCellVoltageChipNumber(int num) {
if (num != m_maxCellVoltageChipNumber) {
m_maxCellVoltageChipNumber = num;
emit maxCellVoltageChipNumberChanged(num);
}
}

int ChargingController::maxCellVoltageCellNumber() const
{
int ChargingController::maxCellVoltageCellNumber() const {
return m_maxCellVoltageCellNumber;
}
void ChargingController::setMaxCellVoltageCellNumber(int num)
{
void ChargingController::setMaxCellVoltageCellNumber(int num) {
if (num != m_maxCellVoltageCellNumber) {
m_maxCellVoltageCellNumber = num;
emit maxCellVoltageCellNumberChanged(num);
}
}

int ChargingController::minCellVoltage() const
{
return m_minCellVoltage;
}
void ChargingController::setMinCellVoltage(int volts)
{
int ChargingController::minCellVoltage() const { return m_minCellVoltage; }
void ChargingController::setMinCellVoltage(int volts) {
if (volts != m_minCellVoltage) {
m_minCellVoltage = volts;
emit minCellVoltageChanged(volts);
}
}

int ChargingController::minCellVoltageChipNumber() const
{
int ChargingController::minCellVoltageChipNumber() const {
return m_minCellVoltageChipNumber;
}
void ChargingController::setMinCellVoltageChipNumber(int num)
{
void ChargingController::setMinCellVoltageChipNumber(int num) {
if (num != m_minCellVoltageChipNumber) {
m_minCellVoltageChipNumber = num;
emit minCellVoltageChipNumberChanged(num);
}
}

int ChargingController::minCellVoltageCellNumber() const
{
int ChargingController::minCellVoltageCellNumber() const {
return m_minCellVoltageCellNumber;
}
void ChargingController::setMinCellVoltageCellNumber(int num)
{
void ChargingController::setMinCellVoltageCellNumber(int num) {
if (num != m_minCellVoltageCellNumber) {
m_minCellVoltageCellNumber = num;
emit minCellVoltageCellNumberChanged(num);
}
}

int ChargingController::cellDelta() const
{
return m_cellDelta;
}
void ChargingController::setCellDelta(int volts)
{
int ChargingController::cellDelta() const { return m_cellDelta; }
void ChargingController::setCellDelta(int volts) {
if (volts != m_cellDelta) {
m_cellDelta = volts;
emit cellDeltaChanged(volts);
}
}

int ChargingController::packVoltage() const
{
return m_packVoltage;
}
void ChargingController::setPackVoltage(int volts)
{
int ChargingController::packVoltage() const { return m_packVoltage; }
void ChargingController::setPackVoltage(int volts) {
if (volts != m_packVoltage) {
m_packVoltage = volts;
emit packVoltageChanged(volts);
}
}

int ChargingController::current() const
{
return m_current;
}
void ChargingController::setCurrent(int amps)
{
int ChargingController::current() const { return m_current; }
void ChargingController::setCurrent(int amps) {
if (amps != m_current) {
m_current = amps;
emit currentChanged(amps);
}
}

int ChargingController::packTemp() const
{
return m_packTemp;
}
void ChargingController::setPackTemp(int degrees)
{
int ChargingController::packTemp() const { return m_packTemp; }
void ChargingController::setPackTemp(int degrees) {
if (degrees != m_packTemp) {
m_packTemp = degrees;
emit packTempChanged(degrees);
Expand Down
4 changes: 4 additions & 0 deletions NERODevelopment/src/controllers/chargingcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include <QObject>

/**
* @brief The ChargingController class
* Controller for the Charging Screen.
*/
class ChargingController : public QObject {
Q_OBJECT
Q_PROPERTY(int charge READ charge WRITE setCharge NOTIFY chargeChanged FINAL)
Expand Down
4 changes: 4 additions & 0 deletions NERODevelopment/src/controllers/efficiencycontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include <QObject>

/**
* @brief The EfficiencyController class
* Controller for the efficiency view
*/
class EfficiencyController : public QObject {
Q_OBJECT
Q_PROPERTY(int currentMaxTorque READ currentMaxTorque WRITE
Expand Down
17 changes: 15 additions & 2 deletions NERODevelopment/src/controllers/homecontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "homecontroller.h"

HomeController::HomeController(QObject *parent)
HomeController::HomeController(Model *model, QObject *parent)
: QObject{parent}, m_speed(0), m_status(false), m_direction(true),
m_packTemp(0.0), m_motorTemp(0.0), m_stateOfCharge(0.0) {}
m_packTemp(0.0), m_motorTemp(0.0), m_stateOfCharge(0.0) {
this->m_model = model;
connect(m_model, &Model::onCurrentDataChange, this,
&HomeController::currentDataDidChange);
}

int HomeController::speed() const { return m_speed; }

Expand Down Expand Up @@ -57,3 +61,12 @@ void HomeController::setStateOfCharge(float stateOfCharge) {
emit stateOfChargeChanged(stateOfCharge);
}
}

void HomeController::currentDataDidChange() {
setPackTemp(*m_model->getPackTemp());
setMotorTemp(*m_model->getMotorTemp());
setDirection(*m_model->getDir());
setStateOfCharge(*m_model->getStateOfCharge());
setSpeed(*m_model->getMph());
setStatus(*m_model->getStatus());
}
9 changes: 8 additions & 1 deletion NERODevelopment/src/controllers/homecontroller.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#ifndef HOMECONTROLLER_H
#define HOMECONTROLLER_H

#include "../models/model.h"
#include <QObject>

/**
* @brief The HomeController class
* Controller for the home screen, aka pit and reverse.
*/
class HomeController : public QObject {
Q_OBJECT
Q_PROPERTY(int speed READ speed WRITE setSpeed NOTIFY speedChanged FINAL)
Expand All @@ -17,7 +22,7 @@ class HomeController : public QObject {
NOTIFY stateOfChargeChanged FINAL)

public:
explicit HomeController(QObject *parent = nullptr);
explicit HomeController(Model *model, QObject *parent = nullptr);
int speed() const;
bool status() const;
bool direction() const;
Expand All @@ -40,8 +45,10 @@ public slots:
void setPackTemp(float);
void setMotorTemp(float);
void setStateOfCharge(float);
void currentDataDidChange();

private:
Model *m_model;
int m_speed;
bool m_status;
bool m_direction;
Expand Down
Loading