-
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
0 parents
commit 6b08879
Showing
27 changed files
with
1,816 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,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
.idea/* | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
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,23 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.3.3' | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
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,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
.idea/* | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
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,7 @@ | ||
status: PUBLISHED | ||
technologies: [Android, IoT] | ||
categories: [Android Things] | ||
languages: [Java] | ||
solutions: [IoT] | ||
github: androidthings/drivers-samples | ||
license: apache2 |
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,35 @@ | ||
ZXSensor Sample for Android Things | ||
================================== | ||
|
||
This sample demonstrates how to control a ZXSensor using I2C or UART with | ||
Android Things. | ||
|
||
Pre-requisites | ||
-------------- | ||
|
||
- Android Things compatible board | ||
- Android Studio 2.2+ | ||
- the following individual components: | ||
- 1 [ZX Distance & Gesture Sensor](https://shop.pimoroni.com/products/zx-distance-and-gesture-sensor) | ||
- jumper wires | ||
- [Female headers](https://shop.pimoroni.com/products/female-headers) | ||
- 1 breadboard | ||
|
||
Schematics | ||
---------- | ||
|
||
![Schematics for Raspberry Pi 3](zxsensor_rpi3_schematics.png) | ||
|
||
Build and install | ||
================= | ||
|
||
On Android Studio, click on the "Run" button. | ||
|
||
If you prefer to run on the command line, from this repository's root directory, type | ||
|
||
```bash | ||
./gradlew zxsensor:installDebug | ||
adb shell am start com.blundell.zxsensor.example/.ZxSensorActivity | ||
``` | ||
|
||
If you have everything set up correctly, when you swipe over the sensor a log will appear in Logcat. |
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,35 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "25.0.3" | ||
defaultConfig { | ||
applicationId "com.blundell.zxsensor" | ||
minSdkVersion 26 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
} | ||
|
||
dependencies { | ||
// compile 'com.blundell:driver-zxsensor:0.0.1' | ||
compile project(':library') | ||
|
||
provided 'com.google.android.things:androidthings:0.5-devpreview' | ||
|
||
} | ||
|
||
repositories { | ||
jcenter() | ||
} | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.3.0' | ||
} | ||
} |
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,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2016 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.androidthings.driversamples"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@android:drawable/sym_def_app_icon" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@android:style/Theme.DeviceDefault"> | ||
|
||
<uses-library android:name="com.google.android.things"/> | ||
|
||
<activity android:name="com.blundell.zxsensor.example.ZxSensorActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
|
||
<!-- Launch activity automatically on boot --> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.IOT_LAUNCHER"/> | ||
<category android:name="android.intent.category.DEFAULT"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
101 changes: 101 additions & 0 deletions
101
demo/src/main/java/com/blundell/zxsensor/example/BoardDefaults.java
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,101 @@ | ||
package com.blundell.zxsensor.example; | ||
|
||
import android.os.Build; | ||
|
||
import com.google.android.things.pio.PeripheralManagerService; | ||
|
||
import java.util.List; | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
public class BoardDefaults { | ||
private static final String DEVICE_EDISON_ARDUINO = "edison_arduino"; | ||
private static final String DEVICE_EDISON = "edison"; | ||
private static final String DEVICE_JOULE = "joule"; | ||
private static final String DEVICE_RPI3 = "rpi3"; | ||
private static final String DEVICE_IMX6UL_PICO = "imx6ul_pico"; | ||
private static final String DEVICE_IMX6UL_VVDN = "imx6ul_iopb"; | ||
private static final String DEVICE_IMX7D_PICO = "imx7d_pico"; | ||
private static String sBoardVariant = ""; | ||
|
||
public static String getUartPin() { | ||
switch (getBoardVariant()) { | ||
// same for Edison Arduino breakout and Edison SOM | ||
case DEVICE_EDISON: | ||
return "UART1"; | ||
case DEVICE_JOULE: | ||
return "UART1"; | ||
case DEVICE_RPI3: | ||
return "UART0"; | ||
case DEVICE_IMX6UL_PICO: | ||
return "UART3"; | ||
case DEVICE_IMX6UL_VVDN: | ||
return "UART2"; | ||
case DEVICE_IMX7D_PICO: | ||
return "UART6"; | ||
default: | ||
throw new UnsupportedOperationException("Unknown device: " + Build.DEVICE); | ||
} | ||
} | ||
|
||
public static String getGpioPin() { | ||
switch (getBoardVariant()) { | ||
case DEVICE_EDISON_ARDUINO: | ||
return "IO7"; | ||
case DEVICE_EDISON: | ||
return "GP45"; | ||
case DEVICE_JOULE: | ||
return "FLASH_TRIGGER"; | ||
case DEVICE_RPI3: | ||
return "BCM23"; | ||
case DEVICE_IMX6UL_PICO: | ||
return "GPIO4_IO23"; | ||
case DEVICE_IMX6UL_VVDN: | ||
return "GPIO3_IO01"; | ||
case DEVICE_IMX7D_PICO: | ||
return "GPIO_174"; | ||
default: | ||
throw new UnsupportedOperationException("Unknown device: " + Build.DEVICE); | ||
} | ||
} | ||
|
||
public static String getI2CPin() { | ||
switch (getBoardVariant()) { | ||
case DEVICE_EDISON_ARDUINO: | ||
return "I2C6"; | ||
case DEVICE_EDISON: | ||
return "I2C1"; | ||
case DEVICE_JOULE: | ||
return "I2C0"; | ||
case DEVICE_RPI3: | ||
return "I2C1"; | ||
case DEVICE_IMX6UL_PICO: | ||
return "I2C2"; | ||
case DEVICE_IMX6UL_VVDN: | ||
return "I2C4"; | ||
case DEVICE_IMX7D_PICO: | ||
return "I2C1"; | ||
default: | ||
throw new UnsupportedOperationException("Unknown device: " + Build.DEVICE); | ||
} | ||
} | ||
|
||
private static String getBoardVariant() { | ||
if (!sBoardVariant.isEmpty()) { | ||
return sBoardVariant; | ||
} | ||
sBoardVariant = Build.DEVICE; | ||
// For the edison check the pin prefix | ||
// to always return Edison Breakout pin name when applicable. | ||
if (sBoardVariant.equals(DEVICE_EDISON)) { | ||
PeripheralManagerService pioService = new PeripheralManagerService(); | ||
List<String> gpioList = pioService.getGpioList(); | ||
if (gpioList.size() != 0) { | ||
String pin = gpioList.get(0); | ||
if (pin.startsWith("IO")) { | ||
sBoardVariant = DEVICE_EDISON_ARDUINO; | ||
} | ||
} | ||
} | ||
return sBoardVariant; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
demo/src/main/java/com/blundell/zxsensor/example/ZxSensorActivity.java
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,102 @@ | ||
package com.blundell.zxsensor.example; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.util.Log; | ||
|
||
import com.blundell.zxsensor.ZxSensor; | ||
import com.blundell.zxsensor.ZxSensorI2c; | ||
import com.blundell.zxsensor.ZxSensorUart; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* ZxSensorActivity is an example that uses the driver | ||
* for the ZX Distance & Gesture Sensor. You can use i2c or UART (UART recommend only for debugging or POC). | ||
*/ | ||
public class ZxSensorActivity extends Activity { | ||
|
||
private static final String TAG = ZxSensorActivity.class.getSimpleName(); | ||
/** | ||
* Toggle this to see the I2C or UART examples | ||
*/ | ||
private static final boolean EXAMPLE_I2C = false; | ||
|
||
private ZxSensorI2c zxSensorI2c; | ||
private ZxSensorUart zxSensorUart; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
Log.d(TAG, "Activity started, swipe your hand over the sensor."); | ||
Log.d(TAG, "Demoing " + (EXAMPLE_I2C ? "I2C" : "UART")); | ||
|
||
if (EXAMPLE_I2C) { | ||
try { | ||
zxSensorI2c = ZxSensor.Factory.openViaI2c(BoardDefaults.getI2CPin(), BoardDefaults.getGpioPin()); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Can't open, did you use the correct pin names?", e); | ||
} | ||
zxSensorI2c.setSwipeLeftListener(swipeLeftListener); | ||
zxSensorI2c.setSwipeRightListener(swipeRightListener); | ||
|
||
} else { | ||
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); | ||
} | ||
} | ||
|
||
private final ZxSensor.SwipeLeftListener swipeLeftListener = new ZxSensor.SwipeLeftListener() { | ||
@Override | ||
public void onSwipeLeft(int speed) { | ||
logSwipe("left", speed); | ||
} | ||
}; | ||
|
||
private final ZxSensor.SwipeRightListener swipeRightListener = new ZxSensor.SwipeRightListener() { | ||
@Override | ||
public void onSwipeRight(int speed) { | ||
logSwipe("right", speed); | ||
} | ||
}; | ||
|
||
private void logSwipe(String direction, int speed) { | ||
Log.d(TAG, "Hey you swiped " + direction + " with velocity " + speed); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
if (EXAMPLE_I2C) { | ||
zxSensorI2c.startMonitoringGestures(); | ||
} else { | ||
zxSensorUart.startMonitoringGestures(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
if (EXAMPLE_I2C) { | ||
zxSensorI2c.stopMonitoringGestures(); | ||
} else { | ||
zxSensorUart.stopMonitoringGestures(); | ||
} | ||
super.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
if (EXAMPLE_I2C) { | ||
zxSensorI2c.close(); | ||
} else { | ||
zxSensorUart.close(); | ||
} | ||
super.onDestroy(); | ||
} | ||
} |
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,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2016 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<resources> | ||
<string name="app_name">zxsensor</string> | ||
</resources> |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.