#484 work on redstone inversion
This commit is contained in:
@@ -33,16 +33,21 @@ function redstone_rtu.new()
|
||||
-- link digital input
|
||||
---@param side string
|
||||
---@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
|
||||
|
||||
if color then
|
||||
f_read = function ()
|
||||
return digital_read(rs.testBundledInput(side, color))
|
||||
if invert then
|
||||
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
|
||||
else
|
||||
f_read = function ()
|
||||
return digital_read(rs.getInput(side))
|
||||
if invert then
|
||||
f_read = function () return digital_read(not rs.getInput(side)) end
|
||||
else
|
||||
f_read = function () return digital_read(rs.getInput(side)) end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,36 +57,58 @@ function redstone_rtu.new()
|
||||
-- link digital output
|
||||
---@param side string
|
||||
---@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_write ---@type function
|
||||
|
||||
if color then
|
||||
f_read = function ()
|
||||
return digital_read(colors.test(rs.getBundledOutput(side), color))
|
||||
end
|
||||
if invert then
|
||||
f_read = function () return digital_read(not colors.test(rs.getBundledOutput(side), color)) end
|
||||
|
||||
f_write = function (level)
|
||||
if level ~= IO_LVL.FLOATING and level ~= IO_LVL.DISCONNECT then
|
||||
local output = rs.getBundledOutput(side)
|
||||
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)
|
||||
-- inverted conditions
|
||||
if digital_write(level) then
|
||||
output = colors.subtract(output, color)
|
||||
else output = colors.combine(output, color) end
|
||||
|
||||
rs.setBundledOutput(side, output)
|
||||
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
|
||||
else
|
||||
f_read = function ()
|
||||
return digital_read(rs.getOutput(side))
|
||||
end
|
||||
if invert then
|
||||
f_read = function () return digital_read(not 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))
|
||||
f_write = function (level)
|
||||
if level ~= IO_LVL.FLOATING and level ~= IO_LVL.DISCONNECT then
|
||||
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
|
||||
@@ -92,23 +119,15 @@ function redstone_rtu.new()
|
||||
-- link analog input
|
||||
---@param side string
|
||||
function public.link_ai(side)
|
||||
unit.connect_input_reg(
|
||||
function ()
|
||||
return rs.getAnalogInput(side)
|
||||
end
|
||||
)
|
||||
unit.connect_input_reg(function () return rs.getAnalogInput(side) end)
|
||||
end
|
||||
|
||||
-- link analog output
|
||||
---@param side string
|
||||
function public.link_ao(side)
|
||||
unit.connect_holding_reg(
|
||||
function ()
|
||||
return rs.getAnalogOutput(side)
|
||||
end,
|
||||
function (value)
|
||||
rs.setAnalogOutput(side, value)
|
||||
end
|
||||
function () return rs.getAnalogOutput(side) end,
|
||||
function (value) rs.setAnalogOutput(side, value) end
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user