summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-19 12:44:44 +1000
committerjacqueline <me@jacqueline.id.au>2024-04-19 12:44:44 +1000
commit727847017d02741d6ff14a0e03db239593902c5f (patch)
tree7afa1ac70e89d0386be48750d7bf12a815b8623c
parent7f630cebddcf6d0b8a31632af7ed617f4173a6e1 (diff)
downloadtangara-fw-727847017d02741d6ff14a0e03db239593902c5f.tar.gz
Add a button to update the samd's firmware
-rw-r--r--lua/settings.lua52
-rw-r--r--src/lua/lua_version.cpp8
2 files changed, 60 insertions, 0 deletions
diff --git a/lua/settings.lua b/lua/settings.lua
index 7059a02d..cb7f65e0 100644
--- a/lua/settings.lua
+++ b/lua/settings.lua
@@ -403,6 +403,38 @@ local DatabaseSettings = SettingsScreen:new {
end
}
+local SamdConfirmation = SettingsScreen:new {
+ title = "Are you sure?",
+ createUi = function(self)
+ SettingsScreen.createUi(self)
+ self.content:Label {
+ w = lvgl.PCT(100),
+ text = "After selecting 'flash', copy the new UF2 file onto the USB drive that appears. The screen will be blank until the update is finished.",
+ long_mode = lvgl.LABEL.LONG_WRAP,
+ }
+
+ local button_container = self.content:Object {
+ w = lvgl.PCT(100),
+ h = lvgl.SIZE_CONTENT,
+ flex = {
+ flex_direction = "row",
+ justify_content = "center",
+ align_items = "space-evenly",
+ align_content = "center",
+ },
+ pad_top = 4,
+ pad_column = 4,
+ }
+ button_container:add_style(styles.list_item)
+
+ local update = button_container:Button {}
+ update:Label { text = "Flash" }
+ update:onClicked(function()
+ require("version").update_samd()
+ end)
+ end
+}
+
local FirmwareSettings = SettingsScreen:new {
title = "Firmware",
createUi = function(self)
@@ -411,6 +443,26 @@ local FirmwareSettings = SettingsScreen:new {
widgets.Row(self.content, "ESP32", version.esp())
widgets.Row(self.content, "SAMD21", version.samd())
widgets.Row(self.content, "Collator", version.collator())
+
+ local button_container = self.content:Object {
+ w = lvgl.PCT(100),
+ h = lvgl.SIZE_CONTENT,
+ flex = {
+ flex_direction = "row",
+ justify_content = "center",
+ align_items = "space-evenly",
+ align_content = "center",
+ },
+ pad_top = 4,
+ pad_column = 4,
+ }
+ button_container:add_style(styles.list_item)
+
+ local update = button_container:Button {}
+ update:Label { text = "Update SAMD21" }
+ update:onClicked(function()
+ backstack.push(SamdConfirmation:new())
+ end)
end
}
diff --git a/src/lua/lua_version.cpp b/src/lua/lua_version.cpp
index c1098a1b..e5f06bb5 100644
--- a/src/lua/lua_version.cpp
+++ b/src/lua/lua_version.cpp
@@ -34,6 +34,13 @@ static auto samd(lua_State* L) -> int {
return 1;
}
+static auto update_samd(lua_State* L) -> int {
+ Bridge* instance = Bridge::Get(L);
+ auto& samd = instance->services().samd();
+ samd.ResetToFlashSamd();
+ return 0;
+}
+
static auto collator(lua_State* L) -> int {
Bridge* instance = Bridge::Get(L);
auto& collator = instance->services().collator();
@@ -45,6 +52,7 @@ static auto collator(lua_State* L) -> int {
static const struct luaL_Reg kVersionFuncs[] = {{"esp", esp},
{"samd", samd},
{"collator", collator},
+ {"update_samd", update_samd},
{NULL, NULL}};
static auto lua_version(lua_State* L) -> int {