DataField -> NamedField<FieldType>

This commit is contained in:
Jasper Blanckenburg 2023-04-04 18:31:06 +02:00
parent 8d701669e4
commit 09f65fcf22
16 changed files with 94 additions and 81 deletions

View File

@ -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 \

View File

@ -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 T> 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

View File

@ -1,10 +1,11 @@
#ifndef DEBUGVIEWITEM_HPP
#define DEBUGVIEWITEM_HPP
#include "gui/common/DataField.hpp"
#include "gui/common/NamedField.hpp"
#include <gui_generated/containers/DebugViewItemBase.hpp>
class DebugViewItem : public DebugViewItemBase, public DataField {
class DebugViewItem : public DebugViewItemBase,
public NamedField<DataFieldType> {
public:
DebugViewItem();
virtual ~DebugViewItem() {}

View File

@ -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 <gui_generated/containers/DebugViewLineBase.hpp>

View File

@ -5,9 +5,10 @@
#include "touchgfx/Unicode.hpp"
#include <gui_generated/containers/DriverViewFieldBase.hpp>
#include "gui/common/DataField.hpp"
#include "gui/common/NamedField.hpp"
class DriverViewField : public DriverViewFieldBase, public DataField {
class DriverViewField : public DriverViewFieldBase,
public NamedField<DataFieldType> {
public:
DriverViewField();
virtual ~DriverViewField() {}

View File

@ -4,7 +4,7 @@
#include <gui/model/ModelListener.hpp>
#include <mvp/Presenter.hpp>
#include "gui/common/DataField.hpp"
#include "gui/common/NamedField.hpp"
using namespace touchgfx;

View File

@ -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"

View File

@ -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 <class T>
NamedField<T>::NamedField(const NamedFieldDescription *fieldDescs)
: fieldDescs{fieldDescs} {}
template <class T> void NamedField<T>::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 <class T> void NamedField<T>::updateValue() {
void *val = desc->getValue();
switch (desc->kind) {
case DataFieldKind::Float:
case NamedFieldKind::Float:
setFloatValue(*static_cast<float *>(val));
break;
case DataFieldKind::Bool:
case NamedFieldKind::Bool:
setBoolValue(*static_cast<int *>(val));
break;
case DataFieldKind::Text:
case NamedFieldKind::Text:
setStrValue(static_cast<const char *>(val));
break;
case DataFieldKind::Int:
case NamedFieldKind::Int:
setIntValue(*static_cast<int *>(val));
break;
}
}
void DataField::setFloatValue(float floatValue) {
template <class T> void NamedField<T>::setFloatValue(float floatValue) {
fieldValue.f = floatValue;
updateValueBuffer();
}
void DataField::setBoolValue(int boolValue) {
template <class T> void NamedField<T>::setBoolValue(int boolValue) {
fieldValue.b = boolValue;
updateValueBuffer();
}
void DataField::setIntValue(int intValue) {
template <class T> void NamedField<T>::setIntValue(int intValue) {
fieldValue.i = intValue;
updateValueBuffer();
}
void DataField::setStrValue(const char *strValue) {
template <class T> void NamedField<T>::setStrValue(const char *strValue) {
touchgfx::Unicode::strncpy(valueBuffer, strValue,
sizeof(valueBuffer) / sizeof(*valueBuffer));
updateValueBuffer();
}
void DataField::updateValueBuffer() {
template <class T> void NamedField<T>::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<DataFieldType>;

View File

@ -1,6 +1,6 @@
#include <gui/containers/DebugViewItem.hpp>
DebugViewItem::DebugViewItem() {}
DebugViewItem::DebugViewItem() : NamedField(dataFieldDescs) {}
void DebugViewItem::initialize() { DebugViewItemBase::initialize(); }

View File

@ -1,4 +1,4 @@
#include "gui/common/DataField.hpp"
#include "gui/common/NamedField.hpp"
#include "touchgfx/Color.hpp"
#include <gui/containers/DebugViewLine.hpp>

View File

@ -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 <gui/containers/DriverViewField.hpp>
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;
}

View File

@ -1,4 +1,4 @@
#include "gui/common/DataField.hpp"
#include "gui/common/NamedField.hpp"
#include <gui/debugview_screen/DebugViewView.hpp>
DebugViewView::DebugViewView() {}

View File

@ -1,7 +1,7 @@
#include <gui/driverview_screen/DriverViewPresenter.hpp>
#include <gui/driverview_screen/DriverViewView.hpp>
#include "gui/common/DataField.hpp"
#include "gui/common/NamedField.hpp"
#include "vehicle.h"
DriverViewPresenter::DriverViewPresenter(DriverViewView &v)

View File

@ -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"

View File

@ -36,7 +36,6 @@
<ClCompile Include="..\..\generated\gui_generated\src\containers\TireTempBase.cpp"/>
<ClCompile Include="..\..\gui\src\containers\DriverViewField.cpp"/>
<ClCompile Include="..\..\generated\gui_generated\src\containers\DriverViewFieldBase.cpp"/>
<ClCompile Include="..\..\gui\src\common\DataField.cpp"/>
<ClCompile Include="..\..\gui\src\containers\DriverViewFieldSelection.cpp"/>
<ClCompile Include="..\..\generated\gui_generated\src\containers\DriverViewFieldSelectionBase.cpp"/>
<ClCompile Include="..\..\gui\src\containers\DebugViewItem.cpp"/>
@ -46,6 +45,7 @@
<ClCompile Include="..\..\generated\gui_generated\src\debugview_screen\DebugViewViewBase.cpp"/>
<ClCompile Include="..\..\gui\src\containers\DebugViewLine.cpp"/>
<ClCompile Include="..\..\generated\gui_generated\src\containers\DebugViewLineBase.cpp"/>
<ClCompile Include="..\..\gui\src\common\NamedField.cpp"/>
</ItemGroup>
<ItemGroup>
<None Include="$(ApplicationRoot)\assets\texts\texts.xml"/>
@ -211,7 +211,6 @@
<ClInclude Include="..\..\generated\gui_generated\include\gui_generated\containers\TireTempBase.hpp"/>
<ClInclude Include="..\..\gui\include\gui\containers\DriverViewField.hpp"/>
<ClInclude Include="..\..\generated\gui_generated\include\gui_generated\containers\DriverViewFieldBase.hpp"/>
<ClInclude Include="..\..\gui\include\gui\common\DataField.hpp"/>
<ClInclude Include="..\..\gui\include\gui\containers\DriverViewFieldSelection.hpp"/>
<ClInclude Include="..\..\generated\gui_generated\include\gui_generated\containers\DriverViewFieldSelectionBase.hpp"/>
<ClInclude Include="..\..\gui\include\gui\containers\DebugViewItem.hpp"/>
@ -221,6 +220,7 @@
<ClInclude Include="..\..\generated\gui_generated\include\gui_generated\debugview_screen\DebugViewViewBase.hpp"/>
<ClInclude Include="..\..\gui\include\gui\containers\DebugViewLine.hpp"/>
<ClInclude Include="..\..\generated\gui_generated\include\gui_generated\containers\DebugViewLineBase.hpp"/>
<ClInclude Include="..\..\gui\include\gui\common\NamedField.hpp"/>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="$(ApplicationRoot)\generated\simulator\touchgfx.rc"/>

View File

@ -309,9 +309,6 @@
<ClCompile Include="..\..\generated\gui_generated\src\containers\DriverViewFieldBase.cpp">
<Filter>Source Files\generated\gui_generated\containers</Filter>
</ClCompile>
<ClCompile Include="..\..\gui\src\common\DataField.cpp">
<Filter>Source Files\gui\common</Filter>
</ClCompile>
<ClCompile Include="..\..\gui\src\containers\DriverViewFieldSelection.cpp">
<Filter>Source Files\gui\containers</Filter>
</ClCompile>
@ -339,6 +336,9 @@
<ClCompile Include="..\..\generated\gui_generated\src\containers\DebugViewLineBase.cpp">
<Filter>Source Files\generated\gui_generated\containers</Filter>
</ClCompile>
<ClCompile Include="..\..\gui\src\common\NamedField.cpp">
<Filter>Source Files\gui\common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="$(ApplicationRoot)\assets\texts\texts.xml">
@ -826,9 +826,6 @@
<ClInclude Include="..\..\generated\gui_generated\include\gui_generated\containers\DriverViewFieldBase.hpp">
<Filter>Header Files\generated\gui_generated\containers</Filter>
</ClInclude>
<ClInclude Include="..\..\gui\include\gui\common\DataField.hpp">
<Filter>Header Files\gui\common</Filter>
</ClInclude>
<ClInclude Include="..\..\gui\include\gui\containers\DriverViewFieldSelection.hpp">
<Filter>Header Files\gui\containers</Filter>
</ClInclude>
@ -856,6 +853,9 @@
<ClInclude Include="..\..\generated\gui_generated\include\gui_generated\containers\DebugViewLineBase.hpp">
<Filter>Header Files\generated\gui_generated\containers</Filter>
</ClInclude>
<ClInclude Include="..\..\gui\include\gui\common\NamedField.hpp">
<Filter>Header Files\gui\common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="$(ApplicationRoot)\generated\simulator\touchgfx.rc">