Skip to content
This repository was archived by the owner on Nov 13, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2014 The Android Open Source Project
Copyright 2018 Roberto Leinardi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
<!-- DRIVER_LIST_START -->
Driver | Type | Usage (add to your gradle dependencies) | Note
:---:|:---:| --- | ---
[driver-hcsr04](driver-hcsr04) | ultrasonic ranging module | `implementation 'com.leinardi.android.things:driver-hcsr04:0.1'` | [![Maven metadata URI](https://img.shields.io/maven-metadata/v/http/jcenter.bintray.com/com/leinardi/android/things/driver-hcsr04/maven-metadata.xml.svg)](https://jcenter.bintray.com/com/leinardi/android/things/driver-hcsr04/maven-metadata.xml) [changelog](driver-hcsr04/CHANGELOG.md) [sample](sample-hcsr04)
[driver-hd44780](driver-hd44780) | alphanumeric dot matrix LCD | `implementation 'com.leinardi.android.things:driver-hd44780:0.2'` | [![Maven metadata URI](https://img.shields.io/maven-metadata/v/http/jcenter.bintray.com/com/leinardi/android/things/driver-hd44780/maven-metadata.xml.svg)](https://jcenter.bintray.com/com/leinardi/android/things/driver-hd44780/maven-metadata.xml) [changelog](driver-hd44780/CHANGELOG.md) [sample](sample-hd44780)
[driver-lsm9ds1](driver-lsm9ds1) | 3D accelerometer, 3D gyroscope, 3D magnetometer and temperature sensor | `implementation 'com.leinardi.android.things:driver-lsm9ds1:0.3'` | [![Maven metadata URI](https://img.shields.io/maven-metadata/v/http/jcenter.bintray.com/com/leinardi/android/things/driver-lsm9ds1/maven-metadata.xml.svg)](https://jcenter.bintray.com/com/leinardi/android/things/driver-lsm9ds1/maven-metadata.xml) [changelog](driver-lsm9ds1/CHANGELOG.md) [sample](sample-lsm9ds1)
[driver-sh1106](driver-sh1106) | OLED display | `implementation 'com.leinardi.android.things:driver-sh1106:0.2'` | [![Maven metadata URI](https://img.shields.io/maven-metadata/v/http/jcenter.bintray.com/com/leinardi/android/things/driver-sh1106/maven-metadata.xml.svg)](https://jcenter.bintray.com/com/leinardi/android/things/driver-sh1106/maven-metadata.xml) [changelog](driver-sh1106/CHANGELOG.md) [sample](sample-sh1106)
Expand All @@ -48,7 +49,7 @@ In addition to this, also the artifact ID of `driver-pcf8574-hd44780` has been c

## License

Copyright 2017 Roberto Leinardi.
Copyright 2018 Roberto Leinardi.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
Expand Down
2 changes: 1 addition & 1 deletion bintray.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Roberto Leinardi.
* Copyright 2018 Roberto Leinardi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Roberto Leinardi.
* Copyright 2018 Roberto Leinardi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion checkstyle.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Roberto Leinardi.
* Copyright 2018 Roberto Leinardi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?><!--
~ Copyright 2017 Roberto Leinardi.
~ Copyright 2018 Roberto Leinardi.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?><!--
~ Copyright 2017 Roberto Leinardi.
~ Copyright 2018 Roberto Leinardi.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions driver-hcsr04/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
4 changes: 4 additions & 0 deletions driver-hcsr04/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

## [0.1] - 2018-01-02
- initial version
112 changes: 112 additions & 0 deletions driver-hcsr04/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# HC-SR04 ultrasonic ranging module driver for Android Things

[![Maven metadata URI](https://img.shields.io/maven-metadata/v/http/jcenter.bintray.com/com/leinardi/android/things/driver-hcsr04/maven-metadata.xml.svg?style=plastic)](https://jcenter.bintray.com/com/leinardi/android/things/driver-hcsr04/maven-metadata.xml)
[![Build Status](https://img.shields.io/travis/leinardi/androidthings-drivers/master.svg?style=plastic)](https://travis-ci.org/leinardi/androidthings-drivers)
[![GitHub license](https://img.shields.io/github/license/leinardi/androidthings-drivers.svg?style=plastic)](https://github.com/leinardi/androidthings-drivers/blob/master/LICENSE)

This driver supports the HC-SR04 ultrasonic ranging module.

NOTE: these drivers are not production-ready. They are offered as sample
implementations of Android Things user space drivers for common peripherals
as part of the Developer Preview release. There is no guarantee
of correctness, completeness or robustness.

This driver is based on the [AndroidThings-UltrasonicSensor from Danesz](https://github.com/Danesz/AndroidThings-UltrasonicSensor).

## How to use the driver

### Gradle dependency

To use the `hcsr04` 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 {
implementation 'com.leinardi.android.things:driver-hcsr04:<version>'
}
```

### Sample usage

```java
public class DistanceActivity extends Activity implements SensorEventListener {
private static final String TAG = DistanceActivity.class.getSimpleName();

private Hcsr04SensorDriver mProximitySensorDriver;
private SensorManager mSensorManager;

private SensorManager.DynamicSensorCallback mDynamicSensorCallback = new SensorManager
.DynamicSensorCallback() {
@Override
public void onDynamicSensorConnected(Sensor sensor) {
if (sensor.getType() == Sensor.TYPE_PROXIMITY) {
mSensorManager.registerListener(DistanceActivity.this,
sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensorManager.registerDynamicSensorCallback(mDynamicSensorCallback);

try {
mProximitySensorDriver = new Hcsr04SensorDriver(trigPin, echoPin);
mProximitySensorDriver.registerProximitySensor();
} catch (IOException e) {
// couldn't configure the device...
}

}

@Override
protected void onDestroy() {
super.onDestroy();
if (mProximitySensorDriver != null) {
mSensorManager.unregisterDynamicSensorCallback(mDynamicSensorCallback);
mSensorManager.unregisterListener(this);
mProximitySensorDriver.unregisterProximitySensor();
try {
mProximitySensorDriver.close();
} catch (IOException e) {
// error closing sensor
} finally {
mProximitySensorDriver = null;
}
}
}

@Override
public void onSensorChanged(SensorEvent event) {
Log.i(TAG, String.format(Locale.getDefault(), "sensor changed: [%f]", event.values[0]));
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
```

## License

Copyright 2018 Roberto Leinardi

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you 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.

[jcenter]: https://bintray.com/leinardi/androidthings/driver-hcsr04/_latestVersion
51 changes: 51 additions & 0 deletions driver-hcsr04/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2018 Roberto Leinardi.
*
* 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.
*/

apply plugin: 'com.android.library'
apply from: rootProject.file('checkstyle.gradle')

android {
compileSdkVersion build_versions.target_sdk
buildToolsVersion build_versions.build_tools

apply from: 'mavenConfig.gradle'

defaultConfig {
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
versionCode build_versions.version_code
versionName mvn_config.version as String
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility build_versions.java_version
targetCompatibility build_versions.java_version
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
compileOnly deps.androidthings
implementation deps.support.annotations
}
Binary file added driver-hcsr04/docs/HCSR04.pdf
Binary file not shown.
36 changes: 36 additions & 0 deletions driver-hcsr04/mavenConfig.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2018 Roberto Leinardi.
*
* 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.
*/

def mvn_config = [:]
mvn_config.repository = 'androidthings'
mvn_config.group_id = 'com.leinardi.android.things'
mvn_config.artifact_id = 'driver-hcsr04'
mvn_config.version = '0.1'
mvn_config.licenses = 'Apache-2.0' // Comma separated
mvn_config.website = 'https://github.com/leinardi/androidthings-drivers'
mvn_config.issue_tracker_url = 'https://github.com/leinardi/androidthings-drivers/issues'
mvn_config.vcs_url = 'https://github.com/leinardi/androidthings-drivers.git'
mvn_config.description = 'HC-SR04 driver for Android Things'
mvn_config.tags = 'hcsr04,android-things,android,raspberry-pi' // Comma separated
mvn_config.inception_year = '2017'
mvn_config.dryRun = false
mvn_config.publish = false
mvn_config.override = true

ext.mvn_config = mvn_config

apply from: rootProject.file('maven.gradle')
apply from: rootProject.file('bintray.gradle')
21 changes: 21 additions & 0 deletions driver-hcsr04/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
25 changes: 25 additions & 0 deletions driver-hcsr04/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
~ Copyright 2018 Roberto Leinardi.
~
~ 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 package="com.leinardi.android.things.driver.hcsr04"
xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<uses-library
android:name="com.google.android.things"
android:required="false" />
</application>
</manifest>
Loading