#604 configuration of redstone RTUs
This commit is contained in:
parent
e3dbda3c54
commit
12ead136a3
@ -1,4 +1,5 @@
|
||||
local constants = require("scada-common.constants")
|
||||
local ppm = require("scada-common.ppm")
|
||||
local rsio = require("scada-common.rsio")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
@ -34,6 +35,7 @@ local IO_MODE = rsio.IO_MODE
|
||||
local LEFT = core.ALIGN.LEFT
|
||||
|
||||
local self = {
|
||||
rs_cfg_phy = false, ---@type string|nil|false
|
||||
rs_cfg_port = 1, ---@type IO_PORT
|
||||
rs_cfg_editing = false, ---@type integer|false
|
||||
|
||||
@ -109,6 +111,23 @@ local function color_to_idx(color)
|
||||
end
|
||||
end
|
||||
|
||||
-- select the subset of redstone entries assigned to the given phy
|
||||
---@param cfg rtu_rs_definition[] the full redstone entry list
|
||||
---@param phy string|nil which phy to get redstone entries for
|
||||
---@param invert boolean? true to get all except this phy
|
||||
---@return rtu_rs_definition[]
|
||||
local function redstone_subset(cfg, phy, invert)
|
||||
local subset = {}
|
||||
|
||||
for i = 1, #cfg do
|
||||
if ((not invert) and cfg[i].relay == phy) or (invert and cfg[i].relay ~= phy) then
|
||||
table.insert(subset, cfg[i])
|
||||
end
|
||||
end
|
||||
|
||||
return subset
|
||||
end
|
||||
|
||||
local redstone = {}
|
||||
|
||||
-- validate a redstone entry
|
||||
@ -146,13 +165,81 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
local rs_c_6 = Div{parent=rs_cfg,x=2,y=4,width=49}
|
||||
local rs_c_7 = Div{parent=rs_cfg,x=2,y=4,width=49}
|
||||
local rs_c_8 = Div{parent=rs_cfg,x=2,y=4,width=49}
|
||||
local rs_c_9 = Div{parent=rs_cfg,x=2,y=4,width=49}
|
||||
local rs_c_10 = Div{parent=rs_cfg,x=2,y=4,width=49}
|
||||
|
||||
local rs_pane = MultiPane{parent=rs_cfg,x=1,y=4,panes={rs_c_1,rs_c_2,rs_c_3,rs_c_4,rs_c_5,rs_c_6,rs_c_7,rs_c_8}}
|
||||
local rs_pane = MultiPane{parent=rs_cfg,x=1,y=4,panes={rs_c_1,rs_c_2,rs_c_3,rs_c_4,rs_c_5,rs_c_6,rs_c_7,rs_c_8,rs_c_9,rs_c_10}}
|
||||
|
||||
TextBox{parent=rs_cfg,x=1,y=2,text=" Redstone Connections",fg_bg=cpair(colors.black,colors.red)}
|
||||
local header = TextBox{parent=rs_cfg,x=1,y=2,text=" Redstone Connections",fg_bg=cpair(colors.black,colors.red)}
|
||||
|
||||
TextBox{parent=rs_c_1,x=1,y=1,text=" port side/color unit/facility",fg_bg=g_lg_fg_bg}
|
||||
local rs_list = ListBox{parent=rs_c_1,x=1,y=2,height=11,width=49,scroll_height=200,fg_bg=bw_fg_bg,nav_fg_bg=g_lg_fg_bg,nav_active=cpair(colors.black,colors.gray)}
|
||||
--#region Interface Selection
|
||||
|
||||
TextBox{parent=rs_c_1,x=1,y=1,text="Configure this computer or a redstone relay."}
|
||||
local iface_list = ListBox{parent=rs_c_1,x=1,y=3,height=10,width=49,scroll_height=1000,fg_bg=bw_fg_bg,nav_fg_bg=g_lg_fg_bg,nav_active=cpair(colors.black,colors.gray)}
|
||||
|
||||
-- update relay interface list
|
||||
function tool_ctl.update_relay_list()
|
||||
local mounts = ppm.list_mounts()
|
||||
|
||||
iface_list.remove_all()
|
||||
|
||||
-- assemble list of configured relays
|
||||
local relays = {}
|
||||
for i = 1, #tmp_cfg.Redstone do
|
||||
local def = tmp_cfg.Redstone[i]
|
||||
if def.relay and not util.table_contains(relays, def.relay) then
|
||||
table.insert(relays, def.relay)
|
||||
end
|
||||
end
|
||||
|
||||
-- add unconfigured connected relays
|
||||
for name, entry in pairs(mounts) do
|
||||
if entry.type == "redstone_relay" and not util.table_contains(relays, name) then
|
||||
table.insert(relays, name)
|
||||
end
|
||||
end
|
||||
|
||||
local function config_rs(name)
|
||||
header.set_value(" Redstone Connections (" .. name .. ")")
|
||||
|
||||
self.rs_cfg_phy = tri(name == "local", nil, name)
|
||||
|
||||
tool_ctl.gen_rs_summary()
|
||||
rs_pane.set_value(2)
|
||||
end
|
||||
|
||||
local line = Div{parent=iface_list,height=2,fg_bg=cpair(colors.black,colors.white)}
|
||||
TextBox{parent=line,x=1,y=1,text="@ local",fg_bg=cpair(colors.black,colors.white)}
|
||||
TextBox{parent=line,x=3,y=2,text="This Computer",fg_bg=cpair(colors.gray,colors.white)}
|
||||
local count = #redstone_subset(ini_cfg.Redstone, nil)
|
||||
TextBox{parent=line,x=33,y=2,width=16,alignment=core.ALIGN.RIGHT,text=count.." connections",fg_bg=cpair(colors.gray,colors.white)}
|
||||
|
||||
PushButton{parent=line,x=41,y=1,min_width=8,height=1,text="CONFIG",callback=function()config_rs("local")end,fg_bg=cpair(colors.black,colors.blue),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg}
|
||||
|
||||
for i = 1, #relays do
|
||||
local name = relays[i]
|
||||
|
||||
line = Div{parent=iface_list,height=2,fg_bg=cpair(colors.black,colors.white)}
|
||||
TextBox{parent=line,x=1,y=1,text="@ "..name,fg_bg=cpair(colors.black,colors.white)}
|
||||
TextBox{parent=line,x=3,y=2,text="Redstone Relay",fg_bg=cpair(colors.gray,colors.white)}
|
||||
TextBox{parent=line,x=18,y=2,text=tri(mounts[name],"ONLINE","OFFLINE"),fg_bg=cpair(tri(mounts[name],colors.green,colors.red),colors.white)}
|
||||
count = #redstone_subset(ini_cfg.Redstone, name)
|
||||
TextBox{parent=line,x=33,y=2,width=16,alignment=core.ALIGN.RIGHT,text=count.." connections",fg_bg=cpair(colors.gray,colors.white)}
|
||||
|
||||
PushButton{parent=line,x=41,y=1,min_width=8,height=1,text="CONFIG",callback=function()config_rs(name)end,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg}
|
||||
end
|
||||
end
|
||||
|
||||
tool_ctl.update_relay_list()
|
||||
|
||||
PushButton{parent=rs_c_1,x=1,y=14,text="\x1b Back",callback=function()main_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
PushButton{parent=rs_c_1,x=27,y=14,min_width=23,text="I don't see my relay!",callback=function()rs_pane.set_value(10)end,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
--#endregion
|
||||
--#region Configuration List
|
||||
|
||||
TextBox{parent=rs_c_2,x=1,y=1,text=" port side/color unit/facility",fg_bg=g_lg_fg_bg}
|
||||
local rs_list = ListBox{parent=rs_c_2,x=1,y=2,height=11,width=49,scroll_height=200,fg_bg=bw_fg_bg,nav_fg_bg=g_lg_fg_bg,nav_active=cpair(colors.black,colors.gray)}
|
||||
|
||||
local function rs_revert()
|
||||
tmp_cfg.Redstone = tool_ctl.deep_copy_rs(ini_cfg.Redstone)
|
||||
@ -160,29 +247,44 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
end
|
||||
|
||||
local function rs_apply()
|
||||
settings.set("Redstone", tmp_cfg.Redstone)
|
||||
-- add the changed data to the existing saved data
|
||||
local new_data = redstone_subset(tmp_cfg.Redstone, self.rs_cfg_phy)
|
||||
local new_save = redstone_subset(ini_cfg.Redstone, self.rs_cfg_phy, true)
|
||||
for i = 1, #new_data do table.insert(new_save, new_data[i]) end
|
||||
|
||||
settings.set("Redstone", new_save)
|
||||
|
||||
if settings.save("/rtu.settings") then
|
||||
load_settings(settings_cfg, true)
|
||||
load_settings(ini_cfg)
|
||||
rs_pane.set_value(4)
|
||||
rs_pane.set_value(5)
|
||||
|
||||
-- for return to list from saved screen
|
||||
-- this will delete unsaved changes for other phy's, which is acceptable
|
||||
tmp_cfg.Redstone = tool_ctl.deep_copy_rs(ini_cfg.Redstone)
|
||||
tool_ctl.gen_rs_summary()
|
||||
else
|
||||
rs_pane.set_value(5)
|
||||
rs_pane.set_value(6)
|
||||
end
|
||||
end
|
||||
|
||||
PushButton{parent=rs_c_1,x=1,y=14,text="\x1b Back",callback=function()main_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
local rs_revert_btn = PushButton{parent=rs_c_1,x=8,y=14,min_width=16,text="Revert Changes",callback=rs_revert,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg}
|
||||
PushButton{parent=rs_c_1,x=35,y=14,min_width=7,text="New +",callback=function()rs_pane.set_value(2)end,fg_bg=cpair(colors.black,colors.blue),active_fg_bg=btn_act_fg_bg}
|
||||
local rs_apply_btn = PushButton{parent=rs_c_1,x=43,y=14,min_width=7,text="Apply",callback=rs_apply,fg_bg=cpair(colors.black,colors.green),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg}
|
||||
local function rs_back()
|
||||
self.rs_cfg_phy = false
|
||||
rs_pane.set_value(1)
|
||||
header.set_value(" Redstone Connections")
|
||||
end
|
||||
|
||||
TextBox{parent=rs_c_2,x=1,y=1,text="Select one of the below ports to use."}
|
||||
PushButton{parent=rs_c_2,x=1,y=14,text="\x1b Back",callback=rs_back,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
local rs_revert_btn = PushButton{parent=rs_c_2,x=8,y=14,min_width=16,text="Revert Changes",callback=rs_revert,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg}
|
||||
PushButton{parent=rs_c_2,x=35,y=14,min_width=7,text="New +",callback=function()rs_pane.set_value(3)end,fg_bg=cpair(colors.black,colors.blue),active_fg_bg=btn_act_fg_bg}
|
||||
local rs_apply_btn = PushButton{parent=rs_c_2,x=43,y=14,min_width=7,text="Apply",callback=rs_apply,fg_bg=cpair(colors.black,colors.green),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg}
|
||||
|
||||
local rs_ports = ListBox{parent=rs_c_2,x=1,y=3,height=10,width=49,scroll_height=200,fg_bg=bw_fg_bg,nav_fg_bg=g_lg_fg_bg,nav_active=cpair(colors.black,colors.gray)}
|
||||
--#endregion
|
||||
--#region Port Selection
|
||||
|
||||
TextBox{parent=rs_c_3,x=1,y=1,text="Select one of the below ports to use."}
|
||||
|
||||
local rs_ports = ListBox{parent=rs_c_3,x=1,y=3,height=10,width=49,scroll_height=200,fg_bg=bw_fg_bg,nav_fg_bg=g_lg_fg_bg,nav_active=cpair(colors.black,colors.gray)}
|
||||
|
||||
local function new_rs(port)
|
||||
self.rs_cfg_editing = false
|
||||
@ -241,7 +343,7 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
|
||||
self.rs_cfg_selection.set_value(text)
|
||||
self.rs_cfg_port = port
|
||||
rs_pane.set_value(3)
|
||||
rs_pane.set_value(4)
|
||||
end
|
||||
|
||||
-- add entries to redstone option list
|
||||
@ -262,38 +364,43 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
TextBox{parent=entry,x=22,y=1,text=PORT_DESC_MAP[i][2],fg_bg=cpair(colors.gray,colors.white)}
|
||||
end
|
||||
|
||||
PushButton{parent=rs_c_2,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
PushButton{parent=rs_c_3,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(2)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
self.rs_cfg_selection = TextBox{parent=rs_c_3,x=1,y=1,height=2,text=""}
|
||||
--#endregion
|
||||
--#region Port Configuration
|
||||
|
||||
PushButton{parent=rs_c_3,x=36,y=3,text="What's that?",min_width=14,callback=function()rs_pane.set_value(7)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
self.rs_cfg_selection = TextBox{parent=rs_c_4,x=1,y=1,height=2,text=""}
|
||||
|
||||
self.rs_cfg_side_l = TextBox{parent=rs_c_3,x=1,y=4,width=11,text="Output Side"}
|
||||
local side = Radio2D{parent=rs_c_3,x=1,y=5,rows=1,columns=6,default=1,options=side_options,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.red}
|
||||
PushButton{parent=rs_c_4,x=36,y=3,text="What's that?",min_width=14,callback=function()rs_pane.set_value(8)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
self.rs_cfg_unit_l = TextBox{parent=rs_c_3,x=25,y=7,width=7,text="Unit ID"}
|
||||
self.rs_cfg_unit = NumberField{parent=rs_c_3,x=33,y=7,width=10,max_chars=2,min=1,max=4,fg_bg=bw_fg_bg}
|
||||
self.rs_cfg_side_l = TextBox{parent=rs_c_4,x=1,y=4,width=11,text="Output Side"}
|
||||
local side = Radio2D{parent=rs_c_4,x=1,y=5,rows=1,columns=6,default=1,options=side_options,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.red}
|
||||
|
||||
self.rs_cfg_unit_l = TextBox{parent=rs_c_4,x=25,y=7,width=7,text="Unit ID"}
|
||||
self.rs_cfg_unit = NumberField{parent=rs_c_4,x=33,y=7,width=10,max_chars=2,min=1,max=4,fg_bg=bw_fg_bg}
|
||||
|
||||
local function set_bundled(bundled)
|
||||
if bundled then self.rs_cfg_color.enable() else self.rs_cfg_color.disable() end
|
||||
end
|
||||
|
||||
self.rs_cfg_shortcut = TextBox{parent=rs_c_3,x=1,y=9,height=4,text="This shortcut will add entries for each of the 4 waste outputs. If you select bundled, 4 colors will be assigned to the selected side. Otherwise, 4 default sides will be used."}
|
||||
self.rs_cfg_shortcut = TextBox{parent=rs_c_4,x=1,y=9,height=4,text="This shortcut will add entries for each of the 4 waste outputs. If you select bundled, 4 colors will be assigned to the selected side. Otherwise, 4 default sides will be used."}
|
||||
self.rs_cfg_shortcut.hide(true)
|
||||
|
||||
self.rs_cfg_bundled = Checkbox{parent=rs_c_3,x=1,y=7,label="Is Bundled?",default=false,box_fg_bg=cpair(colors.red,colors.black),callback=set_bundled,disable_fg_bg=g_lg_fg_bg}
|
||||
self.rs_cfg_color = Radio2D{parent=rs_c_3,x=1,y=9,rows=4,columns=4,default=1,options=color_options,radio_colors=cpair(colors.lightGray,colors.black),color_map=color_options_map,disable_color=colors.gray,disable_fg_bg=g_lg_fg_bg}
|
||||
self.rs_cfg_bundled = Checkbox{parent=rs_c_4,x=1,y=7,label="Is Bundled?",default=false,box_fg_bg=cpair(colors.red,colors.black),callback=set_bundled,disable_fg_bg=g_lg_fg_bg}
|
||||
self.rs_cfg_color = Radio2D{parent=rs_c_4,x=1,y=9,rows=4,columns=4,default=1,options=color_options,radio_colors=cpair(colors.lightGray,colors.black),color_map=color_options_map,disable_color=colors.gray,disable_fg_bg=g_lg_fg_bg}
|
||||
self.rs_cfg_color.disable()
|
||||
|
||||
local rs_err = TextBox{parent=rs_c_3,x=8,y=14,width=30,text="Unit ID must be within 1 to 4.",fg_bg=cpair(colors.red,colors.lightGray),hidden=true}
|
||||
local rs_err = TextBox{parent=rs_c_4,x=8,y=14,width=30,text="Unit ID invalid.",fg_bg=cpair(colors.red,colors.lightGray),hidden=true}
|
||||
rs_err.hide(true)
|
||||
|
||||
local function back_from_rs_opts()
|
||||
rs_err.hide(true)
|
||||
if self.rs_cfg_editing ~= false then rs_pane.set_value(1) else rs_pane.set_value(2) end
|
||||
if self.rs_cfg_editing ~= false then rs_pane.set_value(2) else rs_pane.set_value(3) end
|
||||
end
|
||||
|
||||
local function save_rs_entry()
|
||||
assert(self.rs_cfg_phy ~= false, "tried to save a redstone entry without a phy")
|
||||
|
||||
local port = self.rs_cfg_port
|
||||
local u = tonumber(self.rs_cfg_unit.get_value())
|
||||
|
||||
@ -307,7 +414,11 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
port = port,
|
||||
side = side_options_map[side.get_value()],
|
||||
color = tri(self.rs_cfg_bundled.get_value() and rsio.is_digital(port), color_options_map[self.rs_cfg_color.get_value()], nil),
|
||||
invert = self.rs_cfg_inverted.get_value() or nil,
|
||||
relay = self.rs_cfg_phy
|
||||
}
|
||||
|
||||
if self.rs_cfg_editing == false then
|
||||
-- check for duplicate inputs for this unit/facility
|
||||
if (rsio.get_io_dir(port) == rsio.IO_DIR.IN) then
|
||||
for i = 1, #tmp_cfg.Redstone do
|
||||
@ -318,7 +429,6 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
end
|
||||
end
|
||||
|
||||
if self.rs_cfg_editing == false then
|
||||
table.insert(tmp_cfg.Redstone, def)
|
||||
else
|
||||
def.port = tmp_cfg.Redstone[self.rs_cfg_editing].port
|
||||
@ -332,12 +442,13 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
unit = tri(PORT_DSGN[IO.WASTE_PU + i] == 1, u, nil),
|
||||
port = IO.WASTE_PU + i,
|
||||
side = tri(self.rs_cfg_bundled.get_value(), side_options_map[side.get_value()], default_sides[i + 1]),
|
||||
color = tri(self.rs_cfg_bundled.get_value(), default_colors[i + 1], nil)
|
||||
color = tri(self.rs_cfg_bundled.get_value(), default_colors[i + 1], nil),
|
||||
relay = self.rs_cfg_phy
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
rs_pane.set_value(1)
|
||||
rs_pane.set_value(2)
|
||||
tool_ctl.gen_rs_summary()
|
||||
|
||||
side.set_value(1)
|
||||
@ -349,30 +460,35 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
else rs_err.show() end
|
||||
end
|
||||
|
||||
PushButton{parent=rs_c_3,x=1,y=14,text="\x1b Back",callback=back_from_rs_opts,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
self.rs_cfg_advanced = PushButton{parent=rs_c_3,x=30,y=14,min_width=10,text="Advanced",callback=function()rs_pane.set_value(8)end,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg}
|
||||
PushButton{parent=rs_c_3,x=41,y=14,min_width=9,text="Confirm",callback=save_rs_entry,fg_bg=cpair(colors.black,colors.blue),active_fg_bg=btn_act_fg_bg}
|
||||
PushButton{parent=rs_c_4,x=1,y=14,text="\x1b Back",callback=back_from_rs_opts,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
self.rs_cfg_advanced = PushButton{parent=rs_c_4,x=30,y=14,min_width=10,text="Advanced",callback=function()rs_pane.set_value(9)end,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg}
|
||||
PushButton{parent=rs_c_4,x=41,y=14,min_width=9,text="Confirm",callback=save_rs_entry,fg_bg=cpair(colors.black,colors.blue),active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
TextBox{parent=rs_c_4,x=1,y=1,text="Settings saved!"}
|
||||
PushButton{parent=rs_c_4,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
PushButton{parent=rs_c_4,x=44,y=14,min_width=6,text="Home",callback=function()tool_ctl.go_home()end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
--#endregion
|
||||
|
||||
TextBox{parent=rs_c_5,x=1,y=1,height=5,text="Failed to save the settings file.\n\nThere may not be enough space for the modification or server file permissions may be denying writes."}
|
||||
PushButton{parent=rs_c_5,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
TextBox{parent=rs_c_5,x=1,y=1,text="Settings saved!"}
|
||||
PushButton{parent=rs_c_5,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(2)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
PushButton{parent=rs_c_5,x=44,y=14,min_width=6,text="Home",callback=function()tool_ctl.go_home()end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
TextBox{parent=rs_c_6,x=1,y=1,height=5,text="You already configured this input. There can only be one entry for each input.\n\nPlease select a different port."}
|
||||
TextBox{parent=rs_c_6,x=1,y=1,height=5,text="Failed to save the settings file.\n\nThere may not be enough space for the modification or server file permissions may be denying writes."}
|
||||
PushButton{parent=rs_c_6,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(2)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
PushButton{parent=rs_c_6,x=44,y=14,min_width=6,text="Home",callback=function()tool_ctl.go_home()end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
TextBox{parent=rs_c_7,x=1,y=1,height=4,text="(Normal) Digital Input: On if there is a redstone signal, off otherwise\nInverted Digital Input: On without a redstone signal, off otherwise"}
|
||||
TextBox{parent=rs_c_7,x=1,y=6,height=4,text="(Normal) Digital Output: Redstone signal to 'turn it on', none to 'turn it off'\nInverted Digital Output: No redstone signal to 'turn it on', redstone signal to 'turn it off'"}
|
||||
TextBox{parent=rs_c_7,x=1,y=11,height=2,text="Analog Input: 0-15 redstone power level input\nAnalog Output: 0-15 scaled redstone power level output"}
|
||||
TextBox{parent=rs_c_7,x=1,y=1,height=6,text="You already configured this input for this facility/unit assignment. There can only be one entry for each input per each unit or the facility (for facility inputs).\n\nPlease select a different port."}
|
||||
PushButton{parent=rs_c_7,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(3)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
TextBox{parent=rs_c_8,x=1,y=1,height=5,text="Advanced Options"}
|
||||
self.rs_cfg_inverted = Checkbox{parent=rs_c_8,x=1,y=3,label="Invert",default=false,box_fg_bg=cpair(colors.red,colors.black),callback=function()end,disable_fg_bg=g_lg_fg_bg}
|
||||
TextBox{parent=rs_c_8,x=3,y=4,height=4,text="Digital I/O is already inverted (or not) based on intended use. If you have a non-standard setup, you can use this option to avoid needing a redstone inverter.",fg_bg=cpair(colors.gray,colors.lightGray)}
|
||||
PushButton{parent=rs_c_8,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(3)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
TextBox{parent=rs_c_8,x=1,y=1,height=4,text="(Normal) Digital Input: On if there is a redstone signal, off otherwise\nInverted Digital Input: On without a redstone signal, off otherwise"}
|
||||
TextBox{parent=rs_c_8,x=1,y=6,height=4,text="(Normal) Digital Output: Redstone signal to 'turn it on', none to 'turn it off'\nInverted Digital Output: No redstone signal to 'turn it on', redstone signal to 'turn it off'"}
|
||||
TextBox{parent=rs_c_8,x=1,y=11,height=2,text="Analog Input: 0-15 redstone power level input\nAnalog Output: 0-15 scaled redstone power level output"}
|
||||
PushButton{parent=rs_c_8,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(4)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
TextBox{parent=rs_c_9,x=1,y=1,height=5,text="Advanced Options"}
|
||||
self.rs_cfg_inverted = Checkbox{parent=rs_c_9,x=1,y=3,label="Invert",default=false,box_fg_bg=cpair(colors.red,colors.black),callback=function()end,disable_fg_bg=g_lg_fg_bg}
|
||||
TextBox{parent=rs_c_9,x=3,y=4,height=4,text="Digital I/O is already inverted (or not) based on intended use. If you have a non-standard setup, you can use this option to avoid needing a redstone inverter.",fg_bg=cpair(colors.gray,colors.lightGray)}
|
||||
PushButton{parent=rs_c_9,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(4)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
TextBox{parent=rs_c_10,x=1,y=1,height=10,text="Make sure your relay is either touching the RTU gateway or connected via wired modems. There should be a wired modem on a side of the RTU gateway then one on the device, connected by a cable. The modem on the device needs to be right clicked to connect it (which will turn its border red), at which point the peripheral name will be shown in the chat."}
|
||||
PushButton{parent=rs_c_10,x=1,y=14,text="\x1b Back",callback=function()rs_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg}
|
||||
|
||||
--#endregion
|
||||
|
||||
@ -422,7 +538,7 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
side.set_value(side_to_idx(def.side))
|
||||
self.rs_cfg_color.set_value(value)
|
||||
self.rs_cfg_inverted.set_value(def.invert or false)
|
||||
rs_pane.set_value(3)
|
||||
rs_pane.set_value(4)
|
||||
end
|
||||
|
||||
local function delete_rs_entry(idx)
|
||||
@ -432,13 +548,19 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
|
||||
-- generate the redstone summary list
|
||||
function tool_ctl.gen_rs_summary()
|
||||
assert(self.rs_cfg_phy ~= false, "tried to generate a summary without a phy set")
|
||||
|
||||
rs_list.remove_all()
|
||||
|
||||
local modified = #ini_cfg.Redstone ~= #tmp_cfg.Redstone
|
||||
local ini = redstone_subset(ini_cfg.Redstone, self.rs_cfg_phy)
|
||||
local tmp = redstone_subset(tmp_cfg.Redstone, self.rs_cfg_phy)
|
||||
|
||||
local modified = #ini ~= #tmp
|
||||
|
||||
for i = 1, #tmp_cfg.Redstone do
|
||||
local def = tmp_cfg.Redstone[i]
|
||||
|
||||
if def.relay == self.rs_cfg_phy then
|
||||
local name = rsio.to_string(def.port)
|
||||
local io_dir = tri(rsio.get_io_dir(def.port) == rsio.IO_DIR.IN, "\x1a", "\x1b")
|
||||
local io_c = tri(rsio.is_digital(def.port), colors.blue, colors.purple)
|
||||
@ -462,6 +584,7 @@ function redstone.create(tool_ctl, main_pane, cfg_sys, rs_cfg, style)
|
||||
modified = (a.unit ~= b.unit) or (a.port ~= b.port) or (a.side ~= b.side) or (a.color ~= b.color) or (a.invert ~= b.invert)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if modified then
|
||||
rs_revert_btn.enable()
|
||||
|
||||
@ -76,6 +76,7 @@ local tool_ctl = {
|
||||
gen_summary = nil, ---@type function
|
||||
load_legacy = nil, ---@type function
|
||||
update_peri_list = nil, ---@type function
|
||||
update_relay_list = nil, ---@type function
|
||||
gen_peri_summary = nil, ---@type function
|
||||
gen_rs_summary = nil, ---@type function
|
||||
}
|
||||
@ -128,7 +129,7 @@ end
|
||||
---@param data rtu_rs_definition[]
|
||||
function tool_ctl.deep_copy_rs(data)
|
||||
local array = {}
|
||||
for _, d in ipairs(data) do table.insert(array, { unit = d.unit, port = d.port, side = d.side, color = d.color, invert = d.invert }) end
|
||||
for _, d in ipairs(data) do table.insert(array, { unit = d.unit, port = d.port, side = d.side, color = d.color, invert = d.invert, relay = d.relay }) end
|
||||
return array
|
||||
end
|
||||
|
||||
@ -208,7 +209,6 @@ local function config_view(display)
|
||||
end
|
||||
|
||||
local function show_rs_conns()
|
||||
tool_ctl.gen_rs_summary()
|
||||
main_pane.set_value(9)
|
||||
end
|
||||
|
||||
@ -348,10 +348,12 @@ function configurator.configure(ask_config)
|
||||
---@diagnostic disable-next-line: discard-returns
|
||||
ppm.handle_unmount(param1)
|
||||
tool_ctl.update_peri_list()
|
||||
tool_ctl.update_relay_list()
|
||||
elseif event == "peripheral" then
|
||||
---@diagnostic disable-next-line: discard-returns
|
||||
ppm.mount(param1)
|
||||
tool_ctl.update_peri_list()
|
||||
tool_ctl.update_relay_list()
|
||||
end
|
||||
|
||||
if event == "terminate" then return end
|
||||
|
||||
@ -10,7 +10,6 @@ local redstone = {}
|
||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||
local MODBUS_FCODE = types.MODBUS_FCODE
|
||||
|
||||
local IO_PORT = rsio.IO
|
||||
local IO_LVL = rsio.IO_LVL
|
||||
local IO_MODE = rsio.IO_MODE
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user