-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blundell
committed
Aug 17, 2017
1 parent
6b08879
commit 829b37b
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 `<version>` matches the last version of the driver available on [jcenter][jcenter]. | ||
|
||
``` | ||
dependencies { | ||
compile 'com.blundell:driver-zxsensor:<version>' | ||
} | ||
``` | ||
|
||
### 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 |