#395 pocket navigation system

This commit is contained in:
Mikayla 2023-12-22 16:12:47 +00:00
parent d55442fa53
commit 1a40321c0f
10 changed files with 140 additions and 125 deletions

View File

@ -23,19 +23,16 @@ local LINK_STATE = {
LINKED = 3
}
---@enum NAV_PAGE
local NAV_PAGE = {
HOME = 1,
UNITS = 2,
REACTORS = 3,
BOILERS = 4,
TURBINES = 5,
DIAG = 6,
D_ALARMS = 7
}
iocontrol.LINK_STATE = LINK_STATE
iocontrol.NAV_PAGE = NAV_PAGE
---@class nav_tree_node
---@field _p nav_tree_node|nil page's parent
---@field _c table page's children
---@field pane_elem graphics_element|nil multipane for this branch
---@field pane_id integer this page's ID in it's contained pane
---@field switcher function|nil function to switch this page's active multipane
---@field nav_to function function to navigate to this page
---@field tasks table tasks to run on this page
-- initialize facility-independent components of pocket iocontrol
---@param comms pocket_comms
@ -76,21 +73,54 @@ function iocontrol.init_core(comms)
alarm_buttons = {},
tone_indicators = {} -- indicators to update from supervisor tone states
}
end
---@class pocket_nav
io.nav = {
page = NAV_PAGE.HOME, ---@type NAV_PAGE
sub_pages = { NAV_PAGE.HOME, NAV_PAGE.UNITS, NAV_PAGE.REACTORS, NAV_PAGE.BOILERS, NAV_PAGE.TURBINES, NAV_PAGE.DIAG },
tasks = {}
-- initialize the page navigation tree
function iocontrol.init_nav(root_pane)
local self = {
root = { _p = nil, _c = {}, pane_id = 0, pane_elem = root_pane, nav_to = function () end, tasks = {} }, ---@type nav_tree_node
cur_page = nil ---@type nav_tree_node
}
-- add a task to be performed periodically while on a given page
---@param page NAV_PAGE page to add task to
---@param task function function to execute
function io.nav.register_task(page, task)
if io.nav.tasks[page] == nil then io.nav.tasks[page] = {} end
table.insert(io.nav.tasks[page], task)
function self.root.switcher(pane_id)
if self.root._c[pane_id] then self.root._c[pane_id].nav_to() end
end
---@class pocket_nav
io.nav = {}
-- create a new page entry in the page navigation tree
---@param parent nav_tree_node? a parent page or nil to use the root
---@param pane_id integer the pane number for this page in it's parent's multipane
---@param pane graphics_element? this page's multipane, if it has children
---@return nav_tree_node new_page this new page
function io.nav.new_page(parent, pane_id, pane)
local page = { _p = parent or self.root, _c = {}, pane_id = pane_id, pane_elem = pane, tasks = {} }
page._p._c[pane_id] = page
function page.nav_to()
if page._p.pane_elem then page._p.pane_elem.set_value(page.pane_id) end
self.cur_page = page
end
if pane then
function page.switcher() if page._c[pane_id] then page._c[pane_id].nav_to() end end
end
return page
end
-- get the currently active page
function io.nav.get_current_page() return self.cur_page end
-- attempt to navigate up the tree
function io.nav.nav_up()
local parent = self.cur_page._p
-- if a parent is defined and this element is not root
if parent and parent.pane_id ~= 0 then self.cur_page = parent end
end
return self.root
end
-- initialize facility-dependent components of pocket iocontrol

View File

@ -460,5 +460,4 @@ function pocket.comms(version, nic, pkt_channel, svr_channel, crd_channel, range
return public
end
return pocket

View File

@ -18,7 +18,7 @@ local iocontrol = require("pocket.iocontrol")
local pocket = require("pocket.pocket")
local renderer = require("pocket.renderer")
local POCKET_VERSION = "v0.6.3-alpha"
local POCKET_VERSION = "v0.6.4-alpha"
local println = util.println
local println_ts = util.println_ts
@ -128,7 +128,7 @@ local function main()
-- start connection watchdogs
conn_wd.sv.feed()
conn_wd.api.feed()
log.debug("startup> conn watchdog started")
log.debug("startup> conn watchdogs started")
local io_db = iocontrol.get_db()
local nav = io_db.nav
@ -146,11 +146,8 @@ local function main()
pocket_comms.link_update()
-- update any tasks for the active page
if (type(nav.tasks[nav.page]) == "table") then
for i = 1, #nav.tasks[nav.page] do
nav.tasks[nav.page][i]()
end
end
local page_tasks = nav.get_current_page().tasks
for i = 1, #page_tasks do page_tasks[i]() end
loop_clock.start()
elseif conn_wd.sv.is_timer(param1) then

View File

@ -24,7 +24,6 @@ local TextBox = require("graphics.elements.textbox")
local Sidebar = require("graphics.elements.controls.sidebar")
local LINK_STATE = iocontrol.LINK_STATE
local NAV_PAGE = iocontrol.NAV_PAGE
local ALIGN = core.ALIGN
@ -33,24 +32,20 @@ local cpair = core.cpair
-- create new main view
---@param main graphics_element main displaybox
local function init(main)
local nav = iocontrol.get_db().nav
local ps = iocontrol.get_db().ps
local ps = iocontrol.get_db().ps
-- window header message
TextBox{parent=main,y=1,text="",alignment=ALIGN.LEFT,height=1,fg_bg=style.header}
--
-- root panel panes (connection screens + main screen)
--
--#region root panel panes (connection screens + main screen)
local root_pane_div = Div{parent=main,x=1,y=2}
local conn_sv_wait = conn_waiting(root_pane_div, 6, false)
local conn_api_wait = conn_waiting(root_pane_div, 6, true)
local main_pane = Div{parent=main,x=1,y=2}
local root_panes = { conn_sv_wait, conn_api_wait, main_pane }
local root_pane = MultiPane{parent=root_pane_div,x=1,y=1,panes=root_panes}
local root_pane = MultiPane{parent=root_pane_div,x=1,y=1,panes={conn_sv_wait,conn_api_wait,main_pane}}
root_pane.register(ps, "link_state", function (state)
if state == LINK_STATE.UNLINKED or state == LINK_STATE.API_LINK_ONLY then
@ -62,62 +57,28 @@ local function init(main)
end
end)
--
-- main page panel panes & sidebar
--
--#endregion
--#region main page panel panes & sidebar
local page_div = Div{parent=main_pane,x=4,y=1}
local sidebar_tabs = {
{
char = "#",
color = cpair(colors.black,colors.green)
},
{
char = "U",
color = cpair(colors.black,colors.yellow)
},
{
char = "R",
color = cpair(colors.black,colors.cyan)
},
{
char = "B",
color = cpair(colors.black,colors.lightGray)
},
{
char = "T",
color = cpair(colors.black,colors.white)
},
{
char = "D",
color = cpair(colors.black,colors.orange)
}
{ char = "#", color = cpair(colors.black,colors.green) },
{ char = "U", color = cpair(colors.black,colors.yellow) },
{ char = "R", color = cpair(colors.black,colors.cyan) },
{ char = "B", color = cpair(colors.black,colors.lightGray) },
{ char = "T", color = cpair(colors.black,colors.white) },
{ char = "D", color = cpair(colors.black,colors.orange) }
}
local panes = { home_page(page_div), unit_page(page_div), reactor_page(page_div), boiler_page(page_div), turbine_page(page_div), diag_page(page_div) }
local page_pane = MultiPane{parent=page_div,x=1,y=1,panes={home_page(page_div),unit_page(page_div),reactor_page(page_div),boiler_page(page_div),turbine_page(page_div),diag_page(page_div)}}
local page_pane = MultiPane{parent=page_div,x=1,y=1,panes=panes}
local base = iocontrol.init_nav(page_pane)
local function navigate_sidebar(page)
if page == 1 then
nav.page = nav.sub_pages[NAV_PAGE.HOME]
elseif page == 2 then
nav.page = nav.sub_pages[NAV_PAGE.UNITS]
elseif page == 3 then
nav.page = nav.sub_pages[NAV_PAGE.REACTORS]
elseif page == 4 then
nav.page = nav.sub_pages[NAV_PAGE.BOILERS]
elseif page == 5 then
nav.page = nav.sub_pages[NAV_PAGE.TURBINES]
elseif page == 6 then
nav.page = nav.sub_pages[NAV_PAGE.DIAG]
end
Sidebar{parent=main_pane,x=1,y=1,tabs=sidebar_tabs,fg_bg=cpair(colors.white,colors.gray),callback=base.switcher}
page_pane.set_value(page)
end
Sidebar{parent=main_pane,x=1,y=1,tabs=sidebar_tabs,fg_bg=cpair(colors.white,colors.gray),callback=navigate_sidebar}
--#endregion
end
return init

View File

@ -1,17 +1,23 @@
-- local style = require("pocket.ui.style")
--
-- Boiler Detail Page
--
local core = require("graphics.core")
local iocontrol = require("pocket.iocontrol")
local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox")
local core = require("graphics.core")
-- local cpair = core.cpair
local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox")
local ALIGN = core.ALIGN
-- new boiler page view
---@param root graphics_element parent
local function new_view(root)
local db = iocontrol.get_db()
db.nav.new_page(nil, 4)
local main = Div{parent=root,x=1,y=1}
TextBox{parent=main,text="BOILERS",x=1,y=1,height=1,alignment=ALIGN.CENTER}

View File

@ -1,3 +1,7 @@
--
-- Diagnostic Tools
--
local iocontrol = require("pocket.iocontrol")
local core = require("graphics.core")
@ -15,8 +19,6 @@ local SwitchButton = require("graphics.elements.controls.switch_button")
local cpair = core.cpair
local NAV_PAGE = iocontrol.NAV_PAGE
local ALIGN = core.ALIGN
-- new diagnostics page view
@ -36,23 +38,15 @@ local function new_view(root)
local page_pane = MultiPane{parent=main,x=1,y=1,panes=panes}
local function navigate_diag()
page_pane.set_value(1)
db.nav.page = NAV_PAGE.DIAG
db.nav.sub_pages[NAV_PAGE.DIAG] = NAV_PAGE.DIAG
end
local function navigate_alarm()
page_pane.set_value(2)
db.nav.page = NAV_PAGE.D_ALARMS
db.nav.sub_pages[NAV_PAGE.DIAG] = NAV_PAGE.D_ALARMS
end
local npage_diag = db.nav.new_page(nil, 6, page_pane)
local npage_home = db.nav.new_page(npage_diag, 1)
local npage_alarm = db.nav.new_page(npage_diag, 2)
------------------------
-- Alarm Testing Page --
------------------------
db.nav.register_task(NAV_PAGE.D_ALARMS, db.diag.tone_test.get_tone_states)
table.insert(npage_alarm.tasks, db.diag.tone_test.get_tone_states)
local ttest = db.diag.tone_test
@ -67,7 +61,7 @@ local function new_view(root)
ttest.ready_warn = TextBox{parent=audio,y=2,text="",height=1,alignment=ALIGN.CENTER,fg_bg=cpair(colors.yellow,colors.black)}
PushButton{parent=audio,x=13,y=18,text="\x11 BACK",min_width=8,fg_bg=cpair(colors.black,colors.lightGray),active_fg_bg=c_wht_gray,callback=navigate_diag}
PushButton{parent=audio,x=13,y=18,text="\x11 BACK",min_width=8,fg_bg=cpair(colors.black,colors.lightGray),active_fg_bg=c_wht_gray,callback=npage_home.nav_to}
local tones = Div{parent=audio,x=2,y=3,height=10,width=8,fg_bg=cpair(colors.black,colors.yellow)}
@ -137,7 +131,7 @@ local function new_view(root)
-- App List --
--------------
App{parent=diag_home,x=3,y=4,text="\x0f",title="Alarm",callback=navigate_alarm,app_fg_bg=cpair(colors.black,colors.red),active_fg_bg=cpair(colors.white,colors.gray)}
App{parent=diag_home,x=3,y=4,text="\x0f",title="Alarm",callback=npage_alarm.nav_to,app_fg_bg=cpair(colors.black,colors.red),active_fg_bg=cpair(colors.white,colors.gray)}
App{parent=diag_home,x=10,y=4,text="\x1e",title="LoopT",callback=function()end,app_fg_bg=cpair(colors.black,colors.cyan)}
App{parent=diag_home,x=17,y=4,text="@",title="Comps",callback=function()end,app_fg_bg=cpair(colors.black,colors.orange)}

View File

@ -1,14 +1,24 @@
local core = require("graphics.core")
--
-- Main Home Page
--
local Div = require("graphics.elements.div")
local iocontrol = require("pocket.iocontrol")
local App = require("graphics.elements.controls.app")
local core = require("graphics.core")
local Div = require("graphics.elements.div")
local App = require("graphics.elements.controls.app")
local cpair = core.cpair
-- new home page view
---@param root graphics_element parent
local function new_view(root)
local db = iocontrol.get_db()
db.nav.new_page(nil, 1)
local main = Div{parent=root,x=1,y=1}
App{parent=main,x=3,y=2,text="\x17",title="PRC",callback=function()end,app_fg_bg=cpair(colors.black,colors.purple)}

View File

@ -1,17 +1,23 @@
-- local style = require("pocket.ui.style")
--
-- Reactor Detail Page
--
local core = require("graphics.core")
local iocontrol = require("pocket.iocontrol")
local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox")
local core = require("graphics.core")
-- local cpair = core.cpair
local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox")
local ALIGN = core.ALIGN
-- new reactor page view
---@param root graphics_element parent
local function new_view(root)
local db = iocontrol.get_db()
db.nav.new_page(nil, 3)
local main = Div{parent=root,x=1,y=1}
TextBox{parent=main,text="REACTOR",x=1,y=1,height=1,alignment=ALIGN.CENTER}

View File

@ -1,17 +1,23 @@
-- local style = require("pocket.ui.style")
--
-- Turbine Detail Page
--
local core = require("graphics.core")
local iocontrol = require("pocket.iocontrol")
local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox")
local core = require("graphics.core")
-- local cpair = core.cpair
local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox")
local ALIGN = core.ALIGN
-- new turbine page view
---@param root graphics_element parent
local function new_view(root)
local db = iocontrol.get_db()
db.nav.new_page(nil, 5)
local main = Div{parent=root,x=1,y=1}
TextBox{parent=main,text="TURBINES",x=1,y=1,height=1,alignment=ALIGN.CENTER}

View File

@ -1,17 +1,23 @@
-- local style = require("pocket.ui.style")
--
-- Unit Overview Page
--
local core = require("graphics.core")
local iocontrol = require("pocket.iocontrol")
local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox")
local core = require("graphics.core")
-- local cpair = core.cpair
local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox")
local ALIGN = core.ALIGN
-- new unit page view
---@param root graphics_element parent
local function new_view(root)
local db = iocontrol.get_db()
db.nav.new_page(nil, 2)
local main = Div{parent=root,x=1,y=1}
TextBox{parent=main,text="UNITS",x=1,y=1,height=1,alignment=ALIGN.CENTER}