Multiple simple datafields

Former Member
Former Member
Hi all,

In the Simulation environment, I am trying a create an app with simple datafields from feeds from multiple sensors - I am hoping that both fields will be displayed when I select '2 data fields' in the simulator settings. However, that doesn't appear to be the case. More specifically, my pseudo-code is shown below. The code compiles without errors, but when no UI is shown when I tried to run it (no error either). Please advise. Many thanks in advance :).

class HRField extends Ui.SimpleDataField
{
var mSensor;

function initialize(sensor) {
label = "Heart rate";
mSensor = sensor;
}

function compute() {
return mSensor.getCurrentHeartRate();
}
}

class MO2Field extends Ui.SimpleDataField
{
var mSensor;

function initialize(sensor) {
label = "MO2";
mSensor = sensor;
}

function compute() {
return mSensor.data.currentHemoPercent;
}
}

class AllFields extends App.AppBase
{
var mSensor;
var mSensorTwo;

function onStart()
{
mSensor = new HeartRateSensor();
mSensor.open();

mSensorTwo = new MO2Sensor();
mSensorTwo.open();
}

function getInitialView()
{
return [new HRField(mSensor), new MO2Field(mSensorTwo)];
}

function onStop()
{
return false;
}
}
  • I am hoping that both fields will be displayed when I select '2 data fields' in the simulator settings.


    I've found that selecting 2 or more data fields in the simulator settings will just show multiple copies of the same data field rather than running 2 different instances.

    I have been able to have multiple sensors connected simultaneously by using multiple data fields on an actual device. I just have to rename the data field and give it a unique ID number.

    Roger
  • function getInitialView()
    {
    return [new HRField(mSensor), new MO2Field(mSensorTwo)];
    }


    As described in the documentation, the return from getInitialView() is an Array with 1 or 2 elements. The first element must be a view, and the second must be the input delegate. Passing two views is not going to work, and is likely to cause problems.

    Roger is right. The number of data fields in the layout simply allows you to see what your data field looks like in the various field configurations (top and bottom of a round watch for instance). If you want to display two data fields on a device simultaneously, you have to create two data fields and load them both, or you have to create a data field that draws all of the data you want to display in that fields display area. Options here are to split the display area and render two different numbers (as is done in ${SDK}/samples/MoxyDataField/source/MoxyField.mc), or to split the time and display one number for a period, and then the other number.

    Travis
  • Former Member
    Former Member
    Thank you

    I've found that selecting 2 or more data fields in the simulator settings will just show multiple copies of the same data field rather than running 2 different instances.

    I have been able to have multiple sensors connected simultaneously by using multiple data fields on an actual device. I just have to rename the data field and give it a unique ID number.

    Roger



    Hi both,

    Thanks for your reply!

    Roger, probably a silly question, but how do I give each datafield a unique ID? Do they have to be separate apps altogether?

    If I sideload the datafield on an actual device, will I see the same as on the simulator or do I have a implement separate apps as well?

    Thanks again :)
    Ed
  • how do I give each datafield a unique ID? Do they have to be separate apps altogether?

    Yes. You only need to do this if you want to display two data fields with different data. There are apparently some tricks that some guys are using to avoid it, but I haven't figured them out yet.

    If I sideload the datafield on an actual device, will I see the same as on the simulator or do I have a implement separate apps as well?

    When you load a data field on a device, it will only appear in the data field 'slot' that you assign it to appear. i.e., if you have a 4 field layout and use your data field in the first 'slot', that is the only place it will appear. If you want it to appear in an additional slot, you'll have to enable your data field for that slot as well.

    The simulator behaves the way it does to allow you to see your data field in all the data field positions for the given layout. If you had to enable it for each 'slot', the simulator would have to display something else in the other 'slots', and you'd have to spend a lot more time enabling/disabling the data field in each of the slots for testing.

    Travis