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