added GPS cli app
This commit is contained in:
parent
4f8db600dc
commit
4a7b57c47f
71
src/bin/GPS.hx
Normal file
71
src/bin/GPS.hx
Normal 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;
|
||||
}
|
||||
}
|
@ -154,6 +154,8 @@ class Terminal extends UIApp {
|
||||
return new Redstone();
|
||||
case "disk":
|
||||
return new Disk();
|
||||
case "gps":
|
||||
return new GPS();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user