2022-06-08 21:16:53 +00:00
|
|
|
-- Indicator Light Graphics Element
|
|
|
|
|
|
|
|
local util = require("scada-common.util")
|
|
|
|
|
|
|
|
local element = require("graphics.element")
|
|
|
|
|
|
|
|
---@class indicator_light_args
|
2022-06-11 16:21:14 +00:00
|
|
|
---@field label string indicator label
|
2022-06-08 21:16:53 +00:00
|
|
|
---@field colors cpair on/off colors (a/b respectively)
|
2022-06-11 16:21:14 +00:00
|
|
|
---@field min_label_width? integer label length if omitted
|
2022-06-08 21:16:53 +00:00
|
|
|
---@field parent graphics_element
|
|
|
|
---@field x? integer 1 if omitted
|
|
|
|
---@field y? integer 1 if omitted
|
|
|
|
---@field fg_bg cpair foreground/background colors
|
|
|
|
|
|
|
|
-- new indicator light
|
|
|
|
---@param args indicator_light_args
|
|
|
|
local function indicator_light(args)
|
|
|
|
-- determine width
|
2022-06-11 16:21:14 +00:00
|
|
|
args.width = math.max(args.min_label_width or 1, string.len(args.label)) + 3
|
2022-06-08 21:16:53 +00:00
|
|
|
|
|
|
|
-- create new graphics element base object
|
|
|
|
local e = element.new(args)
|
|
|
|
|
|
|
|
-- on/off blit strings
|
|
|
|
local on_blit = util.strrep(args.colors.blit_a, 2)
|
|
|
|
local off_blit = util.strrep(args.colors.blit_b, 2)
|
|
|
|
|
2022-06-11 16:21:14 +00:00
|
|
|
-- write label and initial indicator light
|
2022-06-08 21:16:53 +00:00
|
|
|
e.setCursorPos(1, 1)
|
|
|
|
e.window.blit(" ", "000", off_blit .. e.fg_bg.blit_bkg)
|
2022-06-11 16:21:14 +00:00
|
|
|
e.window.write(args.label)
|
2022-06-08 21:16:53 +00:00
|
|
|
|
|
|
|
-- on state change
|
|
|
|
---@param new_state boolean indicator state
|
|
|
|
function e.on_update(new_state)
|
|
|
|
e.window.setCursorPos(1, 1)
|
|
|
|
if new_state then
|
|
|
|
e.window.blit(" ", "00", on_blit)
|
|
|
|
else
|
|
|
|
e.window.blit(" ", "00", off_blit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return e.get()
|
|
|
|
end
|
|
|
|
|
|
|
|
return indicator_light
|