#include #include "gui/containers/DriverViewStatusItem.hpp" #include "gui_generated/ami_screen/AMIViewBase.hpp" #include "stw_defines.h" #include "texts/TextKeysAndLanguages.hpp" #include "touchgfx/Color.hpp" #include "touchgfx/TypedText.hpp" #include "touchgfx/Unicode.hpp" #include "touchgfx/widgets/TextAreaWithWildcard.hpp" #include "vehicle_state.h" AMIDataField::AMIDataField(touchgfx::TextAreaWithOneWildcard &textArea, const char *fmt) : fmt(fmt), textArea(textArea) {} void AMIDataField::setValue(float value) { Unicode::snprintfFloat(buffer, sizeof(buffer) / sizeof(*buffer), fmt, value); textArea.setWildcard(buffer); textArea.invalidate(); } AMIView::AMIView() : AMIViewBase(), paField(press1, "%5.1f"), pbField(press1, "%5.1f"), pfField(pressFront, "%5.1f"), prField(pressRear, "%5.1f"), desiredAngleField(desiredAngle, "%5.2f"), measuredAngleField(measuredAngle, "%5.2f"), desiredSpeedField(desiredSpeed, "%5.1f"), measuredSpeedField(measuredSpeed, "%5.1f") {} void AMIView::setupScreen() { AMIViewBase::setupScreen(); } void AMIView::tearDownScreen() { AMIViewBase::tearDownScreen(); } void AMIView::setMission(Mission mission) { switch (mission) { case MISSION_ACCEL: currentMission.setTypedText(TypedText(T_ACCEL_HUGE)); break; case MISSION_SKIDPAD: currentMission.setTypedText(TypedText(T_SKIDPAD_HUGE)); break; case MISSION_AUTOX: currentMission.setTypedText(TypedText(T_AUTOX_HUGE)); break; case MISSION_TRACKDRIVE: currentMission.setTypedText(TypedText(T_TRACKDRIVE_HUGE)); break; case MISSION_BRAKETEST: currentMission.setTypedText(TypedText(T_EBS_HUGE)); break; case MISSION_INSPECTION: currentMission.setTypedText(TypedText(T_INSPECTION_HUGE)); break; case MISSION_MANUAL: case MISSION_NONE: default: currentMission.setTypedText(TypedText(T_INVALID_HUGE)); break; } currentMission.invalidate(); } void AMIView::setASState(ASState state) { if (state == AS_READY || state == AS_DRIVING) { init.setVisible(false); driving.setVisible(true); } else { init.setVisible(true); driving.setVisible(false); } init.invalidate(); driving.invalidate(); } void AMIView::setIniChkState(InitialCheckupState state) { if (state == INICHK_ERROR) { progressBar.setColor(DriverViewStatusItem::COLOR_ERROR); progressBar.setValue(100); } else { if (state == INICHK_WAIT_TS) { progressBar.setColor(DriverViewStatusItem::COLOR_TS); progressBar.setValue(100); } else { progressBar.setColor(DriverViewStatusItem::COLOR_OK); float prog = ((float)vehicle_state.initial_checkup_state) / INICHK_DONE; progressBar.setValue(prog * 100); } } progressBar.invalidate(); const char *label = inichkstate_str(state); touchgfx::Unicode::strncpy(progressBuffer, label, sizeof(progressBuffer) / sizeof(*progressBuffer)); progressLabel.setWildcard(progressBuffer); progressLabel.invalidate(); } void AMIView::updateDataFields() { paField.setValue(vehicle_state.tank_pressure_1); pbField.setValue(vehicle_state.tank_pressure_2); pfField.setValue(vehicle_state.brake_pressure_f); prField.setValue(vehicle_state.brake_pressure_r); // TODO // desiredAngleField.setValue(vehicle_state.desired_angle); // measuredAngleField.setValue(vehicle_state.measured_angle); // desiredSpeedField.setValue(vehicle_state.desired_speed); // measuredSpeedField.setValue(vehicle_state.speed); } void AMIView::setJetsonTimeout(bool timeout) { if (timeout) { desiredAngle.setColor(touchgfx::Color::getColorFromRGB(0xFF, 0, 0)); touchgfx::Unicode::fromUTF8((const uint8_t *)"TIMEOUT", asOKBuffer, sizeof(asOKBuffer) / sizeof(*asOKBuffer)); asOK.setWildcard(asOKBuffer); } else { desiredAngle.setColor(touchgfx::Color::getColorFromRGB(0xFF, 0xFF, 0xFF)); } } void AMIView::setEPSCTimeout(bool timeout) { if (timeout) { measuredAngle.setColor(touchgfx::Color::getColorFromRGB(0xFF, 0, 0)); } else { measuredAngle.setColor(touchgfx::Color::getColorFromRGB(0xFF, 0xFF, 0xFF)); } }