mirror of
https://github.com/kepler155c/opus
synced 2025-04-01 13:16:55 +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
|
end
|
||||||
|
|
||||||
if ptype == 'modem' then
|
if ptype == 'modem' then
|
||||||
if Peripheral.call(name, 'isWireless') then
|
if not Peripheral.call(name, 'isWireless') then
|
||||||
ptype = 'wireless_modem'
|
-- ptype = 'wireless_modem'
|
||||||
else
|
-- else
|
||||||
ptype = 'wired_modem'
|
ptype = 'wired_modem'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -57,10 +57,6 @@ function Peripheral.addDevice(deviceList, side)
|
|||||||
-- this can randomly fail
|
-- this can randomly fail
|
||||||
pcall(function()
|
pcall(function()
|
||||||
deviceList[name] = Peripheral.wrap(side)
|
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)
|
end)
|
||||||
|
|
||||||
if deviceList[name] then
|
if deviceList[name] then
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
local kernel = _G.kernel
|
_G.requireInjector(_ENV)
|
||||||
local os = _G.os
|
|
||||||
|
local Config = require('config')
|
||||||
|
|
||||||
|
local device = _G.device
|
||||||
|
local kernel = _G.kernel
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
_G.network = { }
|
_G.network = { }
|
||||||
|
|
||||||
@ -11,15 +16,44 @@ local function startNetwork()
|
|||||||
})
|
})
|
||||||
end
|
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)
|
kernel.hook('device_attach', function(_, eventData)
|
||||||
if eventData[1] == 'wireless_modem' then
|
local dev = device[eventData[1]]
|
||||||
startNetwork()
|
if dev.type == 'modem' then
|
||||||
|
if setModem(dev) then
|
||||||
|
startNetwork()
|
||||||
|
end
|
||||||
end
|
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...')
|
print('waiting for network...')
|
||||||
startNetwork()
|
startNetwork()
|
||||||
os.pullEvent('network_up')
|
os.pullEvent('network_up')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user