I expected pos2 = infoPos to assign pos2 to the object pos. What I'm finding here is that pos2 gets assigned to null rather than pointing to the object pos. What is the right way to do this?
using Toybox.Application as App;
using Toybox.Position as Position;
using Toybox.WatchUi as Ui;
class myApp extends App.AppBase
{
var pos = null;
//! onStart() is called on application start up
function onStart() {
Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));
}
//! onStop() is called when your application is exiting
function onStop() {
Position.enableLocationEvents(Position.LOCATION_DISABLE, method(:onPosition));
}
function onPosition(info) {
pos=info;
Ui.requestUpdate();
}
// Initial View
function getInitialView()
{
return [new startupView(pos), new startupViewDelegate()];
}
// For this app all that needs to be done is trigger a Ui refresh
// since the settings are only used in onUpdate().
function onSettingsChanged()
{
Ui.requestUpdate();
}
}
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.Application as App;
class startupView extends Ui.View
{
hidden var pos2;
function initialize(infoPos) {
pos2 = infoPos;
}
function onUpdate(dc)
{
var app = App.getApp();
dc.setColor(Gfx.COLOR_RED, Gfx.COLOR_BLACK);
dc.clear();
dc.drawText(3, 1, Gfx.FONT_SMALL, "startupView", Gfx.TEXT_JUSTIFY_LEFT);
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
if (pos != null){
dc.drawText(3, 20, Gfx.FONT_SMALL, "position: " + pos2.position.toDegrees()[0].toString(), Gfx.TEXT_JUSTIFY_LEFT);
dc.drawText(3, 37, Gfx.FONT_SMALL, "position: " + pos2.position.toDegrees()[1].toString(), Gfx.TEXT_JUSTIFY_LEFT);
}
}
}