- Android Framework
- How to set a GPIO
- How to read from a GPIO
- How to read from a ValueSupplier via the framework
This is an open source framework to ease the use of this android system services and ease the logging of the data returned by the services.
inti = 10;
com.grimgal.android.framework.GPIOgpio =
com.grimgal.android.framework.GPIO.create(i);
{
gpio.setOut();
}
if (gpio.isOut()) {
gpio.setValue(false); // Sets the GPIO to logical false// Do something in-betweengpio.setValue(true); // Sets the GPIO to logical true
}
else {
// Error handling
}inti = 10;
com.grimgal.android.framework.GPIOgpio =
com.grimgal.android.framework.GPIO.create(i);
{
gpio.setIn();
}
if (gpio.isIn()) {
booleanvalue = gpio.getValue();
// Do something with the value
}
else {
// Error handling
}IValueSupplierManagervalueSupplierManager =
IValueSupplierManager.
Stub.
asInterface(
ServiceManager.
getService("VALUE_SUPPLIER_MANAGER")
);
byte[] bytes = valueSupplierManager.
value("$SUP_NAME"); // e.g. ODROID_XU3_FAN_USAGEByteBufferwrapped = ByteBuffer.wrap(bytes)
floatvalue = wrapped.getFloat(); // Beware, not all suppliers return a float.// Some return a double, int, long, char etc.Stringlog_directory = "my/log/directory/"; // Beware, write access isn't requestet // by the frameworks and needs to be requestet // by the app!Stringprefix = "my_log_for_suppliert_X";
Stringsupplier = "X";
try {
com.grimgal.android.framework.Framework.init(log_directory, prefix);
IValueSupplierManagerivsm = IValueSupplierManager.Stub.asInterface(ServiceManager.getService("VALUE_SUPPLIER_MANAGER"));
if (ivsm == null) {
com.grimgal.android.framework.Log.e("supplier","ivsm was null");
}
intfound_index = -1;
String[] suppliers = ivsm.list();
com.grimgal.android.framework.Log.v("AppLauncher","Found " +suppliers.length+" Suppliers");
for(intk =0 ; k < suppliers.length ; k++) {
com.grimgal.android.framework.Log.v("supplier",suppliers[k]);
if (suppliers[k].equals(supplier)) {
found_index = k;
}
}
if (found_index == -1) {
// Error handling
}
// Log the value supplied by the value suppliert k each 100ms (10Hz)com.grimgal.android.framework.ValueLog.run(
suppliers[found_index], // Supplier name100, // Periodjava.util.concurrent.TimeUnit.MILLISECONDS// Unit of the period
);
}
catch (IOExceptione) {
// Error handling
}
catch (RemoteExceptione2) {
// Error handling
}
catch (Exceptione3) {
// Error handling
}This project is licensed under Apache 2.0 - see the LICENSE file for details.
- TU Dortmund Embedded System Software Group which made this release possible