Skip to content

Commit

Permalink
Add QRCode class and Lvgl widget for Lua scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Jun 23, 2024
1 parent 54aaf0a commit 5a40f6c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 7 deletions.
11 changes: 4 additions & 7 deletions radio/src/gui/colorlcd/view_about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ const std::string edgetx_url = "https://edgetx.org";
AboutUs::AboutUs() :
BaseDialog(MainWindow::instance(), STR_ABOUT_US, true, 220, LV_SIZE_CONTENT)
{
new StaticText(form, rect_t{0, 0, LV_PCT(100), LV_SIZE_CONTENT},
new StaticText(form, {0, 0, LV_PCT(100), LV_SIZE_CONTENT},
about_str + "\n" + copyright_str,
COLOR_THEME_SECONDARY1 | CENTERED);

auto qrBox = new Window(form, {0, 0, LV_PCT(100), 160});
auto qr = lv_qrcode_create(qrBox->getLvObj(), 150,
makeLvColor(COLOR_THEME_SECONDARY1),
makeLvColor(COLOR_THEME_SECONDARY3));
lv_qrcode_update(qr, edgetx_url.c_str(), edgetx_url.length());
lv_obj_center(qr);
auto qrBox = new Window(form, {0, 0, LV_PCT(100), QR_SZ});
auto qr = new QRCode(qrBox, 0, 0, QR_SZ, edgetx_url);
lv_obj_center(qr->getLvObj());
}
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/view_about.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ class AboutUs : public BaseDialog
{
public:
AboutUs();

static LAYOUT_VAL(QR_SZ, 150, 150)
};
8 changes: 8 additions & 0 deletions radio/src/lua/api_colorlcd_lvgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ static int luaLvglImage(lua_State *L)
return luaLvglObj(L, [=]() { return new LvglWidgetImage(); });
}

static int luaLvglQRCode(lua_State *L)
{
return luaLvglObj(L, [=]() { return new LvglWidgetQRCode(); });
}

static int luaLvglMeter(lua_State *L)
{
return luaLvglObj(L, [=]() { return new LvglWidgetMeter(); });
Expand Down Expand Up @@ -217,6 +222,8 @@ static void buildLvgl(lua_State *L, int srcIndex, int refIndex)
lvobj = new LvglWidgetArc();
else if (strcasecmp(p.type, "image") == 0)
lvobj = new LvglWidgetImage();
else if (strcasecmp(p.type, "qrcode") == 0)
lvobj = new LvglWidgetQRCode();
else if (strcasecmp(p.type, "meter") == 0)
lvobj = new LvglWidgetMeter();
else if (!luaLvglManager->isWidget()) {
Expand Down Expand Up @@ -280,6 +287,7 @@ LROT_FUNCENTRY(rectangle, luaLvglRectangle)
LROT_FUNCENTRY(circle, luaLvglCircle)
LROT_FUNCENTRY(arc, luaLvglArc)
LROT_FUNCENTRY(image, luaLvglImage)
LROT_FUNCENTRY(qrcode, luaLvglQRCode)
LROT_FUNCENTRY(meter, luaLvglMeter)
LROT_FUNCENTRY(button, luaLvglButton)
LROT_FUNCENTRY(toggle, luaLvglToggle)
Expand Down
16 changes: 16 additions & 0 deletions radio/src/lua/lua_lvgl_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,22 @@ void LvglWidgetImage::build(lua_State *L)

//-----------------------------------------------------------------------------

void LvglWidgetQRCode::parseParam(lua_State *L, const char *key)
{
if (!strcmp(key, "data")) {
data = luaL_checkstring(L, -1);
} else {
LvglWidgetObject::parseParam(L, key);
}
}

void LvglWidgetQRCode::build(lua_State *L)
{
window = new QRCode(lvglManager->getCurrentParent(), x, y, w, data);
}

//-----------------------------------------------------------------------------

class LvglWidgetScaleIndicator : public LvglWidgetObjectBase
{
public:
Expand Down
15 changes: 15 additions & 0 deletions radio/src/lua/lua_lvgl_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ class LvglWidgetImage : public LvglWidgetObject

//-----------------------------------------------------------------------------

class LvglWidgetQRCode : public LvglWidgetObject
{
public:
LvglWidgetQRCode() : LvglWidgetObject() {}

void build(lua_State *L) override;

protected:
std::string data;

void parseParam(lua_State *L, const char *key) override;
};

//-----------------------------------------------------------------------------

class LvglWidgetMeterScale;

class LvglWidgetMeter : public LvglWidgetRoundObject
Expand Down
11 changes: 11 additions & 0 deletions radio/src/thirdparty/libopenui/src/static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,14 @@ void StaticLZ4Image::deleteLater(bool detach, bool trash)
Window::deleteLater(detach, trash);
}
}

//-----------------------------------------------------------------------------

QRCode::QRCode(Window *parent, coord_t x, coord_t y, coord_t sz, std::string data) :
Window(parent, {x, y, sz, sz})
{
auto qr = lv_qrcode_create(lvobj, sz,
makeLvColor(COLOR_THEME_SECONDARY1),
makeLvColor(COLOR_THEME_SECONDARY3));
lv_qrcode_update(qr, data.c_str(), data.length());
}
18 changes: 18 additions & 0 deletions radio/src/thirdparty/libopenui/src/static.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class StaticImage : public Window
lv_obj_t *image = nullptr;
};

//-----------------------------------------------------------------------------

class StaticBitmap : public Window
{
public:
Expand All @@ -183,6 +185,8 @@ class StaticBitmap : public Window
BitmapBuffer *img = nullptr;
};

//-----------------------------------------------------------------------------

class StaticLZ4Image : public Window
{
public:
Expand All @@ -198,3 +202,17 @@ class StaticLZ4Image : public Window

void deleteLater(bool detach, bool trash) override;
};

//-----------------------------------------------------------------------------

class QRCode : public Window
{
public:
QRCode(Window *parent, coord_t x, coord_t y, coord_t sz, std::string data);

#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "QRCode"; }
#endif

protected:
};

0 comments on commit 5a40f6c

Please sign in to comment.