From 1af65969ed71ffee5df9f3bedf07185e8790020e Mon Sep 17 00:00:00 2001 From: jfrickmann Date: Fri, 27 Aug 2021 22:21:37 -0400 Subject: [PATCH] Color options for Lua widget get translated to Lua color flags To support new color encoding in Lua widgets --- radio/src/lua/api_colorlcd.cpp | 2 +- radio/src/lua/api_colorlcd.h | 2 ++ radio/src/lua/widgets.cpp | 14 +++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/radio/src/lua/api_colorlcd.cpp b/radio/src/lua/api_colorlcd.cpp index 7be6b70d0..36a776ffa 100644 --- a/radio/src/lua/api_colorlcd.cpp +++ b/radio/src/lua/api_colorlcd.cpp @@ -54,7 +54,7 @@ static int8_t getTextVerticalOffset(LcdFlags flags) } // Return flags with RGB color value instead of indexed theme color -static LcdFlags flagsRGB(LcdFlags flags) +LcdFlags flagsRGB(LcdFlags flags) { // RGB or indexed color? if (flags & RGB_FLAG) diff --git a/radio/src/lua/api_colorlcd.h b/radio/src/lua/api_colorlcd.h index e6fa79859..74c53e183 100644 --- a/radio/src/lua/api_colorlcd.h +++ b/radio/src/lua/api_colorlcd.h @@ -39,3 +39,5 @@ constexpr int8_t text_vertical_offset[7] {2,2,0,2,3,3,7}; extern bool luaLcdAllowed; extern BitmapBuffer * luaLcdBuffer; + +LcdFlags flagsRGB(LcdFlags flags); \ No newline at end of file diff --git a/radio/src/lua/widgets.cpp b/radio/src/lua/widgets.cpp index de41a0a9b..f40ee50ed 100644 --- a/radio/src/lua/widgets.cpp +++ b/radio/src/lua/widgets.cpp @@ -177,12 +177,16 @@ ZoneOption * createOptionsArray(int reference, uint8_t maxOptions) // TRACE("default signed = %d", option->deflt.signedValue); } else if (option->type == ZoneOption::Source || - option->type == ZoneOption::TextSize || - option->type == ZoneOption::Color) { + option->type == ZoneOption::TextSize) { luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number option->deflt.unsignedValue = lua_tounsigned(lsWidgets, -1); // TRACE("default unsigned = %u", option->deflt.unsignedValue); } + else if (option->type == ZoneOption::Color) { + luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number + option->deflt.unsignedValue = COLOR_VAL(flagsRGB(lua_tounsigned(lsWidgets, -1))); + // TRACE("default unsigned = %u", option->deflt.unsignedValue); + } else if (option->type == ZoneOption::Bool) { luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number option->deflt.boolValue = (lua_tounsigned(lsWidgets, -1) != 0); @@ -418,7 +422,11 @@ void LuaWidget::update() lua_newtable(lsWidgets); int i = 0; for (const ZoneOption * option = getOptions(); option->name; option++, i++) { - l_pushtableint(option->name, persistentData->options[i].value.signedValue); + int32_t value = persistentData->options[i].value.signedValue; + if (option->type == ZoneOption::Color) + l_pushtableint(option->name, COLOR2FLAGS(value) | RGB_FLAG); + else + l_pushtableint(option->name, value); } if (lua_pcall(lsWidgets, 2, 0, 0) != 0) {