cout
<<
"USB current: "
<<
module
->
get_usbCurrent
()
<<
" mA"
<<
endl
;
cout
<<
"Logs:"
<<
endl
<<
module
->
get_lastLogs
()
<<
endl
;
}
else
{
cout
<<
argv
[
1
]
<<
" not connected (check identification and USB cable)"
<<
endl
;
}
yFreeAPI
();
return
0
;
}
Each property
xxx
of the module can be read thanks to a method of type
get_xxxx()
, and
properties which are not read-only can be modified with the help of the
set_xxx()
method. For
more details regarding the used functions, refer to the API chapters.
Changing the module settings
When you want to modify the settings of a module, you only need to call the corresponding
set_xxx()
function. However, this modification is performed only in the random access memory
(RAM) of the module: if the module is restarted, the modifications are lost. To memorize them
persistently, it is necessary to ask the module to save its current configuration in its permanent
memory. To do so, use the
saveToFlash()
method. Inversely, it is possible to force the module to
forget its current settings by using the
revertFromFlash()
method. The short example below
allows you to modify the logical name of a module.
#include <iostream>
#include <stdlib.h>
#include "yocto_api.h"
using
namespace
std
;
static
void
usage
(
const
char
*
exe
)
{
cerr
<<
"usage: "
<<
exe
<<
" <serial> <newLogicalName>"
<<
endl
;
exit
(
1
);
}
int
main
(
int
argc,
const
char
*
argv
[])
{
string
errmsg
;
// Setup the API to use local USB devices
if(
yRegisterHub
(
"usb"
, errmsg
)
!=
YAPI_SUCCESS
)
{
cerr
<<
"RegisterHub error: "
<<
errmsg
<<
endl
;
return
1
;
}
if(
argc
<
2
)
usage
(
argv
[
0
]);
YModule
*
module
=
yFindModule
(
argv
[
1
]);
// use serial or logical name
if
(
module
->
isOnline
())
{
if
(
argc
>=
3
)
{
string
newname
=
argv
[
2
];
if
(!
yCheckLogicalName
(
newname
))
{
cerr
<<
"Invalid name ("
<<
newname
<<
")"
<<
endl
;
usage
(
argv
[
0
]);
}
module
->
set_logicalName
(
newname
);
module
->
saveToFlash
();
}
cout
<<
"Current name: "
<<
module
->
get_logicalName
()
<<
endl
;
}
else
{
cout
<<
argv
[
1
]
<<
" not connected (check identification and USB cable)"
<<
endl
;
}
yFreeAPI
();
return
0
;
}
11. Using Yocto-Display with C++
www.yoctopuce.com
61
Summary of Contents for Yocto-Display
Page 1: ...Yocto Display User Manual...
Page 2: ......
Page 40: ...34 www yoctopuce com...
Page 52: ...46 www yoctopuce com...
Page 84: ...78 www yoctopuce com...
Page 92: ...86 www yoctopuce com...
Page 130: ...124 www yoctopuce com...
Page 422: ...416 www yoctopuce com...