refactored Redstone bin

This commit is contained in:
Djeeberjr 2023-05-31 19:19:17 +02:00
parent 8c041766c9
commit c86d0e1d8b

View File

@ -1,44 +1,26 @@
package bin; package bin;
import kernel.ps.ProcessHandle; import lib.CLIAppBase;
import kernel.ps.Process;
import kernel.peripherals.Peripherals.Peripheral; import kernel.peripherals.Peripherals.Peripheral;
import kernel.peripherals.Side;
using tink.CoreApi; using tink.CoreApi;
class Redstone implements Process { class Redstone extends CLIAppBase{
public function new() {} public function new() {
registerSyncSubcommand("on", (args)-> {
Peripheral.instance.getRedstone(args[0]).setOutput(true);
return true;
});
public function run(handle: ProcessHandle):Void { registerSyncSubcommand("off", (args)-> {
var subcommand = handle.args[0]; Peripheral.instance.getRedstone(args[0]).setOutput(false);
return true;
});
if (subcommand == null) { registerSyncSubcommand("get", (args)-> {
handle.write("Usage: redstone <on|off|get> <side>"); var value = Peripheral.instance.getRedstone(args[0]).getAnalogInput();
return handle.close(false);
}
var side:Null<Side> = handle.args[1];
if (side == null) {
handle.write("Invalid side");
return handle.close(false);
}
switch (subcommand) {
case "on":
Peripheral.instance.getRedstone(side).setOutput(true);
case "off":
Peripheral.instance.getRedstone(side).setOutput(false);
case "get":
var value = Peripheral.instance.getRedstone(side).getAnalogInput();
handle.write("Analog input: " + value); handle.write("Analog input: " + value);
case "help": return true;
handle.write("Usage: redstone <on|off|get> <side>"); });
default:
handle.write("Invalid subcommand");
return handle.close(false);
}
return handle.close();
} }
} }