I have used the simpledata field example and have modified it to calculate the estimated finish times for a number of distances. I have obviously done something wrong or missed something out - although it compiles and makes a prg file ok, but when I load it on to the device I can select it in the activity settings data fields but it then crashes the device. In the simulator it runs ok and scrolls through the screens, the only issue I have had is if I don't start the data simulation before running the app.
what am I doing wrong/
using Toybox.WatchUi as Ui;
using Toybox.WatchUi as Ui;
using Toybox.Application as App;
using Toybox.System as Sys;
using Toybox.Time as Time;
class CHetcView extends Ui.SimpleDataField
{
var counter;
var fin5k;
var fin10k;
//! Constructor
function initialize()
{
label = "Dist, 5km, 10km";
counter = 0;
}
//! Handle the update event
function compute(info)
{
var value_picked = null;
var miles = info.elapsedDistance * 0.5;
//Cycle between distance, 5km time(duration), and 10km (Duration)
if (activity.
if( counter == 0 )
{
if( info.elapsedDistance != null )
{
value_picked = info.elapsedDistance / 1000;
}
}
if( counter == 1 )
{
if( info.elapsedDistance <= 5000 )
{
//elapsedTime is in ms.
var options = { :seconds => ((5000 - info.elapsedDistance) / info.currentSpeed) + (info.elapsedTime / 1000) };
fin5k = info.elapsedTime / 1000;
value_picked = Time.Gregorian.duration( options );
}
if ( info.elapsedDistance > 1000 )
{
//elapsedTime is in ms.
var option = { :seconds => (fin5k) };
value_picked = Time.Gregorian.duration ( option );
}
}
if( counter == 2 )
{
if( info.elapsedDistance <= 10000 )
{
//elapsedTime is in ms.
var options = { :seconds => ((10000 - info.elapsedDistance) / info.currentSpeed) + (info.elapsedTime / 1000) };
fin10k = info.elapsedTime / 1000;
value_picked = Time.Gregorian.duration( options );
}
if ( info.elapsedDistance > 10000 )
{
//elapsedTime is in ms.
var option = { :seconds => (fin10k) };
value_picked = Time.Gregorian.duration ( option );
}
}
counter += 1;
if( counter > 2 )
{
counter = 0;
}
return value_picked;
}
}
and the App.mc looks like this:
using Toybox.Application as App;
class CHetcApp extends App.AppBase {
//! onStart() is called on application start up
function onStart() {
}
//! onStop() is called when your application is exiting
function onStop() {
}
//! Return the initial view of your application here
function getInitialView() {
return [ new CHetcView() ];
}
}
I have tried running the following command to launch the simulator:
monkeydo c:\ADT\connectiq\mine\CHetc.prg fr920xt
and I get the following:
File pushed successfully
Connection Finished
Closing shell and port
Found Transport: tcp
Connecting...
Connecting to device...
Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
Failed invoking <symbol>
Unexpected Type Error
@PC = 0x10000030
Unexpected Type Error
Unexpected Type Error
It also seems that if I run the code before start simulate data on the device it crashes.