Giter VIP home page Giter VIP logo

android.framework's Introduction

Android 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.

How to set a GPIO

int i = 10;
com.grimgal.android.framework.GPIO gpio =
      com.grimgal.android.framework.GPIO.create(i);
{
	gpio.setOut();
}
if (gpio.isOut()) {
	gpio.setValue(false); // Sets the GPIO to logical false
	// Do something in-between
	gpio.setValue(true);  // Sets the GPIO to logical true
}
else {
	// Error handling
}

How to read from a GPIO

int i = 10;
com.grimgal.android.framework.GPIO gpio =
      com.grimgal.android.framework.GPIO.create(i);
{
	gpio.setIn();
}
if (gpio.isIn()) {
	boolean value = gpio.getValue();
	// Do something with the value
}
else {
	// Error handling
}

How to read from a ValueSupplier via the framework

IValueSupplierManager valueSupplierManager =
      IValueSupplierManager.
      Stub.
      asInterface(
      	ServiceManager.
      	getService("VALUE_SUPPLIER_MANAGER")
      );
byte[] bytes = valueSupplierManager.
               value("$SUP_NAME"); // e.g. ODROID_XU3_FAN_USAGE
ByteBuffer wrapped = ByteBuffer.wrap(bytes)
float value = wrapped.getFloat(); // Beware, not all suppliers return a float.
                                  // Some return a double, int, long, char etc.

How to log a ValueSupplier via the framework

String log_directory = "my/log/directory/"; // Beware, write access isn't requestet 
                                            // by the frameworks and needs to be requestet 
                                            // by the app!
String prefix = "my_log_for_suppliert_X";
String supplier = "X";
try {
	com.grimgal.android.framework.Framework.init(log_directory, prefix);
	IValueSupplierManager ivsm = IValueSupplierManager.Stub.asInterface(ServiceManager.getService("VALUE_SUPPLIER_MANAGER"));
	if (ivsm == null) {
		com.grimgal.android.framework.Log.e("supplier","ivsm was null");
	}
	int found_index = -1;
	String[] suppliers = ivsm.list();
	com.grimgal.android.framework.Log.v("AppLauncher","Found " +suppliers.length+" Suppliers");
	for(int k =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 name
		100,                                         // Period
		java.util.concurrent.TimeUnit.MILLISECONDS   // Unit of the period
	);
}
catch (IOException e) {
	// Error handling
}
catch (RemoteException e2) {
	// Error handling
}
catch (Exception e3) {
	// Error handling
}

License

This project is licensed under Apache 2.0 - see the LICENSE file for details.

Acknowledgments

android.framework's People

Contributors

dadie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.