This is my first attempt to write a datafield for my Edge Explore. I'm also an absolute novice at programming as the last time I have done any was for my engineering degree >30 years ago. Having said that I thought I would give it a try and having glued together a collection of functions which I found in various examples and some maths functions I have an app which runs in the Simulator and does pretty well what I want. The problem is that on the device itself I get nothing, just a blank field. I'm left wondering what it is that I may have missed which means that the app doesn't work on the device itself.
The app is a virtual pacer for audax events and is intended to calculate the amount of time in hand - in real time - over minimum pace. The inputs are:
Pace speed, and latest time at control point (hours and minutes) from Settings accessed through Garmin Connect. These come up as expected in GC and claim to save settings when entered.
Time of day and Distance to Destination are taken from the device itself.
As I said above, when I run the app in the simulator everything responds in the way it should to inputs from the App Settings Editor and changing the Distance to Destination in the simulator. The maths also seems to be right and giving me the output I expect - it's just not coming up on the device (and making the device alerts go off almost continuously).
I'm sure that there's something vital which I've either missed or misapplied, I would appreciate any pointers (please excuse the inept programming):
using Toybox.WatchUi;
using Toybox.Time;
using Toybox.System as Sys;
using Toybox.Activity;
using Toybox.Application;
class AudaxTimesView extends WatchUi.SimpleDataField {
// Set the label of the data field here.
function initialize() {
SimpleDataField.initialize();
label = "Time in Hand";
}
// The given info object contains all the current workout
// information. Calculate a value and return it in this method.
// Note that compute() and onUpdate() are asynchronous, and there is no
// guarantee that compute() will be called before onUpdate().
function compute(info) {
// See Activity.Info in the documentation for available information.
var LastTimeMinute = Application.getApp().getProperty("LastTimeMinute");
var LastTimeHour = Application.getApp().getProperty("LastTimeHour");
var PacerSpeed = Application.getApp().getProperty("PacerSpeed");
var TimeNow = Sys.getClockTime();
var TimeNowHr = TimeNow.hour;
var TimeNowMin = TimeNow.min;
var TimeNowSec = TimeNow.sec;
var activityInfo = Toybox.Activity.getActivityInfo();
var DTRSelf = activityInfo.distanceToDestination;
var TimeNum = (TimeNowHr * 3600) + (TimeNowMin * 60) + TimeNowSec;
var ControlAge = (LastTimeHour*3600) + (LastTimeMinute*60);
if ((ControlAge - TimeNum) < (-43200)) {
ControlAge = ControlAge + 86400;
}
var DTRPacer = ((ControlAge - TimeNum)*PacerSpeed)/3.6; // calculates how far the pacer is from the end (metres)
var PacerTrail = DTRPacer - DTRSelf; // calculates distance betwwen self and pacer
var TimeInHand = (PacerTrail / (PacerSpeed/3.6)) ; // calculates how long it takes for pacer to catch
var InHandHour = TimeInHand/3600;
var InHandHourInt = InHandHour.toNumber();
var InHandMin = (TimeInHand - (InHandHourInt*3600))/60;
var InHandMinInt = InHandMin.toNumber();
return new Time.Duration(TimeInHand);
}