83 lines
2.1 KiB
C++

#ifndef NAMEDFIELD_HPP
#define NAMEDFIELD_HPP
#include "params.h"
#include "touchgfx/TypedText.hpp"
#include "touchgfx/Unicode.hpp"
#include <stddef.h>
#include <stdint.h>
#include "util.h"
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, DF_BPF, DF_BPR, DF_DistanceTotal, DF_TempMotL,
DF_TempMotR, DF_TempInvL, DF_TempInvR, DF_TempBrakeFL,
DF_TempBrakeFR, DF_TempBrakeRL, DF_TempBrakeRR, DF_LapBest,
DF_LapLast, DF_LVBatVoltage);
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[];
extern DataFieldType dataFieldByAlphaIndex[];
extern size_t dataFieldAlphaIndexByField[];
extern ParamType paramByAlphaIndex[];
extern size_t paramAlphaIndexByParam[];
void namedFieldSort();
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();
};
void *get_r2dprog_text();
#endif // NAMEDFIELD_HPP