From 4a7028f401e38b41f7f115964e666ed2fb6b38de Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Thu, 27 Jun 2024 19:57:43 -0400 Subject: [PATCH] #497 instantly launch pocket program, block network dependent apps until connected --- pocket/iocontrol.lua | 6 ++-- pocket/pocket.lua | 46 +++++++++++++++++++------ pocket/startup.lua | 2 +- pocket/ui/apps/diag_apps.lua | 2 +- pocket/ui/apps/loader.lua | 49 +++++++++++++++++++++++++++ pocket/ui/components/conn_waiting.lua | 6 ++-- pocket/ui/main.lua | 30 +++------------- 7 files changed, 95 insertions(+), 46 deletions(-) create mode 100644 pocket/ui/apps/loader.lua diff --git a/pocket/iocontrol.lua b/pocket/iocontrol.lua index da9c0d7..38e642e 100644 --- a/pocket/iocontrol.lua +++ b/pocket/iocontrol.lua @@ -342,10 +342,8 @@ function iocontrol.report_link_state(state, sv_addr, api_addr) io.ps.publish("crd_conn_quality", 0) end - if state == LINK_STATE.LINKED then - io.ps.publish("sv_addr", sv_addr) - io.ps.publish("api_addr", api_addr) - end + if sv_addr then io.ps.publish("sv_addr", sv_addr) end + if api_addr then io.ps.publish("api_addr", api_addr) end end -- determine supervisor connection quality (trip time) diff --git a/pocket/pocket.lua b/pocket/pocket.lua index 0afc068..e73c3b1 100644 --- a/pocket/pocket.lua +++ b/pocket/pocket.lua @@ -78,15 +78,16 @@ end ---@enum POCKET_APP_ID local APP_ID = { ROOT = 1, + LOADER = 2, -- main app pages - UNITS = 2, - GUIDE = 3, - ABOUT = 4, + UNITS = 3, + GUIDE = 4, + ABOUT = 5, -- diag app page - ALARMS = 5, + ALARMS = 6, -- other - DUMMY = 6, - NUM_APPS = 6 + DUMMY = 7, + NUM_APPS = 7 } pocket.APP_ID = APP_ID @@ -98,9 +99,9 @@ pocket.APP_ID = APP_ID ---@field switcher function|nil function to switch between children ---@field tasks table tasks to run while viewing this page --- allocate the page navigation system ----@param render_queue mqueue -function pocket.init_nav(render_queue) +-- initialize the page navigation system +---@param smem pkt_shared_memory +function pocket.init_nav(smem) local self = { pane = nil, ---@type graphics_element sidebar = nil, ---@type graphics_element @@ -108,6 +109,7 @@ function pocket.init_nav(render_queue) containers = {}, help_map = {}, help_return = nil, + loader_return = nil, cur_app = APP_ID.ROOT } @@ -143,10 +145,13 @@ function pocket.init_nav(render_queue) app.load = function () app.loaded = true end app.unload = function () app.loaded = false end - -- check which connections this requires + -- check which connections this requires (for unload) ---@return boolean requires_sv, boolean requires_api function app.check_requires() return require_sv or false, require_api or false end + -- check if any connection is required (for load) + function app.requires_conn() return require_sv or require_api or false end + -- delayed set of the pane if it wasn't ready at the start ---@param root_pane graphics_element multipane function app.set_root_pane(root_pane) @@ -254,7 +259,14 @@ function pocket.init_nav(render_queue) local app = self.apps[app_id] ---@type pocket_app if app then - if not app.loaded then render_queue.push_data(MQ__RENDER_DATA.LOAD_APP, app_id) end + if app.requires_conn() and not smem.pkt_sys.pocket_comms.is_linked() then + -- bring up the app loader + self.loader_return = app_id + app_id = APP_ID.LOADER + app = self.apps[app_id] + else self.loader_return = nil end + + if not app.loaded then smem.q.mq_render.push_data(MQ__RENDER_DATA.LOAD_APP, app_id) end self.cur_app = app_id self.pane.set_value(app_id) @@ -267,6 +279,14 @@ function pocket.init_nav(render_queue) end end + -- open the app that was blocked on connecting + function nav.on_loader_connected() + if self.loader_return then + nav.open_app(self.loader_return) + end + end + + -- load a given app ---@param app_id POCKET_APP_ID function nav.load_app(app_id) @@ -844,6 +864,10 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav) ---@nodiscard function public.is_api_linked() return self.api.linked end + -- check if we are still linked with the supervisor and coordinator + ---@nodiscard + function public.is_linked() return self.sv.linked and self.api.linked end + return public end diff --git a/pocket/startup.lua b/pocket/startup.lua index b56da4f..a80a4ca 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -123,7 +123,7 @@ local function main() -- setup system ---------------------------------------- - smem_sys.nav = pocket.init_nav(__shared_memory.q.mq_render) + smem_sys.nav = pocket.init_nav(__shared_memory) -- message authentication init if type(config.AuthKey) == "string" and string.len(config.AuthKey) > 0 then diff --git a/pocket/ui/apps/diag_apps.lua b/pocket/ui/apps/diag_apps.lua index be63e95..27ef837 100644 --- a/pocket/ui/apps/diag_apps.lua +++ b/pocket/ui/apps/diag_apps.lua @@ -32,7 +32,7 @@ local function create_pages(root) local alarm_test = Div{parent=root,x=1,y=1} - local alarm_app = db.nav.register_app(APP_ID.ALARMS, alarm_test) + local alarm_app = db.nav.register_app(APP_ID.ALARMS, alarm_test, nil, true) local page = alarm_app.new_page(nil, function () end) page.tasks = { db.diag.tone_test.get_tone_states } diff --git a/pocket/ui/apps/loader.lua b/pocket/ui/apps/loader.lua new file mode 100644 index 0000000..8ea72f0 --- /dev/null +++ b/pocket/ui/apps/loader.lua @@ -0,0 +1,49 @@ +-- +-- Loading Screen App +-- + +local iocontrol = require("pocket.iocontrol") +local pocket = require("pocket.pocket") + +local conn_waiting = require("pocket.ui.components.conn_waiting") + +local core = require("graphics.core") + +local Div = require("graphics.elements.div") +local MultiPane = require("graphics.elements.multipane") +local TextBox = require("graphics.elements.textbox") + +local APP_ID = pocket.APP_ID + +local LINK_STATE = iocontrol.LINK_STATE + +-- create the connecting to SV & API page +---@param root graphics_element parent +local function create_pages(root) + local db = iocontrol.get_db() + + local main = Div{parent=root,x=1,y=1} + + db.nav.register_app(APP_ID.LOADER, main).new_page(nil, function () end) + + local conn_sv_wait = conn_waiting(main, 6, false) + local conn_api_wait = conn_waiting(main, 6, true) + local main_pane = Div{parent=main,x=1,y=2} + + local root_pane = MultiPane{parent=main,x=1,y=1,panes={conn_sv_wait,conn_api_wait,main_pane}} + + root_pane.register(db.ps, "link_state", function (state) + if state == LINK_STATE.UNLINKED or state == LINK_STATE.API_LINK_ONLY then + root_pane.set_value(1) + elseif state == LINK_STATE.SV_LINK_ONLY then + root_pane.set_value(2) + else + root_pane.set_value(3) + db.nav.on_loader_connected() + end + end) + + TextBox{parent=main_pane,text="Connected!",x=1,y=6,alignment=core.ALIGN.CENTER} +end + +return create_pages diff --git a/pocket/ui/components/conn_waiting.lua b/pocket/ui/components/conn_waiting.lua index 9cbe1b3..6b69650 100644 --- a/pocket/ui/components/conn_waiting.lua +++ b/pocket/ui/components/conn_waiting.lua @@ -23,16 +23,16 @@ local function init(parent, y, is_api) local root = Div{parent=parent,x=1,y=1} -- bounding box div - local box = Div{parent=root,x=1,y=y,height=5} + local box = Div{parent=root,x=1,y=y,height=6} local waiting_x = math.floor(parent.get_width() / 2) - 1 if is_api then WaitingAnim{parent=box,x=waiting_x,y=1,fg_bg=cpair(colors.blue,style.root.bkg)} - TextBox{parent=box,text="Connecting to API",alignment=ALIGN.CENTER,y=5,height=1,fg_bg=cpair(colors.white,style.root.bkg)} + TextBox{parent=box,text="Connecting to API",alignment=ALIGN.CENTER,y=5,fg_bg=cpair(colors.white,style.root.bkg)} else WaitingAnim{parent=box,x=waiting_x,y=1,fg_bg=cpair(colors.green,style.root.bkg)} - TextBox{parent=box,text="Connecting to Supervisor",alignment=ALIGN.CENTER,y=5,height=1,fg_bg=cpair(colors.white,style.root.bkg)} + TextBox{parent=box,text="Connecting to Supervisor",alignment=ALIGN.CENTER,y=5,fg_bg=cpair(colors.white,style.root.bkg)} end return root diff --git a/pocket/ui/main.lua b/pocket/ui/main.lua index 40b1104..524a67c 100644 --- a/pocket/ui/main.lua +++ b/pocket/ui/main.lua @@ -10,11 +10,10 @@ local pocket = require("pocket.pocket") local diag_apps = require("pocket.ui.apps.diag_apps") local dummy_app = require("pocket.ui.apps.dummy_app") local guide_app = require("pocket.ui.apps.guide") +local loader_app = require("pocket.ui.apps.loader") local sys_apps = require("pocket.ui.apps.sys_apps") local unit_app = require("pocket.ui.apps.unit") -local conn_waiting = require("pocket.ui.components.conn_waiting") - local home_page = require("pocket.ui.pages.home_page") local style = require("pocket.ui.style") @@ -33,8 +32,6 @@ local SignalBar = require("graphics.elements.indicators.signal") local ALIGN = core.ALIGN local cpair = core.cpair -local LINK_STATE = iocontrol.LINK_STATE - local APP_ID = pocket.APP_ID -- create new main view @@ -42,6 +39,8 @@ local APP_ID = pocket.APP_ID local function init(main) local db = iocontrol.get_db() + local main_pane = Div{parent=main,x=1,y=2} + -- window header message TextBox{parent=main,y=1,text="EARLY ACCESS ALPHA S C ",alignment=ALIGN.LEFT,height=1,fg_bg=style.header} local svr_conn = SignalBar{parent=main,y=1,x=22,compact=true,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.green,colors.gray)} @@ -50,28 +49,6 @@ local function init(main) db.ps.subscribe("svr_conn_quality", svr_conn.set_value) db.ps.subscribe("crd_conn_quality", crd_conn.set_value) - --#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_pane = MultiPane{parent=root_pane_div,x=1,y=1,panes={conn_sv_wait,conn_api_wait,main_pane}} - - root_pane.register(db.ps, "link_state", function (state) - if state == LINK_STATE.UNLINKED or state == LINK_STATE.API_LINK_ONLY then - root_pane.set_value(1) - elseif state == LINK_STATE.SV_LINK_ONLY then - root_pane.set_value(2) - else - root_pane.set_value(3) - end - end) - - --#endregion - --#region main page panel panes & sidebar local page_div = Div{parent=main_pane,x=4,y=1} @@ -80,6 +57,7 @@ local function init(main) unit_app(page_div) guide_app(page_div) + loader_app(page_div) sys_apps(page_div) diag_apps(page_div) dummy_app(page_div)