refactored Redstone bin
This commit is contained in:
parent
8c041766c9
commit
c86d0e1d8b
@ -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);
|
handle.write("Analog input: " + value);
|
||||||
}
|
return true;
|
||||||
|
});
|
||||||
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);
|
|
||||||
case "help":
|
|
||||||
handle.write("Usage: redstone <on|off|get> <side>");
|
|
||||||
default:
|
|
||||||
handle.write("Invalid subcommand");
|
|
||||||
return handle.close(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return handle.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user