From 829b37b0f92e00aa965c84b8925983e5c7672338 Mon Sep 17 00:00:00 2001 From: Blundell Date: Thu, 17 Aug 2017 15:52:06 +0100 Subject: [PATCH] adds README --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..81d2688 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +ZX Sensor driver for Android Things +=================================== + +This driver supports ZXSensor peripherals using the I2C and UART protocols. + +See the [/library](/library) module for the implementation + +See the [/demo](/demo) module for a working example + +How to use the driver +--------------------- + +### Gradle dependency + +To use the `zxsensor` driver, simply add the line below to your project's `build.gradle`, +where `` matches the last version of the driver available on [jcenter][jcenter]. + +``` +dependencies { + compile 'com.blundell:driver-zxsensor:' +} +``` + +### Sample usage + +```java +import com.blundell.zxsensor.ZxSensor; +import com.blundell.zxsensor.ZxSensorUart; + +// Access the ZXSensor (choose I2C or UART) here we show UART: + +ZxSensorUart zxSensorUart; + +try { + zxSensorUart = ZxSensor.Factory.openViaUart(BoardDefaults.getUartPin()); +} catch (IOException e) { + throw new IllegalStateException("Can't open, did you use the correct pin name?", e); +} +zxSensorUart.setSwipeLeftListener(swipeLeftListener); +zxSensorUart.setSwipeRightListener(swipeRightListener); + +ZxSensor.SwipeLeftListener swipeLeftListener = new ZxSensor.SwipeLeftListener() { + @Override + public void onSwipeLeft(int speed) { + Log.d("TUT", "Swipe left detected"); + } + }; + +ZxSensor.SwipeRightListener swipeRightListener = new ZxSensor.SwipeRightListener() { + @Override + public void onSwipeRight(int speed) { + Log.d("TUT", "Swipe right detected"); + } + }; + +// Start monitoring: + +zxSensorUart.startMonitoringGestures(); + +// Stop monitoring: + +zxSensorUart.stopMonitoringGestures(); + +// Close the ZXSensor when finished: + +zxSensorUart.close(); +``` + + +[jcenter]: https://bintray.com/blundell/maven/driver-zxsensor/_latestVersion