Yoctopuce Yocto-I2C Mode D'emploi page 114

Table des Matières

Publicité

14. Utilisation du Yocto-I2C avec Android
YI2cPort
while
String
aa.add(hwid);
s
}
} catch
(YAPI_Exception
e.printStackTrace();
}
aa.notifyDataSetChanged();
handler.postDelayed(r,
}
@Override
protected
void
{
super.onStop();
handler.removeCallbacks(r);
YAPI.FreeAPI();
}
@Override
public
void
onItemSelected(AdapterView<?>
{
String
hwid
_i2cPort
= YI2cPort.FindI2cPort(hwid);
try {
// sample code reading MCP9804 temperature sensor
_i2cPort.set_i2cMode("400kbps");
_i2cPort.set_i2cVoltageLevel(YI2cPort.I2CVOLTAGELEVEL_3V3);
_i2cPort.reset();
} catch
(YAPI_Exception
e.printStackTrace();
}
}
@Override
public
void
onNothingSelected(AdapterView<?> arg0)
{
}
final
Runnable
{
public
void
{
if
(_i2cPort
try {
} catch
}
}
handler.postDelayed(this,
}
};
}
106
s
= YI2cPort.FirstI2cPort();
(s
!= null) {
hwid
= s.get_hardwareId();
= s.nextI2cPort();
e) {
500);
onStop()
= (String) parent.getItemAtPosition(pos);
e) {
r
= new Runnable()
run()
!= null) {
ArrayList<Integer>
ArrayList<Integer> received;
toSend.add(0x05);
received
=
_i2cPort.i2cSendAndReceiveArray(0x1f, toSend,
int
tempReg
= (received.get(0) << 8) + received.get(1);
if
((tempReg
& 0x1000) != 0) {
tempReg
-= 0x2000;
} else {
tempReg
&= 0x0fff;
}
TextView view
= (TextView) findViewById(R.id.tempfield);
view.setText(String.format(Locale.US, "%.3f", tempReg
(YAPI_Exception
e.printStackTrace();
1000);
parent,
View
view,
toSend
= new ArrayList<>(1);
// perform sign extension
// clear status bits
e) {
int
pos,
long
id)
2);
/ 16.0));
www.yoctopuce.com

Publicité

Table des Matières
loading

Table des Matières