Hi,
I'm a Swift developer but newbie with Monkey C
How can I get all available sensors of Garmin watch and print the name?
(make a loop of sensors array and print the name of sensor)
Thank you!
Hi,
I'm a Swift developer but newbie with Monkey C
How can I get all available sensors of Garmin watch and print the name?
(make a loop of sensors array and print the name of sensor)
Thank you!
I’d start with the function which returns an iterator of sensors
https://developer.garmin.com/connect-iq/api-docs/Toybox/Sensor.html#getInfo-instance_function
What I do wrong? Why I get "Cannot find symbol ':size' on type ", Is availableSensors an array or am I wrong?
getRegisteredSensors() returns an iterator, not an array. Note that even though the API functions which return an iterator are not documented to return null, in practice they can return null (I think, based on what others have posted in the forums).
e.g.
var sensorIterator = Sensor.getRegisteredSensors(null); if (sensorIterator != null) { while (true) { var sensor = sensorIterator.next(); if (sensor == null) { break; } System.println(sensor.name); } }
Yes it's awkward.
Personally I would probably go with something like this:
var sensorIterator = Sensor.getRegisteredSensors(null); var sensor = sensorIterator != null ? sensorIterator.next() : null; while (sensor != null) { System.println(sensor.name); sensor = sensorIterator.next(); }
Thank you, It's so different from Swift in Swift things are more easy and friendly.
I still don't know why my sensor var is always null I need to check it
var sensorIterator = Sensor.getRegisteredSensors(null); while (sensorIterator != null) { var sensor = sensorIterator.next(); if (sensor == null) { System.println("No more sensors"); break; } System.println(sensor.name); }
Thank you, It's so different from Swift in Swift things are more easy and friendly.
Yeah...
I still don't know why my sensor var is always null I need to check it
Are you running this in the sim or a real device? I'm not sure if the sim will ever show any registered sensors.