Skip to content

Commit

Permalink
added_stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Imeguras committed Jul 18, 2024
1 parent 3a7e61e commit 1d8c282
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 47 deletions.
1 change: 1 addition & 0 deletions src/contarotacoes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void ContaRotacoes::handleChangedValue(int newValue, int oldValue){
(void)oldValue;
// value< m_maxValue || this should be in the if for better data quality but in case of a ill fate, it might be interesting to see the values
if( newValue >= 0){

this->m_value = newValue;
this->update();
}
Expand Down
24 changes: 23 additions & 1 deletion src/flabel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
+ @file flabel.cpp
* @brief This file contains all the logic that customizes the behaviour of most Text Labels on screen.
* @see flabel.h
Expand All @@ -22,7 +22,29 @@ void FLabel::setVisual(QString newValue, QString oldValue=""){
(void)oldValue;
this->setText(newValue);
}
/**
* @brief TODO
**/
void FLabel::setAveragedVisualChangeSec(float newValue, float oldValue){
this->_counts++;
_alpha = (float)((this->_counts * newValue) + (1.0 - this->_counts) * oldValue);
float truenewvalue = (float)((float)(_alpha/_counts));
auto rateOfChange = (truenewvalue-oldValue)/oldValue * 100;
this->setText(QString::number(truenewvalue)+" / "+QString::number(newValue)+ " W"+" ("+QString::number(rateOfChange)+"%)");
}

void FLabel::setAveragedVisualChangeSec(short newValue, short oldValue){
this->_counts++;
this->_alpha = (float)( (this->_counts * newValue) + (1.0 - this->_counts) * _alpha);
short truenewvalue = ((short)(_alpha/_counts));
short rateOfChange =100;
if(oldValue!=0){
rateOfChange = ((short)((truenewvalue-oldValue)/oldValue)) * 100;
}

//TODO URGENT fix units
this->setText(QString::number(truenewvalue)+" / "+QString::number(oldValue)+ " W"+" ("+QString::number(rateOfChange)+"%)");
}
/**
* @brief Handles the visual representation of an int value
* @param newValue The new value, that will be displayed
Expand Down
12 changes: 10 additions & 2 deletions src/flabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ class FLabel : public QLabel{
Q_OBJECT;
public:
explicit FLabel(QWidget *parent = nullptr);

public slots:
void setVisual(int newValue, int oldValue);
void setVisual(QTime newValue, QTime oldValue);
void setVisual(float newValue, float oldValue);
void setVisual(short newValue, short oldValue);
void setVisual(QString newValue, QString oldValue);
void setVisual(short newValue, short oldValue);
void setVisual(QString newValue, QString oldValue);
void setAveragedVisualChangeSec(float newValue,float oldValue);
void setAveragedVisualChangeSec(short newValue,short oldValue);
private:
//used for rolling averages
int _counts = 0;
float _alpha = 0;


};
#endif // FLABEL_H
34 changes: 34 additions & 0 deletions src/fvlabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @file fvlabel.h
* @brief This file contains the declaration of the FVLabel class
* @see fvlabel.cpp
* @author João Vieira
* This piece of software was developed for the T24e project belonging to the LART Team
*/
#ifndef FVLABEL_H
#define FVLABEL_H
#include <QLabel>
#include "flabel.h"
#include <QObject>
#include <QString>
#include <QDebug>
#include "store.h"
/**
* @brief The FVLabel class is meant to derive from FLabel it will append text to denote the SI variable type such as m for meters for example
**/
class FVLabel : public FLabel{
Q_OBJECT;
public:
explicit FVLabel(QWidget *parent = nullptr);

public slots:
protected:
QString va;
private:
//used for rolling averages
int _counts = 0;
float _alpha = 0;


};
#endif // FVLABEL_H
15 changes: 8 additions & 7 deletions src/references/bson_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#define BSON_ENGINETEMPERATURE "eng_t"
#define BSON_BATTERYVOLTAGE "bat_v"
#ifdef __LART_T14__
#define BSON_GEARSHIFT "gear"
#define BSON_OILPRESSURE "oil_p"
#define BSON_OILTEMPERATURE "oil_t"
#define BSON_DATALOGGERSTATUS "dtl_s"
#define BSON_AFR "af_r"
#define BSON_TCSLIP "tc_s"
#define BSON_TCLAUNCH "tc_l"
#define BSON_GEARSHIFT "gear"
#define BSON_OILPRESSURE "oil_p"
#define BSON_OILTEMPERATURE "oil_t"
#define BSON_DATALOGGERSTATUS "dtl_s"
#define BSON_AFR "af_r"
#define BSON_TCSLIP "tc_s"
#define BSON_TCLAUNCH "tc_l"
#endif
#ifdef __LART_T24__
#define BSON_SOC "soc"
Expand All @@ -30,6 +30,7 @@
#define BSON_POWER "pow"
#define BSON_LAPCOUNT "lap_c"
#define BSON_LAPTIME "lap_t"
#define BSON_HV "hv"
#endif


Expand Down
33 changes: 28 additions & 5 deletions src/store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,21 @@ void store::parseBson(std::vector<std::uint8_t> v){
}
if(j.contains(BSON_POWER)){
short temp = j[BSON_POWER];
this->setPower(temp);
this->setPower(temp);
}
if(j.contains(BSON_LAPTIME)){
this->setLapTime(j[BSON_LAPTIME]);
}
if(j.contains(BSON_LAPCOUNT)){
short temp = j[BSON_LAPCOUNT];
this->setLapCount(temp);
if(j.contains(BSON_LAPCOUNT)){
short temp = j[BSON_LAPCOUNT];
this->setLapCount(temp);

}
if(j.contains(BSON_HV)){
short temp = j[BSON_HV];
this->setHV(temp); ;

}
//if(j.contains(BSON_TYRETEMPERATURE)){
// this->setTyreTemperature(j[BSON_TYRETEMPERATURE]);
//}
Expand Down Expand Up @@ -634,6 +639,14 @@ int store::getLapTime() const{
short store::getLapCount() const{
return this->m_lapCount;
}
/**
* @brief getter for the high voltage variable
* @return The high voltage variable
*/
short store::getHV() const{
return this->m_highVoltage;
}

/**
* @brief getter for the tyre temperature variable
* @return The tyre temperature variable
Expand Down Expand Up @@ -709,6 +722,16 @@ void store::setLapCount(short lapCount){
this->m_lapCount=lapCount;
emit lapCountChanged(this->m_lapCount, oldLapCount);
}
/**
* @brief setter for the high voltage variable
* @param hv The new value for the high voltage variable
**/
void store::setHV(short hv){
short oldHV = this->m_highVoltage;
this->m_highVoltage=hv;
emit hvChanged(this->m_highVoltage, oldHV);
}

//void store::setTyreTemperature(int tyreTemperature){
// int oldTyreTemperature = this->m_tyreTemperature;
// this->m_tyreTemperature=tyreTemperature;
Expand All @@ -731,4 +754,4 @@ void store::setBaudRate(QSerialPort::BaudRate baud){
*/
QSerialPort::BaudRate store::getBaudRate() const{
return baud;
}
}
15 changes: 11 additions & 4 deletions src/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#ifdef __LART_DEPLOY__
#define DEFAULT_DEVICE "/dev/ttyS3"
#else
#define DEFAULT_DEVICE "/dev/ttyACM0"
#define DEFAULT_DEVICE "/dev/ttyUSB0"
#endif
#endif
#else
Expand Down Expand Up @@ -142,13 +142,17 @@ class store: public QObject{
short getPower() const;
int getLapTime() const;
short getLapCount() const;
//int getTyreTemperature() const;
void setSoc(float soc);
short getHV() const;

//int getTyreTemperature() const;

void setSoc(float soc);
void setBatteryTemperature(float batteryTemperature);
void setInverterTemperature(int inverterTemperature);
void setPower(short power);
void setLapTime(int lapTime);
void setLapCount(short lapCount);
void setHV(short hv);
//void setTyreTemperature(int tyreTemperature);
#endif

Expand Down Expand Up @@ -184,7 +188,9 @@ class store: public QObject{
void lapTimeChanged(QTime newLapTime, QTime oldLapTime);
void diffLapTimeChanged(QTime newDiffLapTime, QTime oldDiffLapTime);
void lapCountChanged(short newLapCount, short oldLapCount);
//void tyreTemperatureChanged(int newTyreTemperature, int oldTyreTemperature);
void hvChanged(short newHV, short oldHV );

//void tyreTemperatureChanged(int newTyreTemperature, int oldTyreTemperature);
#endif

private:
Expand All @@ -210,6 +216,7 @@ class store: public QObject{
short m_power=0;
int m_lapTime=0;
short m_lapCount=0;
short m_highVoltage=0;
//int m_tyreTemperature=0;
#endif

Expand Down
11 changes: 8 additions & 3 deletions src/voidsterdebugwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ VoidsterdebugWindow::VoidsterdebugWindow(QWidget *parent, QString serialDev)
FLabel* Telemetry_Label = this->findChild<FLabel*>("Telemetry_Label");

FLabel* Driverless_Label = this->findChild<FLabel*>("Driverless_Label");

connect(store_ref, &store::powerChanged, TotalPowerDraw_Label, (void (FLabel::*)(short, short))&FLabel::setAveragedVisualChangeSec);

connect(store_ref, &store::socChanged, SOC_Label, (void (FLabel::*)(float, float))&FLabel::setVisual);
//connect(store_ref, &store::batteryTemperatureChanged, )
connect(store_ref, &store::hvChanged,InverterVoltage_Label, (void (FLabel::*)(short, short))&FLabel::setVisual );

TotalPowerDraw_Label->setText("Isto é um teste 1");

/*TotalPowerDraw_Label->setText("Isto é um teste 1");
InverterVoltage_Label->setText("Isto é um teste 1");
SOC_Label->setText("Isto é um teste 3");
DTConstraints_Label->setText("Isto é um teste 4");
Expand All @@ -82,7 +87,7 @@ VoidsterdebugWindow::VoidsterdebugWindow(QWidget *parent, QString serialDev)
Telemetry_Label->setText("TL");
Driverless_Label->setText("DL");

*/


#endif
Expand Down
Loading

0 comments on commit 1d8c282

Please sign in to comment.