-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved stratux polling into new pollStratux.js
set pollStratux = true to enable polling.
- Loading branch information
David Ross
committed
Dec 2, 2015
1 parent
1c11ca2
commit 9dcaf8e
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
var pollStratux = false; | ||
var lastPoll = ( new Date).getTime(); | ||
|
||
|
||
(function checkINOP() { | ||
setTimeout(function () { | ||
tick = (new Date).getTime() - lastPoll; | ||
if ( tick > 3000 && pollStratux == true) { | ||
// 3 seconds since our last successful poll. | ||
Pi2D2.speed( 'inop' ); | ||
Pi2D2.compass( 'inop' ); | ||
Pi2D2.pitch( 'inop' ); | ||
Pi2D2.roll( 'inop' ); | ||
Pi2D2.altitude( 'inop' ); | ||
} | ||
checkINOP(); | ||
}, 1000); | ||
})(); | ||
|
||
var lastAltitudeValue; | ||
lastAltitudeCheck = (new Date).getTime() / 1000; | ||
(function computeVSI() { | ||
setTimeout( function () { | ||
timeSpan = ( (new Date).getTime() / 1000 ) - lastAltitudeCheck; | ||
altitudeSpan = Pi2D2.altitude() - lastAltitudeValue; | ||
FPM = altitudeSpan / (timeSpan/60) | ||
|
||
Pi2D2.vertspeed( FPM ); | ||
lastAltitudeValue = Pi2D2.altitude(); | ||
lastAltitudeCheck = (new Date).getTime() / 1000; | ||
computeVSI(); | ||
}, 1000 ); | ||
})(); | ||
|
||
|
||
|
||
|
||
(function poll(){ | ||
setTimeout(function(){ | ||
if ( pollStratux == true ){ | ||
$.ajax({ url: "/getSituation", success: function(data){ | ||
lastPoll = (new Date).getTime(); | ||
//Update values | ||
|
||
speed = Math.round( data.GroundSpeed); | ||
if ( Pi2D2.speed() != speed){ | ||
Pi2D2.speed( speed ); | ||
} | ||
heading = Math.round( data.Gyro_heading ); | ||
if ( Pi2D2.compass() != heading ) { | ||
Pi2D2.compass( heading ); | ||
} | ||
|
||
pitch = Math.round( data.Pitch ); | ||
if ( Pi2D2.pitch != pitch) { | ||
Pi2D2.pitch( pitch ); | ||
} | ||
|
||
roll = Math.round( data.Roll ); | ||
if ( Pi2D2.roll() != roll ){ | ||
Pi2D2.roll( roll ); | ||
} | ||
|
||
altitude = Math.round( data.altitude ); | ||
if ( Pi2D2.altitude() != altitude ) { | ||
Pi2D2.altitude( data.Pressure_alt ); | ||
} | ||
}, dataType: "json"}); | ||
} | ||
//Setup the next poll recursively | ||
poll(); | ||
}, 100); | ||
})(); |