@ -7,8 +7,7 @@ local display = require("display")
local controls = require ( " controls " )
local controls = require ( " controls " )
local bluetooth = require ( " bluetooth " )
local bluetooth = require ( " bluetooth " )
local database = require ( " database " )
local database = require ( " database " )
local screen = require ( " screen " )
local settings = { }
local function SettingsScreen ( title )
local function SettingsScreen ( title )
local menu = widgets.MenuScreen {
local menu = widgets.MenuScreen {
@ -31,10 +30,11 @@ local function SettingsScreen(title)
return menu
return menu
end
end
function settings . bluetooth ( )
local BluetoothSettings = screen : new {
local menu = SettingsScreen ( " Bluetooth " )
createUi = function ( self )
self.menu = SettingsScreen ( " Bluetooth " )
local enable_container = menu.content : Object {
local enable_container = self. menu. content : Object {
flex = {
flex = {
flex_direction = " row " ,
flex_direction = " row " ,
justify_content = " flex-start " ,
justify_content = " flex-start " ,
@ -52,12 +52,12 @@ function settings.bluetooth()
bluetooth.enabled : set ( enabled )
bluetooth.enabled : set ( enabled )
end )
end )
menu.content : Label {
self. menu. content : Label {
text = " Paired Device " ,
text = " Paired Device " ,
pad_bottom = 1 ,
pad_bottom = 1 ,
} : add_style ( theme.settings_title )
} : add_style ( theme.settings_title )
local paired_container = menu.content : Object {
local paired_container = self. menu. content : Object {
flex = {
flex = {
flex_direction = " row " ,
flex_direction = " row " ,
justify_content = " flex-start " ,
justify_content = " flex-start " ,
@ -78,17 +78,17 @@ function settings.bluetooth()
bluetooth.paired_device : set ( )
bluetooth.paired_device : set ( )
end )
end )
menu.content : Label {
self. menu. content : Label {
text = " Nearby Devices " ,
text = " Nearby Devices " ,
pad_bottom = 1 ,
pad_bottom = 1 ,
} : add_style ( theme.settings_title )
} : add_style ( theme.settings_title )
local devices = menu.content : List {
local devices = self. menu. content : List {
w = lvgl.PCT ( 100 ) ,
w = lvgl.PCT ( 100 ) ,
h = lvgl.SIZE_CONTENT ,
h = lvgl.SIZE_CONTENT ,
}
}
menu .bindings = {
self .bindings = {
bluetooth.enabled : bind ( function ( en )
bluetooth.enabled : bind ( function ( en )
if en then
if en then
enable_sw : add_state ( lvgl.STATE . CHECKED )
enable_sw : add_state ( lvgl.STATE . CHECKED )
@ -114,16 +114,18 @@ function settings.bluetooth()
end
end
end )
end )
}
}
end
end
}
function settings . headphones ( )
local HeadphonesSettings = screen : new {
local menu = SettingsScreen ( " Headphones " )
createUi = function ( self )
self.menu = SettingsScreen ( " Headphones " )
menu.content : Label {
self. menu. content : Label {
text = " Maximum volume limit " ,
text = " Maximum volume limit " ,
} : add_style ( theme.settings_title )
} : add_style ( theme.settings_title )
local volume_chooser = menu.content : Dropdown {
local volume_chooser = self. menu. content : Dropdown {
options = " Line Level (-10 dB) \n CD Level (+6 dB) \n Maximum (+10dB) " ,
options = " Line Level (-10 dB) \n CD Level (+6 dB) \n Maximum (+10dB) " ,
selected = 1 ,
selected = 1 ,
}
}
@ -134,11 +136,11 @@ function settings.headphones()
volume.limit_db : set ( limits [ selection ] )
volume.limit_db : set ( limits [ selection ] )
end )
end )
menu.content : Label {
self. menu. content : Label {
text = " Left/Right balance " ,
text = " Left/Right balance " ,
} : add_style ( theme.settings_title )
} : add_style ( theme.settings_title )
local balance = menu.content : Slider {
local balance = self. menu. content : Slider {
w = lvgl.PCT ( 100 ) ,
w = lvgl.PCT ( 100 ) ,
h = 5 ,
h = 5 ,
range = { min = - 100 , max = 100 } ,
range = { min = - 100 , max = 100 } ,
@ -148,9 +150,9 @@ function settings.headphones()
volume.left_bias : set ( balance : value ( ) )
volume.left_bias : set ( balance : value ( ) )
end )
end )
local balance_label = menu.content : Label { }
local balance_label = self. menu. content : Label { }
menu .bindings = {
self .bindings = {
volume.limit_db : bind ( function ( limit )
volume.limit_db : bind ( function ( limit )
for i = 1 , # limits do
for i = 1 , # limits do
if limits [ i ] == limit then
if limits [ i ] == limit then
@ -175,14 +177,14 @@ function settings.headphones()
end
end
end ) ,
end ) ,
}
}
end
}
return menu
local DisplaySettings = screen : new {
end
createUi = function ( self )
self.menu = SettingsScreen ( " Display " )
function settings . display ( )
local menu = SettingsScreen ( " Display " )
local brightness_title = menu.content : Object {
local brightness_title = self.menu . content : Object {
flex = {
flex = {
flex_direction = " row " ,
flex_direction = " row " ,
justify_content = " flex-start " ,
justify_content = " flex-start " ,
@ -196,7 +198,7 @@ function settings.display()
local brightness_pct = brightness_title : Label { }
local brightness_pct = brightness_title : Label { }
brightness_pct : add_style ( theme.settings_title )
brightness_pct : add_style ( theme.settings_title )
local brightness = menu.content : Slider {
local brightness = self. menu. content : Slider {
w = lvgl.PCT ( 100 ) ,
w = lvgl.PCT ( 100 ) ,
h = 5 ,
h = 5 ,
range = { min = 0 , max = 100 } ,
range = { min = 0 , max = 100 } ,
@ -206,19 +208,19 @@ function settings.display()
display.brightness : set ( brightness : value ( ) )
display.brightness : set ( brightness : value ( ) )
end )
end )
menu .bindings = {
self .bindings = {
display.brightness : bind ( function ( b )
display.brightness : bind ( function ( b )
brightness_pct : set { text = tostring ( b ) .. " % " }
brightness_pct : set { text = tostring ( b ) .. " % " }
end )
end )
}
}
end
}
return menu
local InputSettings = screen : new {
end
createUi = function ( self )
self.menu = SettingsScreen ( " Input Method " )
function settings . input ( )
local menu = SettingsScreen ( " Input Method " )
menu.content : Label {
self.menu . content : Label {
text = " Control scheme " ,
text = " Control scheme " ,
} : add_style ( theme.settings_title )
} : add_style ( theme.settings_title )
@ -239,11 +241,11 @@ function settings.input()
option_idx = option_idx + 1
option_idx = option_idx + 1
end
end
local controls_chooser = menu.content : Dropdown {
local controls_chooser = self. menu. content : Dropdown {
options = options ,
options = options ,
}
}
menu .bindings = {
self .bindings = {
controls.scheme : bind ( function ( s )
controls.scheme : bind ( function ( s )
local option = scheme_to_option [ s ]
local option = scheme_to_option [ s ]
controls_chooser : set ( { selected = option } )
controls_chooser : set ( { selected = option } )
@ -256,31 +258,31 @@ function settings.input()
controls.scheme : set ( scheme )
controls.scheme : set ( scheme )
end )
end )
menu.content : Label {
self. menu. content : Label {
text = " Scroll Sensitivity " ,
text = " Scroll Sensitivity " ,
} : add_style ( theme.settings_title )
} : add_style ( theme.settings_title )
local slider_scale = 4 ; -- Power steering
local slider_scale = 4 ; -- Power steering
local sensitivity = menu.content : Slider {
local sensitivity = self. menu. content : Slider {
w = lvgl.PCT ( 90 ) ,
w = lvgl.PCT ( 90 ) ,
h = 5 ,
h = 5 ,
range = { min = 0 , max = 255 / slider_scale } ,
range = { min = 0 , max = 255 / slider_scale } ,
value = controls.scroll_sensitivity : get ( ) / slider_scale ,
value = controls.scroll_sensitivity : get ( ) / slider_scale ,
}
}
sensitivity : onevent ( lvgl.EVENT . VALUE_CHANGED , function ( )
sensitivity : onevent ( lvgl.EVENT . VALUE_CHANGED , function ( )
controls.scroll_sensitivity : set ( sensitivity : value ( ) * slider_scale )
controls.scroll_sensitivity : set ( sensitivity : value ( ) * slider_scale )
end )
end )
end
}
return menu
local DatabaseSettings = screen : new {
end
createUi = function ( self )
self.menu = SettingsScreen ( " Database " )
function settings . database ( )
local menu = SettingsScreen ( " Database " )
local db = require ( " database " )
local db = require ( " database " )
widgets.Row ( menu.content , " Schema version " , db.version ( ) )
widgets.Row ( self.menu . content , " Schema version " , db.version ( ) )
widgets.Row ( menu.content , " Size on disk " , string.format ( " %.1f KiB " , db.size ( ) / 1024 ) )
widgets.Row ( self. menu. content , " Size on disk " , string.format ( " %.1f KiB " , db.size ( ) / 1024 ) )
local actions_container = menu.content : Object {
local actions_container = self. menu. content : Object {
w = lvgl.PCT ( 100 ) ,
w = lvgl.PCT ( 100 ) ,
h = lvgl.SIZE_CONTENT ,
h = lvgl.SIZE_CONTENT ,
flex = {
flex = {
@ -299,55 +301,60 @@ function settings.database()
update : onClicked ( function ( )
update : onClicked ( function ( )
database.update ( )
database.update ( )
end )
end )
end
end
}
function settings . firmware ( )
local FirmwareSettings = screen : new {
local menu = SettingsScreen ( " Firmware " )
createUi = function ( self )
self.menu = SettingsScreen ( " Firmware " )
local version = require ( " version " )
local version = require ( " version " )
widgets.Row ( menu.content , " ESP32 " , version.esp ( ) )
widgets.Row ( self.menu . content , " ESP32 " , version.esp ( ) )
widgets.Row ( menu.content , " SAMD21 " , version.samd ( ) )
widgets.Row ( self.menu . content , " SAMD21 " , version.samd ( ) )
widgets.Row ( menu.content , " Collator " , version.collator ( ) )
widgets.Row ( self.menu . content , " Collator " , version.collator ( ) )
end
end
}
function settings . root ( )
local LicensesScreen = screen : new {
local menu = widgets.MenuScreen {
createUi = function ( self )
self.root = require ( " licenses " ) ( )
end
}
return screen : new {
createUi = function ( self )
self.menu = widgets.MenuScreen {
show_back = true ,
show_back = true ,
title = " Settings " ,
title = " Settings " ,
}
}
menu.list = menu.root : List {
self .list = self. menu. root : List {
w = lvgl.PCT ( 100 ) ,
w = lvgl.PCT ( 100 ) ,
h = lvgl.PCT ( 100 ) ,
h = lvgl.PCT ( 100 ) ,
flex_grow = 1 ,
flex_grow = 1 ,
}
}
local function section ( name )
local function section ( name )
menu .list: add_text ( name ) : add_style ( theme.list_heading )
self .list : add_text ( name ) : add_style ( theme.list_heading )
end
end
local function submenu ( name , fn )
local function submenu ( name , class )
local item = menu .list: add_btn ( nil , name )
local item = self .list: add_btn ( nil , name )
item : onClicked ( function ( )
item : onClicked ( function ( )
backstack.push ( fn )
backstack.push ( class : new ( ) )
end )
end )
item : add_style ( theme.list_item )
item : add_style ( theme.list_item )
end
end
section ( " Audio " )
section ( " Audio " )
submenu ( " Bluetooth " , settings.bluetooth )
submenu ( " Bluetooth " , BluetoothSettings )
submenu ( " Headphones " , settings.headphone s)
submenu ( " Headphones " , HeadphonesSetting s)
section ( " Interface " )
section ( " Interface " )
submenu ( " Display " , settings.display )
submenu ( " Display " , Di splayS ettings)
submenu ( " Input Method " , settings.input )
submenu ( " Input Method " , InputSettings )
section ( " System " )
section ( " System " )
submenu ( " Database " , settings.database )
submenu ( " Database " , DatabaseSettings )
submenu ( " Firmware " , settings.firmware )
submenu ( " Firmware " , FirmwareSettings )
submenu ( " Licenses " , function ( )
submenu ( " Licenses " , LicensesScreen )
return require ( " licenses " ) ( )
end
end )
}
return menu
end
return settings