{
private
ArrayAdapter
<
String
>
aa
;
private
YModule
module
=
null
;
@Override
public
void
onCreate
(
Bundle savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R.
layout
.
modulecontrol
);
Spinner my_spin
=
(
Spinner
)
findViewById
(
R.
id
.
spinner1
);
my_spin.
setOnItemSelectedListener
(this);
aa
=
new
ArrayAdapter
<
String
>(this
, android.
R
.
layout
.
simple_spinner_item
);
aa.
setDropDownViewResource
(
android.
R
.
layout
.
simple_spinner_dropdown_item
);
my_spin.
setAdapter
(
aa
);
}
@Override
protected
void
onStart
()
{
super
.
onStart
();
try
{
aa.
clear
();
YAPI
.
EnableUSBHost
(this);
YAPI
.
RegisterHub
(
"usb"
);
YModule
r
=
YModule
.
FirstModule
();
while
(
r
!=
null
)
{
String
hwid
=
r.
get_hardwareId
();
aa.
add
(
hwid
);
r
=
r.
nextModule
();
}
}
catch
(
YAPI_Exception
e
)
{
e.
printStackTrace
();
}
// refresh Spinner with detected relay
aa.
notifyDataSetChanged
();
}
@Override
protected
void
onStop
()
{
super
.
onStop
();
YAPI
.
FreeAPI
();
}
private
void
DisplayModuleInfo
()
{
TextView field
;
if
(
module
==
null
)
return;
try
{
field
=
(
TextView
)
findViewById
(
R.
id
.
serialfield
);
field.
setText
(
module.
getSerialNumber
());
field
=
(
TextView
)
findViewById
(
R.
id
.
logicalnamefield
);
field.
setText
(
module.
getLogicalName
());
field
=
(
TextView
)
findViewById
(
R.
id
.
luminosityfield
);
field.
setText
(
String
.
format
(
"%d%%"
, module.
getLuminosity
()));
field
=
(
TextView
)
findViewById
(
R.
id
.
uptimefield
);
field.
setText
(
module.
getUpTime
()
/
1000
+
" sec"
);
field
=
(
TextView
)
findViewById
(
R.
id
.
usbcurrentfield
);
field.
setText
(
module.
getUsbCurrent
()
+
" mA"
);
Switch
sw
=
(Switch)
findViewById
(
R.
id
.
beaconswitch
);
sw.
setChecked
(
module.
getBeacon
()
==
YModule
.
BEACON_ON
);
field
=
(
TextView
)
findViewById
(
R.
id
.
logs
);
field.
setText
(
module.
get_lastLogs
());
}
catch
(
YAPI_Exception
e
)
{
e.
printStackTrace
();
}
}
@Override
public
void
onItemSelected
(
AdapterView
<?>
parent,
View
view,
int
pos,
long
id
)
{
String
hwid
=
parent.
getItemAtPosition
(
pos
)
.
toString
();
module
=
YModule
.
FindModule
(
hwid
);
DisplayModuleInfo
();
19. Using the Yocto-Display with Android
www.yoctopuce.com
119
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...