cc-mek-scada/coordinator/ui/components/turbine.lua

50 lines
2.1 KiB
Lua
Raw Normal View History

2024-07-27 16:34:01 +00:00
local iocontrol = require("coordinator.iocontrol")
2022-07-02 21:24:52 +00:00
2022-09-03 17:10:51 +00:00
local style = require("coordinator.ui.style")
2022-07-02 21:24:52 +00:00
local core = require("graphics.core")
2022-12-10 20:44:11 +00:00
local Rectangle = require("graphics.elements.rectangle")
2023-03-05 17:35:36 +00:00
local TextBox = require("graphics.elements.textbox")
2022-12-10 20:44:11 +00:00
2022-07-02 21:24:52 +00:00
local DataIndicator = require("graphics.elements.indicators.data")
local PowerIndicator = require("graphics.elements.indicators.power")
2022-07-02 21:24:52 +00:00
local StateIndicator = require("graphics.elements.indicators.state")
local VerticalBar = require("graphics.elements.indicators.vbar")
2023-05-07 01:27:36 +00:00
local cpair = core.cpair
local border = core.border
2022-07-02 21:24:52 +00:00
-- new turbine view
---@param root graphics_element parent
---@param x integer top left x
---@param y integer top left y
---@param ps psil ps interface
local function new_view(root, x, y, ps)
local text_fg = style.theme.text_fg
local lu_col = style.lu_colors
2024-07-27 16:34:01 +00:00
local db = iocontrol.get_db()
local turbine = Rectangle{parent=root,border=border(1,colors.gray,true),width=23,height=7,x=x,y=y}
2022-07-02 21:24:52 +00:00
local status = StateIndicator{parent=turbine,x=7,y=1,states=style.turbine.states,value=1,min_width=12}
2024-07-27 16:34:01 +00:00
local prod_rate = PowerIndicator{parent=turbine,x=5,y=3,lu_colors=lu_col,label="",unit=db.energy_label,format="%10.2f",value=0,rate=true,width=16,fg_bg=text_fg}
local flow_rate = DataIndicator{parent=turbine,x=5,y=4,lu_colors=lu_col,label="",unit="mB/t",format="%10.0f",value=0,commas=true,width=16,fg_bg=text_fg}
2022-07-02 21:24:52 +00:00
status.register(ps, "computed_status", status.update)
2024-07-27 16:34:01 +00:00
prod_rate.register(ps, "prod_rate", function (val) prod_rate.update(db.energy_convert(val)) end)
flow_rate.register(ps, "steam_input_rate", flow_rate.update)
2023-03-05 17:35:36 +00:00
local steam = VerticalBar{parent=turbine,x=2,y=1,fg_bg=cpair(colors.white,colors.gray),height=4,width=1}
local energy = VerticalBar{parent=turbine,x=3,y=1,fg_bg=cpair(colors.green,colors.gray),height=4,width=1}
TextBox{parent=turbine,text="S",x=2,y=5,width=1,fg_bg=text_fg}
TextBox{parent=turbine,text="E",x=3,y=5,width=1,fg_bg=text_fg}
2022-07-02 21:24:52 +00:00
steam.register(ps, "steam_fill", steam.update)
energy.register(ps, "energy_fill", energy.update)
2022-07-02 21:24:52 +00:00
end
return new_view