2017-09-05 06:09:31 +00:00
|
|
|
requireInjector(getfenv(1))
|
|
|
|
|
|
|
|
local Event = require('event')
|
2016-12-11 19:24:52 +00:00
|
|
|
local Peripheral = require('peripheral')
|
2017-09-05 06:09:31 +00:00
|
|
|
local Util = require('util')
|
2016-12-11 19:24:52 +00:00
|
|
|
|
|
|
|
multishell.setTitle(multishell.getCurrent(), 'Devices')
|
|
|
|
|
|
|
|
local attachColor = colors.green
|
|
|
|
local detachColor = colors.red
|
|
|
|
|
|
|
|
if not term.isColor() then
|
|
|
|
attachColor = colors.white
|
|
|
|
detachColor = colors.lightGray
|
|
|
|
end
|
|
|
|
|
2017-07-24 02:37:07 +00:00
|
|
|
Event.on('peripheral', function(event, side)
|
2016-12-11 19:24:52 +00:00
|
|
|
if side then
|
2017-04-01 23:21:49 +00:00
|
|
|
local dev = Peripheral.addDevice(device, side)
|
2016-12-11 19:24:52 +00:00
|
|
|
if dev then
|
|
|
|
term.setTextColor(attachColor)
|
|
|
|
Util.print('[%s] %s attached', dev.side, dev.name)
|
|
|
|
os.queueEvent('device_attach', dev.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-07-24 02:37:07 +00:00
|
|
|
Event.on('peripheral_detach', function(event, side)
|
2016-12-11 19:24:52 +00:00
|
|
|
if side then
|
|
|
|
local dev = Util.find(device, 'side', side)
|
|
|
|
if dev then
|
|
|
|
term.setTextColor(detachColor)
|
|
|
|
Util.print('[%s] %s detached', dev.side, dev.name)
|
|
|
|
os.queueEvent('device_detach', dev.name)
|
|
|
|
device[dev.name] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
print('waiting for peripheral changes')
|
|
|
|
Event.pullEvents()
|