package kernel.peripherals; import kernel.net.INetworkInterface; import kernel.peripherals.Modem; import kernel.peripherals.Screen; using lua.Table; using Lambda; /** Class responseable for retrieving peripherals. **/ class Peripheral { /** Depends on: KernelEvents **/ public static var instance:Peripheral; private var screens: Array = []; private var modes: Array = []; @:allow(kernel.Init) private function new() { KernelEvents.instance.onPeripheral.handle(this.updatePeripherals); KernelEvents.instance.onPeripheralDetach.handle(this.updatePeripherals); updatePeripherals(); } private function updatePeripherals() { findScreens(); findModems(); } /** Get all connected screens. **/ public function getScreens():Array { return this.screens; } private function findScreens():Void { var allScreens = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "monitor"); this.screens = allScreens.map(s -> return new Screen((cc.Peripheral.wrap(s) : Dynamic), s)); } public function getScreen(addr: String): Screen { return this.screens.find(item -> item.getAddr() == addr); } /** Get all connected modems. **/ public function getModems():Array { return this.modes; } private function findModems():Void { var allModems = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "modem"); this.modes = allModems.map(s -> return new Modem((cc.Peripheral.wrap(s) : Dynamic), s)); } }