added GPS cli app

This commit is contained in:
Djeeberjr 2023-03-28 00:57:04 +02:00
parent 4f8db600dc
commit 4a7b57c47f
2 changed files with 73 additions and 0 deletions

71
src/bin/GPS.hx Normal file
View File

@ -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<Bool> {
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<String>): 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<Float>(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;
}
}

View File

@ -154,6 +154,8 @@ class Terminal extends UIApp {
return new Redstone();
case "disk":
return new Disk();
case "gps":
return new GPS();
default:
return null;
}