Temperature Altitude Data Field

Hi,

I do my first steps with Connect IQ and I try to develop for my Edge 820 a Simple Data field displaying alternatively Altitude and Temperature.

Currently I failed to display temperature (I would like Temperature from Edge's sensor), I try many ways but I think I miss something and I did not find example fo the site) could you help me ?

So please find my (first :-)) code below, Thanks

McEwans

using Toybox.WatchUi as Ui;
using Toybox.System as Sys;
using Toybox.Time as Time;
using Toybox.Sensor as Sensor;

class AltitudeTempView extends Ui.SimpleDataField {

var counter;
function initialize() {
SimpleDataField.initialize();
label = "Temp/Altitude";
counter = 0;}
function compute(info) {
var value_picked = null;
if(counter > 0) {value_picked = info.temperature;}
if(counter > 6) {value_picked = info.altitude;}
counter += 1;
if(counter > 10) {counter = 1;}
return value_picked;}
}
  • Temperature isn't available from info in compute(). You can get it by way of SensorHistory on some devices, but that's not available on the Edge device.

    Also, in general, you want to check anything you want to use from info for null, as not all things are they until recording starts for an activity.

    See the API guide for what you can get from info, and it mentions the null check there too.
  • vicolo retorno

    First thanks a lot for your quick answer !

    I am sure to fully understand, you mean I can not at all display Temperature information into a SimpleDataField ? It's an information only usable into a App ?

    info for null, as not all things are they until recording starts for an activity.

    See the API guide for what you can get from info, and it mentions the null check there too.


    I neither understand your remark concerning null check (Sorry :D), you mean if I check this page I will found list of information I can get with "info" ?

    Thx
    Mc