From ef72b25660912ff247997089abfb93e9f0b52809 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 7 Mar 2024 10:59:03 +1100 Subject: use prototype inheritance for lua screens, rather than functions this gives us a way to give each screen nice little hooks, like 'onShown' and 'onHidden'. later we can use these hooks to disable bindings for screens that aren't in-use. --- lua/settings.lua | 597 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 302 insertions(+), 295 deletions(-) (limited to 'lua/settings.lua') diff --git a/lua/settings.lua b/lua/settings.lua index 952292e4..9d9ccf2d 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -7,8 +7,7 @@ local display = require("display") local controls = require("controls") local bluetooth = require("bluetooth") local database = require("database") - -local settings = {} +local screen = require("screen") local function SettingsScreen(title) local menu = widgets.MenuScreen { @@ -31,323 +30,331 @@ local function SettingsScreen(title) return menu end -function settings.bluetooth() - local menu = SettingsScreen("Bluetooth") - - local enable_container = menu.content:Object { - flex = { - flex_direction = "row", - justify_content = "flex-start", - align_items = "content", - align_content = "flex-start", - }, - w = lvgl.PCT(100), - h = lvgl.SIZE_CONTENT, - pad_bottom = 1, - } - enable_container:Label { text = "Enable", flex_grow = 1 } - local enable_sw = enable_container:Switch {} - enable_sw:onevent(lvgl.EVENT.VALUE_CHANGED, function() - local enabled = enable_sw:enabled() - bluetooth.enabled:set(enabled) - end) - - menu.content:Label { - text = "Paired Device", - pad_bottom = 1, - }:add_style(theme.settings_title) - - local paired_container = menu.content:Object { - flex = { - flex_direction = "row", - justify_content = "flex-start", - align_items = "flex-start", - align_content = "flex-start", - }, - w = lvgl.PCT(100), - h = lvgl.SIZE_CONTENT, - pad_bottom = 2, - } - - local paired_device = paired_container:Label { - flex_grow = 1, - } - local clear_paired = paired_container:Button {} - clear_paired:Label { text = "x" } - clear_paired:onClicked(function() - bluetooth.paired_device:set() - end) - - menu.content:Label { - text = "Nearby Devices", - pad_bottom = 1, - }:add_style(theme.settings_title) - - local devices = menu.content:List { - w = lvgl.PCT(100), - h = lvgl.SIZE_CONTENT, - } - - menu.bindings = { - bluetooth.enabled:bind(function(en) - if en then - enable_sw:add_state(lvgl.STATE.CHECKED) - else - enable_sw:clear_state(lvgl.STATE.CHECKED) - end - end), - bluetooth.paired_device:bind(function(device) - if device then - paired_device:set { text = device.name } - clear_paired:clear_flag(lvgl.FLAG.HIDDEN) - else - paired_device:set { text = "None" } - clear_paired:add_flag(lvgl.FLAG.HIDDEN) - end - end), - bluetooth.devices:bind(function(devs) - devices:clean() - for _, dev in pairs(devs) do - devices:add_btn(nil, dev.name):onClicked(function() - bluetooth.paired_device:set(dev) - end) - end +local BluetoothSettings = screen:new { + createUi = function(self) + self.menu = SettingsScreen("Bluetooth") + + local enable_container = self.menu.content:Object { + flex = { + flex_direction = "row", + justify_content = "flex-start", + align_items = "content", + align_content = "flex-start", + }, + w = lvgl.PCT(100), + h = lvgl.SIZE_CONTENT, + pad_bottom = 1, + } + enable_container:Label { text = "Enable", flex_grow = 1 } + local enable_sw = enable_container:Switch {} + enable_sw:onevent(lvgl.EVENT.VALUE_CHANGED, function() + local enabled = enable_sw:enabled() + bluetooth.enabled:set(enabled) end) - } -end -function settings.headphones() - local menu = SettingsScreen("Headphones") + self.menu.content:Label { + text = "Paired Device", + pad_bottom = 1, + }:add_style(theme.settings_title) + + local paired_container = self.menu.content:Object { + flex = { + flex_direction = "row", + justify_content = "flex-start", + align_items = "flex-start", + align_content = "flex-start", + }, + w = lvgl.PCT(100), + h = lvgl.SIZE_CONTENT, + pad_bottom = 2, + } + + local paired_device = paired_container:Label { + flex_grow = 1, + } + local clear_paired = paired_container:Button {} + clear_paired:Label { text = "x" } + clear_paired:onClicked(function() + bluetooth.paired_device:set() + end) - menu.content:Label { - text = "Maximum volume limit", - }:add_style(theme.settings_title) + self.menu.content:Label { + text = "Nearby Devices", + pad_bottom = 1, + }:add_style(theme.settings_title) + + local devices = self.menu.content:List { + w = lvgl.PCT(100), + h = lvgl.SIZE_CONTENT, + } + + self.bindings = { + bluetooth.enabled:bind(function(en) + if en then + enable_sw:add_state(lvgl.STATE.CHECKED) + else + enable_sw:clear_state(lvgl.STATE.CHECKED) + end + end), + bluetooth.paired_device:bind(function(device) + if device then + paired_device:set { text = device.name } + clear_paired:clear_flag(lvgl.FLAG.HIDDEN) + else + paired_device:set { text = "None" } + clear_paired:add_flag(lvgl.FLAG.HIDDEN) + end + end), + bluetooth.devices:bind(function(devs) + devices:clean() + for _, dev in pairs(devs) do + devices:add_btn(nil, dev.name):onClicked(function() + bluetooth.paired_device:set(dev) + end) + end + end) + } + end +} + +local HeadphonesSettings = screen:new { + createUi = function(self) + self.menu = SettingsScreen("Headphones") + + self.menu.content:Label { + text = "Maximum volume limit", + }:add_style(theme.settings_title) + + local volume_chooser = self.menu.content:Dropdown { + options = "Line Level (-10 dB)\nCD Level (+6 dB)\nMaximum (+10dB)", + selected = 1, + } + local limits = { -10, 6, 10 } + volume_chooser:onevent(lvgl.EVENT.VALUE_CHANGED, function() + -- luavgl dropdown binding uses 0-based indexing :( + local selection = volume_chooser:get('selected') + 1 + volume.limit_db:set(limits[selection]) + end) - local volume_chooser = menu.content:Dropdown { - options = "Line Level (-10 dB)\nCD Level (+6 dB)\nMaximum (+10dB)", - selected = 1, - } - local limits = { -10, 6, 10 } - volume_chooser:onevent(lvgl.EVENT.VALUE_CHANGED, function() - -- luavgl dropdown binding uses 0-based indexing :( - local selection = volume_chooser:get('selected') + 1 - volume.limit_db:set(limits[selection]) - end) - - menu.content:Label { - text = "Left/Right balance", - }:add_style(theme.settings_title) - - local balance = menu.content:Slider { - w = lvgl.PCT(100), - h = 5, - range = { min = -100, max = 100 }, - value = 0, - } - balance:onevent(lvgl.EVENT.VALUE_CHANGED, function() - volume.left_bias:set(balance:value()) - end) + self.menu.content:Label { + text = "Left/Right balance", + }:add_style(theme.settings_title) + + local balance = self.menu.content:Slider { + w = lvgl.PCT(100), + h = 5, + range = { min = -100, max = 100 }, + value = 0, + } + balance:onevent(lvgl.EVENT.VALUE_CHANGED, function() + volume.left_bias:set(balance:value()) + end) - local balance_label = menu.content:Label {} + local balance_label = self.menu.content:Label {} - menu.bindings = { - volume.limit_db:bind(function(limit) - for i = 1, #limits do - if limits[i] == limit then - volume_chooser:set { selected = i - 1 } + self.bindings = { + volume.limit_db:bind(function(limit) + for i = 1, #limits do + if limits[i] == limit then + volume_chooser:set { selected = i - 1 } + end end - end - end), - volume.left_bias:bind(function(bias) - balance:set { - value = bias - } - if bias < 0 then - balance_label:set { - text = string.format("Left %.2fdB", bias / 4) + end), + volume.left_bias:bind(function(bias) + balance:set { + value = bias } - elseif bias > 0 then - balance_label:set { - text = string.format("Right %.2fdB", -bias / 4) - } - else - balance_label:set { text = "Balanced" } - end - end), - } - - return menu -end - -function settings.display() - local menu = SettingsScreen("Display") - - local brightness_title = menu.content:Object { - flex = { - flex_direction = "row", - justify_content = "flex-start", - align_items = "flex-start", - align_content = "flex-start", - }, - w = lvgl.PCT(100), - h = lvgl.SIZE_CONTENT, - } - brightness_title:Label { text = "Brightness", flex_grow = 1 } - local brightness_pct = brightness_title:Label {} - brightness_pct:add_style(theme.settings_title) - - local brightness = menu.content:Slider { - w = lvgl.PCT(100), - h = 5, - range = { min = 0, max = 100 }, - value = display.brightness:get(), - } - brightness:onevent(lvgl.EVENT.VALUE_CHANGED, function() - display.brightness:set(brightness:value()) - end) - - menu.bindings = { - display.brightness:bind(function(b) - brightness_pct:set { text = tostring(b) .. "%" } + if bias < 0 then + balance_label:set { + text = string.format("Left %.2fdB", bias / 4) + } + elseif bias > 0 then + balance_label:set { + text = string.format("Right %.2fdB", -bias / 4) + } + else + balance_label:set { text = "Balanced" } + end + end), + } + end +} + +local DisplaySettings = screen:new { + createUi = function(self) + self.menu = SettingsScreen("Display") + + local brightness_title = self.menu.content:Object { + flex = { + flex_direction = "row", + justify_content = "flex-start", + align_items = "flex-start", + align_content = "flex-start", + }, + w = lvgl.PCT(100), + h = lvgl.SIZE_CONTENT, + } + brightness_title:Label { text = "Brightness", flex_grow = 1 } + local brightness_pct = brightness_title:Label {} + brightness_pct:add_style(theme.settings_title) + + local brightness = self.menu.content:Slider { + w = lvgl.PCT(100), + h = 5, + range = { min = 0, max = 100 }, + value = display.brightness:get(), + } + brightness:onevent(lvgl.EVENT.VALUE_CHANGED, function() + display.brightness:set(brightness:value()) end) - } - return menu -end + self.bindings = { + display.brightness:bind(function(b) + brightness_pct:set { text = tostring(b) .. "%" } + end) + } + end +} -function settings.input() - local menu = SettingsScreen("Input Method") +local InputSettings = screen:new { + createUi = function(self) + self.menu = SettingsScreen("Input Method") - menu.content:Label { - text = "Control scheme", - }:add_style(theme.settings_title) + self.menu.content:Label { + text = "Control scheme", + }:add_style(theme.settings_title) - local schemes = controls.schemes() - local option_to_scheme = {} - local scheme_to_option = {} + local schemes = controls.schemes() + local option_to_scheme = {} + local scheme_to_option = {} - local option_idx = 0 - local options = "" + local option_idx = 0 + local options = "" - for i, v in pairs(schemes) do - option_to_scheme[option_idx] = i - scheme_to_option[i] = option_idx - if option_idx > 0 then - options = options .. "\n" + for i, v in pairs(schemes) do + option_to_scheme[option_idx] = i + scheme_to_option[i] = option_idx + if option_idx > 0 then + options = options .. "\n" + end + options = options .. v + option_idx = option_idx + 1 end - options = options .. v - option_idx = option_idx + 1 - end - - local controls_chooser = menu.content:Dropdown { - options = options, - } - menu.bindings = { - controls.scheme:bind(function(s) - local option = scheme_to_option[s] - controls_chooser:set({ selected = option }) + local controls_chooser = self.menu.content:Dropdown { + options = options, + } + + self.bindings = { + controls.scheme:bind(function(s) + local option = scheme_to_option[s] + controls_chooser:set({ selected = option }) + end) + } + + controls_chooser:onevent(lvgl.EVENT.VALUE_CHANGED, function() + local option = controls_chooser:get('selected') + local scheme = option_to_scheme[option] + controls.scheme:set(scheme) end) - } - - controls_chooser:onevent(lvgl.EVENT.VALUE_CHANGED, function() - local option = controls_chooser:get('selected') - local scheme = option_to_scheme[option] - controls.scheme:set(scheme) - end) - - menu.content:Label { - text = "Scroll Sensitivity", - }:add_style(theme.settings_title) - - local slider_scale = 4; -- Power steering - local sensitivity = menu.content:Slider { - w = lvgl.PCT(90), - h = 5, - range = { min = 0, max = 255/slider_scale }, - value = controls.scroll_sensitivity:get()/slider_scale, - } - sensitivity:onevent(lvgl.EVENT.VALUE_CHANGED, function() - controls.scroll_sensitivity:set(sensitivity:value()*slider_scale) - end) - - return menu -end - -function settings.database() - local menu = SettingsScreen("Database") - local db = require("database") - widgets.Row(menu.content, "Schema version", db.version()) - widgets.Row(menu.content, "Size on disk", string.format("%.1f KiB", db.size() / 1024)) - local actions_container = menu.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, - } - actions_container:add_style(theme.list_item) - - local update = actions_container:Button {} - update:Label { text = "Update" } - update:onClicked(function() - database.update() - end) -end - -function settings.firmware() - local menu = SettingsScreen("Firmware") - local version = require("version") - widgets.Row(menu.content, "ESP32", version.esp()) - widgets.Row(menu.content, "SAMD21", version.samd()) - widgets.Row(menu.content, "Collator", version.collator()) -end - -function settings.root() - local menu = widgets.MenuScreen { - show_back = true, - title = "Settings", - } - menu.list = menu.root:List { - w = lvgl.PCT(100), - h = lvgl.PCT(100), - flex_grow = 1, - } - - local function section(name) - menu.list:add_text(name):add_style(theme.list_heading) + self.menu.content:Label { + text = "Scroll Sensitivity", + }:add_style(theme.settings_title) + + local slider_scale = 4; -- Power steering + local sensitivity = self.menu.content:Slider { + w = lvgl.PCT(90), + h = 5, + range = { min = 0, max = 255 / slider_scale }, + value = controls.scroll_sensitivity:get() / slider_scale, + } + sensitivity:onevent(lvgl.EVENT.VALUE_CHANGED, function() + controls.scroll_sensitivity:set(sensitivity:value() * slider_scale) + end) end - - local function submenu(name, fn) - local item = menu.list:add_btn(nil, name) - item:onClicked(function() - backstack.push(fn) +} + +local DatabaseSettings = screen:new { + createUi = function(self) + self.menu = SettingsScreen("Database") + local db = require("database") + widgets.Row(self.menu.content, "Schema version", db.version()) + widgets.Row(self.menu.content, "Size on disk", string.format("%.1f KiB", db.size() / 1024)) + + local actions_container = self.menu.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, + } + actions_container:add_style(theme.list_item) + + local update = actions_container:Button {} + update:Label { text = "Update" } + update:onClicked(function() + database.update() end) - item:add_style(theme.list_item) end +} + +local FirmwareSettings = screen:new { + createUi = function(self) + self.menu = SettingsScreen("Firmware") + local version = require("version") + widgets.Row(self.menu.content, "ESP32", version.esp()) + widgets.Row(self.menu.content, "SAMD21", version.samd()) + widgets.Row(self.menu.content, "Collator", version.collator()) + end +} - section("Audio") - submenu("Bluetooth", settings.bluetooth) - submenu("Headphones", settings.headphones) +local LicensesScreen = screen:new { + createUi = function(self) + self.root = require("licenses")() + end +} + +return screen:new { + createUi = function(self) + self.menu = widgets.MenuScreen { + show_back = true, + title = "Settings", + } + self.list = self.menu.root:List { + w = lvgl.PCT(100), + h = lvgl.PCT(100), + flex_grow = 1, + } + + local function section(name) + self.list:add_text(name):add_style(theme.list_heading) + end - section("Interface") - submenu("Display", settings.display) - submenu("Input Method", settings.input) + local function submenu(name, class) + local item = self.list:add_btn(nil, name) + item:onClicked(function() + backstack.push(class:new()) + end) + item:add_style(theme.list_item) + end - section("System") - submenu("Database", settings.database) - submenu("Firmware", settings.firmware) - submenu("Licenses", function() - return require("licenses")() - end) + section("Audio") + submenu("Bluetooth", BluetoothSettings) + submenu("Headphones", HeadphonesSettings) - return menu -end + section("Interface") + submenu("Display", DisplaySettings) + submenu("Input Method", InputSettings) -return settings + section("System") + submenu("Database", DatabaseSettings) + submenu("Firmware", FirmwareSettings) + submenu("Licenses", LicensesScreen) + end +} -- cgit v1.2.3 From a78614a5806c9800956f10f993e1c70b74fbf323 Mon Sep 17 00:00:00 2001 From: ailurux Date: Thu, 7 Mar 2024 12:12:32 +1100 Subject: WIP: Getting styles from lua --- lua/settings.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lua/settings.lua') diff --git a/lua/settings.lua b/lua/settings.lua index 952292e4..cb726a2a 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -1,7 +1,7 @@ local lvgl = require("lvgl") local backstack = require("backstack") local widgets = require("widgets") -local theme = require("theme") +local styles = require("styles") local volume = require("volume") local display = require("display") local controls = require("controls") @@ -55,7 +55,7 @@ function settings.bluetooth() menu.content:Label { text = "Paired Device", pad_bottom = 1, - }:add_style(theme.settings_title) + }:add_style(styles.settings_title) local paired_container = menu.content:Object { flex = { @@ -81,7 +81,7 @@ function settings.bluetooth() menu.content:Label { text = "Nearby Devices", pad_bottom = 1, - }:add_style(theme.settings_title) + }:add_style(styles.settings_title) local devices = menu.content:List { w = lvgl.PCT(100), @@ -121,7 +121,7 @@ function settings.headphones() menu.content:Label { text = "Maximum volume limit", - }:add_style(theme.settings_title) + }:add_style(styles.settings_title) local volume_chooser = menu.content:Dropdown { options = "Line Level (-10 dB)\nCD Level (+6 dB)\nMaximum (+10dB)", @@ -136,7 +136,7 @@ function settings.headphones() menu.content:Label { text = "Left/Right balance", - }:add_style(theme.settings_title) + }:add_style(styles.settings_title) local balance = menu.content:Slider { w = lvgl.PCT(100), @@ -194,7 +194,7 @@ function settings.display() } brightness_title:Label { text = "Brightness", flex_grow = 1 } local brightness_pct = brightness_title:Label {} - brightness_pct:add_style(theme.settings_title) + brightness_pct:add_style(styles.settings_title) local brightness = menu.content:Slider { w = lvgl.PCT(100), @@ -220,7 +220,7 @@ function settings.input() menu.content:Label { text = "Control scheme", - }:add_style(theme.settings_title) + }:add_style(styles.settings_title) local schemes = controls.schemes() local option_to_scheme = {} @@ -258,7 +258,7 @@ function settings.input() menu.content:Label { text = "Scroll Sensitivity", - }:add_style(theme.settings_title) + }:add_style(styles.settings_title) local slider_scale = 4; -- Power steering local sensitivity = menu.content:Slider { @@ -292,7 +292,7 @@ function settings.database() pad_top = 4, pad_column = 4, } - actions_container:add_style(theme.list_item) + actions_container:add_style(styles.list_item) local update = actions_container:Button {} update:Label { text = "Update" } @@ -321,7 +321,7 @@ function settings.root() } local function section(name) - menu.list:add_text(name):add_style(theme.list_heading) + menu.list:add_text(name):add_style(styles.list_heading) end local function submenu(name, fn) @@ -329,7 +329,7 @@ function settings.root() item:onClicked(function() backstack.push(fn) end) - item:add_style(theme.list_item) + item:add_style(styles.list_item) end section("Audio") -- cgit v1.2.3 From f1599c237c36f08e96dd5d1ab98bc04e35e1ade1 Mon Sep 17 00:00:00 2001 From: ailurux Date: Mon, 18 Mar 2024 13:11:13 +1100 Subject: Better styling for settings pages + dropdown menus --- lua/settings.lua | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'lua/settings.lua') diff --git a/lua/settings.lua b/lua/settings.lua index cb726a2a..aac5ce9b 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -6,6 +6,7 @@ local volume = require("volume") local display = require("display") local controls = require("controls") local bluetooth = require("bluetooth") +local theme = require("theme") local database = require("database") local settings = {} @@ -23,7 +24,7 @@ local function SettingsScreen(title) align_items = "flex-start", align_content = "flex-start", }, - w = lvgl.PCT(100), + w = lvgl.PCT(90), flex_grow = 1, pad_left = 4, pad_right = 4, @@ -52,10 +53,10 @@ function settings.bluetooth() bluetooth.enabled:set(enabled) end) - menu.content:Label { + theme.set_style(menu.content:Label { text = "Paired Device", pad_bottom = 1, - }:add_style(styles.settings_title) + }, "settings_title") local paired_container = menu.content:Object { flex = { @@ -78,10 +79,10 @@ function settings.bluetooth() bluetooth.paired_device:set() end) - menu.content:Label { + theme.set_style(menu.content:Label { text = "Nearby Devices", pad_bottom = 1, - }:add_style(styles.settings_title) + }, "settings_title") local devices = menu.content:List { w = lvgl.PCT(100), @@ -119,9 +120,9 @@ end function settings.headphones() local menu = SettingsScreen("Headphones") - menu.content:Label { - text = "Maximum volume limit", - }:add_style(styles.settings_title) + theme.set_style(menu.content:Label { + text = "Maxiumum volume limit", + }, "settings_title") local volume_chooser = menu.content:Dropdown { options = "Line Level (-10 dB)\nCD Level (+6 dB)\nMaximum (+10dB)", @@ -134,9 +135,9 @@ function settings.headphones() volume.limit_db:set(limits[selection]) end) - menu.content:Label { + theme.set_style(menu.content:Label { text = "Left/Right balance", - }:add_style(styles.settings_title) + }, "settings_title") local balance = menu.content:Slider { w = lvgl.PCT(100), @@ -191,10 +192,11 @@ function settings.display() }, w = lvgl.PCT(100), h = lvgl.SIZE_CONTENT, + } brightness_title:Label { text = "Brightness", flex_grow = 1 } local brightness_pct = brightness_title:Label {} - brightness_pct:add_style(styles.settings_title) + theme.set_style(brightness_pct, "settings_title") local brightness = menu.content:Slider { w = lvgl.PCT(100), @@ -218,9 +220,9 @@ end function settings.input() local menu = SettingsScreen("Input Method") - menu.content:Label { + theme.set_style(menu.content:Label { text = "Control scheme", - }:add_style(styles.settings_title) + }, "settings_title") local schemes = controls.schemes() local option_to_scheme = {} @@ -256,9 +258,9 @@ function settings.input() controls.scheme:set(scheme) end) - menu.content:Label { + theme.set_style(menu.content:Label { text = "Scroll Sensitivity", - }:add_style(styles.settings_title) + }, "settings_title") local slider_scale = 4; -- Power steering local sensitivity = menu.content:Slider { @@ -321,7 +323,11 @@ function settings.root() } local function section(name) - menu.list:add_text(name):add_style(styles.list_heading) + local elem = menu.list:Label { + text = name, + pad_left = 4, + } + theme.set_style(elem, "settings_title") end local function submenu(name, fn) -- cgit v1.2.3 From dadac304dd930ddf4c5aebcc069c5d9f881b2b60 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 21 Mar 2024 11:51:48 +1100 Subject: Add very basic usb msc ui --- lua/settings.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lua/settings.lua') diff --git a/lua/settings.lua b/lua/settings.lua index 9d9ccf2d..e9e9d370 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -275,6 +275,53 @@ local InputSettings = screen:new { end } +local MassStorageSettings = screen:new { + createUi = function(self) + self.menu = SettingsScreen("USB Storage") + local version = require("version").samd() + if tonumber(version) < 2 then + self.menu.content:Label { + w = lvgl.PCT(100), + text = "Usb Mass Storage requires a SAMD21 firmware version >=2." + } + return + end + + local enable_container = self.menu.content:Object { + flex = { + flex_direction = "row", + justify_content = "flex-start", + align_items = "content", + align_content = "flex-start", + }, + w = lvgl.PCT(100), + h = lvgl.SIZE_CONTENT, + pad_bottom = 1, + } + enable_container:Label { text = "Enable", flex_grow = 1 } + local enable_sw = enable_container:Switch {} + + local usb = require("usb") + local bind_switch = function() + if usb.msc_enabled:get() then + enable_sw:add_state(lvgl.STATE.CHECKED) + else + enable_sw:clear_state(lvgl.STATE.CHECKED) + end + end + + enable_sw:onevent(lvgl.EVENT.VALUE_CHANGED, function() + usb.msc_enabled:set(enable_sw:enabled()) + bind_switch() + end) + + self.bindings = { + usb.msc_enabled:bind(bind_switch), + } + end, + canPop = true +} + local DatabaseSettings = screen:new { createUi = function(self) self.menu = SettingsScreen("Database") @@ -352,6 +399,9 @@ return screen:new { submenu("Display", DisplaySettings) submenu("Input Method", InputSettings) + section("USB") + submenu("Storage", MassStorageSettings) + section("System") submenu("Database", DatabaseSettings) submenu("Firmware", FirmwareSettings) -- cgit v1.2.3 From cddfc2fbf77fbc5b6e6484a86b119b771bc480af Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 21 Mar 2024 13:02:00 +1100 Subject: Dont allow quitting the msc screen when msc is enabled --- lua/settings.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lua/settings.lua') diff --git a/lua/settings.lua b/lua/settings.lua index e9e9d370..fe36fe02 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -8,6 +8,7 @@ local controls = require("controls") local bluetooth = require("bluetooth") local database = require("database") local screen = require("screen") +local usb = require("usb") local function SettingsScreen(title) local menu = widgets.MenuScreen { @@ -301,7 +302,6 @@ local MassStorageSettings = screen:new { enable_container:Label { text = "Enable", flex_grow = 1 } local enable_sw = enable_container:Switch {} - local usb = require("usb") local bind_switch = function() if usb.msc_enabled:get() then enable_sw:add_state(lvgl.STATE.CHECKED) @@ -319,7 +319,9 @@ local MassStorageSettings = screen:new { usb.msc_enabled:bind(bind_switch), } end, - canPop = true + canPop = function() + return not usb.msc_enabled:get() + end } local DatabaseSettings = screen:new { -- cgit v1.2.3