implemented INS
This commit is contained in:
@@ -23,6 +23,8 @@ class GPS {
|
||||
private var cachedPosition:Pos3;
|
||||
private var lastPositionResponse: Array<{pos:Pos3,dist:Float}> = [];
|
||||
|
||||
private var futureResolve: (pos:Null<Pos3>) -> Void = null;
|
||||
|
||||
@:allow(kernel.Init)
|
||||
private function new() {
|
||||
this.loadCachedPosition();
|
||||
@@ -39,6 +41,12 @@ class GPS {
|
||||
}
|
||||
}
|
||||
|
||||
@:allow(kernel.gps.INS)
|
||||
private function setINSPosition(pos:Pos3) {
|
||||
cachedPosition = pos;
|
||||
posAccuracy = 1;
|
||||
}
|
||||
|
||||
public function getPosition():Null<Pos3> {
|
||||
return cachedPosition;
|
||||
}
|
||||
@@ -52,8 +60,18 @@ class GPS {
|
||||
posAccuracy = 0;
|
||||
}
|
||||
|
||||
public function locate() {
|
||||
sendPositionRequest();
|
||||
public function locate():Future<Null<Pos3>> {
|
||||
// TODO: implenet a timeout
|
||||
// TODO: dont send a request twice if the last one is still pending or we moved
|
||||
return new Future<Null<Pos3>>((resolve)->{
|
||||
this.futureResolve = resolve;
|
||||
sendPositionRequest();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private function resolveFuture(pos:Null<Pos3>) {
|
||||
this.futureResolve(pos);
|
||||
}
|
||||
|
||||
private function persistCachedPositon() {
|
||||
@@ -124,13 +142,19 @@ class GPS {
|
||||
|
||||
if (lastPositionResponse.length < 4) return; // We need at least 3 responses to calculate the position
|
||||
|
||||
var calculatedPosition = calculatePosition().round();
|
||||
var calculatedPosition = calculatePosition();
|
||||
|
||||
if (calculatedPosition != null){
|
||||
calculatedPosition = calculatedPosition.round();
|
||||
}
|
||||
|
||||
lastPositionResponse = []; // Reset the response array
|
||||
|
||||
if (calculatedPosition == null) return;
|
||||
cachedPosition = calculatedPosition;
|
||||
posAccuracy = 3;
|
||||
|
||||
resolveFuture(calculatedPosition);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user