#412 updates to RSIO for induction matrix low, high, and analog charge level

This commit is contained in:
Mikayla Fischler
2024-04-20 16:32:18 -04:00
parent a786404092
commit d9efd5b8d2
9 changed files with 226 additions and 199 deletions

View File

@@ -2,6 +2,8 @@
-- Redstone RTU Session I/O Controller
--
local rsio = require("scada-common.rsio")
local rsctl = {}
-- create a new redstone RTU I/O controller
@@ -16,7 +18,7 @@ function rsctl.new(redstone_rtus)
---@return boolean
function public.is_connected(port)
for i = 1, #redstone_rtus do
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
if db.io[port] ~= nil then return true end
end
@@ -28,8 +30,8 @@ function rsctl.new(redstone_rtus)
---@param value boolean
function public.digital_write(port, value)
for i = 1, #redstone_rtus do
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
local io = db.io[port] ---@type rs_db_dig_io|nil
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
local io = db.io[port] ---@type rs_db_dig_io|nil
if io ~= nil then io.write(value) end
end
end
@@ -40,12 +42,25 @@ function rsctl.new(redstone_rtus)
---@return boolean|nil
function public.digital_read(port)
for i = 1, #redstone_rtus do
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
local io = db.io[port] ---@type rs_db_dig_io|nil
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
local io = db.io[port] ---@type rs_db_dig_io|nil
if io ~= nil then return io.read() end
end
end
-- write to an analog redstone port (applies to all RTUs)
---@param port IO_PORT
---@param value number value
---@param min number minimum value for scaling 0 to 15
---@param max number maximum value for scaling 0 to 15
function public.analog_write(port, value, min, max)
for i = 1, #redstone_rtus do
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
local io = db.io[port] ---@type rs_db_ana_io|nil
if io ~= nil then io.write(rsio.analog_write(value, min, max)) end
end
end
return public
end