diff --git a/src/bin/Redstone.hx b/src/bin/Redstone.hx new file mode 100644 index 0000000..23d7f71 --- /dev/null +++ b/src/bin/Redstone.hx @@ -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 { + var subcommand = handle.args[0]; + + var side:Null = 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 { + 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; + } + } +} diff --git a/src/bin/Terminal.hx b/src/bin/Terminal.hx index 5ad0150..eddd316 100644 --- a/src/bin/Terminal.hx +++ b/src/bin/Terminal.hx @@ -141,6 +141,8 @@ class Terminal { return new HelloWorld(); case "net": return new Net(); + case "rs": + return new Redstone(); default: return null; }