Added iris detection
This commit is contained in:
90
startup.lua
90
startup.lua
@ -29,6 +29,7 @@ local mon = peripheral.find("monitor")
|
||||
local gate = peripheral.find("advanced_crystal_interface")
|
||||
or peripheral.find("crystal_interface")
|
||||
or peripheral.find("basic_interface")
|
||||
local transceiver = peripheral.find("transceiver")
|
||||
|
||||
if gate == nil then
|
||||
error("Stargate interface not found! Please connect an interface.")
|
||||
@ -38,6 +39,10 @@ if mon == nil then
|
||||
error("Monitor not found! Please connect a monitor.")
|
||||
end
|
||||
|
||||
if transceiver == nil then
|
||||
print("WARNING: No transceiver found. Remote iris detection disabled.")
|
||||
end
|
||||
|
||||
-- Check iris availability
|
||||
if gate.getIris() == nil then
|
||||
print("Config has Iris enabled, but there is no iris! Disabling Iris")
|
||||
@ -123,6 +128,42 @@ local function Paratimeout()
|
||||
return 2
|
||||
end
|
||||
|
||||
local function MonitorRemoteIris()
|
||||
-- Continuously monitor remote iris state while connected
|
||||
while gate.isStargateConnected() do
|
||||
sleep(2) -- Check every 2 seconds
|
||||
|
||||
if transceiver then
|
||||
local remoteIrisState = transceiver.checkConnectedShielding()
|
||||
|
||||
if remoteIrisState and remoteIrisState > 0 then
|
||||
-- Remote iris closed or closing
|
||||
if remoteIrisState == 100 then
|
||||
utils.log("ALERT: Remote iris fully closed during connection!")
|
||||
else
|
||||
utils.log("ALERT: Remote iris closing: " .. remoteIrisState .. "%")
|
||||
end
|
||||
|
||||
mon.setBackgroundColor(colors.red)
|
||||
mon.clear()
|
||||
mon.setTextScale(1)
|
||||
mon.setCursorPos(6, 5)
|
||||
mon.write("REMOTE IRIS")
|
||||
mon.setCursorPos(8, 7)
|
||||
if remoteIrisState == 100 then
|
||||
mon.write("CLOSED!")
|
||||
else
|
||||
mon.write(remoteIrisState .. "% CLOSED")
|
||||
end
|
||||
mon.setCursorPos(3, 10)
|
||||
mon.write("Connection unsafe")
|
||||
display.drawIrisStatus()
|
||||
end
|
||||
end
|
||||
end
|
||||
return 3 -- Return unique value to indicate iris monitoring ended
|
||||
end
|
||||
|
||||
---------------------------------------------
|
||||
-- INCOMING WORMHOLE HANDLER
|
||||
---------------------------------------------
|
||||
@ -359,12 +400,6 @@ end
|
||||
local function handleOutgoingDial()
|
||||
totalstate = true
|
||||
local PDO = 0
|
||||
|
||||
-- parallel.waitForAny runs functions simultaneously and returns which finished first
|
||||
-- Here we're waiting for either:
|
||||
-- 1 = selectCategory (user selected a gate to dial)
|
||||
-- 2 = Paratimeout (5 minutes passed with no selection)
|
||||
-- This prevents the gate from staying on the selection screen forever
|
||||
PDO = parallel.waitForAny(selectCategory, Paratimeout)
|
||||
|
||||
if (PDO == 1) and totalstate == true then
|
||||
@ -372,7 +407,38 @@ local function handleOutgoingDial()
|
||||
|
||||
os.pullEvent("stargate_outgoing_wormhole")
|
||||
|
||||
display.showConnected(destAddressname, destAddress)
|
||||
-- Check if remote iris is closed using transceiver
|
||||
local remoteIrisState = nil
|
||||
if transceiver then
|
||||
remoteIrisState = transceiver.checkConnectedShielding()
|
||||
end
|
||||
|
||||
if remoteIrisState and remoteIrisState > 0 then
|
||||
-- Remote iris is closed (partially or fully)
|
||||
if remoteIrisState == 100 then
|
||||
utils.log("WARNING: Remote iris is fully closed!")
|
||||
else
|
||||
utils.log("WARNING: Remote iris is " .. remoteIrisState .. "% closed!")
|
||||
end
|
||||
|
||||
mon.setBackgroundColor(colors.red)
|
||||
mon.clear()
|
||||
mon.setTextScale(1)
|
||||
mon.setCursorPos(6, 5)
|
||||
mon.write("REMOTE IRIS")
|
||||
mon.setCursorPos(8, 7)
|
||||
if remoteIrisState == 100 then
|
||||
mon.write("CLOSED!")
|
||||
else
|
||||
mon.write(remoteIrisState .. "% CLOSED")
|
||||
end
|
||||
mon.setCursorPos(3, 10)
|
||||
mon.write("Connection unsafe")
|
||||
display.drawIrisStatus()
|
||||
else
|
||||
-- Remote iris is open or no iris present
|
||||
display.showConnected(destAddressname, destAddress)
|
||||
end
|
||||
|
||||
if (gate.isStargateConnected() == true) then
|
||||
-- parallel.waitForAny runs functions at the same time, returns which finished first
|
||||
@ -380,8 +446,9 @@ local function handleOutgoingDial()
|
||||
-- DisconnectCheck = gate disconnects naturally (timeout or remote disconnect)
|
||||
-- ParaDisconnect = user manually clicks screen to disconnect
|
||||
-- Paratimeout = safety timeout (5 minutes)
|
||||
-- MonitorRemoteIris = continuously checks remote iris state
|
||||
-- Whichever happens first ends the connection
|
||||
PDO = parallel.waitForAny(DisconnectCheck, ParaDisconnect, Paratimeout)
|
||||
PDO = parallel.waitForAny(DisconnectCheck, ParaDisconnect, Paratimeout, MonitorRemoteIris)
|
||||
dialing = false
|
||||
end
|
||||
end
|
||||
@ -398,13 +465,6 @@ end
|
||||
local function mainMenu()
|
||||
while true do
|
||||
display.showMainMenu()
|
||||
|
||||
-- parallel.waitForAny runs multiple functions simultaneously, returns which completes first
|
||||
-- The main menu waits for any of these events:
|
||||
-- 1 = GetClick (user touched the monitor anywhere - assumes they want to dial out)
|
||||
-- 2 = GetActivation (incoming wormhole detected with address)
|
||||
-- Note: We don't wait for CheveronActivation here because it fires at the same time
|
||||
-- as the incoming wormhole event, causing a race condition where we might miss the address
|
||||
local answer = parallel.waitForAny(GetClick, GetActivation)
|
||||
|
||||
if (answer == 1) then
|
||||
|
||||
Reference in New Issue
Block a user