Add three general-purpose fields to DriverView
This commit is contained in:
29
TouchGFX/gui/include/gui/containers/DriverViewField.hpp
Normal file
29
TouchGFX/gui/include/gui/containers/DriverViewField.hpp
Normal 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
|
||||
35
TouchGFX/gui/src/containers/DriverViewField.cpp
Normal file
35
TouchGFX/gui/src/containers/DriverViewField.cpp
Normal 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);
|
||||
}
|
||||
@ -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(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user