
using
namespace
std;
static
void
usage
(void)
{
cout
<<
"usage: demo <serial_number> "
<<
endl
;
cout
<<
" demo <logical_name>"
<<
endl
;
cout
<<
" demo any (use any discovered device)"
<<
endl
;
u64
now = yGetTickCount
()
;
while
(
yGetTickCount
()
- now <
3000
)
{
// wait 3 sec to show the message
}
exit
(
1
)
;
}
int
main
(
int
argc,
const
char
* argv
[])
{
string
errmsg;
string
target;
YRangeFinder *rf;
YLightSensor *ir;
YTemperature *tmp;
if
(
argc <
2
)
{
usage
()
;
}
target =
(
string
)
argv
[
1
]
;
// Setup the API to use local USB devices
if
(
yRegisterHub
(
"usb"
, errmsg
)
!= YAPI_SUCCESS
)
{
cerr
<<
"RegisterHub error: "
<< errmsg <<
endl
;
return
1
;
}
if
(
target ==
"any"
)
{
rf = yFirstRangeFinder
()
;
if
(
rf ==
NULL
)
{
cout
<<
"No module connected (check USB cable)"
<<
endl
;
return
1
;
}
target = rf->
get_module
()
->
get_serialNumber
()
;
}
else
{
rf = yFindRangeFinder
(
".rangeFinder1"
)
;
}
ir = yFindLightSensor
(
".lightSensor1"
)
;
tmp = yFindTemperature
(
".temperature1"
)
;
while(
1
)
{
if
(
!rf->
isOnline
())
{
cout
<<
"Module not connected (check identification and USB cable)"
;
break
;
}
cout
<<
"Distance : "
<< rf->
get_currentValue
()
<<
endl
;
cout
<<
"Ambient IR : "
<< ir->
get_currentValue
()
<<
endl
;
cout
<<
"Temperature : "
<< tmp->
get_currentValue
()
<<
endl
;
cout
<<
" (press Ctrl-C to exit)"
<<
endl
;
ySleep
(
1000
, errmsg
)
;
}
;
yFreeAPI
()
;
return
0
;
}
10.2. Control of the module part
Each module can be controlled in a similar manner, you can find below a simple sample program
displaying the main parameters of the module and enabling you to activate the localization beacon.
#include <iostream>
#include <stdlib.h>
#include "yocto_api.h"
10. Using Yocto-RangeFinder with C++
www.yoctopuce.com
59
Содержание Yocto-RangeFinder
Страница 1: ...Yocto RangeFinder User s guide...
Страница 2: ......
Страница 18: ...12 www yoctopuce com...
Страница 26: ...20 www yoctopuce com...
Страница 42: ...36 www yoctopuce com...
Страница 70: ...gcc lyocto lm lpthread lusb 1 0 lstdc 10 Using Yocto RangeFinder with C 64 www yoctopuce com...
Страница 90: ...84 www yoctopuce com...
Страница 120: ...114 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...21 High level API Reference On failure throws an exception or returns a negative error code 152 www yoctopuce com...
Страница 484: ...478 www yoctopuce com...
Страница 488: ...482 www yoctopuce com...
Страница 490: ...23 Characteristics 484 www yoctopuce com...
Страница 491: ......
Страница 492: ......