
@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
()
;
}
@Override
public
void
onNothingSelected
(
AdapterView<?> arg0
)
{
17. Using the Yocto-RangeFinder with Android
www.yoctopuce.com
109
Summary of Contents for Yocto-RangeFinder
Page 1: ...Yocto RangeFinder User s guide...
Page 2: ......
Page 18: ...12 www yoctopuce com...
Page 26: ...20 www yoctopuce com...
Page 42: ...36 www yoctopuce com...
Page 70: ...gcc lyocto lm lpthread lusb 1 0 lstdc 10 Using Yocto RangeFinder with C 64 www yoctopuce com...
Page 90: ...84 www yoctopuce com...
Page 120: ...114 www yoctopuce com...
Page 130: ...124 www yoctopuce com...
Page 484: ...478 www yoctopuce com...
Page 488: ...482 www yoctopuce com...
Page 490: ...23 Characteristics 484 www yoctopuce com...
Page 491: ......
Page 492: ......