How to use AntPlus.BikeRadar

Im new to connect iq development and rather confused about the whole thing so forgive me if my code is entirely wrong. I am trying to create a very simple test app that connects to my Varia  radar and displays radar info. I presumed for the onUpdate() function to consistently update it would have to get data fed to it by a compute method but when I set this up the onUpdate function didn't display any information at all whereas before it displayed a set of 0's (suggesting that it connected to the radar but wasn't receiving any info). Is there another function such as OnSensor that I have to use instead?

import Toybox.Graphics;
import Toybox.WatchUi;
import Toybox.AntPlus;

class RadarTestView extends WatchUi.View {

function initialize() {
View.initialize();
}
var bikeRadar = new AntPlus.BikeRadar(null);
var data = false;
var radarArray = new [8];

// Load your resources here
function onLayout(dc as Dc) as Void {

dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight());
}

// Called when this View is brought to the foreground. Restore
// the state of this View and prepare it to be shown. This includes
// loading resources into memory.
function onShow() as Void {
}


// Update the view
function onUpdate(dc as Dc) as Void {


var drawValues = [1,2,3,4,5,6,7,8];
for(var i = 0; i<8; i++){

dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
dc.drawText(
dc.getWidth() / drawValues[i], // gets the width of the device and divides by 2
dc.getHeight() / drawValues[i], // gets the height of the device and divides by 2
Graphics.FONT_SMALL, // sets the font size
radarArray[i], // the String to display
Graphics.TEXT_JUSTIFY_LEFT // sets the justification for the text
);
}


}

function compute(info){
var radarInfo = bikeRadar.getRadarInfo();

if(radarInfo){
for(var i = 0; i < 8; i++){
radarArray[i] = radarInfo[i].range;
}

}

}

// Called when this View is removed from the screen. Save the
// state of this View here. This includes freeing resources from
// memory.
function onHide() as Void {
}

}

  • compute is only called in data fields.  Are you building a watch app or a data field?

  • I thought that was the problem but I am unsure what to use instead, do I simply put all that code in onUpdate?

  • In a widget or a watch app, onUpdate isn't automatically called for you as it is in a watch face or DF. You need to use a timer or something like another callback to do a WatchUi.requestUpdate.

    Also note that using radar may prevent you from uploading to the app store

    https://developer.garmin.com/connect-iq/app-review-guidelines/

    and

    https://forums.garmin.com/developer/connect-iq/w/wiki/10/app-approval-exceptions

  • Thanks for the heads up, I was wondering why there were so few radar apps on Connect IQ. As for the timer is there any resource you could link that could help further as I said before I'm quite new to this. Thanks.

  • Timers aren't really that difficult.  There may be a sample in the SDK, but here are the basics.

    Create and start the timer  In this case, it fires every second, 

    var timer= new Timer.Timer();
    timer.start( method(:onTimer), 1000, true ); 

    Then to call onUpdate, this is the callback

    function onTimer() {WatchUi.requestUpdate();}

  • So Ive got my screen to update now however, the data that returns from my radar is just an array of 0's. From what I've seen I am using BikeRadar correctly so I am unsure as to what I am doing wrong

    import Toybox.Graphics;
    import Toybox.WatchUi;
    import Toybox.AntPlus;
    import Toybox.Timer;

    class RadarTestView extends WatchUi.View {

    function initialize() {
    View.initialize();
    }
    var bikeRadar = new AntPlus.BikeRadar(null);
    var data = false;
    var radarArray = new [8];
    var radarSpeed = new [8];
    var d = 0;




    function onTimer() {
    WatchUi.requestUpdate();
    }

    // Load your resources here
    function onLayout(dc as Dc) as Void {

    dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
    dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight());
    var timer = new Timer.Timer();
    timer.start( method(:onTimer), 1000, true );
    }

    // Called when this View is brought to the foreground. Restore
    // the state of this View and prepare it to be shown. This includes
    // loading resources into memory.
    function onShow() as Void {
    }

    // Update the view
    function onUpdate(dc as Dc) as Void {
    dc.clear();
    dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
    dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight());
    dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
    dc.drawText(
    dc.getWidth() / 8, // gets the width of the device and divides by 2
    dc.getHeight() / 8, // gets the height of the device and divides by 2
    Graphics.FONT_SMALL, // sets the font size
    d, // the String to display
    Graphics.TEXT_JUSTIFY_LEFT // sets the justification for the text
    );
    d += 1;
    var radarInfo = bikeRadar.getRadarInfo();

    if(radarInfo){
    for(var i = 0; i < 8; i++){
    radarArray[i] = radarInfo[i].range;
    radarSpeed[i] = radarInfo[i].speed;
    }

    }


    var drawValues = [1,2,3,4,5,6,7,8];
    for(var i = 0; i<8; i++){

    dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
    dc.drawText(
    dc.getWidth() / drawValues[i], // gets the width of the device and divides by 2
    dc.getHeight() / drawValues[i], // gets the height of the device and divides by 2
    Graphics.FONT_SMALL, // sets the font size
    radarArray[i], // distance of each object
    Graphics.TEXT_JUSTIFY_LEFT // sets the justification for the text
    );
    }


    }


    // Called when this View is removed from the screen. Save the
    // state of this View here. This includes freeing resources from
    // memory.
    function onHide() as Void {
    }

    }

  • Are you just using the sim?  Do you have an ANT stick that sees the radar?

    You may want to try this on a real device.

  • I am using a Garmin 530 which is connected to a Varia RTL5I5 to test my program. My program does display an array of Radar Objects but the distance/speed data from said objects are 0 for each.