diff --git a/reactor-plc/config/system.lua b/reactor-plc/config/system.lua index 909dda7..594a7e5 100644 --- a/reactor-plc/config/system.lua +++ b/reactor-plc/config/system.lua @@ -82,8 +82,9 @@ function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit) local plc_c_2 = Div{parent=plc_cfg,x=2,y=4,width=49} local plc_c_3 = Div{parent=plc_cfg,x=2,y=4,width=49} local plc_c_4 = Div{parent=plc_cfg,x=2,y=4,width=49} + local plc_c_5 = Div{parent=plc_cfg,x=2,y=4,width=49} - local plc_pane = MultiPane{parent=plc_cfg,x=1,y=4,panes={plc_c_1,plc_c_2,plc_c_3,plc_c_4}} + local plc_pane = MultiPane{parent=plc_cfg,x=1,y=4,panes={plc_c_1,plc_c_2,plc_c_3,plc_c_4,plc_c_5}} TextBox{parent=plc_cfg,x=1,y=2,text=" PLC Configuration",fg_bg=cpair(colors.black,colors.orange)} @@ -152,13 +153,20 @@ function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit) function self.bundled_emcool(en) if en then color.enable() else color.disable() end end + TextBox{parent=plc_c_5,x=1,y=1,height=5,text="Advanced Options"} + local invert = Checkbox{parent=plc_c_5,x=1,y=3,label="Invert",default=ini_cfg.EmerCoolInvert,box_fg_bg=cpair(colors.orange,colors.black),callback=function()end} + TextBox{parent=plc_c_5,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=plc_c_5,x=1,y=14,text="\x1b Back",callback=function()plc_pane.set_value(4)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + local function submit_emcool() tmp_cfg.EmerCoolSide = side_options_map[side.get_value()] tmp_cfg.EmerCoolColor = util.trinary(bundled.get_value(), color_options_map[color.get_value()], nil) + tmp_cfg.EmerCoolInvert = invert.get_value() next_from_plc() end PushButton{parent=plc_c_4,x=1,y=14,text="\x1b Back",callback=function()plc_pane.set_value(3)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + PushButton{parent=plc_c_4,x=33,y=14,min_width=10,text="Advanced",callback=function()plc_pane.set_value(5)end,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=btn_act_fg_bg,dis_fg_bg=btn_dis_fg_bg} PushButton{parent=plc_c_4,x=44,y=14,text="Next \x1a",callback=submit_emcool,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} --#endregion @@ -461,6 +469,7 @@ function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit) try_set(side, side_to_idx(ini_cfg.EmerCoolSide)) try_set(bundled, ini_cfg.EmerCoolColor ~= nil) if ini_cfg.EmerCoolColor ~= nil then try_set(color, color_to_idx(ini_cfg.EmerCoolColor)) end + try_set(invert, ini_cfg.EmerCoolInvert) try_set(svr_chan, ini_cfg.SVR_Channel) try_set(plc_chan, ini_cfg.PLC_Channel) try_set(timeout, ini_cfg.ConnTimeout) @@ -533,9 +542,11 @@ function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit) if tmp_cfg.EmerCoolEnable then tmp_cfg.EmerCoolSide = config.EMERGENCY_COOL.side tmp_cfg.EmerCoolColor = config.EMERGENCY_COOL.color + tmp_cfg.EmerCoolInvert = false else tmp_cfg.EmerCoolSide = nil tmp_cfg.EmerCoolColor = nil + tmp_cfg.EmerCoolInvert = false end tmp_cfg.SVR_Channel = config.SVR_CHANNEL diff --git a/reactor-plc/configure.lua b/reactor-plc/configure.lua index b2baa6d..fbc25c1 100644 --- a/reactor-plc/configure.lua +++ b/reactor-plc/configure.lua @@ -32,7 +32,8 @@ local changes = { { "v1.6.2", { "AuthKey minimum length is now 8 (if set)" } }, { "v1.6.8", { "ConnTimeout can now have a fractional part" } }, { "v1.6.15", { "Added front panel UI theme", "Added color accessibility modes" } }, - { "v1.7.3", { "Added standard with black off state color mode", "Added blue indicator color modes" } } + { "v1.7.3", { "Added standard with black off state color mode", "Added blue indicator color modes" } }, + { "v1.8.21", { "Added option to invert emergency coolant redstone control" } } } ---@class plc_configurator @@ -76,6 +77,7 @@ local tmp_cfg = { EmerCoolEnable = false, EmerCoolSide = nil, ---@type string|nil EmerCoolColor = nil, ---@type color|nil + EmerCoolInvert = false, ---@type boolean SVR_Channel = nil, ---@type integer PLC_Channel = nil, ---@type integer ConnTimeout = nil, ---@type number @@ -100,6 +102,7 @@ local fields = { { "EmerCoolEnable", "Emergency Coolant", false }, { "EmerCoolSide", "Emergency Coolant Side", nil }, { "EmerCoolColor", "Emergency Coolant Color", nil }, + { "EmerCoolInvert", "Emergency Coolant Invert", false }, { "SVR_Channel", "SVR Channel", 16240 }, { "PLC_Channel", "PLC Channel", 16241 }, { "ConnTimeout", "Connection Timeout", 5 }, diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index 73b95ce..a2929cb 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -43,6 +43,7 @@ function plc.load_config() config.EmerCoolEnable = settings.get("EmerCoolEnable") config.EmerCoolSide = settings.get("EmerCoolSide") config.EmerCoolColor = settings.get("EmerCoolColor") + config.EmerCoolInvert = settings.get("EmerCoolInvert") config.SVR_Channel = settings.get("SVR_Channel") config.PLC_Channel = settings.get("PLC_Channel") @@ -98,6 +99,7 @@ function plc.validate_config(cfg) if cfg.EmerCoolEnable then cfv.assert_eq(rsio.is_valid_side(cfg.EmerCoolSide), true) cfv.assert_eq(cfg.EmerCoolColor == nil or rsio.is_color(cfg.EmerCoolColor), true) + cfv.assert_type_bool(cfg.EmerCoolInvert) end return cfv.valid() @@ -166,7 +168,8 @@ function plc.rps_init(reactor, is_formed) local function _set_emer_cool(state) -- check if this was configured: if it's a table, fields have already been validated. if config.EmerCoolEnable then - local level = rsio.digital_write_active(rsio.IO.U_EMER_COOL, state) + -- use ~= as XOR for simple inversion + local level = rsio.digital_write_active(rsio.IO.U_EMER_COOL, config.EmerCoolInvert ~= state) if level ~= false then if rsio.is_color(config.EmerCoolColor) then diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index c085e95..af54333 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc") local renderer = require("reactor-plc.renderer") local threads = require("reactor-plc.threads") -local R_PLC_VERSION = "v1.8.20" +local R_PLC_VERSION = "v1.8.21" local println = util.println local println_ts = util.println_ts