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;
|
||||
|
||||
// Decoration settings bitmask to detect updates
|
||||
uint8_t decorationSettings = 0;
|
||||
uint8_t decorationSettings = 255;
|
||||
|
||||
// Last time we refreshed the window
|
||||
uint32_t lastRefresh = 0;
|
||||
|
||||
@@ -66,6 +66,13 @@ void ViewMainDecoration::setSlidersVisible(bool visible)
|
||||
sliders[SLIDERS_EXT2]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (visible) {
|
||||
visibilityMask |= VM_SLIDERS;
|
||||
}
|
||||
else {
|
||||
visibilityMask &= ~VM_SLIDERS;
|
||||
}
|
||||
}
|
||||
|
||||
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_RV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
|
||||
if (visible) {
|
||||
visibilityMask |= VM_TRIMS;
|
||||
}
|
||||
else {
|
||||
visibilityMask &= ~VM_TRIMS;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewMainDecoration::setFlightModeVisible(bool visible)
|
||||
{
|
||||
flightMode->setHeight(visible ? FM_LABEL_HEIGHT : 0);
|
||||
|
||||
if (visible) {
|
||||
visibilityMask |= VM_FM;
|
||||
}
|
||||
else {
|
||||
visibilityMask &= ~VM_FM;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewMainDecoration::adjustDecoration()
|
||||
@@ -191,13 +212,14 @@ void ViewMainDecoration::adjustDecoration()
|
||||
|
||||
rect_t ViewMainDecoration::getMainZone() const
|
||||
{
|
||||
coord_t border = (getVisibilityMask() == VM_NONE ?
|
||||
0 : MAIN_ZONE_BORDER);
|
||||
rect_t zone = {
|
||||
trims[TRIMS_LV]->right() + MAIN_ZONE_BORDER,
|
||||
/*topbar->bottom() +*/ MAIN_ZONE_BORDER,
|
||||
trims[TRIMS_LV]->right() + border, border,
|
||||
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())
|
||||
if (trims[TRIMS_LH]->top() < flightMode->top())
|
||||
@@ -205,7 +227,7 @@ rect_t ViewMainDecoration::getMainZone() const
|
||||
else
|
||||
zone.h = flightMode->top();
|
||||
|
||||
zone.h -= MAIN_ZONE_BORDER + zone.y;
|
||||
zone.h -= border + zone.y;
|
||||
|
||||
return zone;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,19 @@ class ViewMainDecoration: public Window
|
||||
// (without decoration)
|
||||
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:
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
@@ -78,6 +91,7 @@ class ViewMainDecoration: public Window
|
||||
Window* sliders[SLIDERS_MAX];
|
||||
Window* trims[TRIMS_MAX];
|
||||
Window* flightMode;
|
||||
unsigned visibilityMask = VM_NONE;
|
||||
|
||||
void createSliders();
|
||||
void createTrims();
|
||||
|
||||
@@ -128,7 +128,6 @@ WidgetSettings::WidgetSettings(Window * parent, Widget * widget) :
|
||||
break;
|
||||
|
||||
case ZoneOption::Color:
|
||||
for (uint8_t part = 0; part < 3; part++)
|
||||
new ColorEdit(form, grid.getFieldSlot(),
|
||||
[=]() -> int { // getValue
|
||||
return (int) widget->getOptionValue(optIdx)->unsignedValue;
|
||||
|
||||
@@ -1888,8 +1888,10 @@ const luaR_value_entry opentxConstants[] = {
|
||||
{ "TITLE_BGCOLOR", COLOR2FLAGS(TITLE_BGCOLOR_INDEX) },
|
||||
|
||||
// Synonyms of the above colors
|
||||
{ "TEXT_COLOR", COLOR2FLAGS(DEFAULT_COLOR_INDEX) },
|
||||
{ "TEXT_BGCOLOR", COLOR2FLAGS(DEFAULT_BGCOLOR_INDEX) },
|
||||
|
||||
{ "WARNING_COLOR", COLOR2FLAGS(HIGHLIGHT_COLOR_INDEX) },
|
||||
|
||||
{ "WHITE", (double)WHITE },
|
||||
{ "GREY", (double)GREY },
|
||||
{ "DARKGREY", (double)DARKGREY },
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#define MANUAL_SCRIPTS_MAX_INSTRUCTIONS (20000/100)
|
||||
#define LUA_WARNING_INFO_LEN 64
|
||||
|
||||
constexpr int LUA_WIDGET_REFRESH = 1000 / 10; // 10 Hz
|
||||
|
||||
lua_State * lsWidgets = NULL;
|
||||
|
||||
extern int custom_lua_atpanic(lua_State *L);
|
||||
@@ -177,6 +179,13 @@ class LuaWidget: public Widget
|
||||
free(errorMessage);
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
{
|
||||
return "LuaWidget";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Window interface
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
@@ -191,7 +200,9 @@ class LuaWidget: public Widget
|
||||
protected:
|
||||
int luaWidgetDataRef;
|
||||
char * errorMessage;
|
||||
uint32_t lastRefresh = 0;
|
||||
|
||||
void checkEvents() override;
|
||||
void setErrorMessage(const char * funcName);
|
||||
};
|
||||
|
||||
@@ -253,6 +264,21 @@ class LuaWidgetFactory: public WidgetFactory
|
||||
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)
|
||||
{
|
||||
refresh(dc);
|
||||
|
||||
Reference in New Issue
Block a user