Fixed various issues while running "teckel12/LuaTelemetry" widget
This commit is contained in:
committed by
Raphael Coeffic
parent
9b648a14e4
commit
f0f6a1e093
@@ -101,7 +101,7 @@ class Layout: public LayoutBase
|
|||||||
ViewMainDecoration* decoration = nullptr;
|
ViewMainDecoration* decoration = nullptr;
|
||||||
|
|
||||||
// Decoration settings bitmask to detect updates
|
// Decoration settings bitmask to detect updates
|
||||||
uint8_t decorationSettings = 0;
|
uint8_t decorationSettings = 255;
|
||||||
|
|
||||||
// Last time we refreshed the window
|
// Last time we refreshed the window
|
||||||
uint32_t lastRefresh = 0;
|
uint32_t lastRefresh = 0;
|
||||||
|
|||||||
@@ -66,6 +66,13 @@ void ViewMainDecoration::setSlidersVisible(bool visible)
|
|||||||
sliders[SLIDERS_EXT2]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
sliders[SLIDERS_EXT2]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
visibilityMask |= VM_SLIDERS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
visibilityMask &= ~VM_SLIDERS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewMainDecoration::setTrimsVisible(bool visible)
|
void ViewMainDecoration::setTrimsVisible(bool visible)
|
||||||
@@ -75,11 +82,25 @@ void ViewMainDecoration::setTrimsVisible(bool visible)
|
|||||||
|
|
||||||
trims[TRIMS_LV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
trims[TRIMS_LV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||||
trims[TRIMS_RV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
trims[TRIMS_RV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
visibilityMask |= VM_TRIMS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
visibilityMask &= ~VM_TRIMS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewMainDecoration::setFlightModeVisible(bool visible)
|
void ViewMainDecoration::setFlightModeVisible(bool visible)
|
||||||
{
|
{
|
||||||
flightMode->setHeight(visible ? FM_LABEL_HEIGHT : 0);
|
flightMode->setHeight(visible ? FM_LABEL_HEIGHT : 0);
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
visibilityMask |= VM_FM;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
visibilityMask &= ~VM_FM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewMainDecoration::adjustDecoration()
|
void ViewMainDecoration::adjustDecoration()
|
||||||
@@ -191,13 +212,14 @@ void ViewMainDecoration::adjustDecoration()
|
|||||||
|
|
||||||
rect_t ViewMainDecoration::getMainZone() const
|
rect_t ViewMainDecoration::getMainZone() const
|
||||||
{
|
{
|
||||||
|
coord_t border = (getVisibilityMask() == VM_NONE ?
|
||||||
|
0 : MAIN_ZONE_BORDER);
|
||||||
rect_t zone = {
|
rect_t zone = {
|
||||||
trims[TRIMS_LV]->right() + MAIN_ZONE_BORDER,
|
trims[TRIMS_LV]->right() + border, border,
|
||||||
/*topbar->bottom() +*/ MAIN_ZONE_BORDER,
|
|
||||||
0, 0 // let's compute them!
|
0, 0 // let's compute them!
|
||||||
};
|
};
|
||||||
|
|
||||||
zone.w = trims[TRIMS_RV]->left() - MAIN_ZONE_BORDER - zone.x;
|
zone.w = trims[TRIMS_RV]->left() - border - zone.x;
|
||||||
|
|
||||||
// min(trims[TRIMS_LH]->top(), flightMode->top())
|
// min(trims[TRIMS_LH]->top(), flightMode->top())
|
||||||
if (trims[TRIMS_LH]->top() < flightMode->top())
|
if (trims[TRIMS_LH]->top() < flightMode->top())
|
||||||
@@ -205,7 +227,7 @@ rect_t ViewMainDecoration::getMainZone() const
|
|||||||
else
|
else
|
||||||
zone.h = flightMode->top();
|
zone.h = flightMode->top();
|
||||||
|
|
||||||
zone.h -= MAIN_ZONE_BORDER + zone.y;
|
zone.h -= border + zone.y;
|
||||||
|
|
||||||
return zone;
|
return zone;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,19 @@ class ViewMainDecoration: public Window
|
|||||||
// (without decoration)
|
// (without decoration)
|
||||||
rect_t getMainZone() const;
|
rect_t getMainZone() const;
|
||||||
|
|
||||||
|
enum VisibilityMask {
|
||||||
|
VM_NONE = 0,
|
||||||
|
VM_TRIMS = 1 << 0,
|
||||||
|
VM_SLIDERS = 1 << 1,
|
||||||
|
VM_FM = 1 << 2,
|
||||||
|
VM_ALL = VM_TRIMS | VM_SLIDERS | VM_FM,
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned getVisibilityMask() const
|
||||||
|
{
|
||||||
|
return visibilityMask;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
@@ -78,6 +91,7 @@ class ViewMainDecoration: public Window
|
|||||||
Window* sliders[SLIDERS_MAX];
|
Window* sliders[SLIDERS_MAX];
|
||||||
Window* trims[TRIMS_MAX];
|
Window* trims[TRIMS_MAX];
|
||||||
Window* flightMode;
|
Window* flightMode;
|
||||||
|
unsigned visibilityMask = VM_NONE;
|
||||||
|
|
||||||
void createSliders();
|
void createSliders();
|
||||||
void createTrims();
|
void createTrims();
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ WidgetSettings::WidgetSettings(Window * parent, Widget * widget) :
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ZoneOption::Color:
|
case ZoneOption::Color:
|
||||||
for (uint8_t part = 0; part < 3; part++)
|
|
||||||
new ColorEdit(form, grid.getFieldSlot(),
|
new ColorEdit(form, grid.getFieldSlot(),
|
||||||
[=]() -> int { // getValue
|
[=]() -> int { // getValue
|
||||||
return (int) widget->getOptionValue(optIdx)->unsignedValue;
|
return (int) widget->getOptionValue(optIdx)->unsignedValue;
|
||||||
|
|||||||
@@ -1888,7 +1888,9 @@ const luaR_value_entry opentxConstants[] = {
|
|||||||
{ "TITLE_BGCOLOR", COLOR2FLAGS(TITLE_BGCOLOR_INDEX) },
|
{ "TITLE_BGCOLOR", COLOR2FLAGS(TITLE_BGCOLOR_INDEX) },
|
||||||
|
|
||||||
// Synonyms of the above colors
|
// Synonyms of the above colors
|
||||||
|
{ "TEXT_COLOR", COLOR2FLAGS(DEFAULT_COLOR_INDEX) },
|
||||||
{ "TEXT_BGCOLOR", COLOR2FLAGS(DEFAULT_BGCOLOR_INDEX) },
|
{ "TEXT_BGCOLOR", COLOR2FLAGS(DEFAULT_BGCOLOR_INDEX) },
|
||||||
|
{ "WARNING_COLOR", COLOR2FLAGS(HIGHLIGHT_COLOR_INDEX) },
|
||||||
|
|
||||||
{ "WHITE", (double)WHITE },
|
{ "WHITE", (double)WHITE },
|
||||||
{ "GREY", (double)GREY },
|
{ "GREY", (double)GREY },
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#define MANUAL_SCRIPTS_MAX_INSTRUCTIONS (20000/100)
|
#define MANUAL_SCRIPTS_MAX_INSTRUCTIONS (20000/100)
|
||||||
#define LUA_WARNING_INFO_LEN 64
|
#define LUA_WARNING_INFO_LEN 64
|
||||||
|
|
||||||
|
constexpr int LUA_WIDGET_REFRESH = 1000 / 10; // 10 Hz
|
||||||
|
|
||||||
lua_State * lsWidgets = NULL;
|
lua_State * lsWidgets = NULL;
|
||||||
|
|
||||||
extern int custom_lua_atpanic(lua_State *L);
|
extern int custom_lua_atpanic(lua_State *L);
|
||||||
@@ -177,6 +179,13 @@ class LuaWidget: public Widget
|
|||||||
free(errorMessage);
|
free(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(DEBUG_WINDOWS)
|
||||||
|
std::string getName() const override
|
||||||
|
{
|
||||||
|
return "LuaWidget";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Window interface
|
// Window interface
|
||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
|
|
||||||
@@ -191,7 +200,9 @@ class LuaWidget: public Widget
|
|||||||
protected:
|
protected:
|
||||||
int luaWidgetDataRef;
|
int luaWidgetDataRef;
|
||||||
char * errorMessage;
|
char * errorMessage;
|
||||||
|
uint32_t lastRefresh = 0;
|
||||||
|
|
||||||
|
void checkEvents() override;
|
||||||
void setErrorMessage(const char * funcName);
|
void setErrorMessage(const char * funcName);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -253,6 +264,21 @@ class LuaWidgetFactory: public WidgetFactory
|
|||||||
int backgroundFunction;
|
int backgroundFunction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void LuaWidget::checkEvents()
|
||||||
|
{
|
||||||
|
Widget::checkEvents();
|
||||||
|
|
||||||
|
uint32_t now = RTOS_GET_MS();
|
||||||
|
if (now - lastRefresh >= LUA_WIDGET_REFRESH) {
|
||||||
|
lastRefresh = now;
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
#if defined(DEBUG_WINDOWS)
|
||||||
|
TRACE_WINDOWS("# refresh: %s", getWindowDebugString().c_str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LuaWidget::paint(BitmapBuffer * dc)
|
void LuaWidget::paint(BitmapBuffer * dc)
|
||||||
{
|
{
|
||||||
refresh(dc);
|
refresh(dc);
|
||||||
|
|||||||
Reference in New Issue
Block a user