NSError
*error;
if
(
argc <
2
)
{
usage
()
;
}
@autoreleasepool
{
// Setup the API to use local USB devices
if([
YAPI RegisterHub:
@"usb"
: &error
]
!= YAPI_SUCCESS
)
{
NSLog
(
@"RegisterHub error: %@"
,
[
error localizedDescription
])
;
return
1
;
}
NSString
*target =
[
NSString
stringWithUTF8String:argv
[
1
]]
;
YGps *gps;
if
([
target isEqualToString:
@"any"
])
{
gps =
[
YGps FirstGps
]
;
if
(
gps ==
NULL
)
{
NSLog
(
@"No module connected (check USB cable)"
)
;
return
1
;
}
}
else
{
gps =
[
YGps FindGps:
[
target stringByAppendingString:
@".gps"
]]
;
}
while(
1
)
{
if(
!
[
gps isOnline
])
{
NSLog
(
@"Module not connected (check identification and USB cable)
\n
"
)
;
break
;
}
if([
gps get_isFixed
]
!= Y_ISFIXED_TRUE
)
{
NSLog
(
@"fixing"
)
;
}
else
{
NSLog
(
@"%@ %@
\n
"
,
[
gps get_latitude
]
,
[
gps get_longitude
])
;
}
NSLog
(
@" (press Ctrl-C to exit)
\n
"
)
;
[
YAPI Sleep:
1000
:
NULL
]
;
}
[
YAPI FreeAPI
]
;
}
return
0
;
}
There are only a few really important lines in this example. We will look at them in details.
yocto_api.h et yocto_latitude.h
These two import files provide access to the functions allowing you to manage Yoctopuce modules.
yocto_api.h
must always be used,
yocto_latitude.h
is necessary to manage modules
containing a latitude sensor, such as Yocto-GPS.
[YAPI RegisterHub]
The
[YAPI RegisterHub]
function initializes the Yoctopuce API and indicates where the
modules should be looked for. When used with the parameter
@"usb"
, it will use the modules
locally connected to the computer running the library. If the initialization does not succeed, this
function returns a value different from
YAPI_SUCCESS
and
errmsg
contains the error message.
[Latitude FindLatitude]
The
[Latitude 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.
YLatitude *latitude =
[
Latitude FindLatitude:
@"YGNSSMK1-123456.latitude"
]
;
YLatitude *latitude =
[
Latitude FindLatitude:
@"YGNSSMK1-123456.MyFunction"
]
;
YLatitude *latitude =
[
Latitude FindLatitude:
@"MyModule.latitude"
]
;
YLatitude *latitude =
[
Latitude FindLatitude:
@"MyModule.MyFunction"
]
;
10. Using Yocto-GPS with Objective-C
68
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: ......