From 09f65fcf22a8134bdb07646ead24441464c792cb Mon Sep 17 00:00:00 2001 From: "Jasper v. Blanckenburg" Date: Tue, 4 Apr 2023 18:31:06 +0200 Subject: [PATCH] DataField -> NamedField --- STM32Make.make | 2 +- .../common/{DataField.hpp => NamedField.hpp} | 29 +++--- .../include/gui/containers/DebugViewItem.hpp | 5 +- .../include/gui/containers/DebugViewLine.hpp | 2 +- .../gui/containers/DriverViewField.hpp | 5 +- .../driverview_screen/DriverViewPresenter.hpp | 2 +- .../gui/driverview_screen/DriverViewView.hpp | 2 +- .../common/{DataField.cpp => NamedField.cpp} | 90 ++++++++++--------- TouchGFX/gui/src/containers/DebugViewItem.cpp | 2 +- TouchGFX/gui/src/containers/DebugViewLine.cpp | 2 +- .../gui/src/containers/DriverViewField.cpp | 12 +-- .../src/debugview_screen/DebugViewView.cpp | 2 +- .../driverview_screen/DriverViewPresenter.cpp | 2 +- .../src/driverview_screen/DriverViewView.cpp | 2 +- TouchGFX/simulator/msvs/Application.vcxproj | 4 +- .../msvs/Application.vcxproj.filters | 12 +-- 16 files changed, 94 insertions(+), 81 deletions(-) rename TouchGFX/gui/include/gui/common/{DataField.hpp => NamedField.hpp} (77%) rename TouchGFX/gui/src/common/{DataField.cpp => NamedField.cpp} (73%) diff --git a/STM32Make.make b/STM32Make.make index 9c04879..174c80b 100644 --- a/STM32Make.make +++ b/STM32Make.make @@ -378,8 +378,8 @@ TouchGFX/generated/texts/src/Texts.cpp \ TouchGFX/generated/texts/src/TypedTextDatabase.cpp \ TouchGFX/gui/src/ami_screen/AMIPresenter.cpp \ TouchGFX/gui/src/ami_screen/AMIView.cpp \ -TouchGFX/gui/src/common/DataField.cpp \ TouchGFX/gui/src/common/FrontendApplication.cpp \ +TouchGFX/gui/src/common/NamedField.cpp \ TouchGFX/gui/src/containers/DebugViewItem.cpp \ TouchGFX/gui/src/containers/DebugViewLine.cpp \ TouchGFX/gui/src/containers/DriverViewField.cpp \ diff --git a/TouchGFX/gui/include/gui/common/DataField.hpp b/TouchGFX/gui/include/gui/common/NamedField.hpp similarity index 77% rename from TouchGFX/gui/include/gui/common/DataField.hpp rename to TouchGFX/gui/include/gui/common/NamedField.hpp index 90283ae..e1e1c02 100644 --- a/TouchGFX/gui/include/gui/common/DataField.hpp +++ b/TouchGFX/gui/include/gui/common/NamedField.hpp @@ -1,5 +1,5 @@ -#ifndef DATAFIELD_HPP -#define DATAFIELD_HPP +#ifndef NAMEDFIELD_HPP +#define NAMEDFIELD_HPP #include "touchgfx/TypedText.hpp" #include "touchgfx/Unicode.hpp" @@ -21,10 +21,10 @@ CountedEnum(DataFieldType, size_t, DF_TSState, DF_ASState, DF_ActiveMission, DF_TSSoC, DF_LVSoC, DF_TSCurrent, DF_TSVoltageBat, DF_TSVoltageVeh, DF_Speed, DF_BBal); -enum class DataFieldKind { Float, Bool, Text, Int }; +enum class NamedFieldKind { Float, Bool, Text, Int }; -struct DataFieldDescription { - DataFieldKind kind; +struct NamedFieldDescription { + NamedFieldKind kind; const char *title; size_t int_digits; size_t decimal_digits; @@ -32,23 +32,26 @@ struct DataFieldDescription { void *(*getValue)(void); }; -extern DataFieldDescription dataFieldDescs[]; +extern NamedFieldDescription dataFieldDescs[]; -class DataField { +template class NamedField { public: - virtual ~DataField() {} + NamedField(const NamedFieldDescription *fieldDescs); + virtual ~NamedField() {} - void setType(DataFieldType type); - DataFieldType getType(); + void setType(T type); + T getType(); virtual void updateValue(); protected: + const NamedFieldDescription *fieldDescs; + touchgfx::Unicode::UnicodeChar titleBuffer[16]; touchgfx::Unicode::UnicodeChar valueBuffer[16]; - DataFieldType type; - const DataFieldDescription *desc; + T type; + const NamedFieldDescription *desc; union { float f; int b; @@ -68,4 +71,4 @@ private: void updateValueBuffer(); }; -#endif // DATAFIELD_HPP +#endif // NAMEDFIELD_HPP diff --git a/TouchGFX/gui/include/gui/containers/DebugViewItem.hpp b/TouchGFX/gui/include/gui/containers/DebugViewItem.hpp index e7a7fbb..5bda9f2 100644 --- a/TouchGFX/gui/include/gui/containers/DebugViewItem.hpp +++ b/TouchGFX/gui/include/gui/containers/DebugViewItem.hpp @@ -1,10 +1,11 @@ #ifndef DEBUGVIEWITEM_HPP #define DEBUGVIEWITEM_HPP -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include -class DebugViewItem : public DebugViewItemBase, public DataField { +class DebugViewItem : public DebugViewItemBase, + public NamedField { public: DebugViewItem(); virtual ~DebugViewItem() {} diff --git a/TouchGFX/gui/include/gui/containers/DebugViewLine.hpp b/TouchGFX/gui/include/gui/containers/DebugViewLine.hpp index 64483cf..4702c21 100644 --- a/TouchGFX/gui/include/gui/containers/DebugViewLine.hpp +++ b/TouchGFX/gui/include/gui/containers/DebugViewLine.hpp @@ -1,7 +1,7 @@ #ifndef DEBUGVIEWLINE_HPP #define DEBUGVIEWLINE_HPP -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include "gui/containers/DebugViewItem.hpp" #include diff --git a/TouchGFX/gui/include/gui/containers/DriverViewField.hpp b/TouchGFX/gui/include/gui/containers/DriverViewField.hpp index 38faa5c..a445247 100644 --- a/TouchGFX/gui/include/gui/containers/DriverViewField.hpp +++ b/TouchGFX/gui/include/gui/containers/DriverViewField.hpp @@ -5,9 +5,10 @@ #include "touchgfx/Unicode.hpp" #include -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" -class DriverViewField : public DriverViewFieldBase, public DataField { +class DriverViewField : public DriverViewFieldBase, + public NamedField { public: DriverViewField(); virtual ~DriverViewField() {} diff --git a/TouchGFX/gui/include/gui/driverview_screen/DriverViewPresenter.hpp b/TouchGFX/gui/include/gui/driverview_screen/DriverViewPresenter.hpp index 9f1d793..cb9d587 100644 --- a/TouchGFX/gui/include/gui/driverview_screen/DriverViewPresenter.hpp +++ b/TouchGFX/gui/include/gui/driverview_screen/DriverViewPresenter.hpp @@ -4,7 +4,7 @@ #include #include -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" using namespace touchgfx; diff --git a/TouchGFX/gui/include/gui/driverview_screen/DriverViewView.hpp b/TouchGFX/gui/include/gui/driverview_screen/DriverViewView.hpp index 21a90f5..bf8b3cc 100644 --- a/TouchGFX/gui/include/gui/driverview_screen/DriverViewView.hpp +++ b/TouchGFX/gui/include/gui/driverview_screen/DriverViewView.hpp @@ -1,7 +1,7 @@ #ifndef DRIVERVIEWVIEW_HPP #define DRIVERVIEWVIEW_HPP -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include "gui/containers/DriverViewFieldSelection.hpp" #include "touchgfx/containers/scrollers/DrawableList.hpp" #include "vehicle.h" diff --git a/TouchGFX/gui/src/common/DataField.cpp b/TouchGFX/gui/src/common/NamedField.cpp similarity index 73% rename from TouchGFX/gui/src/common/DataField.cpp rename to TouchGFX/gui/src/common/NamedField.cpp index e027b95..9787cbb 100644 --- a/TouchGFX/gui/src/common/DataField.cpp +++ b/TouchGFX/gui/src/common/NamedField.cpp @@ -1,4 +1,4 @@ -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include "texts/TextKeysAndLanguages.hpp" #include "touchgfx/Unicode.hpp" @@ -232,50 +232,56 @@ void *get_zero() { return &zero; } -DataFieldDescription dataFieldDescs[] = { - [DF_TSState] = {DataFieldKind::Text, "TSSTATE", 1, 0, get_tsstate_text}, - [DF_ASState] = {DataFieldKind::Text, "ASSTATE", 1, 0, get_asstate_text}, - [DF_ActiveMission] = {DataFieldKind::Text, "MISSION", 1, 0, +NamedFieldDescription dataFieldDescs[] = { + [DF_TSState] = {NamedFieldKind::Text, "TSSTATE", 1, 0, get_tsstate_text}, + [DF_ASState] = {NamedFieldKind::Text, "ASSTATE", 1, 0, get_asstate_text}, + [DF_ActiveMission] = {NamedFieldKind::Text, "MISSION", 1, 0, get_mission_text}, - [DF_R2DProgress] = {DataFieldKind::Text, "R2DPROG", 1, 0, get_r2dprog_text}, - [DF_INVLReady] = {DataFieldKind::Bool, "INVLRDY", 0, 0, + [DF_R2DProgress] = {NamedFieldKind::Text, "R2DPROG", 1, 0, + get_r2dprog_text}, + [DF_INVLReady] = {NamedFieldKind::Bool, "INVLRDY", 0, 0, VEH_BIT_FIELD(errors.invl_ready)}, - [DF_INVRReady] = {DataFieldKind::Bool, "INVRRDY", 0, 0, + [DF_INVRReady] = {NamedFieldKind::Bool, "INVRRDY", 0, 0, VEH_BIT_FIELD(errors.invr_ready)}, - [DF_SDC] = {DataFieldKind::Text, "SDC", 0, 0, get_sdc_text}, - [DF_ERR] = {DataFieldKind::Text, "ERROR", 0, 0, get_err_text}, - [DF_IniChkState] = {DataFieldKind::Text, "ICSTATE", 1, 0, get_inichk_text}, - [DF_LapCount] = {DataFieldKind::Int, "LAPS", 3, 0, VEH_FIELD(lap_count)}, - [DF_TireTempFL] = {DataFieldKind::Float, "TTFL", 2, 1, + [DF_SDC] = {NamedFieldKind::Text, "SDC", 0, 0, get_sdc_text}, + [DF_ERR] = {NamedFieldKind::Text, "ERROR", 0, 0, get_err_text}, + [DF_IniChkState] = {NamedFieldKind::Text, "ICSTATE", 1, 0, get_inichk_text}, + [DF_LapCount] = {NamedFieldKind::Int, "LAPS", 3, 0, VEH_FIELD(lap_count)}, + [DF_TireTempFL] = {NamedFieldKind::Float, "TTFL", 2, 1, VEH_FIELD(tire_temps.fl)}, - [DF_TireTempFR] = {DataFieldKind::Float, "TTFR", 2, 1, + [DF_TireTempFR] = {NamedFieldKind::Float, "TTFR", 2, 1, VEH_FIELD(tire_temps.fr)}, - [DF_TireTempRL] = {DataFieldKind::Float, "TTRL", 2, 1, + [DF_TireTempRL] = {NamedFieldKind::Float, "TTRL", 2, 1, VEH_FIELD(tire_temps.rl)}, - [DF_TireTempRR] = {DataFieldKind::Float, "TTRR", 2, 1, + [DF_TireTempRR] = {NamedFieldKind::Float, "TTRR", 2, 1, VEH_FIELD(tire_temps.rr)}, - [DF_MinCellVolt] = {DataFieldKind::Float, "VMIN", 1, 2, + [DF_MinCellVolt] = {NamedFieldKind::Float, "VMIN", 1, 2, VEH_FIELD(min_cell_volt)}, - [DF_MaxCellTemp] = {DataFieldKind::Float, "TMAX", 2, 1, + [DF_MaxCellTemp] = {NamedFieldKind::Float, "TMAX", 2, 1, VEH_FIELD(max_cell_temp)}, - [DF_TSSoC] = {DataFieldKind::Int, "TSSOC", 3, 0, VEH_FIELD(soc)}, - [DF_LVSoC] = {DataFieldKind::Float, "LVSOC", 3, 0, get_zero}, - [DF_TSCurrent] = {DataFieldKind::Float, "ITS", 3, 0, VEH_FIELD(ts_current)}, - [DF_TSVoltageBat] = {DataFieldKind::Float, "TSVBAT", 3, 1, + [DF_TSSoC] = {NamedFieldKind::Int, "TSSOC", 3, 0, VEH_FIELD(soc)}, + [DF_LVSoC] = {NamedFieldKind::Float, "LVSOC", 3, 0, get_zero}, + [DF_TSCurrent] = {NamedFieldKind::Float, "ITS", 3, 0, + VEH_FIELD(ts_current)}, + [DF_TSVoltageBat] = {NamedFieldKind::Float, "TSVBAT", 3, 1, VEH_FIELD(ts_voltage_bat)}, - [DF_TSVoltageVeh] = {DataFieldKind::Float, "TSVVEH", 3, 1, + [DF_TSVoltageVeh] = {NamedFieldKind::Float, "TSVVEH", 3, 1, VEH_FIELD(ts_voltage_veh)}, - [DF_Speed] = {DataFieldKind::Float, "SPEED", 3, 0, get_zero}, - [DF_BBal] = {DataFieldKind::Float, "BBAL", 3, 1, get_zero}, + [DF_Speed] = {NamedFieldKind::Float, "SPEED", 3, 0, get_zero}, + [DF_BBal] = {NamedFieldKind::Float, "BBAL", 3, 1, get_zero}, }; static_assert(sizeof(dataFieldDescs) / sizeof(dataFieldDescs[0]) == DataFieldType_COUNT, "Incorrect number of data field descriptions"); -void DataField::setType(DataFieldType type) { +template +NamedField::NamedField(const NamedFieldDescription *fieldDescs) + : fieldDescs{fieldDescs} {} + +template void NamedField::setType(T type) { this->type = type; - desc = &dataFieldDescs[type]; + desc = &fieldDescs[type]; touchgfx::Unicode::strncpy(titleBuffer, desc->title, sizeof(titleBuffer) / sizeof(*titleBuffer)); @@ -285,48 +291,48 @@ void DataField::setType(DataFieldType type) { updateValue(); } -void DataField::updateValue() { +template void NamedField::updateValue() { void *val = desc->getValue(); switch (desc->kind) { - case DataFieldKind::Float: + case NamedFieldKind::Float: setFloatValue(*static_cast(val)); break; - case DataFieldKind::Bool: + case NamedFieldKind::Bool: setBoolValue(*static_cast(val)); break; - case DataFieldKind::Text: + case NamedFieldKind::Text: setStrValue(static_cast(val)); break; - case DataFieldKind::Int: + case NamedFieldKind::Int: setIntValue(*static_cast(val)); break; } } -void DataField::setFloatValue(float floatValue) { +template void NamedField::setFloatValue(float floatValue) { fieldValue.f = floatValue; updateValueBuffer(); } -void DataField::setBoolValue(int boolValue) { +template void NamedField::setBoolValue(int boolValue) { fieldValue.b = boolValue; updateValueBuffer(); } -void DataField::setIntValue(int intValue) { +template void NamedField::setIntValue(int intValue) { fieldValue.i = intValue; updateValueBuffer(); } -void DataField::setStrValue(const char *strValue) { +template void NamedField::setStrValue(const char *strValue) { touchgfx::Unicode::strncpy(valueBuffer, strValue, sizeof(valueBuffer) / sizeof(*valueBuffer)); updateValueBuffer(); } -void DataField::updateValueBuffer() { +template void NamedField::updateValueBuffer() { switch (desc->kind) { - case DataFieldKind::Float: { + case NamedFieldKind::Float: { size_t width = desc->int_digits; if (desc->decimal_digits != 0) { width += desc->decimal_digits + 1; // 1 digit for the decimal point @@ -337,16 +343,16 @@ void DataField::updateValueBuffer() { params); break; } - case DataFieldKind::Bool: { + case NamedFieldKind::Bool: { const char *str = fieldValue.b ? "YES" : "NO"; touchgfx::Unicode::strncpy(valueBuffer, str, sizeof(valueBuffer) / sizeof(*valueBuffer)); break; } - case DataFieldKind::Text: + case NamedFieldKind::Text: // This is handled by the child class in setValue() break; - case DataFieldKind::Int: + case NamedFieldKind::Int: touchgfx::Unicode::snprintf(valueBuffer, sizeof(valueBuffer) / sizeof(*valueBuffer), "%*d", desc->int_digits, fieldValue.i); @@ -354,3 +360,5 @@ void DataField::updateValueBuffer() { } valueBufferUpdated(); } + +template class NamedField; diff --git a/TouchGFX/gui/src/containers/DebugViewItem.cpp b/TouchGFX/gui/src/containers/DebugViewItem.cpp index 8e0e212..b996bf1 100644 --- a/TouchGFX/gui/src/containers/DebugViewItem.cpp +++ b/TouchGFX/gui/src/containers/DebugViewItem.cpp @@ -1,6 +1,6 @@ #include -DebugViewItem::DebugViewItem() {} +DebugViewItem::DebugViewItem() : NamedField(dataFieldDescs) {} void DebugViewItem::initialize() { DebugViewItemBase::initialize(); } diff --git a/TouchGFX/gui/src/containers/DebugViewLine.cpp b/TouchGFX/gui/src/containers/DebugViewLine.cpp index 6a6da29..7808738 100644 --- a/TouchGFX/gui/src/containers/DebugViewLine.cpp +++ b/TouchGFX/gui/src/containers/DebugViewLine.cpp @@ -1,4 +1,4 @@ -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include "touchgfx/Color.hpp" #include diff --git a/TouchGFX/gui/src/containers/DriverViewField.cpp b/TouchGFX/gui/src/containers/DriverViewField.cpp index 4a1ce19..1dee30e 100644 --- a/TouchGFX/gui/src/containers/DriverViewField.cpp +++ b/TouchGFX/gui/src/containers/DriverViewField.cpp @@ -1,11 +1,11 @@ -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include "texts/TextKeysAndLanguages.hpp" #include "touchgfx/Color.hpp" #include "touchgfx/TypedText.hpp" #include "touchgfx/Unicode.hpp" #include -DriverViewField::DriverViewField() {} +DriverViewField::DriverViewField() : NamedField(dataFieldDescs) {} void DriverViewField::initialize() { DriverViewFieldBase::initialize(); } @@ -17,12 +17,12 @@ void DriverViewField::setSelected(int selected) { void DriverViewField::typeUpdated() { switch (desc->kind) { - case DataFieldKind::Float: - case DataFieldKind::Int: + case NamedFieldKind::Float: + case NamedFieldKind::Int: value.setTypedText(T_NUMBERWILDCARD); break; - case DataFieldKind::Bool: - case DataFieldKind::Text: + case NamedFieldKind::Bool: + case NamedFieldKind::Text: value.setTypedText(T_DEFAULTWILDCARD_CENTERED); break; } diff --git a/TouchGFX/gui/src/debugview_screen/DebugViewView.cpp b/TouchGFX/gui/src/debugview_screen/DebugViewView.cpp index 3496856..54c4cf6 100644 --- a/TouchGFX/gui/src/debugview_screen/DebugViewView.cpp +++ b/TouchGFX/gui/src/debugview_screen/DebugViewView.cpp @@ -1,4 +1,4 @@ -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include DebugViewView::DebugViewView() {} diff --git a/TouchGFX/gui/src/driverview_screen/DriverViewPresenter.cpp b/TouchGFX/gui/src/driverview_screen/DriverViewPresenter.cpp index 7e815fe..72fe026 100644 --- a/TouchGFX/gui/src/driverview_screen/DriverViewPresenter.cpp +++ b/TouchGFX/gui/src/driverview_screen/DriverViewPresenter.cpp @@ -1,7 +1,7 @@ #include #include -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include "vehicle.h" DriverViewPresenter::DriverViewPresenter(DriverViewView &v) diff --git a/TouchGFX/gui/src/driverview_screen/DriverViewView.cpp b/TouchGFX/gui/src/driverview_screen/DriverViewView.cpp index 0ce8ff9..b9238dc 100644 --- a/TouchGFX/gui/src/driverview_screen/DriverViewView.cpp +++ b/TouchGFX/gui/src/driverview_screen/DriverViewView.cpp @@ -1,4 +1,4 @@ -#include "gui/common/DataField.hpp" +#include "gui/common/NamedField.hpp" #include "gui/containers/DriverViewField.hpp" #include "gui/driverview_screen/DriverViewPresenter.hpp" #include "texts/TextKeysAndLanguages.hpp" diff --git a/TouchGFX/simulator/msvs/Application.vcxproj b/TouchGFX/simulator/msvs/Application.vcxproj index 3a8f012..fd60202 100644 --- a/TouchGFX/simulator/msvs/Application.vcxproj +++ b/TouchGFX/simulator/msvs/Application.vcxproj @@ -36,7 +36,6 @@ - @@ -46,6 +45,7 @@ + @@ -211,7 +211,6 @@ - @@ -221,6 +220,7 @@ + diff --git a/TouchGFX/simulator/msvs/Application.vcxproj.filters b/TouchGFX/simulator/msvs/Application.vcxproj.filters index 1336d28..a55f59d 100644 --- a/TouchGFX/simulator/msvs/Application.vcxproj.filters +++ b/TouchGFX/simulator/msvs/Application.vcxproj.filters @@ -309,9 +309,6 @@ Source Files\generated\gui_generated\containers - - Source Files\gui\common - Source Files\gui\containers @@ -339,6 +336,9 @@ Source Files\generated\gui_generated\containers + + Source Files\gui\common + @@ -826,9 +826,6 @@ Header Files\generated\gui_generated\containers - - Header Files\gui\common - Header Files\gui\containers @@ -856,6 +853,9 @@ Header Files\generated\gui_generated\containers + + Header Files\gui\common +