mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2025-07-26 23:57:07 +00:00
@ -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)
|
||||
|
@ -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[]
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -144,6 +144,7 @@ function threads.thread__main(smem, init)
|
||||
plc_state.no_reactor = true
|
||||
plc_state.degraded = true
|
||||
elseif networked and type == "modem" then
|
||||
---@cast device Modem
|
||||
-- we only care if this is our wireless modem
|
||||
-- note, check init_ok first since nic will be nil if it is false
|
||||
if plc_state.init_ok and nic.is_modem(device) then
|
||||
@ -208,6 +209,7 @@ function threads.thread__main(smem, init)
|
||||
rps.reset_formed()
|
||||
end
|
||||
elseif networked and type == "modem" then
|
||||
---@cast device Modem
|
||||
-- note, check init_ok first since nic will be nil if it is false
|
||||
if device.isWireless() and not (plc_state.init_ok and nic.is_connected()) then
|
||||
-- reconnected modem
|
||||
|
@ -235,7 +235,7 @@ function rtu.init_unit(device)
|
||||
end
|
||||
|
||||
-- create an alarm speaker sounder
|
||||
---@param speaker table device peripheral
|
||||
---@param speaker Speaker device peripheral
|
||||
function rtu.init_sounder(speaker)
|
||||
---@class rtu_speaker_sounder
|
||||
local spkr_ctl = {
|
||||
|
@ -245,6 +245,7 @@ function threads.thread__main(smem)
|
||||
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "modem" then
|
||||
---@cast device Modem
|
||||
-- we only care if this is our wireless modem
|
||||
if nic.is_modem(device) then
|
||||
nic.disconnect()
|
||||
@ -263,6 +264,7 @@ function threads.thread__main(smem)
|
||||
log.warning("non-comms modem disconnected")
|
||||
end
|
||||
elseif type == "speaker" then
|
||||
---@cast device Speaker
|
||||
for i = 1, #sounders do
|
||||
if sounders[i].speaker == device then
|
||||
table.remove(sounders, i)
|
||||
@ -298,6 +300,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
|
||||
nic.connect(device)
|
||||
@ -312,6 +315,7 @@ function threads.thread__main(smem)
|
||||
log.info("wired modem reconnected")
|
||||
end
|
||||
elseif type == "speaker" then
|
||||
---@cast device Speaker
|
||||
table.insert(sounders, rtu.init_sounder(device))
|
||||
|
||||
println_ts("speaker connected")
|
||||
|
@ -77,23 +77,14 @@ end
|
||||
|
||||
-- NIC: Network Interface Controller<br>
|
||||
-- utilizes HMAC-MD5 for message authentication, if enabled
|
||||
---@param modem table modem to use
|
||||
---@param modem Modem modem to use
|
||||
function network.nic(modem)
|
||||
local self = {
|
||||
connected = true, -- used to avoid costly MAC calculations if modem isn't even present
|
||||
channels = {}
|
||||
}
|
||||
|
||||
---@class nic
|
||||
---@field isOpen fun(channel: integer) : boolean check if a channel is open
|
||||
---@field isWireless fun() : boolean determine if this is a wired or wireless modem
|
||||
---@field getNamesRemote fun() : string[] list all remote peripherals on the wired network
|
||||
---@field isPresentRemote fun(name: string) : boolean determine if a peripheral is available on this wired network
|
||||
---@field getTypeRemote fun(name: string) : string|nil get the type of a peripheral is available on this wired network
|
||||
---@field hasTypeRemote fun(name: string, type: string) : boolean|nil check a peripheral is of a particular type
|
||||
---@field getMethodsRemote fun(name: string) : string[] get all available methods for the remote peripheral with the given name
|
||||
---@field callRemote fun(remoteName: string, method: string, ...) : table call a method on a peripheral on this wired network
|
||||
---@field getNameLocal fun() : string|nil returns the network name of the current computer, if the modem is on
|
||||
---@class nic:Modem
|
||||
local public = {}
|
||||
|
||||
-- check if this NIC has a connected modem
|
||||
@ -101,7 +92,7 @@ function network.nic(modem)
|
||||
function public.is_connected() return self.connected end
|
||||
|
||||
-- connect to a modem peripheral
|
||||
---@param reconnected_modem table
|
||||
---@param reconnected_modem Modem
|
||||
function public.connect(reconnected_modem)
|
||||
modem = reconnected_modem
|
||||
self.connected = true
|
||||
|
@ -423,7 +423,7 @@ function ppm.get_fission_reactor() return ppm.get_device("fissionReactorLogicAda
|
||||
-- get the wireless modem (if multiple, returns the first)<br>
|
||||
-- if this is in a CraftOS emulated environment, wired modems will be used instead
|
||||
---@nodiscard
|
||||
---@return table|nil modem function table
|
||||
---@return Modem|nil modem function table
|
||||
function ppm.get_wireless_modem()
|
||||
local w_modem = nil
|
||||
local emulated_env = periphemu ~= nil
|
||||
@ -440,7 +440,7 @@ end
|
||||
|
||||
-- list all connected monitors
|
||||
---@nodiscard
|
||||
---@return table monitors
|
||||
---@return { [string]: ppm_entry } monitors
|
||||
function ppm.get_monitor_list()
|
||||
local list = {}
|
||||
|
||||
|
@ -5,6 +5,66 @@
|
||||
---@class types
|
||||
local types = {}
|
||||
|
||||
--#region CC: TWEAKED CLASSES https://tweaked.cc
|
||||
|
||||
---@class Redirect
|
||||
---@field write fun(text: string) Write text at the current cursor position, moving the cursor to the end of the text.
|
||||
---@field scroll fun(y: integer) Move all positions up (or down) by y pixels.
|
||||
---@field getCursorPos fun() : x: integer, y: integer Get the position of the cursor.
|
||||
---@field setCursorPos fun(x: integer, y: integer) Set the position of the cursor.
|
||||
---@field getCursorBlink fun() : boolean Checks if the cursor is currently blinking.
|
||||
---@field setCursorBlink fun(blink: boolean) Sets whether the cursor should be visible (and blinking) at the current cursor position.
|
||||
---@field getSize fun() : width: integer, height: integer Get the size of the terminal.
|
||||
---@field clear fun() Clears the terminal, filling it with the current background color.
|
||||
---@field clearLine fun() Clears the line the cursor is currently on, filling it with the current background color.
|
||||
---@field getTextColor fun() : color Return the color that new text will be written as.
|
||||
---@field setTextColor fun(color: color) Set the colour that new text will be written as.
|
||||
---@field getBackgroundColor fun() : color Return the current background color.
|
||||
---@field setBackgroundColor fun(color: color) set the current background color.
|
||||
---@field isColor fun() Determine if this terminal supports color.
|
||||
---@field blit fun(text: string, textColor: string, backgroundColor: string) Writes text to the terminal with the specific foreground and background colors.
|
||||
---@diagnostic disable-next-line: duplicate-doc-field
|
||||
---@field setPaletteColor fun(index: color, color: integer) Set the palette for a specific color.
|
||||
---@diagnostic disable-next-line: duplicate-doc-field
|
||||
---@field setPaletteColor fun(index: color, r: number, g: number, b:number) Set the palette for a specific color. R/G/B are 0 to 1.
|
||||
---@field getPaletteColor fun(color: color) : r: number, g: number, b:number Get the current palette for a specific color.
|
||||
|
||||
---@class Window:Redirect
|
||||
---@field getLine fun(y: integer) : content: string, fg: string, bg: string Get the buffered contents of a line in this window.
|
||||
---@field setVisible fun(visible: boolean) Set whether this window is visible. Invisible windows will not be drawn to the screen until they are made visible again.
|
||||
---@field isVisible fun() : visible: boolean Get whether this window is visible. Invisible windows will not be drawn to the screen until they are made visible again.
|
||||
---@field redraw fun() Draw this window. This does nothing if the window is not visible.
|
||||
---@field restoreCursor fun() Set the current terminal's cursor to where this window's cursor is. This does nothing if the window is not visible.
|
||||
---@field getPosition fun() : x: integer, y: integer Get the position of the top left corner of this window.
|
||||
---@field reposition fun(new_x: integer, new_y: integer, new_width?: integer, new_height?: integer, new_parent?: Redirect) Reposition or resize the given window.
|
||||
|
||||
---@class Monitor:Redirect
|
||||
---@field setTextScale fun(scale: number) Set the scale of this monitor.
|
||||
---@field getTextScale fun() : number Get the monitor's current text scale.
|
||||
|
||||
---@class Modem
|
||||
---@field open fun(channel: integer) Open a channel on a modem.
|
||||
---@field isOpen fun(channel: integer) : boolean Check if a channel is open.
|
||||
---@field close fun(channel: integer) Close an open channel, meaning it will no longer receive messages.
|
||||
---@field closeAll fun() Close all open channels.
|
||||
---@field transmit fun(channel: integer, replyChannel: integer, payload: any) Sends a modem message on a certain channel.
|
||||
---@field isWireless fun() : boolean Determine if this is a wired or wireless modem.
|
||||
---@field getNamesRemote fun() : string[] List all remote peripherals on the wired network.
|
||||
---@field isPresentRemote fun(name: string) : boolean Determine if a peripheral is available on this wired network.
|
||||
---@field getTypeRemote fun(name: string) : string|nil Get the type of a peripheral is available on this wired network.
|
||||
---@field hasTypeRemote fun(name: string, type: string) : boolean|nil Check a peripheral is of a particular .
|
||||
---@field getMethodsRemote fun(name: string) : string[] Get all available methods for the remote peripheral with the given name.
|
||||
---@field callRemote fun(remoteName: string, method: string, ...) : table Call a method on a peripheral on this wired network.
|
||||
---@field getNameLocal fun() : string|nil Returns the network name of the current computer, if the modem is on.
|
||||
|
||||
---@class Speaker
|
||||
---@field playNote fun(instrument: string, volume?: number, pitch?: number) : success: boolean Plays a note block note through the speaker.
|
||||
---@field playSound fun(name: string, volume?: number, pitch?: number) : success: boolean Plays a Minecraft sound through the speaker.
|
||||
---@field playAudio fun(audio: number[], volume?: number) : success: boolean Attempt to stream some audio data to the speaker.
|
||||
---@field stop fun() Stop all audio being played by this speaker.
|
||||
|
||||
--#endregion
|
||||
|
||||
--#region CLASSES
|
||||
|
||||
---@class tank_fluid
|
||||
|
@ -157,6 +157,7 @@ local function main()
|
||||
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "modem" then
|
||||
---@cast device Modem
|
||||
-- we only care if this is our wireless modem
|
||||
if nic.is_modem(device) then
|
||||
nic.disconnect()
|
||||
@ -181,6 +182,7 @@ local function main()
|
||||
|
||||
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
|
||||
nic.connect(device)
|
||||
|
Reference in New Issue
Block a user