package kernel.peripherals; import kernel.peripherals.Modem; import kernel.peripherals.Screen; using lua.Table; using Lambda; /** Class responseable for retrieving peripherals. **/ class Peripheral { public static var instance:Peripheral; @:allow(kernel.Init) private function new() {} /** Get all connected screens. **/ public function getScreens(): Array { var allScreens = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "monitor"); return allScreens.map(s -> return new Screen((cc.Peripheral.wrap(s):Dynamic),s)); } public function getScreen(addr: String): Screen { if (!getAllPeripheralsAddr().exists(item -> item == addr)){ return null; } return new Screen((cc.Peripheral.wrap(addr):Dynamic),addr); } /** Get all connected modems. **/ public function getModems(): Array { var allModems = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "modem"); return allModems.map(s -> return new Modem((cc.Peripheral.wrap(s): Dynamic),s)); } /** Get all connected wireless modems. **/ public function getWirelessModems(): Array { return getModems().filter(modem -> return modem.isWireless()); } /** Get all connected wired modems. **/ public function getWiredModems(): Array { return getModems().filter(modem -> return !modem.isWireless()); } public function getAllPeripheralsAddr(): Array { return cc.Peripheral.getNames().toArray(); } }