if
y
<
0
or
y
>
h -
(
h /
4
)
:
vy
=
-vy
l1.
setLayerPosition
(
x
,
y
,
0
)
YAPI
.
Sleep
(
5
,
errmsg
)
YAPI
.
FreeAPI
()
17.4. 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.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import
os
,
sys
from
yocto_api
import
*
def
usage
()
:
sys
.
exit
(
"usage: demo <serial or logical name> [ON/OFF]"
)
errmsg
=
YRefParam
()
if
YAPI
.
RegisterHub
(
"usb"
,
errmsg
)
!=
YAPI
.
SUCCESS
:
sys
.
exit
(
"RegisterHub error: "
+
str
(
errmsg
))
if
len
(
sys
.
argv
)
<
2
:
usage
()
m
=
YModule
.
FindModule
(
sys
.
argv
[
1
])
# # use serial or logical name
if
m.
isOnline
()
:
if
len
(
sys
.
argv
)
>
2
:
if
sys
.
argv
[
2
]
.
upper
()
==
"ON"
:
m.
set_beacon
(
YModule
.
BEACON_ON
)
if
sys
.
argv
[
2
]
.
upper
()
==
"OFF"
:
m.
set_beacon
(
YModule
.
BEACON_OFF
)
print(
"serial: "
+ m.
get_serialNumber
())
print(
"logical name: "
+ m.
get_logicalName
())
print(
"luminosity: "
+
str
(
m.
get_luminosity
()))
if
m.
get_beacon
()
==
YModule
.
BEACON_ON
:
print(
"beacon: ON"
)
else
:
print(
"beacon: OFF"
)
print(
"upTime: "
+
str
(
m.
get_upTime
()
/
1000
)
+
" sec"
)
print(
"USB current: "
+
str
(
m.
get_usbCurrent
())
+
" mA"
)
print(
"logs:
\n
"
+ m.
get_lastLogs
())
else
:
print(
sys
.
argv
[
1
]
+
" not connected (check identification and USB cable)"
)
YAPI
.
FreeAPI
()
Each property
xxx
of the module can be read thanks to a method of type
YModule.get_xxxx()
,
and properties which are not read-only can be modified with the help of the
YModule.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
YModule.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
YModule.saveToFlash()
method. Inversely, it is possible to force
the module to forget its current settings by using the
YModule.revertFromFlash()
method.
The short example below allows you to modify the logical name of a module.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import
os
,
sys
17. Using the Yocto-Display with Python
104
www.yoctopuce.com
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...