Skip to content

Commit

Permalink
push to banana
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno3634-gif committed Aug 22, 2024
1 parent 35724ae commit ab6fb33
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 39 deletions.
30 changes: 28 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
#include <QApplication>
#include <QLocale>
#include <QTranslator>
//static store* store_ref;
//void check_menu(int i);

//VoidsterdebugWindow debugWindow;
//PilotWindow pl;

int main(int argc, char *argv[]){

Expand All @@ -37,12 +41,16 @@ int main(int argc, char *argv[]){
break;
}
}



#ifdef __LART_T24__
#ifdef __LART_DEBUG__

// VoidsterdebugWindow debugWindow;

// debugWindow.show();
/* QObject::connect(store_ref,&store::menuChanged,[](int value){
check_menu(value);
});*/

PilotWindow pl;
pl.show();
Expand All @@ -66,3 +74,21 @@ int main(int argc, char *argv[]){
return a.exec();

}

/*void check_menu(int i)
{
switch (i) {
case 0:
pl.show();
debugWindow.hide();
break;
case 1:
pl.hide();
debugWindow.show();
break;
default:
break;
}
}
*/
29 changes: 24 additions & 5 deletions src/pilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ PilotWindow::PilotWindow(QWidget *parent, QString serialDev)
setWindowTitle("Pilotamos");


store_ref = new store(serialDev);


store_ref = new store(serialDev);
//store_ref->setParent(this);
//store_ref->requestSlotAttachment();

Expand Down Expand Up @@ -66,11 +67,11 @@ PilotWindow::PilotWindow(QWidget *parent, QString serialDev)


//connect(store_ref, &store::rpmChanged,SPEED_DISPLAY, (void (QLCDNumber::*)(short, short))&QLCDNumber::show;
connect(store_ref, &store::vehicleSpeedChanged, INVERTER_TEMP_DISPLAY, QOverload<int>::of(&QLCDNumber::display));
connect(store_ref, &store::inverterTemperatureChanged, INVERTER_TEMP_DISPLAY, QOverload<int>::of(&QLCDNumber::display));
INVERTER_TEMP_DISPLAY->show();


connect(store_ref, &store::vehicleSpeedChanged, MOTOR_TEMP_DISPLAY, QOverload<int>::of(&QLCDNumber::display));
connect(store_ref, &store::motorTemperatureChanged, MOTOR_TEMP_DISPLAY, QOverload<int>::of(&QLCDNumber::display));
MOTOR_TEMP_DISPLAY->show();

connect(store_ref, &store::vehicleSpeedChanged, ACUMULATOR_TEMP_DISPLAY, QOverload<int>::of(&QLCDNumber::display));
Expand All @@ -88,13 +89,14 @@ PilotWindow::PilotWindow(QWidget *parent, QString serialDev)
LV_SOC_BAR->setValue(soc);
});

connect(store_ref,&store::socChanged,[POWER_SOC_BAR](int soc){
POWER_SOC_BAR->setValue(soc);
connect(store_ref,&store::power_limitChanged,[POWER_SOC_BAR](int powerlimit){
POWER_SOC_BAR->setValue(powerlimit);
});

connect(store_ref,&store::socChanged,[CONSUMED_POWER_BAR](int soc){
CONSUMED_POWER_BAR->setValue(soc);
});
// QObject::connect(store_ref,&store::menuChanged,this,&PilotWindow::handleValueChanged);
}


Expand All @@ -114,7 +116,24 @@ store* PilotWindow::getStore(){
**/
PilotWindow::~PilotWindow(){
store_ref->~store();
//delete store_ref;
delete ui;
}


/*void PilotWindow::handleValueChanged(int newValue) {
// Close the current window
if(store_ref->getMenu() == 1)
{
delete store_ref;
VoidsterdebugWindow *debugWindow = new VoidsterdebugWindow();
this->close();
debugWindow->show();
}
}
*/
7 changes: 7 additions & 0 deletions src/pilot.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ class PilotWindow : public QMainWindow
private:

Ui::pilot *ui;

/*public slots:
void handleValueChanged(int newValue);
*/
};





#endif // PILOT_H
6 changes: 4 additions & 2 deletions src/references/bson_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
**/
#define BSON_RPM "rpm"
#define BSON_VEHICLESPEED "vel"
#define BSON_ENGINETEMPERATURE "eng_t"
#define BSON_MOTORTEMPERATURE "eng_t"
#define BSON_BATTERYVOLTAGE "bat_v"

#ifdef __LART_T14__
#define BSON_GEARSHIFT "gear"
#define BSON_OILPRESSURE "oil_p"
Expand All @@ -31,7 +32,8 @@
#define BSON_LAPCOUNT "lap_c"
#define BSON_LAPTIME "lap_t"
#define BSON_HV "hv"
#define BSON_PAGE "page"
#define BSON_MENU "menu"
#define BSON_POWER_LIMIT "power_available"
#endif


Expand Down
142 changes: 120 additions & 22 deletions src/store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
#include "mainwindow.h"
#include "references/bson_var.h"
#include "flabel.h"


#include "pilot.h"
#include "voidsterdebugwindow.h"
#include "qdebug.h"
//VoidsterdebugWindow debugWindow;
//PilotWindow pl;
using json = nlohmann::json;
/**
* @brief Arguably the boilerplate code, necessary to run an Asynchronous Serial Uart communication. Also responsible for handling @b slots and other callback logic
* @see https://doc.qt.io/qt-5/qtserialport-creaderasync-example.html
* wow the above was suggested by copilot. how many times did people have issues with this?
**/
int store::setupSerial() {
QSerialPort* serial= new QSerialPort();

QSerialPort* serial= new QSerialPort();
serial->setPortName(this->dev);
serial->setBaudRate(this->baud);
serial->setDataBits(QSerialPort::Data8);
Expand Down Expand Up @@ -155,7 +158,12 @@ store::store( QString dev, QSerialPort::BaudRate baud, QObject *parent): QObject
}else{
this->dev = dev;
}
setupSerial();
// if(store::initialized){
setupSerial();
// }
// store::initialized = true;


//int8_t retries = LOG_MAX_RETRIES;
//TODO wtf? retry system
startGeneralErrorLog();
Expand Down Expand Up @@ -284,9 +292,9 @@ void store::parseBson(std::vector<std::uint8_t> v){
this->setRpm(j[BSON_RPM]);
}

if(j.contains(BSON_ENGINETEMPERATURE)){
/*if(j.contains(BSON_ENGINETEMPERATURE)){
this->setEngineTemperature(j[BSON_ENGINETEMPERATURE]);
}
}*/

if(j.contains(BSON_BATTERYVOLTAGE)){
EncodingUnion t;
Expand Down Expand Up @@ -328,19 +336,59 @@ void store::parseBson(std::vector<std::uint8_t> v){
}
#endif
#ifdef __LART_T24__
if(j.contains(BSON_SOC)){
EncodingUnion t;
t.encoded=j[BSON_SOC];
this->setSoc(t.decoded);
}
if(j.contains(BSON_MENU))
{
int t;
t =j[BSON_MENU];
this->setMenu(t);
if(m_menu != t)
{
//store::closeSerial();
//VoidsterdebugWindow debugWindow;
//PilotWindow pl;
// VoidsterdebugWindow debugWindow = new VoidsterdebugWindow();
//PilotWindow pl = new PilotWindow();
switch(t)
{
case 0:
//pl.show();

break;
case 1:
// debugWindow.show();
//QMessageBox::information(nullptr, "Menu 0", "Menu 0 has been selected.");
break;
default:
break;
}
}
}
if(j.contains(BSON_SOC)){
EncodingUnion t;
t.encoded=j[BSON_SOC];
this->setSoc(t.decoded);
}
if(j.contains(BSON_MOTORTEMPERATURE)){
// EncodingUnion t;
// t.encoded=j[BSON_MOTORTEMPERATURE];
// this->setmotorTemperature(t.decoded);
this->setmotorTemperature(j[BSON_MOTORTEMPERATURE]);
}
if(j.contains(BSON_POWER_LIMIT)){
EncodingUnion t;
t.encoded=j[BSON_POWER_LIMIT];
this->setPowerLimit(t.decoded);
qDebug()<< t.decoded;
}

if(j.contains(BSON_BATTERYTEMPERATURE)){
EncodingUnion t;
t.encoded=j[BSON_BATTERYTEMPERATURE];
this->setBatteryTemperature(t.decoded);
}
if(j.contains(BSON_INVERTERTEMPERATURE)){
this->setInverterTemperature(j[BSON_INVERTERTEMPERATURE]);
int temp = j[BSON_INVERTERTEMPERATURE];
this->setInverterTemperature(temp);
}
if(j.contains(BSON_POWER)){
short temp = j[BSON_POWER];
Expand Down Expand Up @@ -399,13 +447,25 @@ int store::closeSerial(){
}
return 0;
}

/**
* @brief getter for the rpm variable
* @return The rpm variable
**/
int store::getRpm() const{
return this->m_rotationsPerMinute;
}


void store::updateValue(int newValue) {
if (m_menu != newValue) {
m_menu = newValue;
emit valueChanged(m_menu); // Emitir o sinal de mudança
}
}



/**
* @brief setter for the rpm variable
* @param rpm The new value for the rpm variable
Expand Down Expand Up @@ -641,8 +701,19 @@ void store::setTcLaunch(int tcLaunch){
* @return The state of charge variable
**/
float store::getSoc() const{
return this->m_stateOfCharge;
return this->m_stateOfCharge;
}


/**
* @brief getter for the state of charge variable
* @return The state of charge variable
**/
float store::getPowerLimit() const{
return this->m_power_limit;
}


/**
* @brief getter for the battery temperature variable
* @return The battery temperature variable
Expand All @@ -655,14 +726,18 @@ float store::getBatteryTemperature() const{
* @return The inverter temperature variable
**/
int store::getInverterTemperature() const{
return this->m_inverterTemperature;
return this->m_inverterTemperature;
}

int store::getmotorTemperature() const{
return this->m_motorTemperature;
}
/**
* @brief getter for the power variable
* @return The power variable
**/
short store::getPower() const{
return this->m_power;
return this->m_power_limit;
}
/**
* @brief getter for the lap time @b Double-Word Integer variable,
Expand Down Expand Up @@ -698,10 +773,25 @@ short store::getHV() const{
* @param soc The new value for the state of charge variable
**/
void store::setSoc(float soc){
float oldSoc = this->m_stateOfCharge;
this->m_stateOfCharge=soc;
emit socChanged(this->m_stateOfCharge, oldSoc);
float oldSoc = this->m_stateOfCharge;
this->m_stateOfCharge=soc;
emit socChanged(this->m_stateOfCharge, oldSoc);
}




/**
* @brief setter for the power limit
* @param power limit The new value for the state of charge variable
**/
void store::setPowerLimit(float powerl){
float oldlimit = this->m_power_limit;
this->m_power_limit=powerl;
emit power_limitChanged(this->m_power_limit, oldlimit);
}


/**
* @brief setter for the battery temperature variable
* @param batteryTemperature The new value for the battery temperature variable
Expand All @@ -716,9 +806,17 @@ void store::setBatteryTemperature(float batteryTemperature){
* @param inverterTemperature The new value for the inverter temperature variable
**/
void store::setInverterTemperature(int inverterTemperature){
int oldInverterTemperature = this->m_inverterTemperature;
this->m_inverterTemperature=inverterTemperature;
emit inverterTemperatureChanged(this->m_inverterTemperature, oldInverterTemperature);
int oldInverterTemperature = this->m_inverterTemperature;
this->m_inverterTemperature=inverterTemperature;
emit inverterTemperatureChanged(this->m_inverterTemperature, oldInverterTemperature);
}


void store::setmotorTemperature(int motorTemperature){
int oldmotorTemperature = this->m_motorTemperature;
this->m_motorTemperature=motorTemperature;
emit motorTemperatureChanged(this->m_motorTemperature, oldmotorTemperature);
qDebug()<<motorTemperature;
}
/**
* @brief setter for the power variable
Expand Down
Loading

0 comments on commit ab6fb33

Please sign in to comment.