With sdk 3.0 beta 1, the following won't build due to undefined "ListItem"


class myPowerListener extends AP.BikePowerListener {

hidden enum { ITEM_BATTERY }

var items;

function initialize() {
BikePowerListener.initialize();
items = [ new ListItem("battery", 50, G.COLOR_PINK) ];
}

function onBatteryStatusUpdate(data) {
items[ITEM_BATTERY].setValue(data.batteryStatus);
}
}


Is this a bug? Or is there some other way to access this information?
  • Given what you've provided, that is not a bug. I don't see any declaration of [i[ListItem[/i], and no reference to a module containing class ListItem. It looks like you're copying code from the BikePowerListener documentation, but the context isn't provided and you haven't filled in the blanks. That sample appears to be part of a sample that draws a line graph of the data from the listener.

    You probably don't need list items in your app. The following is probably sufficient.

    using Toybox.AntPlus;

    class myPowerListener extends AntPlus.BikePowerListener {

    hidden var mBatteryStatus;

    function initialize() {
    BikePowerListener.initialize();
    mBatteryStatus = AntPlus.BATT_STATUS_INVALID;
    }

    function onBatteryStatusUpdate(data) {
    mBatteryStatus = data.batteryStatus;
    }
    }


    If all you're not going to respond to changes in device status (you just store the status), you may not need a listener at all. You should be able to query the device for its battery status via device.getBatteryStatus().

    Travis
  • Travis,

    Thanks for your response. I now understand that I was not using the ListItem class properly.

    Bruce