added Restone cli

This commit is contained in:
Djeeberjr 2022-12-19 23:28:46 +01:00
parent 8180599c04
commit 72e71c8e36
2 changed files with 60 additions and 0 deletions

58
src/bin/Redstone.hx Normal file
View File

@ -0,0 +1,58 @@
package bin;
import kernel.peripherals.Peripherals.Peripheral;
import kernel.peripherals.Side;
import lib.cli.TermHandle;
import lib.cli.CLIBase;
using tink.CoreApi;
class Redstone extends CLIBase {
public function new() {
super();
}
public function invoke(handle:TermHandle):Future<Bool> {
var subcommand = handle.args[0];
var side:Null<Side> = getSide(handle.args[1]);
if (side == null) {
handle.writeLn("Invalid side");
return Future.sync(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.writeLn("Analog input: " + value);
default:
handle.writeLn("Invalid subcommand");
return Future.sync(false);
}
return Future.sync(true);
}
private function getSide(side:String):Null<Side> {
switch (side) {
case "top":
return Side.Top;
case "bottom":
return Side.Bottom;
case "left":
return Side.Left;
case "right":
return Side.Right;
case "front":
return Side.Front;
case "back":
return Side.Back;
default:
return null;
}
}
}

View File

@ -141,6 +141,8 @@ class Terminal {
return new HelloWorld();
case "net":
return new Net();
case "rs":
return new Redstone();
default:
return null;
}