From b3f29566ea2204ffbe04ffada205b3c7a1b4d9fb Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Mon, 11 Mar 2024 21:25:34 -0400 Subject: [PATCH] #340 colorblind modes for rtu, reactor-plc, and supervisor --- graphics/themes.lua | 73 ++++++++++++++++++++++++++++++- reactor-plc/configure.lua | 21 ++++----- reactor-plc/panel/front_panel.lua | 46 +++++++++++++++++-- reactor-plc/renderer.lua | 13 ++++-- reactor-plc/startup.lua | 4 +- rtu/configure.lua | 21 ++++----- rtu/panel/front_panel.lua | 43 ++++++++++++++++-- rtu/renderer.lua | 13 ++++-- rtu/startup.lua | 4 +- supervisor/configure.lua | 21 ++++----- supervisor/databus.lua | 8 ++-- supervisor/panel/front_panel.lua | 4 +- supervisor/renderer.lua | 11 ++++- supervisor/startup.lua | 4 +- 14 files changed, 226 insertions(+), 60 deletions(-) diff --git a/graphics/themes.lua b/graphics/themes.lua index c454aab..85928ac 100644 --- a/graphics/themes.lua +++ b/graphics/themes.lua @@ -11,6 +11,7 @@ local themes = {} -- add color mappings for front panels colors.ivory = colors.pink +colors.green_hc = colors.cyan colors.yellow_hc = colors.purple colors.red_off = colors.brown colors.yellow_off = colors.magenta @@ -100,7 +101,7 @@ themes.sandstone = { { c = colors.yellow, hex = 0xf9fb53 }, { c = colors.green_off, hex = 0x16665a }, { c = colors.green, hex = 0x6be551 }, - { c = colors.cyan, hex = 0x34bac8 }, + { c = colors.green_hc, hex = 0x6be551 }, { c = colors.lightBlue, hex = 0x6cc0f2 }, { c = colors.blue, hex = 0x0096ff }, { c = colors.yellow_hc, hex = 0xe3bc2a }, @@ -111,6 +112,39 @@ themes.sandstone = { { c = colors.gray, hex = 0x575757 }, { c = colors.black, hex = 0x191919 }, { c = colors.red_off, hex = 0x672223 } + }, + + -- color re-mappings for assistive modes + color_modes = { + -- standard + {}, + -- deuteranopia + { + { c = colors.green, hex = 0x1081ff }, + { c = colors.green_off, hex = 0x141414 }, + { c = colors.yellow, hex = 0xf7c311 }, + { c = colors.yellow_off, hex = 0x141414 }, + { c = colors.red, hex = 0xfb5615 }, + { c = colors.red_off, hex = 0x141414 } + }, + -- protanopia + { + { c = colors.green, hex = 0x1081ff }, + { c = colors.green_off, hex = 0x141414 }, + { c = colors.yellow, hex = 0xf5e633 }, + { c = colors.yellow_off, hex = 0x141414 }, + { c = colors.red, hex = 0xff521a }, + { c = colors.red_off, hex = 0x141414 } + }, + -- tritanopia + { + { c = colors.green, hex = 0x40cbd7 }, + { c = colors.green_off, hex = 0x141414 }, + { c = colors.yellow, hex = 0xffbc00 }, + { c = colors.yellow_off, hex = 0x141414 }, + { c = colors.red, hex = 0xff0000 }, + { c = colors.red_off, hex = 0x141414 } + } } } @@ -134,7 +168,7 @@ themes.basalt = { { c = colors.yellow, hex = 0xefe37c }, { c = colors.green_off, hex = 0x436b41 }, { c = colors.green, hex = 0x7ae175 }, - { c = colors.cyan, hex = 0x5ec7d1 }, + { c = colors.green_hc, hex = 0x7ae175 }, { c = colors.lightBlue, hex = 0x7dc6f2 }, { c = colors.blue, hex = 0x56aae6 }, { c = colors.yellow_hc, hex = 0xe9cd68 }, @@ -145,6 +179,41 @@ themes.basalt = { { c = colors.gray, hex = 0x5c5f68 }, { c = colors.black, hex = 0x262626 }, { c = colors.red_off, hex = 0x653839 } + }, + + color_modes = { + -- standard + {}, + -- deuteranopia + { + { c = colors.green, hex = 0x3393ff }, + { c = colors.green_hc, hex = 0x99c9ff }, + { c = colors.green_off, hex = 0x333333 }, + { c = colors.yellow, hex = 0xf7c311 }, + { c = colors.yellow_off, hex = 0x333333 }, + { c = colors.red, hex = 0xf18486 }, + { c = colors.red_off, hex = 0x333333 } + }, + -- protanopia + { + { c = colors.green, hex = 0x3393ff }, + { c = colors.green_hc, hex = 0x99c9ff }, + { c = colors.green_off, hex = 0x333333 }, + { c = colors.yellow, hex = 0xf5e633 }, + { c = colors.yellow_off, hex = 0x333333 }, + { c = colors.red, hex = 0xff8058 }, + { c = colors.red_off, hex = 0x333333 } + }, + -- tritanopia + { + { c = colors.green, hex = 0x00ecff }, + { c = colors.green_hc, hex = 0x00ecff }, + { c = colors.green_off, hex = 0x333333 }, + { c = colors.yellow, hex = 0xffbc00 }, + { c = colors.yellow_off, hex = 0x333333 }, + { c = colors.red, hex = 0xdf4949 }, + { c = colors.red_off, hex = 0x333333 } + } } } diff --git a/reactor-plc/configure.lua b/reactor-plc/configure.lua index 80ef86c..c084e7d 100644 --- a/reactor-plc/configure.lua +++ b/reactor-plc/configure.lua @@ -8,6 +8,7 @@ local tcd = require("scada-common.tcd") local util = require("scada-common.util") local core = require("graphics.core") +local themes = require("graphics.themes") local DisplayBox = require("graphics.elements.displaybox") local Div = require("graphics.elements.div") @@ -473,29 +474,29 @@ local function config_view(display) TextBox{parent=clr_c_1,x=1,y=4,height=2,text="Click 'Accessibility' below to access color blind assistive options.",fg_bg=g_lg_fg_bg} TextBox{parent=clr_c_1,x=1,y=7,height=1,text="Front Panel Theme"} - local fp_theme = RadioButton{parent=clr_c_1,x=1,y=8,default=ini_cfg.FrontPanelTheme,options={"Sandstone","Basalt"},callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + local fp_theme = RadioButton{parent=clr_c_1,x=1,y=8,default=ini_cfg.FrontPanelTheme,options=themes.FP_THEME_NAMES,callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} TextBox{parent=clr_c_2,x=1,y=1,height=6,text="By default, this project uses green/red heavily to distinguish ok and not, with some indicators also using multiple colors. By selecting a color blindness below, blues will be used instead of greens on indicators and multi-color indicators will be split up as space permits."} local function recolor(value) if value == 1 then for i = 1, #style.colors do term.setPaletteColor(style.colors[i].c, style.colors[i].hex) end - elseif value == 2 then - term.setPaletteColor(colors.green, 0x1081ff) - term.setPaletteColor(colors.yellow, 0xf5e633) - term.setPaletteColor(colors.red, 0xff521a) - elseif value == 3 then + elseif value == themes.COLOR_MODE.DEUTERANOPIA then term.setPaletteColor(colors.green, 0x1081ff) term.setPaletteColor(colors.yellow, 0xf7c311) term.setPaletteColor(colors.red, 0xfb5615) - elseif value == 4 then + elseif value == themes.COLOR_MODE.PROTANOPIA then + term.setPaletteColor(colors.green, 0x1081ff) + term.setPaletteColor(colors.yellow, 0xf5e633) + term.setPaletteColor(colors.red, 0xff521a) + elseif value == themes.COLOR_MODE.TRITANOPIA then term.setPaletteColor(colors.green, 0x00ecff) term.setPaletteColor(colors.yellow, 0xffbc00) term.setPaletteColor(colors.red, 0xff0000) end end - local c_mode = RadioButton{parent=clr_c_2,x=1,y=8,default=ini_cfg.ColorMode,options={"None","Protanopia","Deuteranopia","Tritanopia"},callback=recolor,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + local c_mode = RadioButton{parent=clr_c_2,x=1,y=8,default=ini_cfg.ColorMode,options=themes.COLOR_MODE_NAMES,callback=recolor,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} local _ = IndLight{parent=clr_c_2,x=20,y=8,label="Good",colors=cpair(colors.black,colors.green),value=true} _ = IndLight{parent=clr_c_2,x=20,y=9,label="Warning",colors=cpair(colors.black,colors.yellow),value=true} @@ -749,9 +750,9 @@ local function config_view(display) elseif f[1] == "LogMode" then val = util.trinary(raw == log.MODE.APPEND, "append", "replace") elseif f[1] == "EmerCoolColor" and raw ~= nil then val = rsio.color_name(raw) elseif f[1] == "FrontPanelTheme" then - if raw == 1 then val = "Sandstone" elseif raw == 2 then val = "Basalt" end + val = util.strval(themes.fp_theme_name(raw)) elseif f[1] == "ColorMode" then - if raw == 1 then val = "Standard" elseif raw == 2 then val = "Protanopia" elseif raw == 3 then val = "Deuteranopia" elseif raw == 4 then val = "Tritanopia" end + val = util.strval(themes.color_mode_name(raw)) end if val == "nil" then val = "" end diff --git a/reactor-plc/panel/front_panel.lua b/reactor-plc/panel/front_panel.lua index 7c087a8..5797c2b 100644 --- a/reactor-plc/panel/front_panel.lua +++ b/reactor-plc/panel/front_panel.lua @@ -12,6 +12,7 @@ local style = require("reactor-plc.panel.style") local core = require("graphics.core") local flasher = require("graphics.flasher") +local themes = require("graphics.themes") local Div = require("graphics.elements.div") local Rectangle = require("graphics.elements.rectangle") @@ -23,6 +24,8 @@ local LED = require("graphics.elements.indicators.led") local LEDPair = require("graphics.elements.indicators.ledpair") local RGBLED = require("graphics.elements.indicators.ledrgb") +local LINK_STATE = types.PANEL_LINK_STATE + local ALIGN = core.ALIGN local cpair = core.cpair @@ -33,7 +36,8 @@ local ind_red = style.ind_red -- create new front panel view ---@param panel graphics_element main displaybox -local function init(panel) +---@param color_mode COLOR_MODE color mode +local function init(panel, color_mode) local s_hi_box = style.theme.highlight_box local disabled_fg = style.fp.disabled_fg @@ -56,13 +60,47 @@ local function init(panel) local reactor = LEDPair{parent=system,label="REACTOR",off=colors.red,c1=colors.yellow,c2=colors.green} local modem = LED{parent=system,label="MODEM",colors=ind_grn} - local network = RGBLED{parent=system,label="NETWORK",colors={colors.green,colors.red,colors.orange,colors.yellow,colors.gray}} - network.update(types.PANEL_LINK_STATE.DISCONNECTED) + + if color_mode == themes.COLOR_MODE.STANDARD then + local network = RGBLED{parent=system,label="NETWORK",colors={colors.green,colors.red,colors.orange,colors.yellow,colors.gray}} + network.update(types.PANEL_LINK_STATE.DISCONNECTED) + network.register(databus.ps, "link_state", network.update) + else + local nt_lnk = RGBLED{parent=system,label="NT LINKED",colors={colors.red_off,colors.red,colors.green}} + local nt_ver = RGBLED{parent=system,label="NT VERSION",colors={colors.red_off,colors.red,colors.green}} + local nt_col = LED{parent=system,label="NT COLLISION",colors=ind_red} + + nt_lnk.register(databus.ps, "link_state", function (state) + local value = 2 + + if state == LINK_STATE.DISCONNECTED then + value = 1 + elseif state == LINK_STATE.LINKED then + value = 3 + end + + nt_lnk.update(value) + end) + + nt_ver.register(databus.ps, "link_state", function (state) + local value = 3 + + if state == LINK_STATE.BAD_VERSION then + value = 2 + elseif state == LINK_STATE.DISCONNECTED then + value = 1 + end + + nt_ver.update(value) + end) + + nt_col.register(databus.ps, "link_state", function (state) nt_col.update(state == LINK_STATE.COLLISION) end) + end + system.line_break() reactor.register(databus.ps, "reactor_dev_state", reactor.update) modem.register(databus.ps, "has_modem", modem.update) - network.register(databus.ps, "link_state", network.update) local rt_main = LED{parent=system,label="RT MAIN",colors=ind_grn} local rt_rps = LED{parent=system,label="RT RPS",colors=ind_grn} diff --git a/reactor-plc/renderer.lua b/reactor-plc/renderer.lua index 31af361..8748cae 100644 --- a/reactor-plc/renderer.lua +++ b/reactor-plc/renderer.lua @@ -18,9 +18,10 @@ local ui = { } -- try to start the UI ----@param theme integer front panel theme ID (1 = sandstone, 2 = basalt) +---@param theme FP_THEME front panel theme +---@param color_mode COLOR_MODE color mode ---@return boolean success, any error_msg -function renderer.try_start_ui(theme) +function renderer.try_start_ui(theme, color_mode) local status, msg = true, nil if ui.display == nil then @@ -38,10 +39,16 @@ function renderer.try_start_ui(theme) term.setPaletteColor(style.theme.colors[i].c, style.theme.colors[i].hex) end + -- apply color mode + local c_mode_overrides = style.theme.color_modes[color_mode] + for i = 1, #c_mode_overrides do + term.setPaletteColor(c_mode_overrides[i].c, c_mode_overrides[i].hex) + end + -- init front panel view status, msg = pcall(function () ui.display = DisplayBox{window=term.current(),fg_bg=style.fp.root} - panel_view(ui.display) + panel_view(ui.display, color_mode) end) if status then diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index 66f6d77..ea51bf6 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.6.15" +local R_PLC_VERSION = "v1.7.0" local println = util.println local println_ts = util.println_ts @@ -183,7 +183,7 @@ local function main() -- front panel time! if not renderer.ui_ready() then local message - plc_state.fp_ok, message = renderer.try_start_ui(config.FrontPanelTheme) + plc_state.fp_ok, message = renderer.try_start_ui(config.FrontPanelTheme, config.ColorMode) if not plc_state.fp_ok then println_ts(util.c("UI error: ", message)) diff --git a/rtu/configure.lua b/rtu/configure.lua index cfda26d..e9f50eb 100644 --- a/rtu/configure.lua +++ b/rtu/configure.lua @@ -9,6 +9,7 @@ local tcd = require("scada-common.tcd") local util = require("scada-common.util") local core = require("graphics.core") +local themes = require("graphics.themes") local DisplayBox = require("graphics.elements.displaybox") local Div = require("graphics.elements.div") @@ -528,29 +529,29 @@ local function config_view(display) TextBox{parent=clr_c_1,x=1,y=4,height=2,text="Click 'Accessibility' below to access color blind assistive options.",fg_bg=g_lg_fg_bg} TextBox{parent=clr_c_1,x=1,y=7,height=1,text="Front Panel Theme"} - local fp_theme = RadioButton{parent=clr_c_1,x=1,y=8,default=ini_cfg.FrontPanelTheme,options={"Sandstone","Basalt"},callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + local fp_theme = RadioButton{parent=clr_c_1,x=1,y=8,default=ini_cfg.FrontPanelTheme,options=themes.FP_THEME_NAMES,callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} TextBox{parent=clr_c_2,x=1,y=1,height=6,text="By default, this project uses green/red heavily to distinguish ok and not, with some indicators also using multiple colors. By selecting a color blindness below, blues will be used instead of greens on indicators and multi-color indicators will be split up as space permits."} local function recolor(value) if value == 1 then for i = 1, #style.colors do term.setPaletteColor(style.colors[i].c, style.colors[i].hex) end - elseif value == 2 then - term.setPaletteColor(colors.green, 0x1081ff) - term.setPaletteColor(colors.yellow, 0xf5e633) - term.setPaletteColor(colors.red, 0xff521a) - elseif value == 3 then + elseif value == themes.COLOR_MODE.DEUTERANOPIA then term.setPaletteColor(colors.green, 0x1081ff) term.setPaletteColor(colors.yellow, 0xf7c311) term.setPaletteColor(colors.red, 0xfb5615) - elseif value == 4 then + elseif value == themes.COLOR_MODE.PROTANOPIA then + term.setPaletteColor(colors.green, 0x1081ff) + term.setPaletteColor(colors.yellow, 0xf5e633) + term.setPaletteColor(colors.red, 0xff521a) + elseif value == themes.COLOR_MODE.TRITANOPIA then term.setPaletteColor(colors.green, 0x00ecff) term.setPaletteColor(colors.yellow, 0xffbc00) term.setPaletteColor(colors.red, 0xff0000) end end - local c_mode = RadioButton{parent=clr_c_2,x=1,y=8,default=ini_cfg.ColorMode,options={"None","Protanopia","Deuteranopia","Tritanopia"},callback=recolor,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + local c_mode = RadioButton{parent=clr_c_2,x=1,y=8,default=ini_cfg.ColorMode,options=themes.COLOR_MODE_NAMES,callback=recolor,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} local _ = IndLight{parent=clr_c_2,x=20,y=8,label="Good",colors=cpair(colors.black,colors.green),value=true} _ = IndLight{parent=clr_c_2,x=20,y=9,label="Warning",colors=cpair(colors.black,colors.yellow),value=true} @@ -1426,9 +1427,9 @@ local function config_view(display) if f[1] == "AuthKey" then val = string.rep("*", string.len(val)) elseif f[1] == "LogMode" then val = util.trinary(raw == log.MODE.APPEND, "append", "replace") elseif f[1] == "FrontPanelTheme" then - if raw == 1 then val = "Sandstone" elseif raw == 2 then val = "Basalt" end + val = util.strval(themes.fp_theme_name(raw)) elseif f[1] == "ColorMode" then - if raw == 1 then val = "Standard" elseif raw == 2 then val = "Protanopia" elseif raw == 3 then val = "Deuteranopia" elseif raw == 4 then val = "Tritanopia" end + val = util.strval(themes.color_mode_name(raw)) end if val == "nil" then val = "" end diff --git a/rtu/panel/front_panel.lua b/rtu/panel/front_panel.lua index 9989e9a..36e72f4 100644 --- a/rtu/panel/front_panel.lua +++ b/rtu/panel/front_panel.lua @@ -10,6 +10,7 @@ local databus = require("rtu.databus") local style = require("rtu.panel.style") local core = require("graphics.core") +local themes = require("graphics.themes") local Div = require("graphics.elements.div") local TextBox = require("graphics.elements.textbox") @@ -18,6 +19,8 @@ local DataIndicator = require("graphics.elements.indicators.data") local LED = require("graphics.elements.indicators.led") local RGBLED = require("graphics.elements.indicators.ledrgb") +local LINK_STATE = types.PANEL_LINK_STATE + local ALIGN = core.ALIGN local cpair = core.cpair @@ -29,7 +32,8 @@ local UNIT_TYPE_LABELS = { "UNKNOWN", "REDSTONE", "BOILER", "TURBINE", "DYNAMIC -- create new front panel view ---@param panel graphics_element main displaybox ---@param units table unit list -local function init(panel, units) +---@param color_mode COLOR_MODE color mode +local function init(panel, units, color_mode) local disabled_fg = style.fp.disabled_fg TextBox{parent=panel,y=1,text="RTU GATEWAY",alignment=ALIGN.CENTER,height=1,fg_bg=style.theme.header} @@ -48,12 +52,43 @@ local function init(panel, units) heartbeat.register(databus.ps, "heartbeat", heartbeat.update) local modem = LED{parent=system,label="MODEM",colors=ind_grn} - local network = RGBLED{parent=system,label="NETWORK",colors={colors.green,colors.red,colors.orange,colors.yellow,colors.gray}} - network.update(types.PANEL_LINK_STATE.DISCONNECTED) + + if color_mode == themes.COLOR_MODE.STANDARD then + local network = RGBLED{parent=system,label="NETWORK",colors={colors.green,colors.red,colors.orange,colors.yellow,colors.gray}} + network.update(types.PANEL_LINK_STATE.DISCONNECTED) + network.register(databus.ps, "link_state", network.update) + else + local nt_lnk = RGBLED{parent=system,label="NT LINKED",colors={colors.red_off,colors.red,colors.green}} + local nt_ver = RGBLED{parent=system,label="NT VERSION",colors={colors.red_off,colors.red,colors.green}} + + nt_lnk.register(databus.ps, "link_state", function (state) + local value = 2 + + if state == LINK_STATE.DISCONNECTED then + value = 1 + elseif state == LINK_STATE.LINKED then + value = 3 + end + + nt_lnk.update(value) + end) + + nt_ver.register(databus.ps, "link_state", function (state) + local value = 3 + + if state == LINK_STATE.BAD_VERSION then + value = 2 + elseif state == LINK_STATE.DISCONNECTED then + value = 1 + end + + nt_ver.update(value) + end) + end + system.line_break() modem.register(databus.ps, "has_modem", modem.update) - network.register(databus.ps, "link_state", network.update) local rt_main = LED{parent=system,label="RT MAIN",colors=ind_grn} local rt_comm = LED{parent=system,label="RT COMMS",colors=ind_grn} diff --git a/rtu/renderer.lua b/rtu/renderer.lua index 2a1a235..8d56a40 100644 --- a/rtu/renderer.lua +++ b/rtu/renderer.lua @@ -19,9 +19,10 @@ local ui = { -- try to start the UI ---@param units table RTU units ----@param theme integer front panel theme ID (1 = sandstone, 2 = basalt) +---@param theme FP_THEME front panel theme +---@param color_mode COLOR_MODE color mode ---@return boolean success, any error_msg -function renderer.try_start_ui(units, theme) +function renderer.try_start_ui(units, theme, color_mode) local status, msg = true, nil if ui.display == nil then @@ -39,10 +40,16 @@ function renderer.try_start_ui(units, theme) term.setPaletteColor(style.theme.colors[i].c, style.theme.colors[i].hex) end + -- apply color mode + local c_mode_overrides = style.theme.color_modes[color_mode] + for i = 1, #c_mode_overrides do + term.setPaletteColor(c_mode_overrides[i].c, c_mode_overrides[i].hex) + end + -- init front panel view status, msg = pcall(function () ui.display = DisplayBox{window=term.current(),fg_bg=style.fp.root} - panel_view(ui.display, units) + panel_view(ui.display, units, color_mode) end) if status then diff --git a/rtu/startup.lua b/rtu/startup.lua index 8888d05..4b92756 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -31,7 +31,7 @@ local sna_rtu = require("rtu.dev.sna_rtu") local sps_rtu = require("rtu.dev.sps_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local RTU_VERSION = "v1.7.15" +local RTU_VERSION = "v1.8.0" local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE @@ -506,7 +506,7 @@ local function main() if sys_config() then -- start UI local message - rtu_state.fp_ok, message = renderer.try_start_ui(units, config.FrontPanelTheme) + rtu_state.fp_ok, message = renderer.try_start_ui(units, config.FrontPanelTheme, config.ColorMode) if not rtu_state.fp_ok then println_ts(util.c("UI error: ", message)) diff --git a/supervisor/configure.lua b/supervisor/configure.lua index 0b63519..1ea1677 100644 --- a/supervisor/configure.lua +++ b/supervisor/configure.lua @@ -7,6 +7,7 @@ local tcd = require("scada-common.tcd") local util = require("scada-common.util") local core = require("graphics.core") +local themes = require("graphics.themes") local DisplayBox = require("graphics.elements.displaybox") local Div = require("graphics.elements.div") @@ -772,29 +773,29 @@ local function config_view(display) TextBox{parent=clr_c_1,x=1,y=4,height=2,text="Click 'Accessibility' below to access color blind assistive options.",fg_bg=g_lg_fg_bg} TextBox{parent=clr_c_1,x=1,y=7,height=1,text="Front Panel Theme"} - local fp_theme = RadioButton{parent=clr_c_1,x=1,y=8,default=ini_cfg.FrontPanelTheme,options={"Sandstone","Basalt"},callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + local fp_theme = RadioButton{parent=clr_c_1,x=1,y=8,default=ini_cfg.FrontPanelTheme,options=themes.FP_THEME_NAMES,callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} TextBox{parent=clr_c_2,x=1,y=1,height=6,text="By default, this project uses green/red heavily to distinguish ok and not, with some indicators also using multiple colors. By selecting a color blindness below, blues will be used instead of greens on indicators and multi-color indicators will be split up as space permits."} local function recolor(value) if value == 1 then for i = 1, #style.colors do term.setPaletteColor(style.colors[i].c, style.colors[i].hex) end - elseif value == 2 then - term.setPaletteColor(colors.green, 0x1081ff) - term.setPaletteColor(colors.yellow, 0xf5e633) - term.setPaletteColor(colors.red, 0xff521a) - elseif value == 3 then + elseif value == themes.COLOR_MODE.DEUTERANOPIA then term.setPaletteColor(colors.green, 0x1081ff) term.setPaletteColor(colors.yellow, 0xf7c311) term.setPaletteColor(colors.red, 0xfb5615) - elseif value == 4 then + elseif value == themes.COLOR_MODE.PROTANOPIA then + term.setPaletteColor(colors.green, 0x1081ff) + term.setPaletteColor(colors.yellow, 0xf5e633) + term.setPaletteColor(colors.red, 0xff521a) + elseif value == themes.COLOR_MODE.TRITANOPIA then term.setPaletteColor(colors.green, 0x00ecff) term.setPaletteColor(colors.yellow, 0xffbc00) term.setPaletteColor(colors.red, 0xff0000) end end - local c_mode = RadioButton{parent=clr_c_2,x=1,y=8,default=ini_cfg.ColorMode,options={"None","Protanopia","Deuteranopia","Tritanopia"},callback=recolor,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + local c_mode = RadioButton{parent=clr_c_2,x=1,y=8,default=ini_cfg.ColorMode,options=themes.COLOR_MODE_NAMES,callback=recolor,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} local _ = IndLight{parent=clr_c_2,x=20,y=8,label="Good",colors=cpair(colors.black,colors.green),value=true} _ = IndLight{parent=clr_c_2,x=20,y=9,label="Warning",colors=cpair(colors.black,colors.yellow),value=true} @@ -1107,9 +1108,9 @@ local function config_view(display) if f[1] == "AuthKey" then val = string.rep("*", string.len(val)) elseif f[1] == "LogMode" then val = util.trinary(raw == log.MODE.APPEND, "append", "replace") elseif f[1] == "FrontPanelTheme" then - if raw == 1 then val = "Sandstone" elseif raw == 2 then val = "Basalt" end + val = util.strval(themes.fp_theme_name(raw)) elseif f[1] == "ColorMode" then - if raw == 1 then val = "Standard" elseif raw == 2 then val = "Protanopia" elseif raw == 3 then val = "Deuteranopia" elseif raw == 4 then val = "Tritanopia" end + val = util.strval(themes.color_mode_name(raw)) elseif f[1] == "CoolingConfig" and type(cfg.CoolingConfig) == "table" then val = "" diff --git a/supervisor/databus.lua b/supervisor/databus.lua index 00185c7..f5daefb 100644 --- a/supervisor/databus.lua +++ b/supervisor/databus.lua @@ -64,7 +64,7 @@ function databus.tx_plc_rtt(reactor_id, rtt) elseif rtt > WARN_RTT then databus.ps.publish("plc_" .. reactor_id .. "_rtt_color", colors.yellow_hc) else - databus.ps.publish("plc_" .. reactor_id .. "_rtt_color", colors.green) + databus.ps.publish("plc_" .. reactor_id .. "_rtt_color", colors.green_hc) end end @@ -95,7 +95,7 @@ function databus.tx_rtu_rtt(session_id, rtt) elseif rtt > WARN_RTT then databus.ps.publish("rtu_" .. session_id .. "_rtt_color", colors.yellow_hc) else - databus.ps.publish("rtu_" .. session_id .. "_rtt_color", colors.green) + databus.ps.publish("rtu_" .. session_id .. "_rtt_color", colors.green_hc) end end @@ -134,7 +134,7 @@ function databus.tx_crd_rtt(rtt) elseif rtt > WARN_RTT then databus.ps.publish("crd_rtt_color", colors.yellow_hc) else - databus.ps.publish("crd_rtt_color", colors.green) + databus.ps.publish("crd_rtt_color", colors.green_hc) end end @@ -165,7 +165,7 @@ function databus.tx_pdg_rtt(session_id, rtt) elseif rtt > WARN_RTT then databus.ps.publish("pdg_" .. session_id .. "_rtt_color", colors.yellow_hc) else - databus.ps.publish("pdg_" .. session_id .. "_rtt_color", colors.green) + databus.ps.publish("pdg_" .. session_id .. "_rtt_color", colors.green_hc) end end diff --git a/supervisor/panel/front_panel.lua b/supervisor/panel/front_panel.lua index add7fcf..9bf8e7b 100644 --- a/supervisor/panel/front_panel.lua +++ b/supervisor/panel/front_panel.lua @@ -96,7 +96,7 @@ local function init(panel) TextBox{parent=plc_entry,x=1,y=2,text="UNIT "..i,alignment=ALIGN.CENTER,width=8,height=1,fg_bg=s_hi_box} TextBox{parent=plc_entry,x=1,y=3,text="",width=8,height=1,fg_bg=s_hi_box} - local conn = LED{parent=plc_entry,x=10,y=2,label="LINK",colors=ind_grn} + local conn = LED{parent=plc_entry,x=10,y=2,label="LINK",colors=cpair(colors.green_hc,colors.green_off)} conn.register(databus.ps, ps_prefix .. "conn", conn.update) local plc_addr = TextBox{parent=plc_entry,x=17,y=2,text=" --- ",width=5,height=1,fg_bg=label_d_fg} @@ -126,7 +126,7 @@ local function init(panel) local crd_page = Div{parent=page_div,x=1,y=1,hidden=true} local crd_box = Div{parent=crd_page,x=2,y=2,width=49,height=4,fg_bg=s_hi_bright} - local crd_conn = LED{parent=crd_box,x=2,y=2,label="CONNECTION",colors=ind_grn} + local crd_conn = LED{parent=crd_box,x=2,y=2,label="CONNECTION",colors=cpair(colors.green_hc,colors.green_off)} crd_conn.register(databus.ps, "crd_conn", crd_conn.update) TextBox{parent=crd_box,x=4,y=3,text="COMPUTER",width=8,height=1,fg_bg=label_d_fg} diff --git a/supervisor/renderer.lua b/supervisor/renderer.lua index 8f9389f..b1c9f06 100644 --- a/supervisor/renderer.lua +++ b/supervisor/renderer.lua @@ -19,9 +19,10 @@ local ui = { } -- try to start the UI ----@param theme integer front panel theme ID (1 = sandstone, 2 = basalt) +---@param theme FP_THEME front panel theme +---@param color_mode COLOR_MODE color mode ---@return boolean success, any error_msg -function renderer.try_start_ui(theme) +function renderer.try_start_ui(theme, color_mode) local status, msg = true, nil if ui.display == nil then @@ -39,6 +40,12 @@ function renderer.try_start_ui(theme) term.setPaletteColor(style.theme.colors[i].c, style.theme.colors[i].hex) end + -- apply color mode + local c_mode_overrides = style.theme.color_modes[color_mode] + for i = 1, #c_mode_overrides do + term.setPaletteColor(c_mode_overrides[i].c, c_mode_overrides[i].hex) + end + -- init front panel view status, msg = pcall(function () ui.display = DisplayBox{window=term.current(),fg_bg=style.fp.root} diff --git a/supervisor/startup.lua b/supervisor/startup.lua index d9c2229..4eae495 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -21,7 +21,7 @@ local supervisor = require("supervisor.supervisor") local svsessions = require("supervisor.session.svsessions") -local SUPERVISOR_VERSION = "v1.2.12" +local SUPERVISOR_VERSION = "v1.3.0" local println = util.println local println_ts = util.println_ts @@ -118,7 +118,7 @@ local function main() databus.tx_hw_modem(true) -- start UI - local fp_ok, message = renderer.try_start_ui(config.FrontPanelTheme) + local fp_ok, message = renderer.try_start_ui(config.FrontPanelTheme, config.ColorMode) if not fp_ok then println_ts(util.c("UI error: ", message))