mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#410 moved diagnostic apps to main app list and added app page nav
This commit is contained in:
parent
e1a632dcc7
commit
526a54903e
@ -29,6 +29,7 @@ local element = {}
|
||||
---|checkbox_args
|
||||
---|hazard_button_args
|
||||
---|multi_button_args
|
||||
---|app_page_selector_args
|
||||
---|push_button_args
|
||||
---|radio_2d_args
|
||||
---|radio_button_args
|
||||
|
75
graphics/elements/controls/app_page_selector.lua
Normal file
75
graphics/elements/controls/app_page_selector.lua
Normal file
@ -0,0 +1,75 @@
|
||||
-- App Page Selector Graphics Element
|
||||
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local core = require("graphics.core")
|
||||
local element = require("graphics.element")
|
||||
|
||||
local MOUSE_CLICK = core.events.MOUSE_CLICK
|
||||
|
||||
---@class app_page_selector_args
|
||||
---@field page_count integer number of pages (will become this element's width)
|
||||
---@field active_color color on/off colors (a/b respectively)
|
||||
---@field callback function function to call on touch
|
||||
---@field parent graphics_element
|
||||
---@field id? string element id
|
||||
---@field x? integer 1 if omitted
|
||||
---@field y? integer auto incremented if omitted
|
||||
---@field fg_bg? cpair foreground/background colors
|
||||
---@field hidden? boolean true to hide on initial draw
|
||||
|
||||
-- new app page selector
|
||||
---@param args app_page_selector_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function app_page_selector(args)
|
||||
element.assert(util.is_int(args.page_count), "page_count is a required field")
|
||||
element.assert(util.is_int(args.active_color), "active_color is a required field")
|
||||
element.assert(type(args.callback) == "function", "callback is a required field")
|
||||
|
||||
args.height = 1
|
||||
args.width = args.page_count
|
||||
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
|
||||
e.value = 1
|
||||
|
||||
-- draw dot selectors
|
||||
function e.redraw()
|
||||
for i = 1, args.page_count do
|
||||
e.w_set_cur(i, 1)
|
||||
e.w_set_fgd(util.trinary(i == e.value, args.active_color, e.fg_bg.fgd))
|
||||
e.w_write("\x07")
|
||||
end
|
||||
end
|
||||
|
||||
-- handle mouse interaction
|
||||
---@param event mouse_interaction mouse event
|
||||
function e.handle_mouse(event)
|
||||
if e.enabled then
|
||||
if event.type == MOUSE_CLICK.TAP then
|
||||
e.set_value(event.current.x)
|
||||
args.callback(e.value)
|
||||
elseif event.type == MOUSE_CLICK.UP then
|
||||
if e.in_frame_bounds(event.current.x, event.current.y) then
|
||||
e.set_value(event.current.x)
|
||||
args.callback(e.value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- set the value (does not call the callback)
|
||||
---@param val integer new value
|
||||
function e.set_value(val)
|
||||
e.value = val
|
||||
e.redraw()
|
||||
end
|
||||
|
||||
-- initial draw
|
||||
e.redraw()
|
||||
|
||||
return e.complete()
|
||||
end
|
||||
|
||||
return app_page_selector
|
@ -1,5 +1,5 @@
|
||||
--
|
||||
-- Diagnostic Tools
|
||||
-- Diagnostic Apps
|
||||
--
|
||||
|
||||
local iocontrol = require("pocket.iocontrol")
|
||||
@ -7,12 +7,10 @@ local iocontrol = require("pocket.iocontrol")
|
||||
local core = require("graphics.core")
|
||||
|
||||
local Div = require("graphics.elements.div")
|
||||
local MultiPane = require("graphics.elements.multipane")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
|
||||
local IndicatorLight = require("graphics.elements.indicators.light")
|
||||
|
||||
local App = require("graphics.elements.controls.app")
|
||||
local Checkbox = require("graphics.elements.controls.checkbox")
|
||||
local PushButton = require("graphics.elements.controls.push_button")
|
||||
local SwitchButton = require("graphics.elements.controls.switch_button")
|
||||
@ -21,32 +19,17 @@ local cpair = core.cpair
|
||||
|
||||
local ALIGN = core.ALIGN
|
||||
|
||||
-- new diagnostics page view
|
||||
-- create diagnostic app pages
|
||||
---@param root graphics_element parent
|
||||
local function new_view(root)
|
||||
local function create_pages(root)
|
||||
local db = iocontrol.get_db()
|
||||
|
||||
local main = Div{parent=root,x=1,y=1}
|
||||
|
||||
local diag_home = Div{parent=main,x=1,y=1}
|
||||
|
||||
TextBox{parent=diag_home,text="Diagnostic Apps",x=1,y=2,height=1,alignment=ALIGN.CENTER}
|
||||
|
||||
local alarm_test = Div{parent=main,x=1,y=1}
|
||||
|
||||
local panes = { diag_home, alarm_test }
|
||||
|
||||
local page_pane = MultiPane{parent=main,x=1,y=1,panes=panes}
|
||||
|
||||
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_home, 2)
|
||||
|
||||
------------------------
|
||||
-- Alarm Testing Page --
|
||||
------------------------
|
||||
|
||||
table.insert(npage_alarm.tasks, db.diag.tone_test.get_tone_states)
|
||||
local alarm_test = Div{parent=root,x=1,y=1}
|
||||
local alarm_tasks = { db.diag.tone_test.get_tone_states }
|
||||
|
||||
local ttest = db.diag.tone_test
|
||||
|
||||
@ -61,8 +44,6 @@ 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=npage_home.nav_to}
|
||||
|
||||
local tones = Div{parent=audio,x=2,y=3,height=10,width=8,fg_bg=cpair(colors.black,colors.yellow)}
|
||||
|
||||
TextBox{parent=tones,text="Tones",height=1,alignment=ALIGN.CENTER,fg_bg=audio.get_fg_bg()}
|
||||
@ -127,15 +108,7 @@ local function new_view(root)
|
||||
|
||||
ttest.tone_indicators = { t_1, t_2, t_3, t_4, t_5, t_6, t_7, t_8 }
|
||||
|
||||
--------------
|
||||
-- App List --
|
||||
--------------
|
||||
|
||||
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)}
|
||||
|
||||
return main
|
||||
return { Alarm = { e = alarm_test, tasks = alarm_tasks } }
|
||||
end
|
||||
|
||||
return new_view
|
||||
return create_pages
|
@ -9,7 +9,6 @@ local style = require("pocket.ui.style")
|
||||
local conn_waiting = require("pocket.ui.components.conn_waiting")
|
||||
|
||||
local boiler_page = require("pocket.ui.pages.boiler_page")
|
||||
local diag_page = require("pocket.ui.pages.diag_page")
|
||||
local home_page = require("pocket.ui.pages.home_page")
|
||||
local reactor_page = require("pocket.ui.pages.reactor_page")
|
||||
local turbine_page = require("pocket.ui.pages.turbine_page")
|
||||
@ -76,11 +75,10 @@ local function init(main)
|
||||
{ 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 = "T", color = cpair(colors.black,colors.white) }
|
||||
}
|
||||
|
||||
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={home_page(page_div),unit_page(page_div),reactor_page(page_div),boiler_page(page_div),turbine_page(page_div)}}
|
||||
|
||||
local base = iocontrol.init_nav(page_pane)
|
||||
|
||||
|
@ -2,30 +2,64 @@
|
||||
-- Main Home Page
|
||||
--
|
||||
|
||||
local iocontrol = require("pocket.iocontrol")
|
||||
local iocontrol = require("pocket.iocontrol")
|
||||
|
||||
local core = require("graphics.core")
|
||||
local diag_apps = require("pocket.ui.apps.diag_apps")
|
||||
|
||||
local Div = require("graphics.elements.div")
|
||||
local core = require("graphics.core")
|
||||
|
||||
local App = require("graphics.elements.controls.app")
|
||||
local Div = require("graphics.elements.div")
|
||||
local MultiPane = require("graphics.elements.multipane")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
|
||||
local AppPageSel = require("graphics.elements.controls.app_page_selector")
|
||||
local App = require("graphics.elements.controls.app")
|
||||
|
||||
local cpair = core.cpair
|
||||
|
||||
local ALIGN = core.ALIGN
|
||||
|
||||
-- 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)}
|
||||
App{parent=main,x=10,y=2,text="\x15",title="CTL",callback=function()end,app_fg_bg=cpair(colors.black,colors.green)}
|
||||
App{parent=main,x=17,y=2,text="\x08",title="DEV",callback=function()end,app_fg_bg=cpair(colors.black,colors.lightGray)}
|
||||
App{parent=main,x=3,y=7,text="\x7f",title="Waste",callback=function()end,app_fg_bg=cpair(colors.black,colors.brown)}
|
||||
App{parent=main,x=10,y=7,text="\xb6",title="Guide",callback=function()end,app_fg_bg=cpair(colors.black,colors.cyan)}
|
||||
local apps = Div{parent=main,x=1,y=1,height=19}
|
||||
|
||||
local apps_1 = Div{parent=apps,x=1,y=1,height=15}
|
||||
local apps_2 = Div{parent=apps,x=1,y=1,height=15}
|
||||
|
||||
local panes = { apps_1, apps_2 }
|
||||
|
||||
local app_pane = MultiPane{parent=apps,x=1,y=1,panes=panes,height=15}
|
||||
|
||||
AppPageSel{parent=apps,x=11,y=18,page_count=2,active_color=colors.lightGray,callback=app_pane.set_value,fg_bg=cpair(colors.gray,colors.black)}
|
||||
|
||||
local d_apps = diag_apps(main)
|
||||
|
||||
local page_panes = { apps, d_apps.Alarm.e }
|
||||
|
||||
local page_pane = MultiPane{parent=main,x=1,y=1,panes=page_panes}
|
||||
|
||||
local npage_home = db.nav.new_page(nil, 1, page_pane)
|
||||
local npage_apps = db.nav.new_page(npage_home, 1)
|
||||
|
||||
local npage_alarm = db.nav.new_page(npage_apps, 2)
|
||||
npage_alarm.tasks = d_apps.Alarm.tasks
|
||||
|
||||
App{parent=apps_1,x=3,y=2,text="\x17",title="PRC",callback=function()end,app_fg_bg=cpair(colors.black,colors.purple)}
|
||||
App{parent=apps_1,x=10,y=2,text="\x15",title="CTL",callback=function()end,app_fg_bg=cpair(colors.black,colors.green)}
|
||||
App{parent=apps_1,x=17,y=2,text="\x08",title="DEV",callback=function()end,app_fg_bg=cpair(colors.black,colors.lightGray)}
|
||||
App{parent=apps_1,x=3,y=7,text="\x7f",title="Waste",callback=function()end,app_fg_bg=cpair(colors.black,colors.brown)}
|
||||
App{parent=apps_1,x=10,y=7,text="\xb6",title="Guide",callback=function()end,app_fg_bg=cpair(colors.black,colors.cyan)}
|
||||
|
||||
TextBox{parent=apps_2,text="Diagnostic Apps",x=1,y=2,height=1,alignment=ALIGN.CENTER}
|
||||
|
||||
App{parent=apps_2,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=apps_2,x=10,y=4,text="\x1e",title="LoopT",callback=function()end,app_fg_bg=cpair(colors.black,colors.cyan)}
|
||||
App{parent=apps_2,x=17,y=4,text="@",title="Comps",callback=function()end,app_fg_bg=cpair(colors.black,colors.orange)}
|
||||
|
||||
return main
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user