#include "touchgfx/Color.hpp" #include "touchgfx/Unicode.hpp" #include "vehicle_state.h" #include #include #include EnduranceView::EnduranceView() : lastLapDelta(lastLapBox, lastLapBat), overallDelta(overallBox, overallBat), plimBuffer(powerLimit, 2, 0), slimBuffer(speedLimit, 2, 0), socBuffer(soc, 3, 0), tbatBuffer(batTemp, 2, 1) {} void EnduranceView::setupScreen() { EnduranceViewBase::setupScreen(); lastLapDelta.setField(lastLapBat); lastLapDelta.setBox(lastLapBox); overallDelta.setField(overallBat); overallDelta.setBox(overallBox); plimBuffer.setField(powerLimit); slimBuffer.setField(speedLimit); socBuffer.setField(soc); tbatBuffer.setField(batTemp); } void EnduranceView::tearDownScreen() { EnduranceViewBase::tearDownScreen(); } void EnduranceView::updateBatDelta() { lastLapDelta.setDelta(vehicle_state.bat_delta_last); overallDelta.setDelta(vehicle_state.bat_delta_overall); } void EnduranceView::updateDetails() { plimBuffer.setIntValue(vehicle_state.power_limit); slimBuffer.setIntValue(vehicle_state.speed_limit); socBuffer.setIntValue(vehicle_state.soc_ts); tbatBuffer.setFloatValue(vehicle_state.max_cell_temp); } void EnduranceView::updateProgress() { progressBar.update(); } BatDelta::BatDelta(touchgfx::BoxWithBorder &box, touchgfx::TextAreaWithOneWildcard &field) : box(box), field(field), value(INT_MIN) {} void BatDelta::setField(touchgfx::TextAreaWithOneWildcard &field) { this->field = field; } void BatDelta::setBox(touchgfx::BoxWithBorder &box) { this->box = box; } void BatDelta::setDelta(float delta) { int deltaRounded = std::round(delta); if (deltaRounded == value) { return; } value = deltaRounded; touchgfx::Unicode::snprintf(buffer, sizeof(buffer) / sizeof(*buffer), "%+3d", value); field.setWildcard(buffer); field.invalidate(); if (value > 10) { box.setColor(touchgfx::Color::getColorFromRGB(0xa8, 0x08, 0x08)); } else if (value > 5) { box.setColor(touchgfx::Color::getColorFromRGB(0xc7, 0x71, 0x08)); } else if (value > 0) { box.setColor(touchgfx::Color::getColorFromRGB(0xdb, 0xb2, 0x0b)); } else if (value > -5) { box.setColor(touchgfx::Color::getColorFromRGB(0x80, 0xba, 0x14)); } else if (value > -10) { box.setColor(touchgfx::Color::getColorFromRGB(0x09, 0x96, 0x3b)); } else { box.setColor(touchgfx::Color::getColorFromRGB(0x05, 0x77, 0xa8)); } box.invalidate(); } ValueBuffer::ValueBuffer(touchgfx::TextAreaWithOneWildcard &field, size_t intDigits, size_t decimalDigits) : field(field), intDigits(intDigits), decimalDigits(decimalDigits) { value.f = NAN; } void ValueBuffer::setField(touchgfx::TextAreaWithOneWildcard &field) { this->field = field; } void ValueBuffer::setIntValue(int value) { if (value == this->value.i) { return; } this->value.i = value; touchgfx::Unicode::snprintf(buffer, sizeof(buffer) / sizeof(*buffer), "%*d", static_cast(intDigits), value); field.setWildcard(buffer); field.invalidate(); } void ValueBuffer::setFloatValue(float value) { if (value == this->value.f) { return; } this->value.f = value; size_t width = intDigits; if (decimalDigits > 0) { width += 1 + decimalDigits; // 1 for the decimal point } float params[3] = {static_cast(width), static_cast(decimalDigits), value}; touchgfx::Unicode::snprintfFloats(buffer, sizeof(buffer) / sizeof(*buffer), "%*.*f", params); field.setWildcard(buffer); field.invalidate(); }