mirror of
https://github.com/kepler155c/opus
synced 2025-01-27 07:34:45 +00:00
support preferred wireless modems
This commit is contained in:
parent
4721b6aec1
commit
17d55e75ce
@ -28,9 +28,9 @@ function Peripheral.addDevice(deviceList, side)
|
||||
end
|
||||
|
||||
if ptype == 'modem' then
|
||||
if Peripheral.call(name, 'isWireless') then
|
||||
ptype = 'wireless_modem'
|
||||
else
|
||||
if not Peripheral.call(name, 'isWireless') then
|
||||
-- ptype = 'wireless_modem'
|
||||
-- else
|
||||
ptype = 'wired_modem'
|
||||
end
|
||||
end
|
||||
@ -57,10 +57,6 @@ function Peripheral.addDevice(deviceList, side)
|
||||
-- this can randomly fail
|
||||
pcall(function()
|
||||
deviceList[name] = Peripheral.wrap(side)
|
||||
if ptype == 'wireless_modem' and not deviceList.wireless_modem then
|
||||
-- TODO: fix this
|
||||
deviceList.wireless_modem = deviceList[name]
|
||||
end
|
||||
end)
|
||||
|
||||
if deviceList[name] then
|
||||
|
@ -1,5 +1,10 @@
|
||||
local kernel = _G.kernel
|
||||
local os = _G.os
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Config = require('config')
|
||||
|
||||
local device = _G.device
|
||||
local kernel = _G.kernel
|
||||
local os = _G.os
|
||||
|
||||
_G.network = { }
|
||||
|
||||
@ -11,15 +16,44 @@ local function startNetwork()
|
||||
})
|
||||
end
|
||||
|
||||
local function setModem(dev)
|
||||
if not device.wireless_modem and dev.isWireless() then
|
||||
local config = Config.load('os', { })
|
||||
if not config.wirelessModem or dev.name == config.wirelessModem then
|
||||
device.wireless_modem = dev
|
||||
os.queueEvent('device_attach', 'wireless_modem')
|
||||
return dev
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- create a psuedo-device named 'wireleess_modem'
|
||||
kernel.hook('device_attach', function(_, eventData)
|
||||
if eventData[1] == 'wireless_modem' then
|
||||
startNetwork()
|
||||
local dev = device[eventData[1]]
|
||||
if dev.type == 'modem' then
|
||||
if setModem(dev) then
|
||||
startNetwork()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
if _G.device.wireless_modem then
|
||||
kernel.hook('device_detach', function(_, eventData)
|
||||
if device.wireless_modem and eventData[1] == device.wireless_modem.name then
|
||||
device['wireless_modem'] = nil
|
||||
os.queueEvent('device_detach', 'wireless_modem')
|
||||
end
|
||||
end)
|
||||
|
||||
for _,dev in pairs(device) do
|
||||
if dev.type == 'modem' then
|
||||
if setModem(dev) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if device.wireless_modem then
|
||||
print('waiting for network...')
|
||||
startNetwork()
|
||||
os.pullEvent('network_up')
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user