#545 #544 added cc graphics and peripheral classes

This commit is contained in:
Mikayla Fischler
2024-09-14 22:16:12 -04:00
parent 85fc8d2920
commit ec2921e393
13 changed files with 95 additions and 30 deletions

View File

@@ -1263,7 +1263,7 @@ local function config_view(display)
-- list connected monitors
local monitors = ppm.get_monitor_list()
for iface, device in pairs(monitors) do
local dev = device.dev
local dev = device.dev ---@type Monitor
dev.setTextScale(0.5)
dev.setTextColor(colors.white)

View File

@@ -111,11 +111,11 @@ function coordinator.load_config()
---@class monitors_struct
local monitors = {
main = nil, ---@type table|nil
main = nil, ---@type Monitor|nil
main_name = "",
flow = nil, ---@type table|nil
flow = nil, ---@type Monitor|nil
flow_name = "",
unit_displays = {}, ---@type table[]
unit_displays = {}, ---@type Monitor[]
unit_name_map = {} ---@type string[]
}

View File

@@ -30,7 +30,7 @@ local renderer = {}
local engine = {
color_mode = 1, ---@type COLOR_MODE
monitors = nil, ---@type monitors_struct|nil
dmesg_window = nil, ---@type table|nil
dmesg_window = nil, ---@type Window|nil
ui_ready = false,
fp_ready = false,
ui = {
@@ -43,7 +43,7 @@ local engine = {
}
-- init a display to the "default", but set text scale to 0.5
---@param monitor table monitor
---@param monitor Monitor monitor
local function _init_display(monitor)
monitor.setTextScale(0.5)
monitor.setTextColor(colors.white)
@@ -64,7 +64,7 @@ local function _init_display(monitor)
end
-- print out that the monitor is too small
---@param monitor table monitor
---@param monitor Monitor monitor
local function _print_too_small(monitor)
monitor.setCursorPos(1, 1)
monitor.setBackgroundColor(colors.black)
@@ -275,7 +275,7 @@ function renderer.fp_ready() return engine.fp_ready end
function renderer.ui_ready() return engine.ui_ready end
-- handle a monitor peripheral being disconnected
---@param device table monitor
---@param device Monitor monitor
---@return boolean is_used if the monitor is one of the configured monitors
function renderer.handle_disconnect(device)
local is_used = false
@@ -326,7 +326,7 @@ end
-- handle a monitor peripheral being reconnected
---@param name string monitor name
---@param device table monitor
---@param device Monitor monitor
---@return boolean is_used if the monitor is one of the configured monitors
function renderer.handle_reconnect(name, device)
local is_used = false
@@ -373,7 +373,7 @@ function renderer.handle_resize(name)
if not engine.monitors then return false, false end
if engine.monitors.main_name == name and engine.monitors.main then
local device = engine.monitors.main ---@type table
local device = engine.monitors.main ---@type Monitor
-- this is necessary if the bottom left block was broken and on reconnect
_init_display(device)
@@ -416,7 +416,7 @@ function renderer.handle_resize(name)
end
else engine.dmesg_window.redraw() end
elseif engine.monitors.flow_name == name and engine.monitors.flow then
local device = engine.monitors.flow ---@type table
local device = engine.monitors.flow ---@type Monitor
-- this is necessary if the bottom left block was broken and on reconnect
_init_display(device)

View File

@@ -9,7 +9,7 @@ local log = require("scada-common.log")
local sounder = {}
local alarm_ctl = {
speaker = nil,
speaker = nil, ---@type Speaker
volume = 0.5,
stream = audio.new_stream()
}
@@ -24,7 +24,7 @@ local function play()
end
-- initialize the annunciator alarm system
---@param speaker table speaker peripheral
---@param speaker Speaker speaker peripheral
---@param volume number speaker volume
function sounder.init(speaker, volume)
alarm_ctl.speaker = speaker
@@ -36,7 +36,7 @@ function sounder.init(speaker, volume)
end
-- reconnect the speaker peripheral
---@param speaker table speaker peripheral
---@param speaker Speaker speaker peripheral
function sounder.reconnect(speaker)
alarm_ctl.speaker = speaker
alarm_ctl.playing = false

View File

@@ -152,7 +152,7 @@ local function main()
-- core coordinator devices
crd_dev = {
modem = ppm.get_wireless_modem(),
speaker = ppm.get_device("speaker")
speaker = ppm.get_device("speaker") ---@type Speaker|nil
},
-- system objects

View File

@@ -68,6 +68,7 @@ function threads.thread__main(smem)
if type ~= nil and device ~= nil then
if type == "modem" then
---@cast device Modem
-- we only really care if this is our wireless modem
-- if it is another modem, handle other peripheral losses separately
if nic.is_modem(device) then
@@ -91,8 +92,10 @@ function threads.thread__main(smem)
log_sys("non-comms modem disconnected")
end
elseif type == "monitor" then
---@cast device Monitor
smem.q.mq_render.push_data(MQ__RENDER_DATA.MON_DISCONNECT, device)
elseif type == "speaker" then
---@cast device Speaker
log_sys("lost alarm sounder speaker")
iocontrol.fp_has_speaker(false)
end
@@ -102,6 +105,7 @@ function threads.thread__main(smem)
if type ~= nil and device ~= nil then
if type == "modem" then
---@cast device Modem
if device.isWireless() and not nic.is_connected() then
-- reconnected modem
log_sys("comms modem reconnected")
@@ -113,8 +117,10 @@ function threads.thread__main(smem)
log_sys("wired modem reconnected")
end
elseif type == "monitor" then
---@cast device Monitor
smem.q.mq_render.push_data(MQ__RENDER_DATA.MON_CONNECT, { name = param1, device = device })
elseif type == "speaker" then
---@cast device Speaker
log_sys("alarm sounder speaker reconnected")
sounder.reconnect(device)
iocontrol.fp_has_speaker(true)