#53 RTU redstone parse checks

This commit is contained in:
Mikayla Fischler 2022-05-18 14:30:48 -04:00
parent 790571b6fc
commit 62d5490dc8
2 changed files with 87 additions and 52 deletions

View File

@ -103,6 +103,19 @@ for entry_idx = 1, #rtu_redstone do
log.debug("init> starting redstone RTU I/O linking for reactor " .. io_reactor .. "...") log.debug("init> starting redstone RTU I/O linking for reactor " .. io_reactor .. "...")
local continue = true
for i = 1, #units do
local unit = units[i] ---@type rtu_unit_registry_entry
if unit.reactor == io_reactor and unit.type == rtu_t.redstone then
-- duplicate entry
log.warning("init> skipping definition block #" .. entry_idx .. " for reactor " .. io_reactor .. " with already defined redstone I/O")
continue = false
break
end
end
if continue then
for i = 1, #io_table do for i = 1, #io_table do
local valid = false local valid = false
local conf = io_table[i] local conf = io_table[i]
@ -125,11 +138,21 @@ for entry_idx = 1, #rtu_redstone do
-- link redstone in RTU -- link redstone in RTU
local mode = rsio.get_io_mode(conf.channel) local mode = rsio.get_io_mode(conf.channel)
if mode == rsio.IO_MODE.DIGITAL_IN then if mode == rsio.IO_MODE.DIGITAL_IN then
-- can't have duplicate inputs
if util.table_contains(capabilities, conf.channel) then
log.warning("init> skipping duplicate input for channel " .. rsio.to_string(conf.channel) .. " on side " .. conf.side)
else
rs_rtu.link_di(conf.side, conf.bundled_color) rs_rtu.link_di(conf.side, conf.bundled_color)
end
elseif mode == rsio.IO_MODE.DIGITAL_OUT then elseif mode == rsio.IO_MODE.DIGITAL_OUT then
rs_rtu.link_do(conf.channel, conf.side, conf.bundled_color) rs_rtu.link_do(conf.channel, conf.side, conf.bundled_color)
elseif mode == rsio.IO_MODE.ANALOG_IN then elseif mode == rsio.IO_MODE.ANALOG_IN then
-- can't have duplicate inputs
if util.table_contains(capabilities, conf.channel) then
log.warning("init> skipping duplicate input for channel " .. rsio.to_string(conf.channel) .. " on side " .. conf.side)
else
rs_rtu.link_ai(conf.side) rs_rtu.link_ai(conf.side)
end
elseif mode == rsio.IO_MODE.ANALOG_OUT then elseif mode == rsio.IO_MODE.ANALOG_OUT then
rs_rtu.link_ao(conf.side) rs_rtu.link_ao(conf.side)
else else
@ -162,6 +185,7 @@ for entry_idx = 1, #rtu_redstone do
log.debug("init> initialized RTU unit #" .. #units .. ": redstone_io (redstone) [1] for reactor " .. io_reactor) log.debug("init> initialized RTU unit #" .. #units .. ": redstone_io (redstone) [1] for reactor " .. io_reactor)
end end
end
-- mounted peripherals -- mounted peripherals
for i = 1, #rtu_devices do for i = 1, #rtu_devices do

View File

@ -107,6 +107,17 @@ util.filter_table = function (t, f, on_delete)
end end
end end
-- check if a table contains the provided element
---@param t table table to check
---@param element any element to check for
util.table_contains = function (t, element)
for i = 1, #t do
if t[i] == element then return true end
end
return false
end
-- MEKANISM POWER -- -- MEKANISM POWER --
-- function kFE(fe) return fe / 1000 end -- function kFE(fe) return fe / 1000 end