78 lines
2.2 KiB
C++
78 lines
2.2 KiB
C++
#ifndef NAMEDFIELD_HPP
|
|
#define NAMEDFIELD_HPP
|
|
|
|
#include "touchgfx/TypedText.hpp"
|
|
#include "touchgfx/Unicode.hpp"
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
// We want to automatically count the number of data field types for the
|
|
// description array. This is wacky preprocessor magic that allows us to do just
|
|
// that. Unfortunately, it doesn't work with enum classes, so we have to use
|
|
// C-style enums.
|
|
#define CountedEnum(NAME, TYPE, ...) \
|
|
enum NAME : TYPE { __VA_ARGS__ }; \
|
|
constexpr size_t NAME##_COUNT = sizeof((int[]){__VA_ARGS__}) / sizeof(int);
|
|
|
|
CountedEnum(DataFieldType, size_t, DF_TSState, DF_ASState, DF_ActiveMission,
|
|
DF_R2DProgress, DF_INVLReady, DF_INVRReady, DF_SDC, DF_ERR,
|
|
DF_IniChkState, DF_LapCount, DF_TireTempFL, DF_TireTempFR,
|
|
DF_TireTempRL, DF_TireTempRR, DF_MinCellVolt, DF_MaxCellTemp,
|
|
DF_TSSoC, DF_LVSoC, DF_TSCurrent, DF_TSVoltageBat, DF_TSVoltageVeh,
|
|
DF_Speed, DF_BBal);
|
|
CountedEnum(ParamFieldType, size_t, PF_BBAL, PF_TC1, PF_TC2, PF_TORQUEMAP,
|
|
PF_TEST1, PF_TEST2, PF_TEST3, PF_TEST4);
|
|
|
|
enum class NamedFieldKind { Float, Bool, Text, Int };
|
|
|
|
struct NamedFieldDescription {
|
|
NamedFieldKind kind;
|
|
const char *title;
|
|
size_t int_digits;
|
|
size_t decimal_digits;
|
|
|
|
void *(*getValue)(void);
|
|
};
|
|
|
|
extern NamedFieldDescription dataFieldDescs[];
|
|
extern NamedFieldDescription paramFieldDescs[];
|
|
|
|
template <class T> class NamedField {
|
|
public:
|
|
NamedField(const NamedFieldDescription *fieldDescs);
|
|
virtual ~NamedField() {}
|
|
|
|
void setType(T type);
|
|
const T &getType();
|
|
|
|
virtual void updateValue();
|
|
|
|
protected:
|
|
const NamedFieldDescription *fieldDescs;
|
|
|
|
touchgfx::Unicode::UnicodeChar titleBuffer[16];
|
|
touchgfx::Unicode::UnicodeChar valueBuffer[16];
|
|
|
|
T type;
|
|
const NamedFieldDescription *desc;
|
|
union {
|
|
float f;
|
|
int b;
|
|
int i;
|
|
} fieldValue;
|
|
|
|
virtual void typeUpdated() = 0;
|
|
virtual void titleBufferUpdated() = 0;
|
|
virtual void valueBufferUpdated() = 0;
|
|
|
|
private:
|
|
void setFloatValue(float floatValue);
|
|
void setBoolValue(int boolValue);
|
|
void setIntValue(int intValue);
|
|
void setStrValue(const char *strValue);
|
|
|
|
void updateValueBuffer();
|
|
};
|
|
|
|
#endif // NAMEDFIELD_HPP
|