Add AMS Error popup

This commit is contained in:
2023-05-05 14:00:00 +02:00
parent cb2d707bd9
commit 24be6312c8
28 changed files with 493 additions and 108 deletions

View File

@ -0,0 +1,20 @@
#ifndef ERRORPOPUP_HPP
#define ERRORPOPUP_HPP
#include "touchgfx/Unicode.hpp"
#include <gui_generated/containers/ErrorPopupBase.hpp>
class ErrorPopup : public ErrorPopupBase {
public:
ErrorPopup();
virtual ~ErrorPopup() {}
virtual void initialize();
void showAMSError();
protected:
touchgfx::Unicode::UnicodeChar detailsBuffer[128];
};
#endif // ERRORPOPUP_HPP

View File

@ -37,6 +37,9 @@ public:
private:
DriverViewPresenter();
void updateProgress();
void updateErrorPopup();
DriverViewView &view;
DataFieldType fields[3];

View File

@ -28,6 +28,9 @@ public:
void setTSSoC(uint8_t soc);
void setProgress(bool active, DriverViewProgressType type, float progress);
void showAMSError();
void clearErrorPopup();
void selectPrevField() override;
void selectNextField() override;
void selectPrevFieldType() override;

View File

@ -0,0 +1,71 @@
#include <gui/containers/ErrorPopup.hpp>
#include "texts/TextKeysAndLanguages.hpp"
#include "touchgfx/Unicode.hpp"
#include "vehicle.h"
ErrorPopup::ErrorPopup() {}
void ErrorPopup::initialize() { ErrorPopupBase::initialize(); }
void ErrorPopup::showAMSError() {
title.setTypedText(T_ERROR_AMS);
title.invalidate();
switch (vehicle_state.last_ams_error.kind) {
case AMS_ERROR_NONE:
touchgfx::Unicode::strncpy(detailsBuffer, "UNKNOWN ERROR",
sizeof(detailsBuffer) / sizeof(*detailsBuffer));
break;
case AMS_ERROR_SLAVE_TIMEOUT:
touchgfx::Unicode::snprintf(
detailsBuffer, sizeof(detailsBuffer) / sizeof(*detailsBuffer),
"Slave timeout: Slave %d", vehicle_state.last_ams_error.arg);
break;
case AMS_ERROR_SLAVE_PANIC: {
const char *panicKindStr = "UNKNOWN";
switch (vehicle_state.last_ams_slave_panic.kind) {
case AMS_SLAVEPANIC_OVERTEMP:
panicKindStr = "OVERTEMPERATURE";
break;
case AMS_SLAVEPANIC_UNDERTEMP:
panicKindStr = "UNDERTEMPERATURE";
break;
case AMS_SLAVEPANIC_OVERVOLTAGE:
panicKindStr = "OVERVOLTAGE";
break;
case AMS_SLAVEPANIC_UNDERVOLTAGE:
panicKindStr = "UNDERVOLTAGE";
break;
case AMS_SLAVEPANIC_TOO_FEW_TEMP:
panicKindStr = "TOO FEW TEMP SENSORS";
break;
case AMS_SLAVEPANIC_OPENWIRE:
panicKindStr = "OPEN WIRE";
break;
}
touchgfx::Unicode::UnicodeChar panicKindBuf[32];
touchgfx::Unicode::strncpy(panicKindBuf, panicKindStr,
sizeof(panicKindBuf) / sizeof(*panicKindBuf));
touchgfx::Unicode::snprintf(
detailsBuffer, sizeof(detailsBuffer) / sizeof(*detailsBuffer),
"Slave panic: Slave %d\n[ID: %d, Kind: %s, Arg: %08x]",
vehicle_state.last_ams_slave_panic.id, panicKindBuf,
vehicle_state.last_ams_slave_panic.arg);
break;
}
case AMS_ERROR_SHUNT_TIMEOUT:
touchgfx::Unicode::strncpy(detailsBuffer, "Shunt timeout",
sizeof(detailsBuffer) / sizeof(*detailsBuffer));
break;
case AMS_ERROR_SHUNT_OVERCURRENT:
touchgfx::Unicode::strncpy(detailsBuffer, "Shunt overcurrent",
sizeof(detailsBuffer) / sizeof(*detailsBuffer));
break;
case AMS_ERROR_SHUNT_OVERTEMP:
touchgfx::Unicode::strncpy(detailsBuffer, "Shunt overtemperature",
sizeof(detailsBuffer) / sizeof(*detailsBuffer));
break;
}
details.setWildcard(detailsBuffer);
details.invalidate();
}

View File

@ -5,7 +5,7 @@
#include "vehicle.h"
DriverViewPresenter::DriverViewPresenter(DriverViewView &v)
: view(v), fields{DF_MinCellVolt, DF_Speed, DF_TSCurrent} {}
: view(v), fields{DF_MinCellVolt, DF_TSVoltageVeh, DF_TSCurrent} {}
void DriverViewPresenter::activate() {
for (size_t i = 0; i < 3; i++) {
@ -18,6 +18,23 @@ void DriverViewPresenter::deactivate() {}
void DriverViewPresenter::vehicleStateUpdated() {
view.setTireTemps(vehicle_state.tire_temps);
view.setTSSoC(vehicle_state.soc);
updateProgress();
updateErrorPopup();
view.updateFieldValues();
}
void DriverViewPresenter::nextScreen() {
static_cast<FrontendApplication *>(Application::getInstance())
->gotoVehicleConfigScreenNoTransition();
}
void DriverViewPresenter::setFieldType(size_t i, DataFieldType type) {
fields[i] = type;
view.setFieldType(i, type);
}
void DriverViewPresenter::updateProgress() {
if (vehicle_state.ts_state == TS_PRECHARGE) {
float progress = 0;
if (vehicle_state.ts_voltage_bat != 0) {
@ -32,16 +49,12 @@ void DriverViewPresenter::vehicleStateUpdated() {
} else {
view.setProgress(false, DriverViewProgressType::PRECHARGE, 0);
}
view.updateFieldValues();
}
void DriverViewPresenter::nextScreen() {
static_cast<FrontendApplication *>(Application::getInstance())
->gotoVehicleConfigScreenNoTransition();
}
void DriverViewPresenter::setFieldType(size_t i, DataFieldType type) {
fields[i] = type;
view.setFieldType(i, type);
void DriverViewPresenter::updateErrorPopup() {
if (vehicle_state.ts_state == TS_ERROR) {
view.showAMSError();
} else {
view.clearErrorPopup();
}
}

View File

@ -89,6 +89,17 @@ void DriverViewView::setProgress(bool active, DriverViewProgressType type,
}
}
void DriverViewView::showAMSError() {
errorPopup.setVisible(true);
errorPopup.showAMSError();
errorPopup.invalidate();
}
void DriverViewView::clearErrorPopup() {
errorPopup.setVisible(false);
errorPopup.invalidate();
}
void DriverViewView::selectNextField() {
if (!fieldTypeSelection.isVisible()) {
fieldTypeSelection.setVisible(true);