Skip to content

Commit 1d8c282

Browse files
author
Imeguras
committed
added_stuff
1 parent 3a7e61e commit 1d8c282

9 files changed

+143
-47
lines changed

src/contarotacoes.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void ContaRotacoes::handleChangedValue(int newValue, int oldValue){
7777
(void)oldValue;
7878
// 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
7979
if( newValue >= 0){
80+
8081
this->m_value = newValue;
8182
this->update();
8283
}

src/flabel.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
+ @file flabel.cpp
33
* @brief This file contains all the logic that customizes the behaviour of most Text Labels on screen.
44
* @see flabel.h
@@ -22,7 +22,29 @@ void FLabel::setVisual(QString newValue, QString oldValue=""){
2222
(void)oldValue;
2323
this->setText(newValue);
2424
}
25+
/**
26+
* @brief TODO
27+
**/
28+
void FLabel::setAveragedVisualChangeSec(float newValue, float oldValue){
29+
this->_counts++;
30+
_alpha = (float)((this->_counts * newValue) + (1.0 - this->_counts) * oldValue);
31+
float truenewvalue = (float)((float)(_alpha/_counts));
32+
auto rateOfChange = (truenewvalue-oldValue)/oldValue * 100;
33+
this->setText(QString::number(truenewvalue)+" / "+QString::number(newValue)+ " W"+" ("+QString::number(rateOfChange)+"%)");
34+
}
2535

36+
void FLabel::setAveragedVisualChangeSec(short newValue, short oldValue){
37+
this->_counts++;
38+
this->_alpha = (float)( (this->_counts * newValue) + (1.0 - this->_counts) * _alpha);
39+
short truenewvalue = ((short)(_alpha/_counts));
40+
short rateOfChange =100;
41+
if(oldValue!=0){
42+
rateOfChange = ((short)((truenewvalue-oldValue)/oldValue)) * 100;
43+
}
44+
45+
//TODO URGENT fix units
46+
this->setText(QString::number(truenewvalue)+" / "+QString::number(oldValue)+ " W"+" ("+QString::number(rateOfChange)+"%)");
47+
}
2648
/**
2749
* @brief Handles the visual representation of an int value
2850
* @param newValue The new value, that will be displayed

src/flabel.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ class FLabel : public QLabel{
1919
Q_OBJECT;
2020
public:
2121
explicit FLabel(QWidget *parent = nullptr);
22+
2223
public slots:
2324
void setVisual(int newValue, int oldValue);
2425
void setVisual(QTime newValue, QTime oldValue);
2526
void setVisual(float newValue, float oldValue);
26-
void setVisual(short newValue, short oldValue);
27-
void setVisual(QString newValue, QString oldValue);
27+
void setVisual(short newValue, short oldValue);
28+
void setVisual(QString newValue, QString oldValue);
29+
void setAveragedVisualChangeSec(float newValue,float oldValue);
30+
void setAveragedVisualChangeSec(short newValue,short oldValue);
31+
private:
32+
//used for rolling averages
33+
int _counts = 0;
34+
float _alpha = 0;
35+
2836

2937
};
3038
#endif // FLABEL_H

src/fvlabel.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @file fvlabel.h
3+
* @brief This file contains the declaration of the FVLabel class
4+
* @see fvlabel.cpp
5+
* @author João Vieira
6+
* This piece of software was developed for the T24e project belonging to the LART Team
7+
*/
8+
#ifndef FVLABEL_H
9+
#define FVLABEL_H
10+
#include <QLabel>
11+
#include "flabel.h"
12+
#include <QObject>
13+
#include <QString>
14+
#include <QDebug>
15+
#include "store.h"
16+
/**
17+
* @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
18+
**/
19+
class FVLabel : public FLabel{
20+
Q_OBJECT;
21+
public:
22+
explicit FVLabel(QWidget *parent = nullptr);
23+
24+
public slots:
25+
protected:
26+
QString va;
27+
private:
28+
//used for rolling averages
29+
int _counts = 0;
30+
float _alpha = 0;
31+
32+
33+
};
34+
#endif // FVLABEL_H

src/references/bson_var.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
#define BSON_ENGINETEMPERATURE "eng_t"
1616
#define BSON_BATTERYVOLTAGE "bat_v"
1717
#ifdef __LART_T14__
18-
#define BSON_GEARSHIFT "gear"
19-
#define BSON_OILPRESSURE "oil_p"
20-
#define BSON_OILTEMPERATURE "oil_t"
21-
#define BSON_DATALOGGERSTATUS "dtl_s"
22-
#define BSON_AFR "af_r"
23-
#define BSON_TCSLIP "tc_s"
24-
#define BSON_TCLAUNCH "tc_l"
18+
#define BSON_GEARSHIFT "gear"
19+
#define BSON_OILPRESSURE "oil_p"
20+
#define BSON_OILTEMPERATURE "oil_t"
21+
#define BSON_DATALOGGERSTATUS "dtl_s"
22+
#define BSON_AFR "af_r"
23+
#define BSON_TCSLIP "tc_s"
24+
#define BSON_TCLAUNCH "tc_l"
2525
#endif
2626
#ifdef __LART_T24__
2727
#define BSON_SOC "soc"
@@ -30,6 +30,7 @@
3030
#define BSON_POWER "pow"
3131
#define BSON_LAPCOUNT "lap_c"
3232
#define BSON_LAPTIME "lap_t"
33+
#define BSON_HV "hv"
3334
#endif
3435

3536

src/store.cpp

+28-5
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,21 @@ void store::parseBson(std::vector<std::uint8_t> v){
344344
}
345345
if(j.contains(BSON_POWER)){
346346
short temp = j[BSON_POWER];
347-
this->setPower(temp);
347+
this->setPower(temp);
348348
}
349349
if(j.contains(BSON_LAPTIME)){
350350
this->setLapTime(j[BSON_LAPTIME]);
351351
}
352-
if(j.contains(BSON_LAPCOUNT)){
353-
short temp = j[BSON_LAPCOUNT];
354-
this->setLapCount(temp);
352+
if(j.contains(BSON_LAPCOUNT)){
353+
short temp = j[BSON_LAPCOUNT];
354+
this->setLapCount(temp);
355355

356356
}
357+
if(j.contains(BSON_HV)){
358+
short temp = j[BSON_HV];
359+
this->setHV(temp); ;
360+
361+
}
357362
//if(j.contains(BSON_TYRETEMPERATURE)){
358363
// this->setTyreTemperature(j[BSON_TYRETEMPERATURE]);
359364
//}
@@ -634,6 +639,14 @@ int store::getLapTime() const{
634639
short store::getLapCount() const{
635640
return this->m_lapCount;
636641
}
642+
/**
643+
* @brief getter for the high voltage variable
644+
* @return The high voltage variable
645+
*/
646+
short store::getHV() const{
647+
return this->m_highVoltage;
648+
}
649+
637650
/**
638651
* @brief getter for the tyre temperature variable
639652
* @return The tyre temperature variable
@@ -709,6 +722,16 @@ void store::setLapCount(short lapCount){
709722
this->m_lapCount=lapCount;
710723
emit lapCountChanged(this->m_lapCount, oldLapCount);
711724
}
725+
/**
726+
* @brief setter for the high voltage variable
727+
* @param hv The new value for the high voltage variable
728+
**/
729+
void store::setHV(short hv){
730+
short oldHV = this->m_highVoltage;
731+
this->m_highVoltage=hv;
732+
emit hvChanged(this->m_highVoltage, oldHV);
733+
}
734+
712735
//void store::setTyreTemperature(int tyreTemperature){
713736
// int oldTyreTemperature = this->m_tyreTemperature;
714737
// this->m_tyreTemperature=tyreTemperature;
@@ -731,4 +754,4 @@ void store::setBaudRate(QSerialPort::BaudRate baud){
731754
*/
732755
QSerialPort::BaudRate store::getBaudRate() const{
733756
return baud;
734-
}
757+
}

src/store.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#ifdef __LART_DEPLOY__
4747
#define DEFAULT_DEVICE "/dev/ttyS3"
4848
#else
49-
#define DEFAULT_DEVICE "/dev/ttyACM0"
49+
#define DEFAULT_DEVICE "/dev/ttyUSB0"
5050
#endif
5151
#endif
5252
#else
@@ -142,13 +142,17 @@ class store: public QObject{
142142
short getPower() const;
143143
int getLapTime() const;
144144
short getLapCount() const;
145-
//int getTyreTemperature() const;
146-
void setSoc(float soc);
145+
short getHV() const;
146+
147+
//int getTyreTemperature() const;
148+
149+
void setSoc(float soc);
147150
void setBatteryTemperature(float batteryTemperature);
148151
void setInverterTemperature(int inverterTemperature);
149152
void setPower(short power);
150153
void setLapTime(int lapTime);
151154
void setLapCount(short lapCount);
155+
void setHV(short hv);
152156
//void setTyreTemperature(int tyreTemperature);
153157
#endif
154158

@@ -184,7 +188,9 @@ class store: public QObject{
184188
void lapTimeChanged(QTime newLapTime, QTime oldLapTime);
185189
void diffLapTimeChanged(QTime newDiffLapTime, QTime oldDiffLapTime);
186190
void lapCountChanged(short newLapCount, short oldLapCount);
187-
//void tyreTemperatureChanged(int newTyreTemperature, int oldTyreTemperature);
191+
void hvChanged(short newHV, short oldHV );
192+
193+
//void tyreTemperatureChanged(int newTyreTemperature, int oldTyreTemperature);
188194
#endif
189195

190196
private:
@@ -210,6 +216,7 @@ class store: public QObject{
210216
short m_power=0;
211217
int m_lapTime=0;
212218
short m_lapCount=0;
219+
short m_highVoltage=0;
213220
//int m_tyreTemperature=0;
214221
#endif
215222

src/voidsterdebugwindow.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ VoidsterdebugWindow::VoidsterdebugWindow(QWidget *parent, QString serialDev)
6161
FLabel* Telemetry_Label = this->findChild<FLabel*>("Telemetry_Label");
6262

6363
FLabel* Driverless_Label = this->findChild<FLabel*>("Driverless_Label");
64-
64+
connect(store_ref, &store::powerChanged, TotalPowerDraw_Label, (void (FLabel::*)(short, short))&FLabel::setAveragedVisualChangeSec);
65+
66+
connect(store_ref, &store::socChanged, SOC_Label, (void (FLabel::*)(float, float))&FLabel::setVisual);
67+
//connect(store_ref, &store::batteryTemperatureChanged, )
68+
connect(store_ref, &store::hvChanged,InverterVoltage_Label, (void (FLabel::*)(short, short))&FLabel::setVisual );
6569

66-
TotalPowerDraw_Label->setText("Isto é um teste 1");
70+
71+
/*TotalPowerDraw_Label->setText("Isto é um teste 1");
6772
InverterVoltage_Label->setText("Isto é um teste 1");
6873
SOC_Label->setText("Isto é um teste 3");
6974
DTConstraints_Label->setText("Isto é um teste 4");
@@ -82,7 +87,7 @@ VoidsterdebugWindow::VoidsterdebugWindow(QWidget *parent, QString serialDev)
8287
Telemetry_Label->setText("TL");
8388
8489
Driverless_Label->setText("DL");
85-
90+
*/
8691

8792

8893
#endif

0 commit comments

Comments
 (0)