├── pio-softpwm
├── .gitignore
├── CHANGELOG.md
├── proguard-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── cpp
│ │ ├── CMakeLists.txt
│ │ ├── native_debug.h
│ │ ├── softpwm.h
│ │ ├── softpwm.cpp
│ │ ├── jni_helpers.h
│ │ └── jni_helpers.cpp
│ │ └── java
│ │ └── com
│ │ └── leinardi
│ │ └── android
│ │ └── things
│ │ └── pio
│ │ └── SoftPwm.java
├── mavenConfig.gradle
├── build.gradle
└── README.md
├── sample-softpwm
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── leinardi
│ │ └── android
│ │ └── things
│ │ └── sample
│ │ └── softpwm
│ │ └── SoftPwmActivity.java
├── proguard-rules.pro
├── README.md
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitmodules
├── .idea
├── dictionaries
│ └── leinardi.xml
├── copyright
│ ├── profiles_settings.xml
│ └── Apache_2_0.xml
├── checkstyle-idea.xml
└── codeStyleSettings.xml
├── settings.gradle
├── gradle.properties
├── .gitignore
├── .travis.yml
├── checkstyle.gradle
├── versions-plugin.gradle
├── config
└── checkstyle
│ ├── checkstyle-suppressions.xml
│ └── checkstyle.xml
├── bintray.gradle
├── maven.gradle
├── gradlew.bat
├── README.md
├── CODE-OF-CONDUCT.md
├── gradlew
├── versions.gradle
└── LICENSE
/pio-softpwm/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-softpwm/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leinardi/androidthings-pio/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "libandroidthings"]
2 | path = libandroidthings
3 | url = https://github.com/androidthings/native-libandroidthings.git
4 |
--------------------------------------------------------------------------------
/pio-softpwm/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | ## [0.2] - 2018-04-07
4 | - update to Android Things devpreview-0.7
5 |
6 | ## [0.1] - 2017-12-31
7 | - initial version
8 |
--------------------------------------------------------------------------------
/.idea/dictionaries/leinardi.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | leinardi
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | include ':pio-softpwm', ':sample-softpwm'
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2018 Roberto Leinardi.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | KEYSTORE_PATH=../keystore/release.keystore
17 | KEYSTORE_PROPERTIES_PATH=../keystore/keystore.properties
18 |
--------------------------------------------------------------------------------
/sample-softpwm/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Sample SoftPWM
19 |
20 |
--------------------------------------------------------------------------------
/.idea/copyright/Apache_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Android ###
2 | # Built application files
3 | *.apk
4 | *.ap_
5 |
6 | # Files for the ART/Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 | out/
16 |
17 | # Gradle files
18 | .gradle/
19 | build/
20 |
21 | # Local configuration file (sdk path, etc)
22 | local.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # Intellij
37 | *.iml
38 | *.iws
39 | .idea/*
40 | !.idea/codeStyleSettings.xml
41 | !.idea/checkstyle-idea.xml
42 | !/.idea/copyright/
43 |
44 | # External native build folder generated in Android Studio 2.2 and later
45 | .externalNativeBuild
46 |
47 | .DS_Store
48 |
--------------------------------------------------------------------------------
/pio-softpwm/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample-softpwm/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample-softpwm/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2018 Roberto Leinardi.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | #Sun Dec 31 16:29:06 CET 2017
18 | distributionBase=GRADLE_USER_HOME
19 | distributionPath=wrapper/dists
20 | zipStoreBase=GRADLE_USER_HOME
21 | zipStorePath=wrapper/dists
22 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
23 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 | sudo: true
4 |
5 | os:
6 | - linux
7 | addons:
8 | apt_packages:
9 | - pandoc
10 | before_install:
11 | - mkdir -p $ANDROID_HOME/licenses
12 | - echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license
13 | - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> $ANDROID_HOME/licenses/android-sdk-license
14 | install:
15 | - echo y | sdkmanager "ndk-bundle"
16 | - echo y | sdkmanager "cmake;3.6.4111459"
17 | - echo y | sdkmanager "lldb;3.1"
18 | android:
19 | components:
20 | - tools
21 | - platform-tools
22 | - tools
23 | - build-tools-26.0.0
24 | - android-26
25 | licenses:
26 | - android-sdk-preview-license-.+
27 | - android-sdk-license-.+
28 | - google-gdk-license-.+
29 |
30 | script:
31 | - ./gradlew clean check --profile
32 | - pandoc `ls -1rt build/reports/profile/profile-*.html | tail -n1` -t plain
33 | - ./gradlew dependencyUpdates
34 |
--------------------------------------------------------------------------------
/checkstyle.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'com.leinardi.android.checkstyle'
18 |
19 | checkstyle {
20 | ignoreFailures = false // Whether this task will ignore failures and continue running the build.
21 | configFile rootProject.file('config/checkstyle/checkstyle.xml')
22 | // The Checkstyle configuration file to use.
23 | toolVersion = '8.5' // The version of Checkstyle you want to be used
24 | }
25 |
--------------------------------------------------------------------------------
/pio-softpwm/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
20 |
21 |
22 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/versions-plugin.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'com.github.ben-manes.versions'
18 |
19 | dependencyUpdates.resolutionStrategy = {
20 | componentSelection { rules ->
21 | rules.all { ComponentSelection selection ->
22 | boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier ->
23 | selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
24 | }
25 | if (rejected) {
26 | selection.reject('Release candidate')
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/pio-softpwm/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | # Add FindAndroidThings.cmake dir to the module path.
4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_DIR}/libandroidthings)
5 | # Resolve Android Things headers and libraries
6 | find_package(AndroidThings REQUIRED)
7 |
8 | add_library(softpwm SHARED
9 | softpwm.cpp
10 | jni_helpers.cpp)
11 |
12 | target_include_directories(softpwm PRIVATE
13 | ${ANDROID_NDK}/sources/android/native_app_glue
14 | ${ANDROIDTHINGS_INCLUDE_DIRS})
15 |
16 | add_library(native-app-glue STATIC
17 | ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
18 |
19 | # now build app's shared lib
20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror")
21 |
22 | add_library(androidthings SHARED
23 | IMPORTED)
24 | set_target_properties(androidthings
25 | PROPERTIES IMPORTED_LOCATION
26 | ${ANDROIDTHINGS_LIBRARIES})
27 |
28 | # Include libraries needed for softpwm lib
29 | target_link_libraries(softpwm
30 | android
31 | log
32 | native-app-glue
33 | androidthings)
34 |
--------------------------------------------------------------------------------
/pio-softpwm/src/main/cpp/native_debug.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include
17 |
18 | #define LOG_TAG "SOFT-PWM"
19 | #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
20 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
21 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
22 | #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
23 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
24 | #define ASSERT(cond, fmt, ...) \
25 | if (!(cond)) { \
26 | __android_log_assert(#cond, LOG_TAG, fmt, ##__VA_ARGS__); \
27 | }
28 |
--------------------------------------------------------------------------------
/config/checkstyle/checkstyle-suppressions.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/pio-softpwm/mavenConfig.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | def mvn_config = [:]
18 | mvn_config.repository = 'androidthings'
19 | mvn_config.group_id = 'com.leinardi.android.things'
20 | mvn_config.artifact_id = 'pio-softpwm'
21 | mvn_config.version = '0.2'
22 | mvn_config.licenses = 'Apache-2.0' // Comma separated
23 | mvn_config.website = 'https://github.com/leinardi/androidthings-pio'
24 | mvn_config.issue_tracker_url = 'https://github.com/leinardi/androidthings-pio/issues'
25 | mvn_config.vcs_url = 'https://github.com/leinardi/androidthings-pio.git'
26 | mvn_config.description = 'Software PWM implementation for Android Things'
27 | mvn_config.tags = 'pwm,software-pwm,android-things,android,raspberry-pi' // Comma separated
28 | mvn_config.inception_year = '2017'
29 | mvn_config.dryRun = false
30 | mvn_config.publish = false
31 | mvn_config.override = true
32 |
33 | ext.mvn_config = mvn_config
34 |
35 | apply from: rootProject.file('maven.gradle')
36 |
--------------------------------------------------------------------------------
/sample-softpwm/README.md:
--------------------------------------------------------------------------------
1 | ## Software PWM sample for Android Things
2 |
3 | This sample demonstrates how to control both software and hardware PWM.
4 |
5 | ## Pre-requisites
6 |
7 | - Android Things compatible board
8 | - Android Studio 3.0+
9 |
10 |
11 | # Build and install
12 |
13 | On Android Studio, click on the "Run" button.
14 |
15 | If you prefer to run on the command line, from this repository's root directory, type
16 |
17 | ```bash
18 | ./gradlew sample-softpwm:installDebug
19 | adb shell am start com.leinardi.android.things.sample.softpwm/.SoftPwmActivity
20 | ```
21 |
22 | If you have everything set up correctly, BCM21 will be providing software PWM
23 | with a frequency of 100 Hz and a duty cycle of 30%. Same settings are applied
24 | also to the hardware PWM1.
25 |
26 |
27 | ## License
28 |
29 | Copyright 2018 Roberto Leinardi.
30 |
31 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
32 | license agreements. See the NOTICE file distributed with this work for
33 | additional information regarding copyright ownership. The ASF licenses this
34 | file to you under the Apache License, Version 2.0 (the "License"); you may not
35 | use this file except in compliance with the License. You may obtain a copy of
36 | the License at
37 |
38 | http://www.apache.org/licenses/LICENSE-2.0
39 |
40 | Unless required by applicable law or agreed to in writing, software
41 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
42 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
43 | License for the specific language governing permissions and limitations under
44 | the License.
45 |
--------------------------------------------------------------------------------
/pio-softpwm/src/main/cpp/softpwm.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef ANDROIDTHINGS_PIO_SOFTPWM_H
18 | #define ANDROIDTHINGS_PIO_SOFTPWM_H
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | class SoftPwm {
27 | public:
28 | SoftPwm(JNIEnv *env, const char *gpioName);
29 |
30 | ~SoftPwm();
31 |
32 | void setEnabled(bool enabled);
33 |
34 | void setPwmDutyCycle(double dutyCycle);
35 |
36 | void setPwmFrequencyHz(double freqHz);
37 |
38 | private:
39 | JNIEnv *mEnv;
40 | const char *mGpioName;
41 | APeripheralManagerClient *mClient;
42 | AGpio *mGpio;
43 |
44 | double mDutyCycle = 0;
45 | double mFreqHz;
46 | const useconds_t HZ_IN_MICROSECONDS = 1000000;
47 | useconds_t mPeriodTotal;
48 | useconds_t mPeriodHigh;
49 | useconds_t mPeriodLow;
50 |
51 | std::atomic_flag mLock = ATOMIC_FLAG_INIT;
52 | std::thread mPwmThread;
53 |
54 | void startThread();
55 |
56 | void stopThread();
57 |
58 | void run();
59 | };
60 |
61 | #endif //ANDROIDTHINGS_PIO_SOFTPWM_H
62 |
--------------------------------------------------------------------------------
/sample-softpwm/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'com.android.application'
18 | apply from: rootProject.file('checkstyle.gradle')
19 |
20 | android {
21 | compileSdkVersion build_versions.target_sdk
22 | buildToolsVersion build_versions.build_tools
23 |
24 | defaultConfig {
25 | applicationId "com.leinardi.android.things.sample.softpwm"
26 | minSdkVersion build_versions.min_sdk
27 | targetSdkVersion build_versions.target_sdk
28 | versionCode build_versions.version_code
29 | versionName "1.0"
30 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
31 |
32 | }
33 |
34 | compileOptions {
35 | sourceCompatibility build_versions.java_version
36 | targetCompatibility build_versions.java_version
37 | }
38 |
39 | buildTypes {
40 | release {
41 | minifyEnabled false
42 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
43 | }
44 | }
45 |
46 | }
47 |
48 | dependencies {
49 | implementation fileTree(dir: 'libs', include: ['*.jar'])
50 | compileOnly deps.androidthings
51 | implementation deps.support.annotations
52 | implementation project(':pio-softpwm')
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/bintray.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'com.jfrog.bintray'
18 |
19 | group mvn_config.group_id
20 | version mvn_config.version
21 |
22 | bintray {
23 | user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
24 | key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
25 |
26 | configurations = ['archives']
27 | dryRun = mvn_config.dryRun //[Default: false] Whether to run this as dry-run, without deploying
28 | publish = mvn_config.publish //[Default: false] Whether version should be auto published after an upload
29 | override = mvn_config.override //[Default: false] Whether to override version artifacts already published
30 |
31 | pkg {
32 | repo = mvn_config.repository
33 | name = mvn_config.artifact_id
34 | userOrg = user
35 | licenses = mvn_config.licenses.split(',')
36 | websiteUrl = mvn_config.website
37 | issueTrackerUrl = mvn_config.issue_tracker_url
38 | vcsUrl = mvn_config.vcs_url
39 | labels = mvn_config.tags.split(',')
40 | version {
41 | name = mvn_config.version
42 | desc = mvn_config.description
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/pio-softpwm/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'com.android.library'
18 | apply from: rootProject.file('checkstyle.gradle')
19 |
20 | android {
21 | compileSdkVersion build_versions.target_sdk
22 | buildToolsVersion build_versions.build_tools
23 |
24 | apply from: 'mavenConfig.gradle'
25 |
26 | defaultConfig {
27 | minSdkVersion build_versions.min_sdk
28 | targetSdkVersion build_versions.target_sdk
29 | versionCode build_versions.version_code
30 | versionName mvn_config.version as String
31 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
32 | ndk {
33 | abiFilters 'armeabi-v7a'
34 | }
35 | externalNativeBuild {
36 | cmake {
37 | arguments "-DPROJECT_DIR=${rootProject.projectDir}"
38 | }
39 | }
40 | }
41 | externalNativeBuild {
42 | cmake {
43 | path "src/main/cpp/CMakeLists.txt"
44 | }
45 | }
46 | compileOptions {
47 | sourceCompatibility build_versions.java_version
48 | targetCompatibility build_versions.java_version
49 | }
50 |
51 | buildTypes {
52 | release {
53 | minifyEnabled false
54 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
55 | }
56 | }
57 |
58 | }
59 |
60 | dependencies {
61 | compileOnly deps.androidthings
62 | implementation deps.support.annotations
63 | }
64 |
--------------------------------------------------------------------------------
/sample-softpwm/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
23 |
24 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/maven.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'com.github.dcendents.android-maven'
18 |
19 | install {
20 | repositories.mavenInstaller.pom.project {
21 | name mvn_config.artifact_id
22 | description mvn_config.description
23 | url mvn_config.website
24 | inceptionYear mvn_config.inception_year
25 |
26 | packaging 'aar'
27 | groupId mvn_config.group_id
28 | artifactId mvn_config.artifact_id
29 | version mvn_config.version
30 |
31 | licenses {
32 | license {
33 | name 'The Apache Software License, Version 2.0'
34 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
35 | distribution 'repo'
36 | }
37 | }
38 | scm {
39 | connection mvn_config.vcs_url
40 | url mvn_config.website
41 |
42 | }
43 | developers {
44 | developer {
45 | name "Roberto Leinardi"
46 | email "roberto@leinardi.com"
47 | }
48 | }
49 | }
50 | }
51 |
52 | task sourcesJar(type: Jar) {
53 | from android.sourceSets.main.java.srcDirs
54 | classifier = 'sources'
55 | }
56 |
57 | task javadoc(type: Javadoc) {
58 | source = android.sourceSets.main.java.srcDirs
59 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
60 | }
61 |
62 | task javadocJar(type: Jar, dependsOn: javadoc) {
63 | classifier = 'javadoc'
64 | from javadoc.destinationDir
65 | }
66 | artifacts {
67 | archives javadocJar
68 | archives sourcesJar
69 | }
70 |
71 | afterEvaluate {
72 | javadoc.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
73 | }
74 |
75 | apply from: rootProject.file('bintray.gradle')
76 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Things user-space PIO
2 |
3 | [](https://github.com/leinardi/androidthings-pio/releases)
4 | [](https://travis-ci.org/leinardi/androidthings-pio)
5 | [](https://github.com/leinardi/androidthings-pio/blob/master/LICENSE)
6 |
7 |
8 | Sample PIO for Android Things.
9 |
10 | NOTE: these PIO are not production-ready. They are offered as sample
11 | implementations of Android Things user space PIO
12 | as part of the Developer Preview release. There is no guarantee
13 | of correctness, completeness or robustness.
14 |
15 |
16 | # How to use a PIO
17 |
18 | For your convenience, PIO in this repository are also published to JCenter
19 | as Maven artifacts. Look at their artifact and group ID in their build.gradle
20 | and add them as dependencies to your own project.
21 |
22 | For example, to use the `pio-softpwm` driver, version `0.1`, simply add the line
23 | below to your project's `build.gradle`:
24 |
25 |
26 | ```
27 | dependencies {
28 | compile 'com.leinardi.android.things:pio-softpwm:0.2'
29 | }
30 | ```
31 |
32 |
33 | ## Current contrib drivers
34 |
35 |
36 | Driver | Type | Usage (add to your gradle dependencies) | Note
37 | :---:|:---:| --- | ---
38 | [pio-softpwm](pio-softpwm) | Software PWM | `implementation 'com.leinardi.android.things:pio-softpwm:0.1'` | [](https://jcenter.bintray.com/com/leinardi/android/things/pio-softpwm/maven-metadata.xml) [changelog](pio-softpwm/CHANGELOG.md)
39 |
40 |
41 |
42 | ## License
43 |
44 | Copyright 2017 Roberto Leinardi.
45 |
46 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
47 | license agreements. See the NOTICE file distributed with this work for
48 | additional information regarding copyright ownership. The ASF licenses this
49 | file to you under the Apache License, Version 2.0 (the "License"); you may not
50 | use this file except in compliance with the License. You may obtain a copy of
51 | the License at
52 |
53 | http://www.apache.org/licenses/LICENSE-2.0
54 |
55 | Unless required by applicable law or agreed to in writing, software
56 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
57 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
58 | License for the specific language governing permissions and limitations under
59 | the License.
60 |
--------------------------------------------------------------------------------
/sample-softpwm/src/main/java/com/leinardi/android/things/sample/softpwm/SoftPwmActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.leinardi.android.things.sample.softpwm;
18 |
19 | import android.app.Activity;
20 | import android.os.Bundle;
21 | import android.util.Log;
22 |
23 | import com.google.android.things.pio.PeripheralManager;
24 | import com.google.android.things.pio.Pwm;
25 | import com.leinardi.android.things.pio.SoftPwm;
26 |
27 | import java.io.IOException;
28 |
29 | /**
30 | * SoftPwmActivity is an example that use both software and hardware PWM.
31 | */
32 | public class SoftPwmActivity extends Activity {
33 | private static final String TAG = SoftPwmActivity.class.getSimpleName();
34 | public static final float PWM_FREQUENCY_HZ = 100f; // Max 300 Hz for SoftPwm!
35 |
36 | private Pwm mSoftPwm;
37 | private Pwm mHardPwm;
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | Log.i(TAG, "Starting SoftPwmActivity");
43 | PeripheralManager pioService = PeripheralManager.getInstance();
44 | try {
45 | mSoftPwm = SoftPwm.openSoftPwm("BCM21");
46 | mHardPwm = pioService.openPwm("PWM0");
47 |
48 | mSoftPwm.setPwmFrequencyHz(PWM_FREQUENCY_HZ);
49 | mHardPwm.setPwmFrequencyHz(PWM_FREQUENCY_HZ);
50 |
51 | mSoftPwm.setPwmDutyCycle(31);
52 | mHardPwm.setPwmDutyCycle(31);
53 |
54 | mSoftPwm.setEnabled(true);
55 | mHardPwm.setEnabled(true);
56 | } catch (IOException e) {
57 | Log.e(TAG, "Error", e);
58 | }
59 | }
60 |
61 | @Override
62 | protected void onDestroy() {
63 | super.onDestroy();
64 | Log.i(TAG, "Closing sensor");
65 |
66 | try {
67 | mSoftPwm.close();
68 | } catch (IOException e) {
69 | Log.w(TAG, "Unable to close PWM device", e);
70 | } finally {
71 | mSoftPwm = null;
72 | }
73 | try {
74 | mHardPwm.close();
75 | } catch (IOException e) {
76 | Log.w(TAG, "Unable to close PWM device", e);
77 | } finally {
78 | mHardPwm = null;
79 | }
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/CODE-OF-CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, gender identity and expression, level of experience,
9 | education, socio-economic status, nationality, personal appearance, race,
10 | religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at roberto@leinardi.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 |
--------------------------------------------------------------------------------
/pio-softpwm/README.md:
--------------------------------------------------------------------------------
1 | # Software PWM library for Android Things
2 |
3 | [](https://jcenter.bintray.com/com/leinardi/android/things/pio-softpwm/maven-metadata.xml)
4 | [](https://travis-ci.org/leinardi/androidthings-pio)
5 | [](https://github.com/leinardi/androidthings-pio/blob/master/LICENSE)
6 |
7 | This library provides a software PWM that can be used with any GPIO pin.
8 |
9 | ## Warning
10 | PWM signals that are not driven from a hardware channel
11 | are destined to be **too inaccurate for most use cases**.
12 | The multiprocess and multithreaded nature of a system like
13 | Android makes it too likely for the scheduler to cause minor
14 | disruptions that affect the output signal.
15 |
16 | One common use case for software PWM is power the speed of DC
17 | motors (e.g. via the L298) if the accuracy of the speed is not
18 | that important. If possible always use [hardware PWM](https://developer.android.com/things/sdk/pio/pwm.html).
19 |
20 | Currently the maximum frequency supported by this library is 300 Hz.
21 |
22 | ## How to use SoftPWM
23 |
24 | ### Gradle dependency
25 |
26 | To use the `pio-softpwm` simply add the line below to your project's `build.gradle`,
27 | where `` matches the last version of the library available on [jcenter][jcenter].
28 |
29 | ```
30 | dependencies {
31 | implementation 'com.leinardi.android.things:pio-softpwm:'
32 | }
33 | ```
34 |
35 | ### Sample usage
36 |
37 | ```java
38 | import com.leinardi.android.things.pio.SoftPwm;
39 |
40 | public class HomeActivity extends Activity {
41 | // GPIO Name
42 | private static final String GPIO_NAME = ...; // e.g. BCM20
43 |
44 | private Pwm mPwm;
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | // Attempt to access the PWM port
50 | try {
51 | mPwm = SoftPwm.openSoftPwm(GPIO_NAME);
52 | initializePwm(mPwm);
53 | } catch (IOException e) {
54 | Log.w(TAG, "Unable to access PWM", e);
55 | }
56 | }
57 |
58 | public void initializePwm(Pwm pwm) throws IOException {
59 | pwm.setPwmFrequencyHz(120);
60 | pwm.setPwmDutyCycle(25);
61 |
62 | // Enable the PWM signal
63 | pwm.setEnabled(true);
64 | }
65 |
66 | @Override
67 | protected void onDestroy() {
68 | super.onDestroy();
69 |
70 | if (mPwm != null) {
71 | try {
72 | mPwm.close();
73 | mPwm = null;
74 | } catch (IOException e) {
75 | Log.w(TAG, "Unable to close PWM", e);
76 | }
77 | }
78 | }
79 | }
80 |
81 | ```
82 |
83 | ## License
84 |
85 | Copyright 2017 Roberto Leinardi
86 |
87 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
88 | license agreements. See the NOTICE file distributed with this work for
89 | additional information regarding copyright ownership. The ASF licenses this
90 | file to you under the Apache License, Version 2.0 (the "License"); you may not
91 | use this file except in compliance with the License. You may obtain a copy of
92 | the License at
93 |
94 | http://www.apache.org/licenses/LICENSE-2.0
95 |
96 | Unless required by applicable law or agreed to in writing, software
97 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
98 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
99 | License for the specific language governing permissions and limitations under
100 | the License.
101 |
102 | [jcenter]: https://bintray.com/leinardi/androidthings/pio-softpwm/_latestVersion
103 |
--------------------------------------------------------------------------------
/pio-softpwm/src/main/java/com/leinardi/android/things/pio/SoftPwm.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.leinardi.android.things.pio;
18 |
19 | import com.google.android.things.pio.PeripheralManager;
20 | import com.google.android.things.pio.Pwm;
21 |
22 | import java.io.IOException;
23 |
24 | /**
25 | * Controls a GPIO pin providing PWM capabilities. Opening a GPIO pin takes ownership of it for the whole system,
26 | * preventing anyone else from opening/accessing the GPIO until you call close(). Forgetting to call close() will
27 | * prevent anyone (including the same process/app) from using the GPIO.
28 | */
29 | public class SoftPwm implements Pwm {
30 | public static final int MAX_FREQ = 300;
31 | private static final String TAG = SoftPwm.class.getSimpleName();
32 |
33 | static {
34 | System.loadLibrary("softpwm");
35 | }
36 |
37 | private final long mJniSoftPwmPtr;
38 |
39 | private SoftPwm(String gpioName) throws IOException {
40 | mJniSoftPwmPtr = jniSoftPwmNew(gpioName);
41 | }
42 |
43 | /**
44 | * Open a GPIO pin providing software PWM. A GPIO pin can only be opened once at any given time on the system.
45 | * To close and release the GPIO pin, you need to call close() explicitly.
46 | *
47 | * @param gpioName Name of the GPIO pin as returned by {@link PeripheralManager#getGpioList()}.
48 | * @return The {@link SoftPwm} object
49 | * @throws IOException
50 | */
51 | public static SoftPwm openSoftPwm(String gpioName) throws IOException {
52 | return new SoftPwm(gpioName);
53 | }
54 |
55 | @Override
56 | public void close() {
57 | jniSoftPwmDelete(mJniSoftPwmPtr);
58 | }
59 |
60 | /**
61 | * Enable the GPIO/PWM pin. Frequency must be set via {@link #setPwmFrequencyHz(double)} before enabling the pin,
62 | * but frequency and duty cycle settings can be set in both enabled and disabled state and will be remembered if the
63 | * PWM is disabled and then re-enabled.
64 | *
65 | * @param enabled True to enable the PWM, false to disable.
66 | */
67 | @Override
68 | public void setEnabled(boolean enabled) throws IOException {
69 | jniSoftPwmSetEnabled(mJniSoftPwmPtr, enabled);
70 | }
71 |
72 | /**
73 | * Set the duty cycle.
74 | *
75 | * @param dutyCycle A double between 0 and 100 (inclusive).
76 | */
77 | @Override
78 | public void setPwmDutyCycle(double dutyCycle) {
79 | if (dutyCycle < 0 || dutyCycle > 100) {
80 | throw new IllegalArgumentException("Invalid duty cycle value (must be between 0 and 100 included). "
81 | + "Duty cycle:" + dutyCycle);
82 | }
83 | jniSoftPwmSetPwmDutyCycle(mJniSoftPwmPtr, dutyCycle);
84 | }
85 |
86 | /**
87 | * Set the frequency of the signal.
88 | *
89 | * @param freqHz Frequency in Hertz to use for the signal. Must be positive (max 300 Hz).
90 | */
91 | @Override
92 | public void setPwmFrequencyHz(double freqHz) {
93 | if (freqHz <= 0 || freqHz > MAX_FREQ) {
94 | throw new IllegalArgumentException("Invalid frequency value (must be bigger than 0 and lower than "
95 | + MAX_FREQ + "Hz). Freq:" + freqHz);
96 | }
97 | if (freqHz > 40) {
98 | double adjustedFreq = regressionLine(freqHz);
99 | jniSoftPwmSetPwmFrequencyHz(mJniSoftPwmPtr, adjustedFreq);
100 | } else {
101 | jniSoftPwmSetPwmFrequencyHz(mJniSoftPwmPtr, freqHz);
102 | }
103 |
104 | }
105 |
106 | /**
107 | * For higher frequencies we need to compensate a little to stay close to the desired value.
108 | * This equation represent the regression line: https://en.wikipedia.org/wiki/Least_squares
109 | */
110 | private double regressionLine(double freqHz) {
111 | return -6.261 + (1.151 * freqHz);
112 | }
113 |
114 | private native long jniSoftPwmNew(String gpioName) throws IOException;
115 |
116 | private native void jniSoftPwmDelete(long ptr);
117 |
118 | private native void jniSoftPwmSetEnabled(long ptr, boolean enabled);
119 |
120 | private native void jniSoftPwmSetPwmDutyCycle(long ptr, double dutyCycle);
121 |
122 | private native void jniSoftPwmSetPwmFrequencyHz(long ptr, double freqHz);
123 | }
124 |
--------------------------------------------------------------------------------
/pio-softpwm/src/main/cpp/softpwm.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include "jni_helpers.h"
22 | #include "native_debug.h"
23 | #include "softpwm.h"
24 |
25 | #define HIGH 1
26 | #define LOW 0
27 |
28 | SoftPwm::SoftPwm(JNIEnv *env, const char *gpioName) {
29 | mEnv = env;
30 | mGpioName = gpioName;
31 | mClient = APeripheralManagerClient_new();
32 | if (!mClient) {
33 | throwIOException(env, "failed to open peripheral manager mClient");
34 | return;
35 | }
36 | int openResult = APeripheralManagerClient_openGpio(mClient, mGpioName, &mGpio);
37 | if (openResult != 0) {
38 | throwIOException(env, "failed to open GPIO: %s", mGpioName);
39 | return;
40 | }
41 | int setDirectionResult = AGpio_setDirection(mGpio, AGPIO_DIRECTION_OUT_INITIALLY_LOW);
42 | if (setDirectionResult != 0) {
43 | throwIOException(env, "failed to set direction for GPIO: %s", mGpioName);
44 | return;
45 | }
46 | }
47 |
48 | SoftPwm::~SoftPwm() {
49 | stopThread();
50 | if (mGpio) {
51 | AGpio_delete(mGpio);
52 | }
53 | if (mClient) {
54 | APeripheralManagerClient_delete(mClient);
55 | }
56 | }
57 |
58 | void SoftPwm::setEnabled(bool enabled) {
59 | if (enabled) {
60 | startThread();
61 | } else {
62 | stopThread();
63 | }
64 | }
65 |
66 | void SoftPwm::startThread() {
67 | stopThread();
68 | mLock.test_and_set(std::memory_order_acquire);
69 | mPwmThread = std::thread(&SoftPwm::run, this);
70 | }
71 |
72 | void SoftPwm::stopThread() {
73 | if (mPwmThread.joinable()) {
74 | mLock.clear(std::memory_order_release);
75 | mPwmThread.join();
76 | }
77 | }
78 |
79 | void SoftPwm::run() {
80 | while (mLock.test_and_set(std::memory_order_acquire)) {
81 | if (mPeriodHigh != 0) {
82 | if (AGpio_setValue(mGpio, HIGH) != 0) {
83 | LOGE("failed to set value for GPIO: %s", mGpioName);
84 | continue;
85 | }
86 | usleep(mPeriodHigh);
87 | }
88 | if (mPeriodLow != 0) {
89 | if (AGpio_setValue(mGpio, LOW) != 0) {
90 | LOGE("failed to set value for GPIO: %s", mGpioName);
91 | continue;
92 | }
93 | usleep(mPeriodLow);
94 | }
95 | }
96 | }
97 |
98 | void SoftPwm::setPwmDutyCycle(double dutyCycle) {
99 | mDutyCycle = dutyCycle;
100 | mPeriodHigh = (useconds_t) lround((float) mPeriodTotal / 100.0 * (float) dutyCycle);
101 | mPeriodLow = mPeriodTotal - mPeriodHigh;
102 | }
103 |
104 | void SoftPwm::setPwmFrequencyHz(double freqHz) {
105 | mFreqHz = freqHz;
106 | mPeriodTotal = (useconds_t) lround((float) HZ_IN_MICROSECONDS / freqHz);
107 | setPwmDutyCycle(mDutyCycle);
108 | }
109 |
110 | extern "C"
111 | JNIEXPORT jlong JNICALL
112 | Java_com_leinardi_android_things_pio_SoftPwm_jniSoftPwmNew(JNIEnv *env, jobject instance, jstring gpioName_) {
113 | const char *gpioName = env->GetStringUTFChars(gpioName_, 0);
114 | return (long) (new SoftPwm(env, gpioName));
115 | }
116 |
117 | extern "C"
118 | JNIEXPORT void JNICALL
119 | Java_com_leinardi_android_things_pio_SoftPwm_jniSoftPwmDelete(JNIEnv *env, jobject instance, jlong ptr) {
120 | delete (SoftPwm *) (ptr);
121 | }
122 |
123 | extern "C"
124 | JNIEXPORT void JNICALL
125 | Java_com_leinardi_android_things_pio_SoftPwm_jniSoftPwmSetEnabled(JNIEnv *env, jobject instance, jlong ptr,
126 | jboolean enabled) {
127 | SoftPwm *softPwm = (SoftPwm *) ptr;
128 | softPwm->setEnabled(enabled);
129 | }
130 |
131 | extern "C"
132 | JNIEXPORT void JNICALL
133 | Java_com_leinardi_android_things_pio_SoftPwm_jniSoftPwmSetPwmDutyCycle(JNIEnv *env, jobject instance, jlong ptr,
134 | jdouble dutyCycle) {
135 | SoftPwm *softPwm = (SoftPwm *) ptr;
136 | softPwm->setPwmDutyCycle(dutyCycle);
137 | }
138 |
139 | extern "C"
140 | JNIEXPORT void JNICALL
141 | Java_com_leinardi_android_things_pio_SoftPwm_jniSoftPwmSetPwmFrequencyHz(JNIEnv *env, jobject instance, jlong ptr,
142 | jdouble freqHz) {
143 | SoftPwm *softPwm = (SoftPwm *) ptr;
144 | softPwm->setPwmFrequencyHz(freqHz);
145 | }
146 |
--------------------------------------------------------------------------------
/pio-softpwm/src/main/cpp/jni_helpers.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include
17 |
18 | /**
19 | * Instructs the JNI environment to throw an exception.
20 | *
21 | * @param pEnv JNI environment
22 | * @param szClassName class name to throw
23 | * @param szFmt sprintf-style format string
24 | * @param ... sprintf-style args
25 | * @return 0 on success; a negative value on failure
26 | */
27 | jint throwException(JNIEnv* pEnv, const char* szClassName, const char* szFmt, va_list va_args);
28 |
29 | /**
30 | * Instructs the JNI environment to throw a NoClassDefFoundError.
31 | *
32 | * @param pEnv JNI environment
33 | * @param szFmt sprintf-style format string
34 | * @param ... sprintf-style args
35 | * @return 0 on success; a negative value on failure
36 | */
37 | jint throwNoClassDefError(JNIEnv* pEnv, const char* szFmt, ...);
38 |
39 | /**
40 | * Instructs the JNI environment to throw a RuntimeException.
41 | *
42 | * @param pEnv JNI environment
43 | * @param szFmt sprintf-style format string
44 | * @param ... sprintf-style args
45 | * @return 0 on success; a negative value on failure
46 | */
47 | jint throwRuntimeException(JNIEnv* pEnv, const char* szFmt, ...);
48 |
49 | /**
50 | * Instructs the JNI environment to throw a IllegalArgumentException.
51 | *
52 | * @param pEnv JNI environment
53 | * @param szFmt sprintf-style format string
54 | * @param ... sprintf-style args
55 | * @return 0 on success; a negative value on failure
56 | */
57 | jint throwIllegalArgumentException(JNIEnv* pEnv, const char* szFmt, ...);
58 |
59 | /**
60 | * Instructs the JNI environment to throw a IllegalStateException.
61 | *
62 | * @param pEnv JNI environment
63 | * @param szFmt sprintf-style format string
64 | * @param ... sprintf-style args
65 | * @return 0 on success; a negative value on failure
66 | */
67 | jint throwIllegalStateException(JNIEnv* pEnv, const char* szFmt, ...);
68 |
69 | /**
70 | * Instructs the JNI environment to throw an IOException.
71 | *
72 | * @param pEnv JNI environment
73 | * @param szFmt sprintf-style format string
74 | * @param ... sprintf-style args
75 | * @return 0 on success; a negative value on failure
76 | */
77 | jint throwIOException(JNIEnv* pEnv, const char* szFmt, ...);
78 |
79 | /**
80 | * Instructs the JNI environment to throw an AssertionError.
81 | *
82 | * @param pEnv JNI environment
83 | * @param szFmt sprintf-style format string
84 | * @param ... sprintf-style args
85 | * @return 0 on success; a negative value on failure
86 | */
87 | jint throwAssertionError(JNIEnv* pEnv, const char* szFmt, ...);
88 |
89 | /**
90 | * Instructs the JNI environment to throw an OutOfMemoryError.
91 | *
92 | * @param pEnv JNI environment
93 | * @param szFmt sprintf-style format string
94 | * @param ... sprintf-style args
95 | * @return 0 on success; a negative value on failure
96 | */
97 | jint throwOutOfMemoryError(JNIEnv* pEnv, const char* szFmt, ...);
98 |
99 | /**
100 | * Finds the specified class. If it's not found, instructs the JNI environment to throw an
101 | * exception.
102 | *
103 | * @param pEnv JNI environment
104 | * @param szClassName the classname to find in JNI format (e.g. "java/lang/String")
105 | * @return the class or NULL if not found (in which case a pending exception will be queued). This
106 | * returns a global reference (JNIEnv::NewGlobalRef).
107 | */
108 | jclass findClassOrThrow(JNIEnv *pEnv, const char* szClassName);
109 |
110 | /**
111 | * Finds the specified field of the specified class. If it's not found, instructs the JNI
112 | * environment to throw an exception.
113 | *
114 | * @param pEnv JNI environment
115 | * @param clazz the class to lookup the field in
116 | * @param szFieldName the name of the field to find
117 | * @param szSig the signature of the field
118 | * @return the field or NULL if not found (in which case a pending exception will be queued)
119 | */
120 | jfieldID getFieldIdOrThrow(JNIEnv* pEnv, jclass clazz, const char* szFieldName, const char* szSig);
121 |
122 | /**
123 | * Finds the specified method of the specified class. If it's not found, instructs the JNI
124 | * environment to throw an exception.
125 | *
126 | * @param pEnv JNI environment
127 | * @param clazz the class to lookup the method in
128 | * @param szMethodName the name of the method to find
129 | * @param szSig the signature of the method
130 | * @return the method or NULL if not found (in which case a pending exception will be queued)
131 | */
132 | jmethodID getMethodIdOrThrow(
133 | JNIEnv* pEnv,
134 | jclass clazz,
135 | const char* szMethodName,
136 | const char* szSig);
137 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/pio-softpwm/src/main/cpp/jni_helpers.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include
17 | #include
18 | #include
19 |
20 | #include "jni_helpers.h"
21 |
22 | #define MSG_SIZE 1024
23 |
24 | /**
25 | * Instructs the JNI environment to throw an exception.
26 | *
27 | * @param pEnv JNI environment
28 | * @param szClassName class name to throw
29 | * @param szFmt sprintf-style format string
30 | * @param ... sprintf-style args
31 | * @return 0 on success; a negative value on failure
32 | */
33 | jint throwException(JNIEnv *pEnv, const char *szClassName, const char *szFmt, va_list va_args) {
34 | char szMsg[MSG_SIZE];
35 | vsnprintf(szMsg, MSG_SIZE, szFmt, va_args);
36 | jclass exClass = pEnv->FindClass(szClassName);
37 | return pEnv->ThrowNew(exClass, szMsg);
38 | }
39 |
40 | /**
41 | * Instructs the JNI environment to throw a NoClassDefFoundError.
42 | *
43 | * @param pEnv JNI environment
44 | * @param szFmt sprintf-style format string
45 | * @param ... sprintf-style args
46 | * @return 0 on success; a negative value on failure
47 | */
48 | jint throwNoClassDefError(JNIEnv *pEnv, const char *szFmt, ...) {
49 | va_list va_args;
50 | va_start(va_args, szFmt);
51 | jint ret = throwException(pEnv, "java/lang/NoClassDefFoundError", szFmt, va_args);
52 | va_end(va_args);
53 | return ret;
54 | }
55 |
56 | /**
57 | * Instructs the JNI environment to throw a RuntimeException.
58 | *
59 | * @param pEnv JNI environment
60 | * @param szFmt sprintf-style format string
61 | * @param ... sprintf-style args
62 | * @return 0 on success; a negative value on failure
63 | */
64 | jint throwRuntimeException(JNIEnv *pEnv, const char *szFmt, ...) {
65 | va_list va_args;
66 | va_start(va_args, szFmt);
67 | jint ret = throwException(pEnv, "java/lang/RuntimeException", szFmt, va_args);
68 | va_end(va_args);
69 | return ret;
70 | }
71 |
72 | /**
73 | * Instructs the JNI environment to throw an IllegalArgumentException.
74 | *
75 | * @param pEnv JNI environment
76 | * @param szFmt sprintf-style format string
77 | * @param ... sprintf-style args
78 | * @return 0 on success; a negative value on failure
79 | */
80 | jint throwIllegalArgumentException(JNIEnv *pEnv, const char *szFmt, ...) {
81 | va_list va_args;
82 | va_start(va_args, szFmt);
83 | jint ret = throwException(pEnv, "java/lang/IllegalArgumentException", szFmt, va_args);
84 | va_end(va_args);
85 | return ret;
86 | }
87 |
88 | /**
89 | * Instructs the JNI environment to throw an IllegalStateException.
90 | *
91 | * @param pEnv JNI environment
92 | * @param szFmt sprintf-style format string
93 | * @param ... sprintf-style args
94 | * @return 0 on success; a negative value on failure
95 | */
96 | jint throwIllegalStateException(JNIEnv *pEnv, const char *szFmt, ...) {
97 | va_list va_args;
98 | va_start(va_args, szFmt);
99 | jint ret = throwException(pEnv, "java/lang/IllegalStateException", szFmt, va_args);
100 | va_end(va_args);
101 | return ret;
102 | }
103 |
104 | /**
105 | * Instructs the JNI environment to throw an OutOfMemoryError.
106 | *
107 | * @param pEnv JNI environment
108 | * @param szFmt sprintf-style format string
109 | * @param ... sprintf-style args
110 | * @return 0 on success; a negative value on failure
111 | */
112 | jint throwOutOfMemoryError(JNIEnv *pEnv, const char *szFmt, ...) {
113 | va_list va_args;
114 | va_start(va_args, szFmt);
115 | jint ret = throwException(pEnv, "java/lang/OutOfMemoryError", szFmt, va_args);
116 | va_end(va_args);
117 | return ret;
118 | }
119 |
120 | /**
121 | * Instructs the JNI environment to throw an AssertionError.
122 | *
123 | * @param pEnv JNI environment
124 | * @param szFmt sprintf-style format string
125 | * @param ... sprintf-style args
126 | * @return 0 on success; a negative value on failure
127 | */
128 | jint throwAssertionError(JNIEnv *pEnv, const char *szFmt, ...) {
129 | va_list va_args;
130 | va_start(va_args, szFmt);
131 | jint ret = throwException(pEnv, "java/lang/AssertionError", szFmt, va_args);
132 | va_end(va_args);
133 | return ret;
134 | }
135 |
136 | /**
137 | * Instructs the JNI environment to throw an IOException.
138 | *
139 | * @param pEnv JNI environment
140 | * @param szFmt sprintf-style format string
141 | * @param ... sprintf-style args
142 | * @return 0 on success; a negative value on failure
143 | */
144 | jint throwIOException(JNIEnv *pEnv, const char *szFmt, ...) {
145 | va_list va_args;
146 | va_start(va_args, szFmt);
147 | jint ret = throwException(pEnv, "java/io/IOException", szFmt, va_args);
148 | va_end(va_args);
149 | return ret;
150 | }
151 |
152 | /**
153 | * Finds the specified class. If it's not found, instructs the JNI environment to throw an
154 | * exception.
155 | *
156 | * @param pEnv JNI environment
157 | * @param szClassName the classname to find in JNI format (e.g. "java/lang/String")
158 | * @return the class or NULL if not found (in which case a pending exception will be queued). This
159 | * returns a global reference (JNIEnv::NewGlobalRef).
160 | */
161 | jclass findClassOrThrow(JNIEnv *pEnv, const char *szClassName) {
162 | jclass clazz = pEnv->FindClass(szClassName);
163 | if (!clazz) {
164 | return NULL;
165 | }
166 | return (jclass) pEnv->NewGlobalRef(clazz);
167 | }
168 |
169 | /**
170 | * Finds the specified field of the specified class. If it's not found, instructs the JNI
171 | * environment to throw an exception.
172 | *
173 | * @param pEnv JNI environment
174 | * @param clazz the class to lookup the field in
175 | * @param szFieldName the name of the field to find
176 | * @param szSig the signature of the field
177 | * @return the field or NULL if not found (in which case a pending exception will be queued)
178 | */
179 | jfieldID getFieldIdOrThrow(JNIEnv *pEnv, jclass clazz, const char *szFieldName, const char *szSig) {
180 | return pEnv->GetFieldID(clazz, szFieldName, szSig);
181 | }
182 |
183 | /**
184 | * Finds the specified method of the specified class. If it's not found, instructs the JNI
185 | * environment to throw an exception.
186 | *
187 | * @param pEnv JNI environment
188 | * @param clazz the class to lookup the method in
189 | * @param szMethodName the name of the method to find
190 | * @param szSig the signature of the method
191 | * @return the method or NULL if not found (in which case a pending exception will be queued)
192 | */
193 | jmethodID getMethodIdOrThrow(
194 | JNIEnv *pEnv,
195 | jclass clazz,
196 | const char *szMethodName,
197 | const char *szSig) {
198 | return pEnv->GetMethodID(clazz, szMethodName, szSig);
199 | }
200 |
--------------------------------------------------------------------------------
/versions.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Roberto Leinardi.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * Shared file between builds so that they can all use the same dependencies and
19 | * maven repositories.
20 | **/
21 | ext.deps = [:]
22 | def versions = [:]
23 | versions.android_checkstyle_plugin = "1.0.0"
24 | versions.android_gradle_plugin = "3.1.0"
25 | versions.android_maven_gradle_plugin = "2.1"
26 | versions.androidthings = "0.7-devpreview"
27 | versions.apache_commons = "2.5"
28 | versions.arch = hasProperty("ARCH_VERSION") ? getProperty("ARCH_VERSION") : "1.0.0"
29 | versions.atsl_rules = "1.0.1"
30 | versions.atsl_runner = "1.0.1"
31 | versions.constraint_layout = "1.0.2"
32 | versions.dagger = "2.13"
33 | versions.dexmaker = "2.2.0"
34 | versions.espresso = "3.0.1"
35 | versions.glide = "3.8.0"
36 | versions.gradle_bintray_plugin = "1.8.0"
37 | versions.gradle_versions_plugin = "0.17.0"
38 | versions.hamcrest = "1.3"
39 | versions.joystick = "1.1.0"
40 | versions.junit = "4.12"
41 | versions.kotlin = "1.2"
42 | versions.mockito = "2.7.19"
43 | versions.mockito_all = "1.10.19"
44 | versions.mockwebserver = "3.8.1"
45 | versions.powermock = "1.6.6"
46 | versions.paging = "1.0.0-alpha3"
47 | versions.play_services = "11.6.2"
48 | versions.retrofit = "2.3.0"
49 | versions.rx_android = "2.0.1"
50 | versions.rxjava2 = "2.1.7"
51 | versions.support = "27.1.1"
52 | versions.timber = "4.6.0"
53 | ext.versions = versions
54 |
55 | def deps = [:]
56 |
57 | def support = [:]
58 | support.annotations = "com.android.support:support-annotations:$versions.support"
59 | support.app_compat = "com.android.support:appcompat-v7:$versions.support"
60 | support.cardview = "com.android.support:cardview-v7:$versions.support"
61 | support.core_utils = "com.android.support:support-core-utils:$versions.support"
62 | support.design = "com.android.support:design:$versions.support"
63 | support.fragment = "com.android.support:support-fragment:$versions.support"
64 | support.recyclerview = "com.android.support:recyclerview-v7:$versions.support"
65 | support.v4 = "com.android.support:support-v4:$versions.support"
66 | deps.support = support
67 |
68 | def room = [:]
69 | room.compiler = "android.arch.persistence.room:compiler:$versions.arch"
70 | room.runtime = "android.arch.persistence.room:runtime:$versions.arch"
71 | room.rxjava2 = "android.arch.persistence.room:rxjava2:$versions.arch"
72 | room.testing = "android.arch.persistence.room:testing:$versions.arch"
73 | deps.room = room
74 |
75 | def lifecycle = [:]
76 | lifecycle.compiler = "android.arch.lifecycle:compiler:$versions.arch"
77 | lifecycle.extensions = "android.arch.lifecycle:extensions:$versions.arch"
78 | lifecycle.java8 = "android.arch.lifecycle:common-java8:$versions.arch"
79 | lifecycle.runtime = "android.arch.lifecycle:runtime:$versions.arch"
80 | deps.lifecycle = lifecycle
81 |
82 | def arch_core = [:]
83 | arch_core.testing = "android.arch.core:core-testing:$versions.arch"
84 | deps.arch_core = arch_core
85 |
86 | def play_services = [:]
87 | play_services.googl_plus = "com.google.android.gms:play-services-plus:$versions.play_services"
88 | play_services.account_login = "com.google.android.gms:play-services-auth:$versions.play_services"
89 | play_services.actions_base_client_library = "com.google.android.gms:play-services-base:$versions.play_services"
90 | play_services.sign_in = "com.google.android.gms:play-services-identity:$versions.play_services"
91 | play_services.analytics = "com.google.android.gms:play-services-analytics:$versions.play_services"
92 | play_services.awareness = "com.google.android.gms:play-services-awareness:$versions.play_services"
93 | play_services.cast = "com.google.android.gms:play-services-cast:$versions.play_services"
94 | play_services.cloud_messaging = "com.google.android.gms:play-services-gcm:$versions.play_services"
95 | play_services.drive = "com.google.android.gms:play-services-drive:$versions.play_services"
96 | play_services.fit = "com.google.android.gms:play-services-fitness:$versions.play_services"
97 | play_services.location_and_activity_recognition = "com.google.android.gms:play-services-location:$versions.play_services"
98 | play_services.maps = "com.google.android.gms:play-services-maps:$versions.play_services"
99 | play_services.mobile_ads = "com.google.android.gms:play-services-ads:$versions.play_services"
100 | play_services.places = "com.google.android.gms:play-services-places:$versions.play_services"
101 | play_services.mobile_vision = "com.google.android.gms:play-services-vision:$versions.play_services"
102 | play_services.nearby = "com.google.android.gms:play-services-nearby:$versions.play_services"
103 | play_services.panorama_viewer = "com.google.android.gms:play-services-panorama:$versions.play_services"
104 | play_services.play_game_services = "com.google.android.gms:play-services-games:$versions.play_services"
105 | play_services.safety_net = "com.google.android.gms:play-services-safetynet:$versions.play_services"
106 | play_services.android_pay = "com.google.android.gms:play-services-wallet:$versions.play_services"
107 | play_services.android_wear = "com.google.android.gms:play-services-wearable:$versions.play_services"
108 | deps.play_services = play_services
109 |
110 | def retrofit = [:]
111 | retrofit.gson = "com.squareup.retrofit2:converter-gson:$versions.retrofit"
112 | retrofit.runtime = "com.squareup.retrofit2:retrofit:$versions.retrofit"
113 | deps.retrofit = retrofit
114 |
115 |
116 | def dagger = [:]
117 | dagger.android = "com.google.dagger:dagger-android:$versions.dagger"
118 | dagger.android_support = "com.google.dagger:dagger-android-support:$versions.dagger"
119 | dagger.android_support_compiler = "com.google.dagger:dagger-android-processor:$versions.dagger"
120 | dagger.compiler = "com.google.dagger:dagger-compiler:$versions.dagger"
121 | dagger.runtime = "com.google.dagger:dagger:$versions.dagger"
122 |
123 | deps.dagger = dagger
124 |
125 | def espresso = [:]
126 | espresso.core = "com.android.support.test.espresso:espresso-core:$versions.espresso"
127 | espresso.contrib = "com.android.support.test.espresso:espresso-contrib:$versions.espresso"
128 | espresso.intents = "com.android.support.test.espresso:espresso-intents:$versions.espresso"
129 | deps.espresso = espresso
130 |
131 | def atsl = [:]
132 | atsl.runner = "com.android.support.test:runner:$versions.atsl_runner"
133 | atsl.rules = "com.android.support.test:rules:$versions.atsl_runner"
134 | deps.atsl = atsl
135 |
136 | def mockito = [:]
137 | mockito.core = "org.mockito:mockito-core:$versions.mockito"
138 | mockito.all = "org.mockito:mockito-all:$versions.mockito_all"
139 | deps.mockito = mockito
140 |
141 | def powermock = [:]
142 | powermock.module_junit4 = "org.powermock:powermock-module-junit4:$versions.powermock"
143 | powermock.api_mockito = "org.powermock:powermock-api-mockito:$versions.powermock"
144 | deps.powermock = powermock
145 |
146 | def kotlin = [:]
147 | kotlin.stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jre7:$versions.kotlin"
148 | kotlin.test = "org.jetbrains.kotlin:kotlin-test-junit:$versions.kotlin"
149 | kotlin.plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
150 | deps.kotlin = kotlin
151 |
152 | deps.android_checkstyle_plugin = "com.leinardi.android:android-checkstyle-plugin:$versions.android_checkstyle_plugin"
153 | deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin"
154 | deps.android_maven_gradle_plugin = "com.github.dcendents:android-maven-gradle-plugin:$versions.android_maven_gradle_plugin"
155 | deps.androidthings = "com.google.android.things:androidthings:$versions.androidthings"
156 | deps.constraint_layout = "com.android.support.constraint:constraint-layout:$versions.constraint_layout"
157 | deps.dexmaker = "com.linkedin.dexmaker:dexmaker-mockito:$versions.dexmaker"
158 | deps.glide = "com.github.bumptech.glide:glide:$versions.glide"
159 | deps.gradle_bintray_plugin = "com.jfrog.bintray.gradle:gradle-bintray-plugin:$versions.gradle_bintray_plugin"
160 | deps.gradle_versions_plugin = "com.github.ben-manes:gradle-versions-plugin:$versions.gradle_versions_plugin"
161 | deps.hamcrest = "org.hamcrest:hamcrest-all:$versions.hamcrest"
162 | deps.joystick = "com.github.erz05:JoyStick:$versions.joystick"
163 | deps.junit = "junit:junit:$versions.junit"
164 | deps.mock_web_server = "com.squareup.okhttp3:mockwebserver:$versions.mockwebserver"
165 | deps.paging = "android.arch.paging:runtime:$versions.paging"
166 | deps.rx_android = "io.reactivex.rxjava2:rxandroid:$versions.rx_android"
167 | deps.rxjava2 = "io.reactivex.rxjava2:rxjava:$versions.rxjava2"
168 | deps.timber = "com.jakewharton.timber:timber:$versions.timber"
169 | ext.deps = deps
170 |
171 | def build_versions = [:]
172 | build_versions.min_sdk = 24
173 | build_versions.target_sdk = 27
174 | build_versions.build_tools = "27.0.3"
175 | build_versions.java_version = JavaVersion.VERSION_1_7
176 | build_versions.version_code = 'git rev-list --count HEAD'.execute().text.trim() as int
177 | ext.build_versions = build_versions
178 |
179 |
180 | def addRepos(RepositoryHandler handler) {
181 | handler.google()
182 | handler.jcenter()
183 | handler.mavenCentral()
184 | // handler.maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
185 | }
186 |
187 | ext.addRepos = this.&addRepos
188 |
--------------------------------------------------------------------------------
/.idea/codeStyleSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
254 |
255 |
256 |
--------------------------------------------------------------------------------
/config/checkstyle/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2014 The Android Open Source Project
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------