Add three general-purpose fields to DriverView

This commit is contained in:
2023-03-18 22:51:13 +01:00
parent 5fe5d509a4
commit c6f237b87e
28 changed files with 536 additions and 57 deletions

View File

@ -0,0 +1,29 @@
#ifndef DRIVERVIEWFIELD_HPP
#define DRIVERVIEWFIELD_HPP
#include "touchgfx/TypedText.hpp"
#include "touchgfx/Unicode.hpp"
#include <gui_generated/containers/DriverViewFieldBase.hpp>
class DriverViewField : public DriverViewFieldBase {
public:
DriverViewField();
virtual ~DriverViewField() {}
virtual void initialize();
void setName(const touchgfx::TypedText &text);
void setValue(float newValue);
void setPrecision(size_t intDigits, size_t decimalDigits);
protected:
private:
Unicode::UnicodeChar valueBuffer[16];
size_t intDigits;
size_t decimalDigits;
float fieldValue;
void updateValueBuffer();
};
#endif // DRIVERVIEWFIELD_HPP

View File

@ -0,0 +1,35 @@
#include "touchgfx/Unicode.hpp"
#include <gui/containers/DriverViewField.hpp>
DriverViewField::DriverViewField()
: intDigits{0}, decimalDigits{0}, fieldValue{0} {}
void DriverViewField::initialize() { DriverViewFieldBase::initialize(); }
void DriverViewField::setName(const touchgfx::TypedText &text) {
title.setTypedText(text);
title.invalidate();
}
void DriverViewField::setValue(float newValue) {
fieldValue = newValue;
updateValueBuffer();
}
void DriverViewField::setPrecision(size_t intDigits, size_t decimalDigits) {
this->intDigits = intDigits;
this->decimalDigits = decimalDigits;
updateValueBuffer();
}
void DriverViewField::updateValueBuffer() {
size_t width = intDigits;
if (decimalDigits != 0) {
width += decimalDigits + 1; // 1 digit for the decimal point
}
float params[3] = {(float)width, (float)decimalDigits, fieldValue};
Unicode::snprintfFloats(valueBuffer,
sizeof(valueBuffer) / sizeof(Unicode::UnicodeChar),
"%*.*f", params);
value.setWildcard(valueBuffer);
}

View File

@ -1,8 +1,20 @@
#include "texts/TextKeysAndLanguages.hpp"
#include <gui/driverview_screen/DriverViewView.hpp>
DriverViewView::DriverViewView() {}
void DriverViewView::setupScreen() { DriverViewViewBase::setupScreen(); }
void DriverViewView::setupScreen() {
DriverViewViewBase::setupScreen();
field1.setName(T_FIELD_MINCELLVOLT);
field1.setValue(3.21);
field1.setPrecision(1, 2);
field2.setName(T_FIELD_SPEED);
field2.setValue(42.0);
field2.setPrecision(3, 0);
field3.setName(T_FIELD_TSCURRENT);
field3.setValue(131.0);
field3.setPrecision(3, 0);
}
void DriverViewView::tearDownScreen() { DriverViewViewBase::tearDownScreen(); }