Skip to content

Instantly share code, notes, and snippets.

@sarfata
Created June 6, 2014 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarfata/720545a754cb8d03b0ec to your computer and use it in GitHub Desktop.
Save sarfata/720545a754cb8d03b0ec to your computer and use it in GitHub Desktop.
AA Hackathon - Example pebblejs app
/*
* Example provided by Pebble for the American Airlines - Gogo in flight - Wearable World Hackathon
*
* To use this project, please go to cloudpebble.net and create a new Pebble.js project.
* Copy and paste this gist in the app.js file.
*
* You will need to update the gogoStatusURL to point to a valid Gogo Inflight test server.
* An example JSON file is provided too.
*/
var UI = require('ui');
var Vector2 = require('vector2');
var ajax = require('ajax');
var gogoStatusURL = 'http://airborne.gogoinflight.com/abp/ws/absServices/statusTray';
var GogoApp = function() {
this.fetching = false;
this.splash = new UI.Card({ title: 'GOGO', backgroundColor: 'white' });
this.splash.show();
var self = this;
setTimeout(function() { self.gogoUpdate(); }, 2000);
};
GogoApp.prototype.gogoUpdate = function() {
if (!this.fetching) {
var self = this;
console.log("Getting flight information from onboard computer");
ajax( { url: gogoStatusURL, type: 'json' },
function(data) { self.onGogoData(data); },
function(error) { self.onGogoError(error) ; });
}
else {
console.log("Not starting a new request. Existing ongoing request...");
}
};
GogoApp.prototype.onGogoData = function(data) {
var textField = function (x, y, w, h, text, font, align) {
if (typeof text !== 'string') {
text = '';
}
if (typeof font !== 'string') {
font = 'GOTHIC_18_BOLD';
}
if (typeof align !== 'string') {
align = 'center';
}
return new UI.Text({ position: new Vector2(x, y), size: new Vector2(w, h), font: font, textAlign: align, text: text });
};
console.log("Got data!");
// Remove the splashscreen if it was here
if (this.splash) {
this.main = new UI.Stage({ backgroundColor: 'black' });
this.itinerary = textField(0, 0, 144, 40, "...", 'BITHAM_30_BLACK');
this.main.add(this.itinerary);
this.flightNumber = textField(0, 40, 144, 20, '', 'GOTHIC_18');
this.main.add(this.flightNumber);
this.remainingTime = textField(10, 60, 124, 30, '', 'GOTHIC_28');
this.main.add(this.remainingTime);
this.altitude = textField(0, 90, 144, 20, 'Alt: ', 'GOTHIC_18', 'left');
this.main.add(this.altitude);
this.speed = textField(0, 110, 144, 58, 'Speed: ', 'GOTHIC_18', 'left');
this.main.add(this.speed);
var self = this;
this.main.on('click', 'select', function(e) {
console.log("click");
self.gogoUpdate();
});
this.main.show();
this.splash.hide();
this.splash = null;
}
var flightInfo = data.Response.flightInfo;
console.log("FlightInfo : " + JSON.stringify(flightInfo));
this.flightNumber.text(flightInfo.flightNumberInfo + " " + flightInfo.tailNumber);
this.itinerary.text(flightInfo.departureAirportCodeIata + "-" + flightInfo.destinationAirportCodeIata);
var arrivalTime = new Date(flightInfo.expectedArrival);
var remainingMinutes = Math.round((arrivalTime.getTime() - Date.now()) / 1000 / 60);
this.remainingTime.text(Math.round(remainingMinutes / 60) + "h " + remainingMinutes % 60 + "m");
this.altitude.text('Alt: ' + Math.round(flightInfo.altitude) + " ft");
this.speed.text('Gnd Speed: ' + Math.round(flightInfo.HSpeed) + ' knots\nVrt Speed: ' + Math.round(flightInfo.VSpeed) + ' ft/s');
console.log('still alive');
};
GogoApp.prototype.onGogoError = function(error) {
console.log("GoGo error: " + error);
};
new GogoApp();
{ "Response" : { "flightInfo" : { "HSpeed" : 188.69823,
"VSpeed" : 0,
"abpVersion" : "3.1.0",
"airlineCode" : "AAL",
"airlineCodeIata" : "AA",
"airlineName" : "American Airlines",
"altitude" : 11155.200000000001,
"departureAirportCode" : "KMIA",
"departureAirportCodeIata" : "MIA",
"destination" : "SFO",
"destinationAirportCode" : "KSFO",
"destinationAirportCodeIata" : "SFO",
"expectedArrival" : "2014-06-01T06:13:35Z",
"flightNumberAlpha" : "AAL",
"flightNumberInfo" : "AAL275",
"flightNumberNumeric" : 275,
"latitude" : 37.815100000000001,
"localTime" : "2014-06-01T04:52:46.0Z0:0",
"longitude" : -112.4721,
"origin" : "MIA",
"tailNumber" : "N943AN",
"utcTime" : "2014-06-01T04:52:46Z",
"videoService" : true
},
"gogoFacts" : "Did you know that some birds crossing the Caribbean fly at around 10,000 feet? That\\'s the same altitude Gogo service becomes active. In fact, a flock of whooper swans was once detected on radar at 29,000 feet.",
"serviceInfo" : { "quality" : "Good",
"remaining" : 1860,
"service" : "Active"
},
"status" : 200
} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment