Relevant code here:
class MineApp extends App.AppBase {
//! onStart() is called on application start up
function onStart() {
System.println("onStart");
}
//! onStop() is called when your application is exiting
function onStop() {
System.println("onStop");
}
//! Return the initial view of your application here
function getInitialView() {
System.println("getInitialView");
Ui.requestUpdate();
return [ new MineView(), new MineDelegate() ];
}
function initialize(){
System.println("initialize");
var test = Sensor.setEnabledSensors([Sensor.SENSOR_HEARTRATE, Sensor.SENSOR_BIKECADENCE, Sensor.SENSOR_BIKESPEED, Sensor.SENSOR_BIKEPOWER, Sensor.SENSOR_TEMPERATURE, Sensor.SENSOR_FOOTPOD]);
Sensor.enableSensorEvents( method(:onSensor) );
Comm.setMailboxListener( method(:onMail) );
Comm.emptyMailbox();
timer = transmitPeriod;
Ui.requestUpdate();
}
//// Handle sensor Data ////
function onSensor(sensorInfo){
var senorInfo = Sensor.getInfo();
if(senorInfo.altitude != null){
timer--;
if(timer <= 0){
timer = transmitPeriod;
var devSettings = System.getDeviceSettings();
if(devSettings.phoneConnected == true){
var listener = new CommListener();
var data = fetchSensorData();
var json = jsonSensorData(data);
Comm.transmit(json, null, listener);
}
}
Ui.requestUpdate();
}
}
//// Handle Phone Communciations ////
function onMail(mailIter){
var mail;
System.println("onMail");
mail = mailIter.next();
while( mail != null ){
System.println(mail);
var vibe = new Attention.VibeProfile(100, 500);
var vibeLow = new Attention.VibeProfile(0, 200);
var vibeLong = new Attention.VibeProfile(100, 1000);
Attention.vibrate([vibe, vibeLow, vibe, vibeLow, vibeLong]);
mail = mailIter.next();
}
Comm.emptyMailbox();
Ui.requestUpdate();
}
}
class CommListener extends Comm.ConnectionListener{
function onComplete(){
System.println("Transmit Complete");
Comm.emptyMailbox();
}
function onError(){
System.println("Transmit Failed");
Comm.emptyMailbox();
}
}