From 4a7b57c47f290f2de1b748a16710a41c9288e076 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Tue, 28 Mar 2023 00:57:04 +0200 Subject: [PATCH] added GPS cli app --- src/bin/GPS.hx | 71 +++++++++++++++++++++++++++++++++++++++++++++ src/bin/Terminal.hx | 2 ++ 2 files changed, 73 insertions(+) create mode 100644 src/bin/GPS.hx diff --git a/src/bin/GPS.hx b/src/bin/GPS.hx new file mode 100644 index 0000000..edd90a3 --- /dev/null +++ b/src/bin/GPS.hx @@ -0,0 +1,71 @@ +package bin; + +import lib.Pos3; +import lib.Vec.Vec3; +import lib.cli.TermHandle; +import lib.cli.CLIApp; + +using tink.CoreApi; + +class GPS extends CLIApp { + private var handle:TermHandle; + + public function new() {} + + public function invoke(handle: TermHandle):Future { + this.handle = handle; + + var subcommand = handle.args[0]; + var subcommand_args = handle.args.slice(1); + + switch (subcommand) { + case "set": + return Future.sync(setManuelPos(subcommand_args)); + case "status": + return Future.sync(getGPSStatus()); + case "locate": + kernel.gps.GPS.instance.locate(); + return Future.sync(true); + default: + handle.writeLn("Unknown subcommand: " + subcommand); + return Future.sync(false); + + } + + return Future.sync(true); + } + + private function setManuelPos(args: Array): Bool { + var x: Float = Std.parseFloat(args[0]); + var y: Float = Std.parseFloat(args[1]); + var z: Float = Std.parseFloat(args[2]); + + var pos: Pos3 = new Vec3(x, y, z); + + kernel.gps.GPS.instance.setManualPosition(pos); + + return true; + } + + private function getGPSStatus(): Bool { + + var pos = kernel.gps.GPS.instance.getPosition(); + if (pos != null) { + handle.writeLn('Position x:${pos.x} y:${pos.y} z:${pos.z}'); + } else { + handle.writeLn("Position not available"); + return true; + } + + var acc = kernel.gps.GPS.instance.getAccuracy(); + if (acc == 1){ + handle.writeLn("Accuracy: Low"); + } else if (acc == 2){ + handle.writeLn("Accuracy: Medium"); + } else if (acc == 3){ + handle.writeLn("Accuracy: High"); + } + + return true; + } +} diff --git a/src/bin/Terminal.hx b/src/bin/Terminal.hx index 9e49195..b7b3f1e 100644 --- a/src/bin/Terminal.hx +++ b/src/bin/Terminal.hx @@ -154,6 +154,8 @@ class Terminal extends UIApp { return new Redstone(); case "disk": return new Disk(); + case "gps": + return new GPS(); default: return null; }