#484 work on redstone inversion

This commit is contained in:
Mikayla Fischler
2025-04-20 11:28:02 -04:00
parent 657261642c
commit f7c0a1d97d
3 changed files with 55 additions and 35 deletions

View File

@@ -20,6 +20,7 @@ local NumberField = require("graphics.elements.form.NumberField")
---@field port IO_PORT ---@field port IO_PORT
---@field side side ---@field side side
---@field color color|nil ---@field color color|nil
---@field invert true|nil
local tri = util.trinary local tri = util.trinary

View File

@@ -33,16 +33,21 @@ function redstone_rtu.new()
-- link digital input -- link digital input
---@param side string ---@param side string
---@param color integer ---@param color integer
function public.link_di(side, color) ---@param invert boolean|nil
function public.link_di(side, color, invert)
local f_read ---@type function local f_read ---@type function
if color then if color then
f_read = function () if invert then
return digital_read(rs.testBundledInput(side, color)) f_read = function () return digital_read(not rs.testBundledInput(side, color)) end
else
f_read = function () return digital_read(rs.testBundledInput(side, color)) end
end end
else else
f_read = function () if invert then
return digital_read(rs.getInput(side)) f_read = function () return digital_read(not rs.getInput(side)) end
else
f_read = function () return digital_read(rs.getInput(side)) end
end end
end end
@@ -52,36 +57,58 @@ function redstone_rtu.new()
-- link digital output -- link digital output
---@param side string ---@param side string
---@param color integer ---@param color integer
function public.link_do(side, color) ---@param invert boolean|nil
function public.link_do(side, color, invert)
local f_read ---@type function local f_read ---@type function
local f_write ---@type function local f_write ---@type function
if color then if color then
f_read = function () if invert then
return digital_read(colors.test(rs.getBundledOutput(side), color)) f_read = function () return digital_read(not colors.test(rs.getBundledOutput(side), color)) end
end
f_write = function (level) f_write = function (level)
if level ~= IO_LVL.FLOATING and level ~= IO_LVL.DISCONNECT then if level ~= IO_LVL.FLOATING and level ~= IO_LVL.DISCONNECT then
local output = rs.getBundledOutput(side) local output = rs.getBundledOutput(side)
if digital_write(level) then -- inverted conditions
output = colors.combine(output, color) if digital_write(level) then
else output = colors.subtract(output, color)
output = colors.subtract(output, color) else output = colors.combine(output, color) end
rs.setBundledOutput(side, output)
end end
end
else
f_read = function () return digital_read(colors.test(rs.getBundledOutput(side), color)) end
rs.setBundledOutput(side, output) f_write = function (level)
if level ~= IO_LVL.FLOATING and level ~= IO_LVL.DISCONNECT then
local output = rs.getBundledOutput(side)
if digital_write(level) then
output = colors.combine(output, color)
else output = colors.subtract(output, color) end
rs.setBundledOutput(side, output)
end
end end
end end
else else
f_read = function () if invert then
return digital_read(rs.getOutput(side)) f_read = function () return digital_read(not rs.getOutput(side)) end
end
f_write = function (level) f_write = function (level)
if level ~= IO_LVL.FLOATING and level ~= IO_LVL.DISCONNECT then if level ~= IO_LVL.FLOATING and level ~= IO_LVL.DISCONNECT then
rs.setOutput(side, digital_write(level)) rs.setOutput(side, not digital_write(level))
end
end
else
f_read = function () return digital_read(rs.getOutput(side)) end
f_write = function (level)
if level ~= IO_LVL.FLOATING and level ~= IO_LVL.DISCONNECT then
rs.setOutput(side, digital_write(level))
end
end end
end end
end end
@@ -92,23 +119,15 @@ function redstone_rtu.new()
-- link analog input -- link analog input
---@param side string ---@param side string
function public.link_ai(side) function public.link_ai(side)
unit.connect_input_reg( unit.connect_input_reg(function () return rs.getAnalogInput(side) end)
function ()
return rs.getAnalogInput(side)
end
)
end end
-- link analog output -- link analog output
---@param side string ---@param side string
function public.link_ao(side) function public.link_ao(side)
unit.connect_holding_reg( unit.connect_holding_reg(
function () function () return rs.getAnalogOutput(side) end,
return rs.getAnalogOutput(side) function (value) rs.setAnalogOutput(side, value) end
end,
function (value)
rs.setAnalogOutput(side, value)
end
) )
end end

View File

@@ -31,7 +31,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
local sps_rtu = require("rtu.dev.sps_rtu") local sps_rtu = require("rtu.dev.sps_rtu")
local turbinev_rtu = require("rtu.dev.turbinev_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu")
local RTU_VERSION = "v1.11.7" local RTU_VERSION = "v1.11.8"
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
local RTU_HW_STATE = databus.RTU_HW_STATE local RTU_HW_STATE = databus.RTU_HW_STATE