Display inverter & motor temperatures

This commit is contained in:
2023-05-05 14:50:10 +02:00
parent 24be6312c8
commit a097d2b3aa
26 changed files with 431 additions and 212 deletions

View File

@ -0,0 +1,31 @@
#ifndef TEMPERATURE_HPP
#define TEMPERATURE_HPP
#include <gui_generated/containers/TemperatureBase.hpp>
class Temperature : public TemperatureBase {
public:
Temperature();
virtual ~Temperature() {}
virtual void initialize();
virtual void setTemp(int temp_in_celsius);
/**
* @brief Set the temperature thresholds for the color coding.
*
* @param thresholds Array of 4 integers
*/
void setTempThresholds(int *thresholds);
protected:
private:
int temp;
int tempThresholds[4];
Unicode::UnicodeChar valueBuffer[3];
void updateValueBuffer();
};
#endif // TEMPERATURE_HPP

View File

@ -1,24 +0,0 @@
#ifndef TIRETEMP_HPP
#define TIRETEMP_HPP
#include <gui_generated/containers/TireTempBase.hpp>
#include <sys/_stdint.h>
class TireTemp : public TireTempBase {
public:
TireTemp();
virtual ~TireTemp() {}
virtual void initialize();
virtual void setTemp(int temp_in_celsius);
protected:
private:
int temp;
Unicode::UnicodeChar valueBuffer[3];
void updateValueBuffer();
};
#endif // TIRETEMP_HPP

View File

@ -24,7 +24,7 @@ public:
void setFieldType(size_t i, DataFieldType type);
void updateFieldValues();
void setTireTemps(const TireTemps &temps);
void setTemps(const Temperatures &temps);
void setTSSoC(uint8_t soc);
void setProgress(bool active, DriverViewProgressType type, float progress);

View File

@ -249,13 +249,13 @@ NamedFieldDescription dataFieldDescs[] = {
[DF_IniChkState] = {NamedFieldKind::Text, "ICSTATE", 1, 0, get_inichk_text},
[DF_LapCount] = {NamedFieldKind::Int, "LAPS", 3, 0, VEH_FIELD(lap_count)},
[DF_TireTempFL] = {NamedFieldKind::Float, "TTFL", 2, 1,
VEH_FIELD(tire_temps.fl)},
VEH_FIELD(temps.tire_fl)},
[DF_TireTempFR] = {NamedFieldKind::Float, "TTFR", 2, 1,
VEH_FIELD(tire_temps.fr)},
VEH_FIELD(temps.tire_fr)},
[DF_TireTempRL] = {NamedFieldKind::Float, "TTRL", 2, 1,
VEH_FIELD(tire_temps.rl)},
VEH_FIELD(temps.tire_rl)},
[DF_TireTempRR] = {NamedFieldKind::Float, "TTRR", 2, 1,
VEH_FIELD(tire_temps.rr)},
VEH_FIELD(temps.tire_rr)},
[DF_MinCellVolt] = {NamedFieldKind::Float, "VMIN", 1, 2,
VEH_FIELD(min_cell_volt)},
[DF_MaxCellTemp] = {NamedFieldKind::Float, "TMAX", 2, 1,

View File

@ -1,12 +1,17 @@
#include <gui/containers/Temperature.hpp>
#include <cstring>
#include "touchgfx/Color.hpp"
#include "touchgfx/Unicode.hpp"
#include <gui/containers/TireTemp.hpp>
TireTemp::TireTemp() : temp{0} { updateValueBuffer(); }
Temperature::Temperature() : temp{0}, tempThresholds{0, 0, 0, 0} {
updateValueBuffer();
}
void TireTemp::initialize() { TireTempBase::initialize(); }
void Temperature::initialize() { TemperatureBase::initialize(); }
void TireTemp::setTemp(int temp_in_celsius) {
void Temperature::setTemp(int temp_in_celsius) {
if (temp_in_celsius < 0) {
// No space for displaying negative values
temp_in_celsius = 0;
@ -18,13 +23,13 @@ void TireTemp::setTemp(int temp_in_celsius) {
temp = temp_in_celsius;
updateValueBuffer();
if (temp < 35) {
if (temp < tempThresholds[0]) {
bg.setColor(touchgfx::Color::getColorFromRGB(0x05, 0x76, 0xb7));
} else if (temp < 40) {
} else if (temp < tempThresholds[1]) {
bg.setColor(touchgfx::Color::getColorFromRGB(0x05, 0x76, 0x64));
} else if (temp < 50) {
} else if (temp < tempThresholds[2]) {
bg.setColor(touchgfx::Color::getColorFromRGB(0x05, 0x95, 0x38));
} else if (temp < 60) {
} else if (temp < tempThresholds[3]) {
bg.setColor(touchgfx::Color::getColorFromRGB(0xdd, 0x6e, 0x22));
} else {
bg.setColor(touchgfx::Color::getColorFromRGB(0xdd, 0x2f, 0x22));
@ -33,7 +38,11 @@ void TireTemp::setTemp(int temp_in_celsius) {
bg.invalidate(); // TODO: Only invalidate if color changed
}
void TireTemp::updateValueBuffer() {
void Temperature::setTempThresholds(int *thresholds) {
memcpy(tempThresholds, thresholds, sizeof(tempThresholds));
}
void Temperature::updateValueBuffer() {
// Unicode::utoa(temp, valueBuffer, 3, 10);
Unicode::snprintf(valueBuffer,
sizeof(valueBuffer) / sizeof(Unicode::UnicodeChar), "%02d",

View File

@ -16,7 +16,7 @@ void DriverViewPresenter::activate() {
void DriverViewPresenter::deactivate() {}
void DriverViewPresenter::vehicleStateUpdated() {
view.setTireTemps(vehicle_state.tire_temps);
view.setTemps(vehicle_state.temps);
view.setTSSoC(vehicle_state.soc);
updateProgress();
updateErrorPopup();

View File

@ -17,6 +17,17 @@ void DriverViewView::setupScreen() {
getField(i).setType(fieldTypes[i]);
}
fieldTypeSelection.setNumberOfItems(DataFieldType_COUNT);
int tireThresholds[4] = {35, 40, 50, 60};
tireTempFL.setTempThresholds(tireThresholds);
tireTempFR.setTempThresholds(tireThresholds);
tireTempRL.setTempThresholds(tireThresholds);
tireTempRR.setTempThresholds(tireThresholds);
int invThresholds[4] = {30, 40, 50, 60};
invTempL.setTempThresholds(invThresholds);
invTempR.setTempThresholds(invThresholds);
int motorThresholds[4] = {30, 45, 60, 80};
motorTempL.setTempThresholds(motorThresholds);
motorTempR.setTempThresholds(motorThresholds);
}
void DriverViewView::tearDownScreen() { DriverViewViewBase::tearDownScreen(); }
@ -37,11 +48,15 @@ void DriverViewView::updateFieldValues() {
}
}
void DriverViewView::setTireTemps(const TireTemps &temps) {
tireTempFL.setTemp(temps.fl);
tireTempFR.setTemp(temps.fr);
tireTempRL.setTemp(temps.rl);
tireTempRR.setTemp(temps.rr);
void DriverViewView::setTemps(const Temperatures &temps) {
tireTempFL.setTemp(roundf(temps.tire_fl));
tireTempFR.setTemp(roundf(temps.tire_fr));
tireTempRL.setTemp(roundf(temps.tire_rl));
tireTempRR.setTemp(roundf(temps.tire_rr));
invTempL.setTemp(roundf(temps.inv_l));
invTempR.setTemp(roundf(temps.inv_r));
motorTempL.setTemp(roundf(temps.mot_l));
motorTempR.setTemp(roundf(temps.mot_r));
}
void DriverViewView::setTSSoC(uint8_t soc) {