16.5. Control of the Latitude function
A few lines of code are enough to use a Yocto-GPS. Here is the skeleton of a Java code snippet to
use the Latitude function.
[
...
]
// Retrieving the object representing the module (connected here locally by USB)
YAPI.
EnableUSBHost
(this)
;
YAPI.
RegisterHub
(
"usb"
)
;
latitude = YLatitude.
FindLatitude
(
"YGNSSMK1-123456.latitude"
)
;
// Hot-plug is easy: just check that the device is online
if
(
latitude.
isOnline
())
{
//Use latitude.get_currentValue()
...
}
[
...
]
Let us look at these lines in more details.
YAPI.EnableUSBHost
The
YAPI.EnableUSBHost
function initializes the API with the Context of the current application.
This function takes as argument an object of the
android.content.Context
class (or of a
subclass). If you intend to connect your application only to other machines through the network, this
function is facultative.
YAPI.RegisterHub
The
yAPI.RegisterHub
function initializes the Yoctopuce API and indicates where the modules
should be looked for. The parameter is the address of the virtual hub able to see the devices. If the
string "usb" is passed as parameter, the API works with modules locally connected to the machine. If
the initialization does not succeed, an exception is thrown.
YLatitude.FindLatitude
The
YLatitude.FindLatitude
function allows you to find a latitude sensor from the serial
number of the module on which it resides and from its function name. You can use logical names as
well, as long as you have initialized them. Let us imagine a Yocto-GPS module with serial number
YGNSSMK1-123456
which you have named "
MyModule
", and for which you have given the
latitude
function the name "
MyFunction
". The following five calls are strictly equivalent, as long as
"
MyFunction
" is defined only once.
latitude = YLatitude.
FindLatitude
(
"YGNSSMK1-123456.latitude"
)
latitude = YLatitude.
FindLatitude
(
"YGNSSMK1-123456.MyFunction"
)
latitude = YLatitude.
FindLatitude
(
"MyModule.latitude"
)
latitude = YLatitude.
FindLatitude
(
"MyModule.MyFunction"
)
latitude = YLatitude.
FindLatitude
(
"MyFunction"
)
YLatitude.FindLatitude
returns an object which you can then use at will to control the
latitude sensor.
isOnline
The
isOnline()
method of the object returned by
YLatitude.FindLatitude
allows you to
know if the corresponding module is present and in working order.
get_latitude
The
get_latitude()
method of the object returned by
YGps.FindGps
provides the latitude
currently measured by the Yocto-GPS. The value returned is a string, the format will vary according
to the Yocto-GPS configuration. To get a floating point value, no matter the configuartion, use the
YLatitude Class.
16. Using the Yocto-GPS with Android
108
www.yoctopuce.com
Summary of Contents for Yocto-GPS
Page 1: ...Yocto GPS User s guide...
Page 2: ......
Page 6: ...22 Characteristics 557 Blueprint 559 Index 561...
Page 10: ...4 www yoctopuce com...
Page 14: ...8 www yoctopuce com...
Page 18: ...12 www yoctopuce com...
Page 22: ...16 www yoctopuce com...
Page 38: ...32 www yoctopuce com...
Page 42: ...36 www yoctopuce com...
Page 54: ...48 www yoctopuce com...
Page 72: ...66 www yoctopuce com...
Page 92: ...86 www yoctopuce com...
Page 122: ...116 www yoctopuce com...
Page 132: ...126 www yoctopuce com...
Page 564: ...22 Characteristics 558 www yoctopuce com...
Page 565: ......
Page 566: ......