YAML storage (#7071)

YAML storage
This commit is contained in:
Raphael Coeffic
2019-11-12 14:50:05 +01:00
committed by Bertrand Songis
parent bb2ca31dad
commit 8b4d2b698d
69 changed files with 5577 additions and 425 deletions
+6 -6
View File
@@ -41,8 +41,8 @@ class Layout1x1: public Layout
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
persistentData->options[1].boolValue = true;
persistentData->options[0] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[1] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
}
unsigned int getZonesCount() const override
@@ -53,11 +53,11 @@ class Layout1x1: public Layout
Zone getZone(unsigned int index) const override
{
Zone zone = { 10, 10, LCD_W - 2*10, LCD_H - 2*10 };
if (persistentData->options[0].boolValue) {
if (persistentData->options[0].value.boolValue) {
zone.y += MENU_HEADER_HEIGHT;
zone.h -= MENU_HEADER_HEIGHT;
}
if (persistentData->options[1].boolValue) {
if (persistentData->options[1].value.boolValue) {
zone.x += 35;
zone.w -= 2*35;
zone.h -= 35;
@@ -72,11 +72,11 @@ class Layout1x1: public Layout
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// if (persistentData->options[0].value.boolValue) {
// drawTopBar();
// }
//
// if (persistentData->options[1].boolValue) {
// if (persistentData->options[1].value.boolValue) {
// // Sliders + Trims + Flight mode
// lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name, sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | FONT(XS)) / 2,
// 232,
+8 -8
View File
@@ -49,10 +49,10 @@ class Layout2P1: public Layout
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
persistentData->options[1].boolValue = true;
persistentData->options[2].boolValue = true;
persistentData->options[3].boolValue = true;
persistentData->options[0] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[1] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[2] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[3] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
}
unsigned int getZonesCount() const override
@@ -72,11 +72,11 @@ class Layout2P1: public Layout
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// if (persistentData->options[0].value.boolValue) {
// drawTopBar();
// }
//
// if (persistentData->options[1].boolValue) {
// if (persistentData->options[1].value.boolValue) {
// // Flight mode
// lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
@@ -86,12 +86,12 @@ class Layout2P1: public Layout
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | FONT(XS));
// }
//
// if (persistentData->options[2].boolValue) {
// if (persistentData->options[2].value.boolValue) {
// // Pots and rear sliders positions
// drawMainPots();
// }
//
// if (persistentData->options[3].boolValue) {
// if (persistentData->options[3].value.boolValue) {
// // Trims
// drawTrims(mixerCurrentFlightMode);
// }
+3 -3
View File
@@ -40,7 +40,7 @@ class Layout2x1: public Layout
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
persistentData->options[0] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
}
unsigned int getZonesCount() const override
@@ -53,7 +53,7 @@ class Layout2x1: public Layout
Zone zone;
zone.w = (LCD_W-3*10) / 2;
zone.x = (index & 1) ? 20 + zone.w : 10;
if (persistentData->options[0].boolValue) {
if (persistentData->options[0].value.boolValue) {
zone.h = (LCD_H-MENU_HEADER_HEIGHT-2*10);
zone.y = MENU_HEADER_HEIGHT + 10;
}
@@ -71,7 +71,7 @@ class Layout2x1: public Layout
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// if (persistentData->options[0].value.boolValue) {
// drawTopBar();
// }
//
+3 -3
View File
@@ -40,7 +40,7 @@ class Layout2x2: public Layout
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
persistentData->options[0] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
}
unsigned int getZonesCount() const override
@@ -53,7 +53,7 @@ class Layout2x2: public Layout
Zone zone;
zone.w = (LCD_W-3*10) / 2;
zone.x = (index & 1) ? 20 + zone.w : 10;
if (persistentData->options[0].boolValue) {
if (persistentData->options[0].value.boolValue) {
zone.h = (LCD_H-MENU_HEADER_HEIGHT-3*10) / 2;
zone.y = MENU_HEADER_HEIGHT + 10;
}
@@ -74,7 +74,7 @@ class Layout2x2: public Layout
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// if (persistentData->options[0].value.boolValue) {
// drawTopBar();
// }
//
+16 -16
View File
@@ -47,14 +47,14 @@ class Layout2x4: public Layout
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
persistentData->options[1].boolValue = true;
persistentData->options[2].boolValue = true;
persistentData->options[3].boolValue = true;
persistentData->options[4].boolValue = true;
persistentData->options[5].unsignedValue = RGB(77, 112, 203);
persistentData->options[6].boolValue = false;
persistentData->options[7].unsignedValue = RGB(77, 112, 203);
persistentData->options[0] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[1] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[2] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[3] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[4] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[5] = ZoneOptionValueTyped { ZOV_Unsigned, OPTION_VALUE_UNSIGNED( RGB(77,112,203)) };
persistentData->options[6] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) };
persistentData->options[7] = ZoneOptionValueTyped { ZOV_Unsigned, OPTION_VALUE_UNSIGNED( RGB(77,112,203)) };
}
unsigned int getZonesCount() const override
@@ -79,11 +79,11 @@ class Layout2x4: public Layout
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// if (persistentData->options[0].value.boolValue) {
// drawTopBar();
// }
//
// if (persistentData->options[1].boolValue) {
// if (persistentData->options[1].value.boolValue) {
// // Flight mode
// lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
@@ -93,23 +93,23 @@ class Layout2x4: public Layout
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | FONT(XS));
// }
//
// if (persistentData->options[2].boolValue) {
// if (persistentData->options[2].value.boolValue) {
// // Pots and rear sliders positions
// drawMainPots();
// }
//
// if (persistentData->options[3].boolValue) {
// if (persistentData->options[3].value.boolValue) {
// // Trims
// drawTrims(mixerCurrentFlightMode);
// }
//
// if (persistentData->options[4].boolValue) {
// lcdSetColor(persistentData->options[5].unsignedValue);
// if (persistentData->options[4].value.boolValue) {
// lcdSetColor(persistentData->options[5].value.unsignedValue);
// lcdDrawSolidFilledRect(50, 50, 180, 170, CUSTOM_COLOR);
// }
//
// if (persistentData->options[6].boolValue) {
// lcdSetColor(persistentData->options[7].unsignedValue);
// if (persistentData->options[6].value.boolValue) {
// lcdSetColor(persistentData->options[7].value.unsignedValue);
// lcdDrawSolidFilledRect(250, 50, 180, 170, CUSTOM_COLOR);
// }
//
+3 -2
View File
@@ -53,7 +53,8 @@ void ThemeBase::init() const
int i = 0;
for (const ZoneOption * option = options; option->name; option++, i++) {
// TODO compiler bug? The CPU freezes ... g_eeGeneral.themeData.options[i] = &option->deflt;
memcpy(&g_eeGeneral.themeData.options[i], &option->deflt, sizeof(ZoneOptionValue));
memcpy(&g_eeGeneral.themeData.options[i].value, &option->deflt, sizeof(ZoneOptionValue));
g_eeGeneral.themeData.options[i].type = zoneValueEnumFromType(option->type);
}
}
}
@@ -70,7 +71,7 @@ void ThemeBase::load() const
ZoneOptionValue * ThemeBase::getOptionValue(unsigned int index) const
{
return &g_eeGeneral.themeData.options[index];
return &g_eeGeneral.themeData.options[index].value;
}
const char * ThemeBase::getFilePath(const char * filename) const
+7 -2
View File
@@ -34,11 +34,16 @@ class PageTab;
class ThemeBase;
void registerTheme(ThemeBase * theme);
// YAML_GENERATOR defs
#if !defined(USE_IDX)
#define USE_IDX
#endif
class ThemeBase: public Theme
{
public:
struct PersistentData {
ZoneOptionValue options[MAX_THEME_OPTIONS];
ZoneOptionValueTyped options[MAX_THEME_OPTIONS] USE_IDX;
};
ThemeBase(const char * name, const ZoneOption * options = nullptr):
@@ -79,7 +84,7 @@ class ThemeBase: public Theme
virtual void drawMenuHeader(BitmapBuffer * dc, std::vector<PageTab *> & tabs, uint8_t currentIndex) const = 0;
virtual void drawMessageBox(const char * title, const char * text, const char * action, uint32_t flags) const;
virtual void drawMessageBox(const char * title, const char * text, const char * action, uint32_t flags) const override;
// virtual void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const = 0;
void drawCheckBox(BitmapBuffer * dc, bool checked, coord_t x, coord_t y, bool focus) const override;
+2 -2
View File
@@ -337,7 +337,7 @@ class FlyskyTheme: public ThemeBase
dc->drawBitmap(0, 0, backgroundBitmap);
}
else {
lcdSetColor(g_eeGeneral.themeData.options[0].unsignedValue);
lcdSetColor(g_eeGeneral.themeData.options[0].value.unsignedValue);
dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, CUSTOM_COLOR);
}
}
@@ -441,4 +441,4 @@ FlyskyTheme flyskyTheme;
#if defined(PCBFLYSKY)
ThemeBase * defaultTheme = &flyskyTheme;
Theme * theme = &flyskyTheme;
#endif
#endif
+3 -3
View File
@@ -287,8 +287,8 @@ class FrskyTheme: public ThemeBase
{
TRACE("TODO THEME::UPDATE()");
#if 0
uint32_t color = g_eeGeneral.themeData.options[1].unsignedValue;
uint32_t bg_color = UNEXPECTED_SHUTDOWN() ? WHITE : g_eeGeneral.themeData.options[0].unsignedValue;
uint32_t color = g_eeGeneral.themeData.options[1].value.unsignedValue;
uint32_t bg_color = UNEXPECTED_SHUTDOWN() ? WHITE : g_eeGeneral.themeData.options[0].value.unsignedValue;
lcdColorTable[DEFAULT_BGCOLOR_INDEX] = bg_color;
lcdColorTable[FOCUS_BGCOLOR_INDEX] = color;
@@ -316,7 +316,7 @@ class FrskyTheme: public ThemeBase
dc->drawBitmap(0, 0, backgroundBitmap);
}
else {
lcdSetColor(g_eeGeneral.themeData.options[0].unsignedValue);
lcdSetColor(g_eeGeneral.themeData.options[0].value.unsignedValue);
dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, CUSTOM_COLOR);
}
}
+10 -3
View File
@@ -24,15 +24,21 @@
#include <list>
#include <string.h>
#include "zone.h"
#include "debug.h"
#define MAX_WIDGET_OPTIONS 5
// YAML_GENERATOR defs
#if !defined(USE_IDX)
#define USE_IDX
#endif
class WidgetFactory;
class Widget
{
public:
struct PersistentData {
ZoneOptionValue options[MAX_WIDGET_OPTIONS];
ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS] USE_IDX;
};
Widget(const WidgetFactory * factory, const Zone & zone, PersistentData * persistentData):
@@ -64,7 +70,7 @@ class Widget
inline ZoneOptionValue * getOptionValue(unsigned int index) const
{
return &persistentData->options[index];
return &persistentData->options[index].value;
}
virtual void refresh() = 0;
@@ -109,7 +115,8 @@ class WidgetFactory
for (const ZoneOption * option = options; option->name; option++) {
TRACE("WidgetFactory::initPersistentData() setting option '%s'", option->name);
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
memcpy(&persistentData->options[i++], &option->deflt, sizeof(ZoneOptionValue));
memcpy(&persistentData->options[i++].value, &option->deflt, sizeof(ZoneOptionValue));
persistentData->options[i++].type = zoneValueEnumFromType(option->type);
}
}
}
+4 -4
View File
@@ -43,10 +43,10 @@ const ZoneOption GaugeWidget::options[] = {
void GaugeWidget::refresh()
{
mixsrc_t index = persistentData->options[0].unsignedValue;
int32_t min = persistentData->options[1].signedValue;
int32_t max = persistentData->options[2].signedValue;
uint16_t color = persistentData->options[3].unsignedValue;
mixsrc_t index = persistentData->options[0].value.unsignedValue;
int32_t min = persistentData->options[1].value.signedValue;
int32_t max = persistentData->options[2].value.signedValue;
uint16_t color = persistentData->options[3].value.unsignedValue;
int32_t value = getValue(index);
int32_t value_in_range = value;
+12 -3
View File
@@ -73,13 +73,22 @@ class OutputsWidget: public Widget
void twoColumns()
{
uint8_t endColumn = drawChannels(zone.x, zone.y, zone.w / 2, zone.h, persistentData->options[0].unsignedValue, persistentData->options[1].boolValue, persistentData->options[2].unsignedValue);
drawChannels(zone.x + zone.w / 2 + 2, zone.y, zone.w / 2, zone.h, endColumn + 1, persistentData->options[1].boolValue, persistentData->options[2].unsignedValue);
uint8_t endColumn = drawChannels(zone.x, zone.y, zone.w / 2, zone.h,
persistentData->options[0].value.unsignedValue,
persistentData->options[1].value.boolValue,
persistentData->options[2].value.unsignedValue);
drawChannels(zone.x + zone.w / 2 + 2, zone.y, zone.w / 2, zone.h, endColumn + 1,
persistentData->options[1].value.boolValue,
persistentData->options[2].value.unsignedValue);
}
void oneColumn()
{
drawChannels(zone.x, zone.y, zone.w, zone.h, persistentData->options[0].unsignedValue, persistentData->options[1].boolValue, persistentData->options[2].unsignedValue);
drawChannels(zone.x, zone.y, zone.w, zone.h,
persistentData->options[0].value.unsignedValue,
persistentData->options[1].value.boolValue,
persistentData->options[2].value.unsignedValue);
}
static const ZoneOption options[];
+11 -5
View File
@@ -45,12 +45,18 @@ const ZoneOption TextWidget::options[] = {
void TextWidget::refresh()
{
lcdSetColor(persistentData->options[1].unsignedValue);
LcdFlags fontsize = FONTSIZE(persistentData->options[2].unsignedValue << 8);
if(persistentData->options[3].boolValue) {
lcdDrawSizedText(zone.x+1, zone.y+1, persistentData->options[0].stringValue, sizeof(persistentData->options[0].stringValue), ZCHAR|fontsize|BLACK);
lcdSetColor(persistentData->options[1].value.unsignedValue);
LcdFlags fontsize = FONTSIZE(persistentData->options[2].value.unsignedValue << 8);
if(persistentData->options[3].value.boolValue) {
lcdDrawSizedText(zone.x+1, zone.y+1,
persistentData->options[0].value.stringValue,
sizeof(persistentData->options[0].value.stringValue),
ZCHAR|fontsize|BLACK);
}
lcdDrawSizedText(zone.x, zone.y, persistentData->options[0].stringValue, sizeof(persistentData->options[0].stringValue), ZCHAR|fontsize|CUSTOM_COLOR);
lcdDrawSizedText(zone.x, zone.y,
persistentData->options[0].value.stringValue,
sizeof(persistentData->options[0].value.stringValue),
ZCHAR|fontsize|CUSTOM_COLOR);
}
BaseWidgetFactory<TextWidget> textWidget("Text", TextWidget::options);
+1 -1
View File
@@ -40,7 +40,7 @@ const ZoneOption TimerWidget::options[] = {
void TimerWidget::refresh()
{
uint32_t index = persistentData->options[0].unsignedValue;
uint32_t index = persistentData->options[0].value.unsignedValue;
TimerData & timerData = g_model.timers[index];
TimerState & timerState = timersStates[index];
+3 -3
View File
@@ -44,8 +44,8 @@ void ValueWidget::refresh()
{
const int NUMBERS_PADDING = 4;
mixsrc_t field = persistentData->options[0].unsignedValue;
lcdSetColor(persistentData->options[1].unsignedValue);
mixsrc_t field = persistentData->options[0].value.unsignedValue;
lcdSetColor(persistentData->options[1].value.unsignedValue);
int x = zone.x;
int y = zone.y;
@@ -112,7 +112,7 @@ void ValueWidget::refresh()
}
}
if(persistentData->options[2].boolValue) {
if(persistentData->options[2].value.boolValue) {
drawSource(xLabel + 1, yLabel + 1, field, attrLabel|BLACK);
drawSourceValue(xValue + 1, yValue + 1, field, attrValue|BLACK);
}
+3 -3
View File
@@ -59,8 +59,8 @@ class WidgetsContainer: public WidgetsContainerInterface
};
struct PersistentData {
ZonePersistentData zones[N];
ZoneOptionValue options[O];
ZonePersistentData zones[N];
ZoneOptionValueTyped options[O];
};
public:
@@ -120,7 +120,7 @@ class WidgetsContainer: public WidgetsContainerInterface
inline ZoneOptionValue * getOptionValue(unsigned int index) const
{
return &persistentData->options[index];
return &persistentData->options[index].value;
}
virtual unsigned int getZonesCount() const = 0;
+46 -8
View File
@@ -3,19 +3,20 @@
#define _ZONE_H_
#include <inttypes.h>
#include "storage/yaml/yaml_defs.h"
#define LEN_ZONE_OPTION_STRING 8
#if defined(_MSC_VER)
#define OPTION_VALUE_UNSIGNED(x) uint32_t(x)
#define OPTION_VALUE_SIGNED(x) uint32_t(x)
#define OPTION_VALUE_BOOL(x) bool(x)
#define OPTION_VALUE_STRING(...) *(ZoneOptionValue *)(const char *) #__VA_ARGS__
#define OPTION_VALUE_UNSIGNED(x) { uint32_t(x) }
#define OPTION_VALUE_SIGNED(x) { uint32_t(x) }
#define OPTION_VALUE_BOOL(x) { bool(x) }
#define OPTION_VALUE_STRING(...) { *(ZoneOptionValue *)(const char *) #__VA_ARGS__ }
#else
#define OPTION_VALUE_UNSIGNED(x) { .unsignedValue = (x) }
#define OPTION_VALUE_SIGNED(x) { .signedValue = (x) }
#define OPTION_VALUE_BOOL(x) { .boolValue = (x) }
#define OPTION_VALUE_STRING(...) { .stringValue = {__VA_ARGS__} }
#define OPTION_VALUE_UNSIGNED(x) { .unsignedValue = (x) }
#define OPTION_VALUE_SIGNED(x) { .signedValue = (x) }
#define OPTION_VALUE_BOOL(x) { .boolValue = (x) }
#define OPTION_VALUE_STRING(...) { .stringValue = { __VA_ARGS__ } }
#endif
struct Zone
@@ -31,6 +32,13 @@ union ZoneOptionValue
char stringValue[LEN_ZONE_OPTION_STRING];
};
enum ZoneOptionValueEnum {
ZOV_Unsigned=0,
ZOV_Signed,
ZOV_Bool,
ZOV_String
};
struct ZoneOption
{
enum Type {
@@ -52,4 +60,34 @@ struct ZoneOption
ZoneOptionValue max;
};
struct ZoneOptionValueTyped
{
ZoneOptionValueEnum type;
ZoneOptionValue value FUNC(select_zov);
};
inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type)
{
switch(type) {
case ZoneOption::File:
case ZoneOption::String:
return ZOV_String;
case ZoneOption::Integer:
return ZOV_Signed;
case ZoneOption::Bool:
return ZOV_Bool;
case ZoneOption::Color:
case ZoneOption::Timer:
case ZoneOption::Switch:
case ZoneOption::Source:
case ZoneOption::TextSize:
default:
return ZOV_Unsigned;
}
}
#endif