diff --git a/src/contarotacoes.cpp b/src/contarotacoes.cpp index 3da702c..76800cc 100644 --- a/src/contarotacoes.cpp +++ b/src/contarotacoes.cpp @@ -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(); } diff --git a/src/flabel.cpp b/src/flabel.cpp index 1825933..b896028 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -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 @@ -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 diff --git a/src/flabel.h b/src/flabel.h index 3e8d7d5..7477941 100644 --- a/src/flabel.h +++ b/src/flabel.h @@ -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 diff --git a/src/fvlabel.h b/src/fvlabel.h new file mode 100644 index 0000000..d056657 --- /dev/null +++ b/src/fvlabel.h @@ -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 +#include "flabel.h" +#include +#include +#include +#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 diff --git a/src/references/bson_var.h b/src/references/bson_var.h index 24180f1..96d580b 100644 --- a/src/references/bson_var.h +++ b/src/references/bson_var.h @@ -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" @@ -30,6 +30,7 @@ #define BSON_POWER "pow" #define BSON_LAPCOUNT "lap_c" #define BSON_LAPTIME "lap_t" + #define BSON_HV "hv" #endif diff --git a/src/store.cpp b/src/store.cpp index a3f1e70..6925dfe 100644 --- a/src/store.cpp +++ b/src/store.cpp @@ -344,16 +344,21 @@ void store::parseBson(std::vector 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]); //} @@ -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 @@ -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; @@ -731,4 +754,4 @@ void store::setBaudRate(QSerialPort::BaudRate baud){ */ QSerialPort::BaudRate store::getBaudRate() const{ return baud; -} \ No newline at end of file +} diff --git a/src/store.h b/src/store.h index 412f4e3..8e2f777 100644 --- a/src/store.h +++ b/src/store.h @@ -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 @@ -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 @@ -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: @@ -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 diff --git a/src/voidsterdebugwindow.cpp b/src/voidsterdebugwindow.cpp index 206195b..4162178 100644 --- a/src/voidsterdebugwindow.cpp +++ b/src/voidsterdebugwindow.cpp @@ -61,9 +61,14 @@ VoidsterdebugWindow::VoidsterdebugWindow(QWidget *parent, QString serialDev) FLabel* Telemetry_Label = this->findChild("Telemetry_Label"); FLabel* Driverless_Label = this->findChild("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"); @@ -82,7 +87,7 @@ VoidsterdebugWindow::VoidsterdebugWindow(QWidget *parent, QString serialDev) Telemetry_Label->setText("TL"); Driverless_Label->setText("DL"); - +*/ #endif diff --git a/src/voidsterdebugwindow.ui b/src/voidsterdebugwindow.ui index e7b71a4..8d1b7f8 100644 --- a/src/voidsterdebugwindow.ui +++ b/src/voidsterdebugwindow.ui @@ -468,7 +468,7 @@ LukHudX - Qt::LeftToRight + Qt::LayoutDirection::LeftToRight true @@ -488,7 +488,7 @@ - QLayout::SetDefaultConstraint + QLayout::SizeConstraint::SetDefaultConstraint @@ -496,7 +496,7 @@ 55320 / 44300 W (-1%/s) - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter false @@ -512,7 +512,7 @@ 50% (5 hours of juice left) - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -522,14 +522,14 @@ 620 V (+5%) - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - Qt::Vertical + Qt::Orientation::Vertical @@ -549,7 +549,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -569,7 +569,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -585,7 +585,7 @@ Limit: 80.000 - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -599,7 +599,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -612,7 +612,7 @@ - Total Power Draw(Curr/Exp): + Total Power Draw(Curr): @@ -623,7 +623,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -636,7 +636,7 @@ - QLayout::SetDefaultConstraint + QLayout::SizeConstraint::SetDefaultConstraint 10 @@ -673,7 +673,7 @@ VCU State() : - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -717,7 +717,7 @@ TCU State() : - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -733,7 +733,6 @@ Source Code Pro 11 - 75 true @@ -760,7 +759,7 @@ Telemetry() : - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -782,7 +781,7 @@ Driverless(#) : - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -823,7 +822,7 @@ Datalogger() : - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -858,7 +857,6 @@ Source Code Pro 11 - 75 true @@ -879,7 +877,6 @@ Source Code Pro 11 - 75 true @@ -906,7 +903,7 @@ Shutdown Circuit() : - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -922,7 +919,6 @@ Source Code Pro 11 - 75 true @@ -943,7 +939,6 @@ Source Code Pro 11 - 75 true @@ -1017,7 +1012,7 @@ 0 0 668 - 33 + 26