Sorry to start a new thread on tis but the "Reply" button wasn't working...
Anyway, I've been trying to get app settings from Garmin Connect into a Data Field which I've written (it's my first attempt at this, so apologies for the inept code) and getting the settings from GCM causes the datafield to crash. The intended use of the datafield requires settings to be changed "in the field", maybe several times in a given ride so I can't rely on carefully chosen defaults.
I've stripped the code down to the bare minimum to try to work out what's going on and I have the following:
settings.xml
<resources>
<properties>
<property id="CloseMinute" type="number">30</property>
</properties>
<settings>
<setting propertyKey="@Properties.CloseMinute" title="@Strings.CloseMinute">
<settingConfig type="numeric" min = "0" max = "59"/>
</setting>
</settings>
</resources>
AudaxDevApp.mc
using Toybox.Application;
class AudaxDevApp extends Application.AppBase {
function initialize() {
AppBase.initialize();
AppBase.initialize();
}
// onStart() is called on application start up
function onStart(state) {
}
function onSettingsChanged() {
CloseMinute = Application.getApp().getProperty("CloseMinute");
}
// onStop() is called when your application is exiting
function onStop(state) {
}
// Return the initial view of your application here
function getInitialView() {
return [ new AudaxDevView() ];
}
}
AudaxDevView.mc
using Toybox.WatchUi;
using Toybox.Time;
using Toybox.System as Sys;
using Toybox.Activity;
using Toybox.Application;
class AudaxDevView extends WatchUi.SimpleDataField {
var CloseMinute = 30;
var OutputType = 11;
// Set the label of the data field here.
function initialize() {
SimpleDataField.initialize();
label = "My Label";
}
function compute(info) {
// See Activity.Info in the documentation for available information.
if (CloseMinute == null) {
OutputType = 1;
} else if (CloseMinute instanceof Number) {
OutputType = 2;
} else if (CloseMinute instanceof Long) {
OutputType = 3;
} else if (CloseMinute instanceof Float) {
OutputType = 4;
} else if (CloseMinute instanceof Double) {
OutputType = 5;
} else if (CloseMinute instanceof String) {
OutputType = 6;
} else {
OutputType = 7;
}
return OutputType;
}
}
As you can see there's no maths so no chance of dividing by zero, as far as I can see the only output to the datafield should be a number corresponding to whatever type the variable CloseMinute actually is. I was expecting that whatever the getProperty() call returned from GCM there should be an output corresponding to what it is an instance of - even if it is 7 to indicate "none of the above".
On running the datafield it returns a value of "2" which indicates that it is a number, but as soon as I update the setting from GCM the whole datafield (including the label) goes blank. This suggests to me that it's actually getting the property/setting from GCM that's causing the crash.
This is doubly frustrating as the actual datafield runs exactly as I intend with variables at their initialised (but not updated) values, but this isn't really much use as timings for every ride are different.