Make DriverView fields more modular
This commit is contained in:
36
TouchGFX/gui/include/gui/common/DataField.hpp
Normal file
36
TouchGFX/gui/include/gui/common/DataField.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef DATAFIELD_HPP
|
||||
#define DATAFIELD_HPP
|
||||
|
||||
#include "touchgfx/TypedText.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);
|
||||
|
||||
enum class DataFieldKind { Numeric, Bool, Text };
|
||||
|
||||
struct DataFieldDescription {
|
||||
DataFieldKind kind;
|
||||
touchgfx::TypedText title;
|
||||
size_t int_digits;
|
||||
size_t decimal_digits;
|
||||
|
||||
void* (*getValue)(void);
|
||||
};
|
||||
|
||||
extern DataFieldDescription dataFieldDescs[];
|
||||
|
||||
#endif // DATAFIELD_HPP
|
||||
@ -5,6 +5,8 @@
|
||||
#include "touchgfx/Unicode.hpp"
|
||||
#include <gui_generated/containers/DriverViewFieldBase.hpp>
|
||||
|
||||
#include "gui/common/DataField.hpp"
|
||||
|
||||
class DriverViewField : public DriverViewFieldBase {
|
||||
public:
|
||||
DriverViewField();
|
||||
@ -12,16 +14,20 @@ public:
|
||||
|
||||
virtual void initialize();
|
||||
|
||||
void setName(const touchgfx::TypedText &text);
|
||||
void setType(const DataFieldDescription &desc);
|
||||
void setValue(float newValue);
|
||||
void setPrecision(size_t intDigits, size_t decimalDigits);
|
||||
void setValue(const char *str);
|
||||
void setValue(int boolValue);
|
||||
|
||||
protected:
|
||||
private:
|
||||
Unicode::UnicodeChar valueBuffer[16];
|
||||
|
||||
DataFieldKind fieldKind;
|
||||
size_t intDigits;
|
||||
size_t decimalDigits;
|
||||
float fieldValue;
|
||||
float floatValue;
|
||||
int boolValue;
|
||||
|
||||
void updateValueBuffer();
|
||||
};
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
#include <gui/model/ModelListener.hpp>
|
||||
#include <mvp/Presenter.hpp>
|
||||
|
||||
#include "gui/common/DataField.hpp"
|
||||
|
||||
using namespace touchgfx;
|
||||
|
||||
class DriverViewView;
|
||||
@ -33,6 +35,8 @@ private:
|
||||
DriverViewPresenter();
|
||||
|
||||
DriverViewView &view;
|
||||
|
||||
DataFieldType fields[3];
|
||||
};
|
||||
|
||||
#endif // DRIVERVIEWPRESENTER_HPP
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#ifndef DRIVERVIEWVIEW_HPP
|
||||
#define DRIVERVIEWVIEW_HPP
|
||||
|
||||
#include "gui/common/DataField.hpp"
|
||||
#include "vehicle.h"
|
||||
#include <gui/driverview_screen/DriverViewPresenter.hpp>
|
||||
#include <gui_generated/driverview_screen/DriverViewViewBase.hpp>
|
||||
@ -12,11 +13,17 @@ public:
|
||||
virtual void setupScreen();
|
||||
virtual void tearDownScreen();
|
||||
|
||||
void setFieldType(size_t i, const DataFieldDescription &desc);
|
||||
void setFieldValue(size_t i, float value);
|
||||
void setFieldValue(size_t i, const char *value);
|
||||
void setFieldValue(size_t i, int value);
|
||||
|
||||
void setTireTemps(const TireTemps &temps);
|
||||
void setTSSoC(uint8_t soc);
|
||||
void setMinCellVolt(float v);
|
||||
|
||||
protected:
|
||||
private:
|
||||
DriverViewField &getField(size_t i);
|
||||
};
|
||||
|
||||
#endif // DRIVERVIEWVIEW_HPP
|
||||
|
||||
Reference in New Issue
Block a user