Skip to content

Commit

Permalink
Merge pull request #490 from MikaylaFischler/devel
Browse files Browse the repository at this point in the history
2024.05.15 Release
  • Loading branch information
MikaylaFischler authored May 15, 2024
2 parents 4fe6792 + 41b7a68 commit afc38e7
Show file tree
Hide file tree
Showing 25 changed files with 950 additions and 104 deletions.
2 changes: 2 additions & 0 deletions coordinator/configure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1449,9 +1449,11 @@ function configurator.configure(start_code, message)
elseif event == "paste" then
display.handle_paste(param1)
elseif event == "peripheral_detach" then
---@diagnostic disable-next-line: discard-returns
ppm.handle_unmount(param1)
tool_ctl.gen_mon_list()
elseif event == "peripheral" then
---@diagnostic disable-next-line: discard-returns
ppm.mount(param1)
tool_ctl.gen_mon_list()
elseif event == "monitor_resize" then
Expand Down
19 changes: 17 additions & 2 deletions coordinator/iocontrol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ function iocontrol.init(conf, comms, temp_scale)
---@class ioctl_unit
local entry = {
unit_id = i,
connected = false,
rtu_hw = { boilers = {}, turbines = {} },

num_boilers = 0,
num_turbines = 0,
Expand Down Expand Up @@ -319,12 +321,14 @@ function iocontrol.init(conf, comms, temp_scale)
for _ = 1, conf.cooling.r_cool[i].BoilerCount do
table.insert(entry.boiler_ps_tbl, psil.create())
table.insert(entry.boiler_data_tbl, {})
table.insert(entry.rtu_hw.boilers, { connected = false, faulted = false })
end

-- create turbine tables
for _ = 1, conf.cooling.r_cool[i].TurbineCount do
table.insert(entry.turbine_ps_tbl, psil.create())
table.insert(entry.turbine_data_tbl, {})
table.insert(entry.rtu_hw.turbines, { connected = false, faulted = false })
end

-- create tank tables
Expand Down Expand Up @@ -897,6 +901,7 @@ function iocontrol.update_unit_statuses(statuses)
end

if #reactor_status == 0 then
unit.connected = false
unit.unit_ps.publish("computed_status", 1) -- disconnected
elseif #reactor_status == 3 then
local mek_status = reactor_status[1]
Expand Down Expand Up @@ -956,6 +961,8 @@ function iocontrol.update_unit_statuses(statuses)
unit.unit_ps.publish(key, val)
end
end

unit.connected = true
else
log.debug(log_header .. "reactor status length mismatch")
valid = false
Expand All @@ -970,7 +977,10 @@ function iocontrol.update_unit_statuses(statuses)
local boil_sum = 0

for id = 1, #unit.boiler_ps_tbl do
if rtu_statuses.boilers[id] == nil then
local connected = rtu_statuses.boilers[id] ~= nil
unit.rtu_hw.boilers[id].connected = connected

if not connected then
-- disconnected
unit.boiler_ps_tbl[id].publish("computed_status", 1)
end
Expand All @@ -982,6 +992,7 @@ function iocontrol.update_unit_statuses(statuses)
local ps = unit.boiler_ps_tbl[id] ---@type psil

local rtu_faulted = _record_multiblock_status(boiler, data, ps)
unit.rtu_hw.boilers[id].faulted = rtu_faulted

if rtu_faulted then
ps.publish("computed_status", 3) -- faulted
Expand Down Expand Up @@ -1013,7 +1024,10 @@ function iocontrol.update_unit_statuses(statuses)
local flow_sum = 0

for id = 1, #unit.turbine_ps_tbl do
if rtu_statuses.turbines[id] == nil then
local connected = rtu_statuses.turbines[id] ~= nil
unit.rtu_hw.turbines[id].connected = connected

if not connected then
-- disconnected
unit.turbine_ps_tbl[id].publish("computed_status", 1)
end
Expand All @@ -1025,6 +1039,7 @@ function iocontrol.update_unit_statuses(statuses)
local ps = unit.turbine_ps_tbl[id] ---@type psil

local rtu_faulted = _record_multiblock_status(turbine, data, ps)
unit.rtu_hw.turbines[id].faulted = rtu_faulted

if rtu_faulted then
ps.publish("computed_status", 3) -- faulted
Expand Down
33 changes: 19 additions & 14 deletions coordinator/session/pocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,26 @@ function pocket.new_session(id, s_addr, in_queue, out_queue, timeout)
}

_send(CRDN_TYPE.API_GET_FAC, data)
elseif pkt.type == CRDN_TYPE.API_GET_UNITS then
local data = {}

for i = 1, #db.units do
local u = db.units[i] ---@type ioctl_unit
table.insert(data, {
u.unit_id,
u.num_boilers,
u.num_turbines,
u.num_snas,
u.has_tank
})
elseif pkt.type == CRDN_TYPE.API_GET_UNIT then
if pkt.length == 1 and type(pkt.data[1]) == "number" then
local u = db.units[pkt.data[1]] ---@type ioctl_unit

if u then
local data = {
u.unit_id,
u.connected,
u.rtu_hw,
u.alarms,
u.annunciator,
u.reactor_data,
u.boiler_data_tbl,
u.turbine_data_tbl,
u.tank_data_tbl
}

_send(CRDN_TYPE.API_GET_UNIT, data)
end
end

_send(CRDN_TYPE.API_GET_UNITS, data)
else
log.debug(log_header .. "handler received unsupported CRDN packet type " .. pkt.type)
end
Expand Down
2 changes: 1 addition & 1 deletion coordinator/startup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local renderer = require("coordinator.renderer")
local sounder = require("coordinator.sounder")
local threads = require("coordinator.threads")

local COORDINATOR_VERSION = "v1.4.5"
local COORDINATOR_VERSION = "v1.4.6"

local CHUNK_LOAD_DELAY_S = 30.0

Expand Down
2 changes: 1 addition & 1 deletion coordinator/ui/components/unit_detail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ local function init(parent, id)
local rad_wrn = IndicatorLight{parent=annunciator,label="Radiation Warning",colors=ind_yel}
local r_rtrip = IndicatorLight{parent=annunciator,label="RCP Trip",colors=ind_red}
local r_cflow = IndicatorLight{parent=annunciator,label="RCS Flow Low",colors=ind_yel}
local r_clow = IndicatorLight{parent=annunciator,label="Coolant Level Low",colors=ind_yel}
local r_clow = IndicatorLight{parent=annunciator,label="Coolant Level Low",colors=ind_yel}
local r_temp = IndicatorLight{parent=annunciator,label="Reactor Temp. High",colors=ind_red}
local r_rhdt = IndicatorLight{parent=annunciator,label="Reactor High Delta T",colors=ind_yel}
local r_firl = IndicatorLight{parent=annunciator,label="Fuel Input Rate Low",colors=ind_yel}
Expand Down
2 changes: 1 addition & 1 deletion graphics/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")

local core = {}

core.version = "2.2.3"
core.version = "2.2.4"

core.flasher = flasher
core.events = events
Expand Down
3 changes: 3 additions & 0 deletions graphics/element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ function element.new(args, child_offset_x, child_offset_y)
---@param offset_y integer y offset for mouse events
---@param next_y integer next line if no y was provided
function protected.prepare_template(offset_x, offset_y, next_y)
-- don't auto incrememnt y if inheriting height, that would cause an assertion
next_y = util.trinary(args.height == nil, 1, next_y)

-- record offsets in case there is a reposition
self.offset_x = offset_x
self.offset_y = offset_y
Expand Down
10 changes: 5 additions & 5 deletions graphics/elements/controls/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local function app_button(args)
element.assert(type(args.app_fg_bg) == "table", "app_fg_bg is a required field")

args.height = 4
args.width = 5
args.width = 7

-- create new graphics element base object
local e = element.new(args)
Expand All @@ -46,7 +46,7 @@ local function app_button(args)
end

-- draw icon
e.w_set_cur(1, 1)
e.w_set_cur(2, 1)
e.w_set_fgd(fgd)
e.w_set_bkg(bkg)
e.w_write("\x9f\x83\x83\x83")
Expand All @@ -55,16 +55,16 @@ local function app_button(args)
e.w_write("\x90")
e.w_set_fgd(fgd)
e.w_set_bkg(bkg)
e.w_set_cur(1, 2)
e.w_set_cur(2, 2)
e.w_write("\x95 ")
e.w_set_fgd(bkg)
e.w_set_bkg(fgd)
e.w_write("\x95")
e.w_set_cur(1, 3)
e.w_set_cur(2, 3)
e.w_write("\x82\x8f\x8f\x8f\x81")

-- write the icon text
e.w_set_cur(3, 2)
e.w_set_cur(4, 2)
e.w_set_fgd(fgd)
e.w_set_bkg(bkg)
e.w_write(args.text)
Expand Down
98 changes: 71 additions & 27 deletions graphics/elements/controls/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ local element = require("graphics.element")

local MOUSE_CLICK = core.events.MOUSE_CLICK

---@class sidebar_tab
---@field char string character identifier
---@field color cpair tab colors (fg/bg)

---@class sidebar_args
---@field tabs table sidebar tab options
---@field callback function function to call on tab change
---@field parent graphics_element
---@field id? string element id
---@field x? integer 1 if omitted
Expand All @@ -27,21 +21,16 @@ local MOUSE_CLICK = core.events.MOUSE_CLICK
---@param args sidebar_args
---@return graphics_element element, element_id id
local function sidebar(args)
element.assert(type(args.tabs) == "table", "tabs is a required field")
element.assert(#args.tabs > 0, "at least one tab is required")
element.assert(type(args.callback) == "function", "callback is a required field")

args.width = 3

-- create new graphics element base object
local e = element.new(args)

element.assert(e.frame.h >= (#args.tabs * 3), "height insufficent to display all tabs")

-- default to 1st tab
e.value = 1

local was_pressed = false
local tabs = {}

-- show the button state
---@param pressed? boolean if the currently selected tab should appear as actively pressed
Expand All @@ -51,10 +40,18 @@ local function sidebar(args)
was_pressed = pressed
pressed_idx = pressed_idx or e.value

for i = 1, #args.tabs do
local tab = args.tabs[i] ---@type sidebar_tab
-- clear
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
for y = 1, e.frame.h do
e.w_set_cur(1, y)
e.w_write(" ")
end

local y = ((i - 1) * 3) + 1
-- draw tabs
for i = 1, #tabs do
local tab = tabs[i] ---@type sidebar_tab
local y = tab.y_start

e.w_set_cur(1, y)

Expand All @@ -66,13 +63,29 @@ local function sidebar(args)
e.w_set_bkg(tab.color.bkg)
end

e.w_write(" ")
e.w_set_cur(1, y + 1)
if e.value == i then
e.w_write(" " .. tab.char .. "\x10")
else e.w_write(" " .. tab.char .. " ") end
e.w_set_cur(1, y + 2)
e.w_write(" ")
if tab.tall then
e.w_write(" ")
e.w_set_cur(1, y + 1)
end

e.w_write(tab.label)

if tab.tall then
e.w_set_cur(1, y + 2)
e.w_write(" ")
end
end
end

-- determine which tab was pressed
---@param y integer y coordinate
local function find_tab(y)
for i = 1, #tabs do
local tab = tabs[i] ---@type sidebar_tab

if y >= tab.y_start and y <= tab.y_end then
return i
end
end
end

Expand All @@ -81,23 +94,25 @@ local function sidebar(args)
function e.handle_mouse(event)
-- determine what was pressed
if e.enabled then
local cur_idx = math.ceil(event.current.y / 3)
local ini_idx = math.ceil(event.initial.y / 3)
local cur_idx = find_tab(event.current.y)
local ini_idx = find_tab(event.initial.y)
local tab = tabs[cur_idx]

if args.tabs[cur_idx] ~= nil then
-- handle press if a callback was provided
if tab ~= nil and type(tab.callback) == "function" then
if event.type == MOUSE_CLICK.TAP then
e.value = cur_idx
draw(true)
-- show as unpressed in 0.25 seconds
tcd.dispatch(0.25, function () draw(false) end)
args.callback(e.value)
tab.callback()
elseif event.type == MOUSE_CLICK.DOWN then
draw(true, cur_idx)
elseif event.type == MOUSE_CLICK.UP then
if cur_idx == ini_idx and e.in_frame_bounds(event.current.x, event.current.y) then
e.value = cur_idx
draw(false)
args.callback(e.value)
tab.callback()
else draw(false) end
end
elseif event.type == MOUSE_CLICK.UP then
Expand All @@ -113,6 +128,35 @@ local function sidebar(args)
draw(false)
end

-- update the sidebar navigation options
---@param items table sidebar entries
function e.on_update(items)
local next_y = 1

tabs = {}

for i = 1, #items do
local item = items[i]
local height = util.trinary(item.tall, 3, 1)

---@class sidebar_tab
local entry = {
y_start = next_y, ---@type integer
y_end = next_y + height - 1, ---@type integer
tall = item.tall, ---@type boolean
label = item.label, ---@type string
color = item.color, ---@type cpair
callback = item.callback ---@type function|nil
}

next_y = next_y + height

tabs[i] = entry
end

draw()
end

-- element redraw
e.redraw = draw

Expand Down
Loading

0 comments on commit afc38e7

Please sign in to comment.