From 72791d042b767ba964a2eabc3cb64091ddedba67 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Fri, 3 Feb 2023 15:19:00 -0500 Subject: [PATCH] #149 validate display sizes on startup --- coordinator/renderer.lua | 24 +++++++++++++++++++++ coordinator/startup.lua | 18 +++++++++++++--- coordinator/ui/components/processctl.lua | 2 ++ coordinator/ui/components/unit_overview.lua | 2 ++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/coordinator/renderer.lua b/coordinator/renderer.lua index 0d99db3..51816f6 100644 --- a/coordinator/renderer.lua +++ b/coordinator/renderer.lua @@ -1,4 +1,5 @@ local log = require("scada-common.log") +local util = require("scada-common.util") local style = require("coordinator.ui.style") @@ -85,6 +86,29 @@ function renderer.reset(recolor) end end +-- check main display width +---@return boolean width_okay +function renderer.validate_main_display_width() + local w, _ = engine.monitors.primary.getSize() + return w == 164 +end + +-- check display sizes +---@return boolean valid all unit display dimensions OK +function renderer.validate_unit_display_sizes() + local valid = true + + for id, monitor in pairs(engine.monitors.unit_displays) do + local w, h = monitor.getSize() + if w ~= 79 or h ~= 52 then + log.warning(util.c("unit ", id, " display resolution not 79 wide by 52 tall: ", w, ", ", h)) + valid = false + end + end + + return valid +end + -- initialize the dmesg output window function renderer.init_dmesg() local disp_x, disp_y = engine.monitors.primary.getSize() diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 3025eb3..d173eb1 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol") local renderer = require("coordinator.renderer") local sounder = require("coordinator.sounder") -local COORDINATOR_VERSION = "beta-v0.8.13" +local COORDINATOR_VERSION = "beta-v0.8.14" local print = util.print local println = util.println @@ -84,13 +84,25 @@ local function main() return end - log.info("monitors ready, dmesg output incoming...") - -- init renderer renderer.set_displays(monitors) renderer.reset(config.RECOLOR) + + if not renderer.validate_main_display_width() then + println("boot> main display must be 8 blocks wide") + log.fatal("main display not wide enough") + return + elseif not renderer.validate_unit_display_sizes() then + println("boot> one or more unit display dimensions incorrect; they must be 4x4 blocks") + log.fatal("unit display dimensions incorrect") + return + end + renderer.init_dmesg() + -- lets get started! + log.info("monitors ready, dmesg output incoming...") + log_graphics("displays connected and reset") log_sys("system start on " .. os.date("%c")) log_boot("starting " .. COORDINATOR_VERSION) diff --git a/coordinator/ui/components/processctl.lua b/coordinator/ui/components/processctl.lua index 4bda49f..922799b 100644 --- a/coordinator/ui/components/processctl.lua +++ b/coordinator/ui/components/processctl.lua @@ -35,6 +35,8 @@ local period = core.flasher.PERIOD ---@param x integer top left x ---@param y integer top left y local function new_view(root, x, y) + assert(root.height() >= (y + 24), "main display not of sufficient vertical resolution (add an additional row of monitors)") + local facility = iocontrol.get_db().facility local units = iocontrol.get_db().units diff --git a/coordinator/ui/components/unit_overview.lua b/coordinator/ui/components/unit_overview.lua index 3846be4..672c6ea 100644 --- a/coordinator/ui/components/unit_overview.lua +++ b/coordinator/ui/components/unit_overview.lua @@ -39,6 +39,8 @@ local function make(parent, x, y, unit) height = 25 end + assert(parent.height() >= (y + height), "main display not of sufficient vertical resolution (add an additional row of monitors)") + -- bounding box div local root = Div{parent=parent,x=x,y=y,width=80,height=height}