├── adc ├── .gitignore ├── gradle.properties ├── src │ ├── main │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── adc │ │ ├── mcp300x │ │ └── Mcp300xTest.java │ │ └── ads1xxx │ │ └── Ads1xxxTest.java ├── CHANGELOG.md ├── proguard-rules.pro ├── build.gradle └── README.md ├── bmx280 ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── src │ └── main │ │ └── AndroidManifest.xml └── build.gradle ├── tm1637 ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── tm1637 │ │ │ ├── Font.java │ │ │ └── Tm1637.java │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── tm1637 │ │ └── TextUtilsMock.java ├── build.gradle └── README.md ├── rainbowhat ├── .gitignore ├── gradle.properties ├── src │ └── main │ │ └── AndroidManifest.xml ├── CHANGELOG.md └── build.gradle ├── sensehat ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── sensehat │ │ │ └── SenseHat.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── sensehat │ │ └── SenseHatDeviceTest.java ├── build.gradle └── README.md ├── ssd1306 ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── ssd1306 │ │ └── Ssd1306Test.java ├── build.gradle └── README.md ├── vcnl4200 ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── src │ └── main │ │ └── AndroidManifest.xml ├── proguard-rules.pro ├── build.gradle └── README.md ├── matrixkeypad ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── matrixkeypad │ │ │ └── MatrixKey.java │ ├── androidTest │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── matrixkeypad │ │ │ └── MatrixKeypadDriverInstrumentedTest.java │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── matrixkeypad │ │ └── MatrixKeypadTest.java └── build.gradle ├── testingutils ├── .gitignore ├── src │ └── main │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── thermalprinter ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── androidTest │ │ ├── res │ │ │ └── drawable-nodpi │ │ │ │ └── sample_icon.png │ │ └── AndroidManifest.xml │ └── main │ │ └── AndroidManifest.xml ├── proguard-rules.pro ├── build.gradle └── README.md ├── gps ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── gps │ │ │ └── GpsModuleCallback.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── gps │ │ ├── NmeaSampleData.java │ │ └── LoopbackUartDevice.java └── build.gradle ├── pwmservo ├── gradle.properties ├── CHANGELOG.md ├── src │ └── main │ │ └── AndroidManifest.xml ├── build.gradle └── README.md ├── apa102 ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── apa102 │ │ ├── BytesMatcherTest.java │ │ ├── BytesMatcher.java │ │ └── ColorMock.java ├── build.gradle └── README.md ├── pwmspeaker ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── pwmspeaker │ │ │ └── Speaker.java │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── pwmspeaker │ │ └── SpeakerTest.java ├── build.gradle └── README.md ├── .gitignore ├── cap1xxx ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ ├── cap1xxx │ │ │ └── BitwiseUtil.java │ │ │ └── cap12xx │ │ │ └── Cap12xx.java │ ├── androidTest │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── cap1xxx │ │ │ └── Cap1xxxInputDriverInstrumentedTest.java │ ├── sharedTest │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── cap1xxx │ │ │ └── ArrayFillingAnswer.java │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── cap1xxx │ │ ├── ArrayFillingAnswerTest.java │ │ └── BitwiseUtilTest.java └── build.gradle ├── mma7660fc ├── gradle.properties ├── CHANGELOG.md ├── src │ └── main │ │ └── AndroidManifest.xml └── build.gradle ├── zxgesturesensor ├── gradle.properties ├── CHANGELOG.md ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── zxgesturesensor │ │ ├── SimpleGestureDetector.java │ │ └── GestureDetector.java └── build.gradle ├── ht16k33 ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── ht16k33 │ │ └── TextUtilsMock.java ├── build.gradle └── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── motorhat ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── motorhat │ │ └── MotorHatTest.java ├── build.gradle └── README.md ├── button ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ └── AndroidManifest.xml │ ├── androidTest │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── button │ │ │ ├── ButtonInputDriverInstrumentedTest.java │ │ │ └── ButtonTestActivity.java │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── things │ │ └── contrib │ │ └── driver │ │ └── button │ │ ├── ViewConfigurationMock.java │ │ └── ButtonInputDriverTest.java ├── build.gradle └── README.md ├── lowpan ├── gradle.properties ├── CHANGELOG.md ├── src │ └── main │ │ └── AndroidManifest.xml ├── build.gradle └── README.md ├── voicehat ├── gradle.properties ├── CHANGELOG.md ├── src │ ├── main │ │ └── AndroidManifest.xml │ └── androidTest │ │ ├── java │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── things │ │ │ └── contrib │ │ │ └── driver │ │ │ └── voicehat │ │ │ ├── InstrumentationTestUtils.java │ │ │ └── Max98357AInstrumentationTest.java │ │ └── AndroidManifest.xml └── build.gradle ├── settings.gradle ├── CONTRIBUTING.md └── gradlew.bat /adc/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /bmx280/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /tm1637/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /rainbowhat/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sensehat/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ssd1306/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /vcnl4200/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /matrixkeypad/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /testingutils/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /thermalprinter/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /gps/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="GPS" 2 | ARTIFACT_VERSION=1.1 3 | -------------------------------------------------------------------------------- /pwmservo/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="PWM servo" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /apa102/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="RGB LED strip" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /ssd1306/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="OLED display" 2 | ARTIFACT_VERSION=1.1 3 | -------------------------------------------------------------------------------- /pwmspeaker/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="PWM speaker/buzzer" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | local.properties 4 | .idea 5 | .DS_Store 6 | build 7 | -------------------------------------------------------------------------------- /cap1xxx/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="capacitive touch buttons" 2 | ARTIFACT_VERSION=2.0 3 | -------------------------------------------------------------------------------- /mma7660fc/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="accelerometer sensor" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /zxgesturesensor/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="zx gesture sensor" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /sensehat/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="metadriver for the Sense HAT" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /tm1637/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="4-digit numeric segment display" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /ht16k33/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="7-digit alphanumeric segment display" 2 | ARTIFACT_VERSION=1.1 3 | -------------------------------------------------------------------------------- /matrixkeypad/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="driver for generic matrix keypads" 2 | ARTIFACT_VERSION=1.0 -------------------------------------------------------------------------------- /thermalprinter/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="Driver for a thermal printer" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /bmx280/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="temperature, pressure and humidity sensor" 2 | ARTIFACT_VERSION=1.0 3 | -------------------------------------------------------------------------------- /vcnl4200/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="proximity and ambient light sensor" 2 | ARTIFACT_VERSION=1.0 3 | SAMPLE= 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidthings/contrib-drivers/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /motorhat/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="DC Motor HAT" 2 | ARTIFACT_VERSION=1.0 3 | SAMPLE="https://github.com/androidthings/robocar" 4 | -------------------------------------------------------------------------------- /button/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="push button over GPIO" 2 | ARTIFACT_VERSION=1.0 3 | SAMPLE="https://github.com/androidthings/sample-button" 4 | -------------------------------------------------------------------------------- /lowpan/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="LoWPAN support over UART" 2 | ARTIFACT_VERSION=1.0 3 | SAMPLE="https://github.com/androidthings/sample-lowpan" 4 | -------------------------------------------------------------------------------- /voicehat/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="driver for VoiceHat" 2 | ARTIFACT_VERSION=1.1 3 | SAMPLE="https://github.com/androidthings/sample-googleassistant" 4 | -------------------------------------------------------------------------------- /rainbowhat/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="metadriver for the Rainbow HAT" 2 | SAMPLE="https://github.com/androidthings/weatherstation" 3 | ARTIFACT_VERSION=1.1 4 | -------------------------------------------------------------------------------- /thermalprinter/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.0] - 2018-08-02 4 | - Makes `PrinterJob` public 5 | 6 | ## [0.1] - 2018-04-03 7 | - Initial version -------------------------------------------------------------------------------- /adc/gradle.properties: -------------------------------------------------------------------------------- 1 | TYPE="Analog to Digital Converters" 2 | ARTIFACT_VERSION=2.1 3 | SAMPLE="https://github.com/androidthings/drivers-samples/tree/master/ads1015" 4 | -------------------------------------------------------------------------------- /thermalprinter/src/androidTest/res/drawable-nodpi/sample_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidthings/contrib-drivers/HEAD/thermalprinter/src/androidTest/res/drawable-nodpi/sample_icon.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Aug 29 13:06:01 PDT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /vcnl4200/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.3] - 2018-04-29 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.2] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.1] - 2017-10-05 17 | - initial version 18 | -------------------------------------------------------------------------------- /motorhat/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.3] - 2018-04-29 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.2] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.1] - 2017-11-27 17 | - initial version with support for DC motors 18 | -------------------------------------------------------------------------------- /lowpan/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.4] - 2018-04-12 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.3] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.2] - 2017-12-12 17 | - Update to DP6.1 18 | 19 | ## [0.1] - 2017-12-11 20 | - Initial version 21 | -------------------------------------------------------------------------------- /matrixkeypad/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.3] - 2018-04-05 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | - change InputDriver instantiation and emitted events 11 | 12 | ## [0.2] - 2018-02-09 13 | ### Updated 14 | - update to Android Things devpreview-0.7 15 | - change manager initialization syntax 16 | 17 | ## [0.1] - 2017-07-27 18 | - Initial version 19 | -------------------------------------------------------------------------------- /zxgesturesensor/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.3] - 2018-04-05 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | - change InputDriver instantiation and emitted events 11 | 12 | ## [0.2] - 2018-02-09 13 | ### Updated 14 | - update to Android Things devpreview-0.7 15 | - change manager initialization syntax 16 | 17 | ## [0.1] - 2017-06-28 18 | - initial version 19 | -------------------------------------------------------------------------------- /sensehat/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.4] - 2018-02-09 8 | ### Updated 9 | - update to Android Things devpreview-0.7 10 | - change manager initialization syntax 11 | 12 | ## [0.3] - 2017-08-03 13 | ### Updated 14 | - added required=false to uses-library on manifests 15 | 16 | ## [0.2] - 2017-05-09 17 | ### Updated 18 | - supportlibrary bumped to 0.4 19 | 20 | ## [0.1] - 2016-12-13 21 | - initial version 22 | -------------------------------------------------------------------------------- /pwmservo/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.5] - 2018-04-29 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.4] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.3] - 2017-08-03 17 | ### Updated 18 | - added required=false to uses-library on manifests 19 | 20 | ## [0.2] - 2017-05-09 21 | ### Updated 22 | - supportlibrary bumped to 0.4 23 | 24 | ## [0.1] - 2016-12-13 25 | - initial version 26 | -------------------------------------------------------------------------------- /tm1637/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.5] - 2018-04-29 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.4] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.3] - 2017-08-03 17 | ### Updated 18 | - added required=false to uses-library on manifests 19 | 20 | ## [0.2] - 2017-05-09 21 | ### Updated 22 | - supportlibrary bumped to 0.4 23 | 24 | ## [0.1] - 2016-12-13 25 | - initial version 26 | -------------------------------------------------------------------------------- /mma7660fc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.5] - 2018-04-29 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.4] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.3] - 2017-08-03 17 | ### Updated 18 | - added required=false to uses-library on manifests 19 | 20 | ## [0.2] - 2017-05-09 21 | ### Updated 22 | - supportlibrary bumped to 0.4 23 | 24 | ## [0.1] - 2016-12-13 25 | - initial version 26 | -------------------------------------------------------------------------------- /pwmspeaker/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.5] - 2018-04-29 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.4] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.3] - 2017-08-03 17 | ### Updated 18 | - added required=false to uses-library on manifests 19 | 20 | ## [0.2] - 2017-05-09 21 | ### Updated 22 | - supportlibrary bumped to 0.4 23 | 24 | ## [0.1] - 2016-12-13 25 | - initial version 26 | -------------------------------------------------------------------------------- /apa102/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.7] - 2018-04-29 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.6] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.5] - 2017-08-03 17 | ### Updated 18 | - added required=false to uses-library on manifests 19 | 20 | ## [0.4] - 2017-06-16 21 | ### Fixed 22 | - fix framing packet (issue #31) 23 | 24 | ## [0.3] - 2017-05-09 25 | ### Updated 26 | - supportlibrary bumped to 0.4 27 | 28 | ## [0.2] - 2017-01-18 29 | ### Added 30 | - MAX_BRIGHTNESS 31 | - getBrightness() 32 | 33 | ## [0.1] - 2016-12-13 34 | - initial version 35 | -------------------------------------------------------------------------------- /bmx280/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.6] - 2018-04-29 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | 11 | ## [0.5] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.4] - 2017-08-03 17 | ### Added 18 | - Humidity support for the BME280 class of sensors 19 | ### Updated 20 | - added required=false to uses-library on manifests 21 | 22 | ## [0.3] - 2017-06-16 23 | ### Fixed 24 | - optional I2C address to driver constructor (issue #40) 25 | 26 | ## [0.2] - 2017-05-09 27 | ### Updated 28 | - supportlibrary bumped to 0.4 29 | 30 | ## [0.1] - 2016-12-13 31 | - initial version 32 | -------------------------------------------------------------------------------- /cap1xxx/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [2.0] - 2018-07-16 4 | ### Updated 5 | - renamed to Cap1xxx 6 | - deprecated Cap12xx artifact 7 | 8 | ## [1.0] - 2018-05-05 9 | ### Updated 10 | - update to Android Things 1.0 11 | 12 | ## [0.6] - 2018-04-05 13 | ### Updated 14 | - update to Android Things devpreview-0.8 15 | - change InputDriver instantiation and emitted events 16 | 17 | ## [0.5] - 2018-02-09 18 | ### Updated 19 | - update to Android Things devpreview-0.7 20 | - change manager initialization syntax 21 | 22 | ## [0.4] - 2017-08-03 23 | ### Updated 24 | - added required=false to uses-library on manifests 25 | 26 | ## [0.3] - 2017-05-09 27 | ### Updated 28 | - supportlibrary bumped to 0.4 29 | 30 | ## [0.2] - 2017-01-18 31 | 32 | ## [0.1] - 2016-12-13 33 | - initial version 34 | -------------------------------------------------------------------------------- /ht16k33/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.1] - 2018-05-30 4 | ### Updated 5 | - Added constants for individual segments for finer display control 6 | 7 | ## [1.0] - 2018-05-05 8 | ### Updated 9 | - update to Android Things 1.0 10 | 11 | ## [0.6] - 2018-04-03 12 | ### Updated 13 | - Added alternate constructors taking an I2C address 14 | 15 | ## [0.5] - 2018-02-09 16 | ### Updated 17 | - update to Android Things devpreview-0.7 18 | - change manager initialization syntax 19 | 20 | ## [0.4] - 2017-08-03 21 | ### Updated 22 | - added required=false to uses-library on manifests 23 | 24 | ## [0.3] - 2017-05-09 25 | ### Updated 26 | - supportlibrary bumped to 0.4 27 | 28 | ## [0.2] - 2017-01-18 29 | ### Added 30 | - dot can be in any position now 31 | 32 | ## [0.1] - 2016-12-13 33 | - initial version 34 | -------------------------------------------------------------------------------- /testingutils/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /gps/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.1] - 2018-06-19 4 | ### Fixed 5 | - Support partial GSV satellite messages 6 | 7 | ## [1.0] - 2018-05-05 8 | ### Updated 9 | - update to Android Things 1.0 10 | 11 | ## [0.6] - 2018-04-12 12 | ### Updated 13 | - update to Android Things devpreview-0.8 14 | - add callbacks for NMEA and status 15 | 16 | ## [0.5] - 2018-02-09 17 | ### Updated 18 | - update to Android Things devpreview-0.7 19 | - change manager initialization syntax 20 | 21 | ## [0.4] - 2017-08-03 22 | ### Updated 23 | - added required=false to uses-library on manifests 24 | 25 | ## [0.3] - 2017-05-09 26 | ### Updated 27 | - supportlibrary bumped to 0.4 28 | 29 | ## [0.2] - 2017-01-18 30 | ### Fixed 31 | - only parse data received from UART and exclude '0's from message buffer 32 | 33 | ## [0.1] - 2016-12-13 34 | - initial version 35 | -------------------------------------------------------------------------------- /button/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0] - 2018-05-05 4 | ### Updated 5 | - update to Android Things 1.0 6 | 7 | ## [0.7] - 2018-04-05 8 | ### Updated 9 | - update to Android Things devpreview-0.8 10 | - change InputDriver instantiation and emitted events 11 | 12 | ## [0.6] - 2018-02-09 13 | ### Updated 14 | - update to Android Things devpreview-0.7 15 | - change manager initialization syntax 16 | 17 | ## [0.5] - 2017-11-20 18 | - added `setDebounceDelay` to `ButtonInputDriver` 19 | 20 | ## [0.4] - 2017-08-03 21 | ### Updated 22 | - added required=false to uses-library on manifests 23 | 24 | ## [0.3] - 2017-05-09 25 | ### Updated 26 | - supportlibrary bumped to 0.4 27 | 28 | ## [0.2] - 2017-01-18 29 | ### Fixed 30 | - driver unregister was calling UserDriverManager.register instead of unregister 31 | 32 | ## [0.1] - 2016-12-13 33 | - initial version 34 | -------------------------------------------------------------------------------- /ssd1306/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.1] - 2018-06-07 4 | ### Updated 5 | - I2C address for I2C_ADDRESS_SA0_LOW and I2C_ADDRESS_SA0_HIGH 6 | 7 | ## [1.0] - 2018-05-05 8 | ### Updated 9 | - update to Android Things 1.0 10 | 11 | ## [0.7] - 2018-04-29 12 | ### Updated 13 | - update to Android Things devpreview-0.8 14 | 15 | ## [0.6] - 2018-02-09 16 | ### Updated 17 | - update to Android Things devpreview-0.7 18 | - change manager initialization syntax 19 | 20 | ## [0.5] - 2017-08-03 21 | ### Updated 22 | - added required=false to uses-library on manifests 23 | 24 | ## [0.4] - 2017-06-16 25 | ### Fixed 26 | - allow configurable width and height (issue #53) 27 | 28 | ## [0.3] - 2017-05-09 29 | ### Updated 30 | - supportlibrary bumped to 0.4 31 | 32 | ## [0.2] - 2017-01-18 33 | ### Added 34 | - I2C optional "address" parameter in driver constructor 35 | 36 | ## [0.1] - 2016-12-13 37 | - initial version 38 | -------------------------------------------------------------------------------- /matrixkeypad/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /adc/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /lowpan/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /thermalprinter/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /thermalprinter/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /gps/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /voicehat/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.1] - 2018-07-30 4 | ### Updated 5 | - update to add rpi3 b+ support 6 | 7 | ## [1.0] - 2018-05-05 8 | ### Updated 9 | - update to Android Things 1.0 10 | 11 | ## [0.7] - 2018-02-09 12 | ### Updated 13 | - update to Android Things devpreview-0.7 14 | - change manager initialization syntax 15 | 16 | ## [0.6] - 2017-12-11 17 | - republish using proper gradle to maven dependency graph conversion 18 | 19 | ## [0.5] - 2017-12-07 20 | - bundle transitive peripheral dependencies 21 | 22 | ## [0.4] - 2017-11-29 23 | - Removes `AudioDriver` registration from VoiceHat 24 | - Removes uses of `I2sDevice` 25 | - Adds static methods to access Max98357A DAC 26 | - Makes VoiceHat constructor private 27 | 28 | ## [0.3] - 2017-10-01 29 | - Adds support for LED and button 30 | - Refactors class 31 | - Adds class to directly interact with the audio chip 32 | 33 | ## [0.2] - 2017-08-28 34 | - Fix issue #69 35 | 36 | ## [0.1] - 2017-07-11 37 | - Initial version 38 | -------------------------------------------------------------------------------- /adc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [2.1] - 2018-08-14 4 | ### Updated 5 | - Fix logic to enable successive channel reads. 6 | 7 | ## [2.0] - 2018-08-01 8 | ### Added 9 | - New driver for MCP300x chip family 10 | - New driver for ADS1xxx chip family. Supersedes Adcv2x driver. 11 | ### Updated 12 | - Renamed package and artifact name to `adc` to include expanded chipset support. 13 | ### Removed 14 | - Deprecated Adcv2x driver 15 | 16 | ## [1.0] - 2018-05-05 17 | ### Updated 18 | - update to Android Things 1.0 19 | 20 | ## [0.5] - 2018-04-29 21 | ### Updated 22 | - update to Android Things devpreview-0.8 23 | 24 | ## [0.4] - 2018-02-09 25 | ### Updated 26 | - update to Android Things devpreview-0.7 27 | - change manager initialization syntax 28 | 29 | ## [0.3] - 2017-08-03 30 | ### Updated 31 | - added required=false to uses-library on manifests 32 | 33 | ## [0.2] - 2017-05-15 34 | ### Updated 35 | - support library bumped to 0.4 36 | 37 | ## [0.1] - 2017-05-13 38 | - initial version 39 | -------------------------------------------------------------------------------- /apa102/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /bmx280/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /button/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tm1637/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /vcnl4200/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /zxgesturesensor/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /cap1xxx/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ht16k33/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /mma7660fc/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /pwmservo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sensehat/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ssd1306/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /voicehat/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /pwmspeaker/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /rainbowhat/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /motorhat/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /adc/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/atripaldi/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /vcnl4200/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/prashanthsw/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /cap1xxx/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /thermalprinter/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/google/home/fleker/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /testingutils/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/google/home/mangini/tools/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /button/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /lowpan/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation 'com.android.support:support-annotations:27.1.0' 30 | compileOnly 'com.google.android.things:androidthings:1.0' 31 | } 32 | -------------------------------------------------------------------------------- /zxgesturesensor/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | } 32 | -------------------------------------------------------------------------------- /voicehat/src/androidTest/java/com/google/android/things/contrib/driver/voicehat/InstrumentationTestUtils.java: -------------------------------------------------------------------------------- 1 | package com.google.android.things.contrib.driver.voicehat; 2 | 3 | import android.media.AudioFormat; 4 | import android.os.Build; 5 | import junit.framework.Assert; 6 | 7 | /** 8 | * A collection of common methods across tests. 9 | */ 10 | public class InstrumentationTestUtils { 11 | /* package */ static final String VOICE_HAT_TRIGGER_GPIO_RPI = "BCM16"; 12 | /* package */ static final String VOICE_HAT_BUTTON_GPIO_RPI = "BCM23"; 13 | /* package */ static final String VOICE_HAT_LED_GPIO_RPI = "BCM25"; 14 | 15 | /* package */ static final AudioFormat AUDIO_FORMAT_STEREO = new AudioFormat.Builder() 16 | .setChannelMask(AudioFormat.CHANNEL_IN_STEREO) 17 | .setEncoding(AudioFormat.ENCODING_PCM_16BIT) 18 | .setSampleRate(16000) 19 | .build(); 20 | 21 | /* package */ static void assertRaspberryPiOnly() { 22 | // This test requires a Raspberry Pi to run 23 | Assert.assertTrue(Build.DEVICE.equals("rpi3") || Build.DEVICE.equals("rpi3bp")); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /matrixkeypad/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 ':adc' 18 | include ':apa102' 19 | include ':button' 20 | include ':bmx280' 21 | include ':cap1xxx' 22 | include ':gps' 23 | include ':ht16k33' 24 | include ':lowpan' 25 | include ':matrixkeypad' 26 | include ':mma7660fc' 27 | include ':motorhat' 28 | include ':pwmservo' 29 | include ':pwmspeaker' 30 | include ':tm1637' 31 | include ':ssd1306' 32 | include ':rainbowhat' 33 | include ':sensehat' 34 | include ':thermalprinter' 35 | include ':vcnl4200' 36 | include ':voicehat' 37 | include ':zxgesturesensor' 38 | 39 | include ':testingutils' 40 | -------------------------------------------------------------------------------- /ssd1306/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | 31 | testImplementation 'com.google.android.things:androidthings:1.0' 32 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 33 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 34 | } 35 | -------------------------------------------------------------------------------- /mma7660fc/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation 'com.google.android.things:androidthings:1.0' 33 | testImplementation 'junit:junit:4.12' 34 | testImplementation 'org.mockito:mockito-core:1.10.19' 35 | } 36 | -------------------------------------------------------------------------------- /pwmservo/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation 'com.google.android.things:androidthings:1.0' 33 | testImplementation 'junit:junit:4.12' 34 | testImplementation 'org.mockito:mockito-core:1.10.19' 35 | } 36 | -------------------------------------------------------------------------------- /pwmspeaker/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation 'com.google.android.things:androidthings:1.0' 33 | testImplementation 'junit:junit:4.12' 34 | testImplementation 'org.mockito:mockito-core:1.10.19' 35 | } 36 | -------------------------------------------------------------------------------- /adc/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation 'com.google.android.things:androidthings:1.0' 33 | testImplementation project(':testingutils') 34 | testImplementation 'junit:junit:4.12' 35 | testImplementation 'org.mockito:mockito-core:1.10.19' 36 | } 37 | -------------------------------------------------------------------------------- /bmx280/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation 'com.google.android.things:androidthings:1.0' 33 | testImplementation project(':testingutils') 34 | testImplementation 'junit:junit:4.12' 35 | testImplementation 'org.mockito:mockito-core:1.10.19' 36 | } 37 | -------------------------------------------------------------------------------- /sensehat/src/main/java/com/google/android/things/contrib/driver/sensehat/SenseHat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.sensehat; 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * Driver factory for the Sense Hat. 23 | */ 24 | @SuppressWarnings({"unused", "WeakerAccess"}) 25 | public class SenseHat { 26 | public static final int I2C_ADDRESS = 0x46; 27 | public static final String BUS_DISPLAY = "I2C1"; 28 | public static final int DISPLAY_WIDTH = LedMatrix.WIDTH; 29 | public static final int DISPLAY_HEIGHT = LedMatrix.HEIGHT; 30 | 31 | public static LedMatrix openDisplay() throws IOException { 32 | return new LedMatrix(BUS_DISPLAY); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /voicehat/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /cap1xxx/src/sharedTest/java/com/google/android/things/contrib/driver/cap1xxx/ArrayFillingAnswer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.cap1xxx; 17 | 18 | import org.mockito.invocation.InvocationOnMock; 19 | import org.mockito.stubbing.Answer; 20 | 21 | import java.util.Arrays; 22 | 23 | public class ArrayFillingAnswer implements Answer { 24 | private byte mValue; 25 | 26 | ArrayFillingAnswer(byte value) { 27 | mValue = value; 28 | } 29 | 30 | @Override 31 | public Void answer(InvocationOnMock invocation) throws Throwable { 32 | byte[] buffer = invocation.getArgumentAt(1, byte[].class); 33 | Arrays.fill(buffer, mValue); 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /rainbowhat/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.1] - 2018-07-30 4 | ### Updated 5 | - update to add rpi3 b+ support 6 | 7 | ## [1.0] - 2018-05-05 8 | ### Updated 9 | - update to Android Things 1.0 10 | 11 | ## [0.11] - 2018-04-29 12 | ### Updated 13 | - update to use latest drivers compatible with devpreview-0.8 14 | 15 | ## [0.10] - 2018-02-09 16 | ### Updated 17 | - update to Android Things devpreview-0.7 18 | - change manager initialization syntax 19 | 20 | ## [0.9] - 2017-12-18 21 | ### Updated 22 | - updates dependencies 23 | 24 | ## [0.8] - 2017-12-11 25 | ### Updated 26 | - republish using proper gradle to maven dependency graph conversion 27 | 28 | ## [0.7] - 2017-12-07 29 | ### Updated 30 | - bundle transitive peripheral dependencies 31 | 32 | ## [0.6] - 2017-12-06 33 | ### Updated 34 | - change PIO names for devpreview 0.6 35 | 36 | ## [0.5] - 2017-08-03 37 | ### Updated 38 | - added required=false to uses-library on manifests 39 | 40 | ## [0.4] - 2017-05-17 41 | ### Added 42 | - support for NXP IMX7UL Pico pinout 43 | - methods for direct led and button addressing 44 | 45 | ## [0.3] - 2017-05-13 46 | ### Updated 47 | - supportlibrary bumped to 0.4 48 | 49 | ## [0.2] - 2017-01-18 50 | ### Added 51 | - LEDSTRING_LENGTH constant 52 | 53 | ### Updated 54 | - createButtonInputDriver visibility to public 55 | 56 | ## [0.1] - 2016-12-13 57 | - initial version 58 | -------------------------------------------------------------------------------- /cap1xxx/src/androidTest/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxxInputDriverInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.cap1xxx; 17 | 18 | import android.support.test.rule.ActivityTestRule; 19 | 20 | import org.junit.Rule; 21 | import org.junit.Test; 22 | 23 | import java.io.IOException; 24 | 25 | public class Cap1xxxInputDriverInstrumentedTest { 26 | 27 | @Rule 28 | public ActivityTestRule mActivityRule 29 | = new ActivityTestRule<>(Cap1xxxTestActivity.class); 30 | 31 | @Test 32 | public void buttonDriverInjectsKeyEvents() throws IOException { 33 | Cap1xxxTestActivity activity = mActivityRule.getActivity(); 34 | activity.testKeyEvents(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /apa102/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation 'com.google.android.things:androidthings:1.0' 33 | testImplementation 'junit:junit:4.12' 34 | testImplementation 'org.mockito:mockito-core:1.10.19' 35 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 36 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 37 | } 38 | -------------------------------------------------------------------------------- /ht16k33/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation 'junit:junit:4.12' 33 | testImplementation 'com.google.android.things:androidthings:1.0' 34 | testImplementation 'org.mockito:mockito-core:1.10.19' 35 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 36 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 37 | } 38 | -------------------------------------------------------------------------------- /tm1637/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation 'com.google.android.things:androidthings:1.0' 33 | testImplementation 'junit:junit:4.12' 34 | testImplementation 'org.mockito:mockito-core:1.10.19' 35 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 36 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 37 | } 38 | -------------------------------------------------------------------------------- /gps/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | compileOnly 'com.google.android.things:androidthings:1.0' 32 | 33 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 34 | androidTestImplementation 'com.google.android.things:androidthings:1.0' 35 | androidTestImplementation 'junit:junit:4.12' 36 | androidTestImplementation 'org.mockito:mockito-android:2.7.15' 37 | } 38 | -------------------------------------------------------------------------------- /button/src/test/java/com/google/android/things/contrib/driver/button/ViewConfigurationMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.button; 17 | 18 | import android.view.ViewConfiguration; 19 | 20 | import org.mockito.Mockito; 21 | import org.mockito.invocation.InvocationOnMock; 22 | import org.mockito.stubbing.Answer; 23 | import org.powermock.api.mockito.PowerMockito; 24 | 25 | public class ViewConfigurationMock { 26 | 27 | public static void mockStatic() { 28 | PowerMockito.mockStatic(ViewConfiguration.class); 29 | Mockito.when(ViewConfiguration.getTapTimeout()).thenAnswer(new Answer() { 30 | @Override 31 | public Integer answer(InvocationOnMock invocation) throws Throwable { 32 | return 100; 33 | } 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sensehat/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation 'com.android.support:support-annotations:27.1.0' 30 | compileOnly 'com.google.android.things:androidthings:1.0' 31 | androidTestImplementation 'com.google.android.things:androidthings:1.0' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 33 | androidTestImplementation 'com.android.support.test:rules:1.0.1' 34 | } 35 | 36 | android { 37 | defaultConfig { 38 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /vcnl4200/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | testImplementation project(':testingutils') 33 | testImplementation 'com.google.android.things:androidthings:1.0' 34 | testImplementation 'junit:junit:4.12' 35 | testImplementation 'org.mockito:mockito-core:1.10.19' 36 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 37 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 38 | } 39 | -------------------------------------------------------------------------------- /matrixkeypad/src/main/java/com/google/android/things/contrib/driver/matrixkeypad/MatrixKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.matrixkeypad; 17 | 18 | /** 19 | * A small class which contains properties related to the properties of an individual 20 | * key on the matrix keypad. 21 | */ 22 | public class MatrixKey { 23 | private final int mKeyCode; 24 | private boolean mPressed; 25 | 26 | // A default private implementation to prevent construction. 27 | private MatrixKey() { mKeyCode = -1; } 28 | 29 | /* package */ MatrixKey(int keyCode) { 30 | this.mKeyCode = keyCode; 31 | } 32 | 33 | public int getKeyCode() { 34 | return mKeyCode; 35 | } 36 | 37 | public boolean isPressed() { 38 | return mPressed; 39 | } 40 | 41 | /* package */ void setPressed(boolean pressed) { 42 | mPressed = pressed; 43 | } 44 | } -------------------------------------------------------------------------------- /motorhat/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | apply plugin: 'com.android.library' 17 | 18 | android { 19 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 20 | 21 | defaultConfig { 22 | minSdkVersion DEFAULT_MIN_SDK_VERSION 23 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 24 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 25 | } 26 | } 27 | 28 | dependencies { 29 | compileOnly 'com.google.android.things:androidthings:1.0' 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | 32 | androidTestImplementation 'com.google.android.things:androidthings:1.0' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 34 | 35 | testImplementation 'com.google.android.things:androidthings:1.0' 36 | testImplementation 'junit:junit:4.12' 37 | testImplementation 'org.mockito:mockito-core:1.10.19' 38 | } 39 | -------------------------------------------------------------------------------- /apa102/src/test/java/com/google/android/things/contrib/driver/apa102/BytesMatcherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.apa102; 18 | 19 | import org.junit.Test; 20 | 21 | import java.io.IOException; 22 | 23 | import static junit.framework.Assert.assertFalse; 24 | import static junit.framework.Assert.assertTrue; 25 | 26 | public class BytesMatcherTest { 27 | @Test 28 | public void match() throws IOException { 29 | BytesMatcher bm = new BytesMatcher("foo".getBytes()); 30 | assertFalse(bm.matches("fo".getBytes())); 31 | assertTrue(bm.matches("foo".getBytes())); 32 | assertTrue(bm.matches("hopfoobar".getBytes())); 33 | assertFalse(bm.matches("noneofthose".getBytes())); 34 | } 35 | 36 | @Test 37 | public void matchEmpty() throws IOException { 38 | BytesMatcher bm = new BytesMatcher("".getBytes()); 39 | assertTrue(bm.matches("foo".getBytes())); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tm1637/src/test/java/com/google/android/things/contrib/driver/tm1637/TextUtilsMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | package com.google.android.things.contrib.driver.tm1637; 17 | 18 | import android.text.TextUtils; 19 | 20 | import org.mockito.Mockito; 21 | import org.mockito.invocation.InvocationOnMock; 22 | import org.mockito.stubbing.Answer; 23 | import org.powermock.api.mockito.PowerMockito; 24 | 25 | import static org.mockito.Matchers.any; 26 | 27 | public class TextUtilsMock { 28 | 29 | public static void mockStatic() { 30 | PowerMockito.mockStatic(TextUtils.class); 31 | Mockito.when(TextUtils.isEmpty(any(CharSequence.class))).thenAnswer(new Answer() { 32 | @Override 33 | public Boolean answer(InvocationOnMock invocation) throws Throwable { 34 | CharSequence cs = invocation.getArgumentAt(0, CharSequence.class); 35 | return cs == null || cs.length() < 1; 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ht16k33/src/test/java/com/google/android/things/contrib/driver/ht16k33/TextUtilsMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | package com.google.android.things.contrib.driver.ht16k33; 17 | 18 | import android.text.TextUtils; 19 | 20 | import org.mockito.Mockito; 21 | import org.mockito.invocation.InvocationOnMock; 22 | import org.mockito.stubbing.Answer; 23 | import org.powermock.api.mockito.PowerMockito; 24 | 25 | import static org.mockito.Matchers.any; 26 | 27 | public class TextUtilsMock { 28 | 29 | public static void mockStatic() { 30 | PowerMockito.mockStatic(TextUtils.class); 31 | Mockito.when(TextUtils.isEmpty(any(CharSequence.class))).thenAnswer(new Answer() { 32 | @Override 33 | public Boolean answer(InvocationOnMock invocation) throws Throwable { 34 | CharSequence cs = invocation.getArgumentAt(0, CharSequence.class); 35 | return cs == null || cs.length() < 1; 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /testingutils/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | 28 | buildTypes { 29 | release { 30 | minifyEnabled false 31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 32 | } 33 | } 34 | } 35 | 36 | dependencies { 37 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 38 | exclude group: 'com.android.support', module: 'support-annotations' 39 | }) 40 | 41 | implementation 'org.hamcrest:hamcrest-core:1.3' 42 | 43 | testImplementation 'com.google.android.things:androidthings:1.0' 44 | testImplementation 'junit:junit:4.12' 45 | } 46 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement (CLA). 9 | 10 | * If you are an individual writing original source code and you're sure you 11 | own the intellectual property, then you'll need to sign an 12 | [individual CLA](https://developers.google.com/open-source/cla/individual). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then you'll need to sign a 15 | [corporate CLA](https://developers.google.com/open-source/cla/corporate). 16 | 17 | Follow either of the two links above to access the appropriate CLA and 18 | instructions for how to sign and return it. Once we receive it, we'll be able to 19 | accept your pull requests. 20 | 21 | ## Contributing A Patch 22 | 23 | 1. Submit an issue describing your proposed change to the repo in question. 24 | 1. The repo owner will respond to your issue promptly. 25 | 1. If your proposed change is accepted, and you haven't already done so, sign a 26 | Contributor License Agreement (see details above). 27 | 1. Fork the desired repo, develop and test your code changes. 28 | 1. Ensure that your code adheres to the existing style in the sample to which 29 | you are contributing. Refer to the 30 | [Android Code Style Guide](https://source.android.com/source/code-style.html) 31 | for the recommended coding standards for this organization. 32 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 33 | 1. Submit a pull request. 34 | 35 | -------------------------------------------------------------------------------- /thermalprinter/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. 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 | 19 | android { 20 | compileSdkVersion 27 21 | 22 | defaultConfig { 23 | minSdkVersion 27 24 | targetSdkVersion 27 25 | versionCode 1 26 | versionName "1.0" 27 | 28 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 29 | 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation 'com.android.support:support-annotations:27.1.1' 35 | implementation 'com.google.android.things:androidthings:1.0' 36 | 37 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:+' 38 | androidTestImplementation 'org.mockito:mockito-core:2.8.9' 39 | androidTestImplementation 'com.google.dexmaker:dexmaker:1.2' 40 | androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2' 41 | 42 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 43 | testImplementation 'org.powermock:powermock-classloading-base:1.6.6' 44 | testImplementation 'org.powermock:powermock-classloading-xstream:1.6.6' 45 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 46 | } 47 | -------------------------------------------------------------------------------- /button/src/androidTest/java/com/google/android/things/contrib/driver/button/ButtonInputDriverInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.button; 17 | 18 | import android.support.test.rule.ActivityTestRule; 19 | import android.view.KeyEvent; 20 | 21 | import junit.framework.Assert; 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | 25 | import static junit.framework.Assert.assertEquals; 26 | 27 | public class ButtonInputDriverInstrumentedTest { 28 | 29 | @Rule 30 | public ActivityTestRule mActivityRule 31 | = new ActivityTestRule<>(ButtonTestActivity.class); 32 | 33 | @Test 34 | public void buttonDriverInjectsKeyEvents() throws InterruptedException { 35 | ButtonTestActivity activity = mActivityRule.getActivity(); 36 | 37 | activity.sendMockButtonEvent(true); // press 38 | KeyEvent event = activity.getNextKeyDownEvent(); 39 | assertEquals(ButtonTestActivity.KEYCODE, event.getKeyCode()); 40 | 41 | activity.sendMockButtonEvent(false); // release 42 | event = activity.getNextKeyUpEvent(); 43 | assertEquals(ButtonTestActivity.KEYCODE, event.getKeyCode()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /matrixkeypad/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | } 28 | 29 | dependencies { 30 | compileOnly 'com.google.android.things:androidthings:1.0' 31 | 32 | androidTestImplementation 'com.google.android.things:androidthings:1.0' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 34 | androidTestImplementation 'org.mockito:mockito-core:1.10.19' 35 | androidTestImplementation 'com.google.dexmaker:dexmaker:1.2' 36 | androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2' 37 | 38 | testImplementation 'com.google.android.things:androidthings:1.0' 39 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 40 | testImplementation 'org.powermock:powermock-classloading-base:1.6.6' 41 | testImplementation 'org.powermock:powermock-classloading-xstream:1.6.6' 42 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 43 | } 44 | -------------------------------------------------------------------------------- /button/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | compileOnly 'com.google.android.things:androidthings:1.0' 32 | 33 | androidTestImplementation 'com.google.android.things:androidthings:1.0' 34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 35 | androidTestImplementation 'org.mockito:mockito-core:1.10.19' 36 | androidTestImplementation 'com.google.dexmaker:dexmaker:1.2' 37 | androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2' 38 | 39 | testImplementation 'com.google.android.things:androidthings:1.0' 40 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 41 | testImplementation 'org.powermock:powermock-classloading-base:1.6.6' 42 | testImplementation 'org.powermock:powermock-classloading-xstream:1.6.6' 43 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 44 | } 45 | -------------------------------------------------------------------------------- /gps/src/main/java/com/google/android/things/contrib/driver/gps/GpsModuleCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.gps; 18 | 19 | import android.location.GnssStatus; 20 | import android.location.Location; 21 | 22 | /** 23 | * Callback invoked when new data is emitted from a 24 | * GPS module. 25 | */ 26 | public abstract class GpsModuleCallback { 27 | /** 28 | * Callback reporting GPS satellite status. 29 | * 30 | * @param status Latest status information from GPS module. 31 | */ 32 | public abstract void onGpsSatelliteStatus(GnssStatus status); 33 | 34 | /** 35 | * Callback reporting an updated date/time from 36 | * the GPS satellite. 37 | * 38 | * @param timestamp Last received timestamp from GPS. 39 | */ 40 | public abstract void onGpsTimeUpdate(long timestamp); 41 | 42 | /** 43 | * Callback reporting a location fix from the GPS module. 44 | * 45 | * @param location Latest location update. 46 | */ 47 | public abstract void onGpsLocationUpdate(Location location); 48 | 49 | /** 50 | * Callback reporting raw NMEA sentences from the GPS module. 51 | * 52 | * @param nmeaMessage NMEA message data. 53 | */ 54 | public abstract void onNmeaMessage(String nmeaMessage); 55 | } 56 | -------------------------------------------------------------------------------- /rainbowhat/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | } 28 | 29 | dependencies { 30 | compileOnly 'com.google.android.things:androidthings:1.0' 31 | api 'com.google.android.things.contrib:driver-apa102:1.0' 32 | api 'com.google.android.things.contrib:driver-button:1.0' 33 | api 'com.google.android.things.contrib:driver-bmx280:1.0' 34 | api 'com.google.android.things.contrib:driver-ht16k33:1.0' 35 | api 'com.google.android.things.contrib:driver-pwmspeaker:1.0' 36 | api 'com.google.android.things.contrib:driver-pwmservo:1.0' 37 | 38 | androidTestImplementation 'com.google.android.things:androidthings:1.0' 39 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 40 | androidTestImplementation 'org.mockito:mockito-core:1.10.19' 41 | androidTestImplementation 'com.google.dexmaker:dexmaker:1.2' 42 | androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2' 43 | androidTestImplementation 'junit:junit:4.12' 44 | } 45 | -------------------------------------------------------------------------------- /cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/BitwiseUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.cap1xxx; 18 | 19 | /** 20 | * Collection of helpers for bitwise operations 21 | */ 22 | class BitwiseUtil { 23 | 24 | /** 25 | * Set a bit in the provided value at the given index. 26 | * @return the updated value. 27 | */ 28 | static byte setBit(byte value, int bitIndex) { 29 | return (byte)((value | (1 << bitIndex)) & 0xFF); 30 | } 31 | 32 | /** 33 | * Clear a bit in the provided value at the given index. 34 | * @return the updated value. 35 | */ 36 | static byte clearBit(byte value, int bitIndex) { 37 | return (byte)((value & ~(1 << bitIndex)) & 0xFF); 38 | } 39 | 40 | /** 41 | * Return true if the provided bit index is set in the given value. 42 | */ 43 | static boolean isBitSet(byte value, int bitIndex) { 44 | return ((value & (1 << bitIndex)) & 0xFF) != 0; 45 | } 46 | 47 | /** 48 | * Mask the bits of the provided value into base, according to 49 | * the provided bitmask and return the updated value. 50 | */ 51 | static byte applyBitRange(byte base, int value, int bitmask) { 52 | return (byte) (base & ~bitmask | (value & bitmask)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /apa102/src/test/java/com/google/android/things/contrib/driver/apa102/BytesMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.apa102; 18 | 19 | import org.hamcrest.BaseMatcher; 20 | import org.hamcrest.Description; 21 | 22 | import java.util.Arrays; 23 | 24 | public class BytesMatcher extends BaseMatcher { 25 | private byte[] mExpectedBytes; 26 | 27 | BytesMatcher(byte[] expectedBytes) { 28 | mExpectedBytes = expectedBytes; 29 | } 30 | 31 | public static BytesMatcher contains(byte... expectedBytes) { 32 | return new BytesMatcher(expectedBytes); 33 | } 34 | 35 | @Override 36 | public void describeTo(Description description) { 37 | description.appendText(Arrays.toString(mExpectedBytes)); 38 | } 39 | 40 | @Override 41 | public boolean matches(Object item) { 42 | byte[] spiData = (byte[]) item; 43 | for (int i = 0; i < spiData.length - mExpectedBytes.length + 1; i++) { 44 | int j; 45 | for (j = 0; j < mExpectedBytes.length; j++) { 46 | if (spiData[i+j] != mExpectedBytes[j]) { 47 | break; 48 | } 49 | } 50 | if (j == mExpectedBytes.length) { 51 | return true; 52 | } 53 | } 54 | return false; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /voicehat/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation 'com.android.support:support-annotations:27.1.0' 31 | compileOnly 'com.google.android.things:androidthings:1.0' 32 | api 'com.google.android.things.contrib:driver-button:1.0' 33 | 34 | androidTestImplementation 'com.google.android.things:androidthings:1.0' 35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 36 | androidTestImplementation 'org.mockito:mockito-core:1.10.19' 37 | androidTestImplementation 'com.google.dexmaker:dexmaker:1.2' 38 | androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2' 39 | 40 | testImplementation 'com.google.android.things:androidthings:1.0' 41 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 42 | testImplementation 'org.powermock:powermock-classloading-base:1.6.6' 43 | testImplementation 'org.powermock:powermock-classloading-xstream:1.6.6' 44 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 45 | } 46 | -------------------------------------------------------------------------------- /vcnl4200/README.md: -------------------------------------------------------------------------------- 1 | Android Things driver for VCNL4200 proximity sensor and ambient light sensor 2 | =================================== 3 | 4 | This driver provides support for VCNL4200, a module that serves as both a high-sensitivity 5 | long distance proximity sensor and an ambient light sensor. The module datasheet 6 | is available at https://www.vishay.com/docs/84430/vcnl4200.pdf 7 | 8 | NOTE: these drivers are not production-ready. They are offered as sample 9 | implementations of Android Things user space drivers for common peripherals 10 | as part of the Developer Preview release. There is no guarantee 11 | of correctness, completeness or robustness. 12 | 13 | How to use the driver 14 | --------------------- 15 | 16 | ### Gradle dependency 17 | 18 | To use the `vcnl4200` driver, simply add the line below to your project's `build.gradle`, 19 | where `` matches the last version of the driver available on [jcenter][jcenter]. 20 | 21 | ``` 22 | dependencies { 23 | compile 'com.google.android.things.contrib:driver-vcnl4200:' 24 | } 25 | ``` 26 | 27 | ### Sample usage 28 | 29 | [TBD] 30 | 31 | 32 | License 33 | ------- 34 | 35 | Copyright 2017 Google Inc. 36 | 37 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 38 | license agreements. See the NOTICE file distributed with this work for 39 | additional information regarding copyright ownership. The ASF licenses this 40 | file to you under the Apache License, Version 2.0 (the "License"); you may not 41 | use this file except in compliance with the License. You may obtain a copy of 42 | the License at 43 | 44 | http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | Unless required by applicable law or agreed to in writing, software 47 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 48 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 49 | License for the specific language governing permissions and limitations under 50 | the License. 51 | 52 | [product]: https://www.adafruit.com/product/2348 53 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-vcnl4200/_latestVersion 54 | -------------------------------------------------------------------------------- /button/src/test/java/com/google/android/things/contrib/driver/button/ButtonInputDriverTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.button; 17 | 18 | import org.junit.Rule; 19 | import org.junit.Test; 20 | import org.junit.rules.ExpectedException; 21 | import org.mockito.Mock; 22 | import org.mockito.Mockito; 23 | import org.mockito.junit.MockitoJUnit; 24 | import org.mockito.junit.MockitoRule; 25 | 26 | import java.io.IOException; 27 | 28 | import static org.mockito.Mockito.times; 29 | 30 | public class ButtonInputDriverTest { 31 | 32 | @Mock 33 | Button mButton; 34 | 35 | @Rule 36 | public MockitoRule mMockitoRule = MockitoJUnit.rule(); 37 | 38 | @Rule 39 | public ExpectedException mExpectedException = ExpectedException.none(); 40 | 41 | @Test 42 | public void close() throws IOException { 43 | ButtonInputDriver driver = new ButtonInputDriver(mButton, 0); 44 | driver.close(); 45 | Mockito.verify(mButton).close(); 46 | } 47 | 48 | @Test 49 | public void close_safeToCallTwice() throws IOException { 50 | ButtonInputDriver driver = new ButtonInputDriver(mButton, 0); 51 | driver.close(); 52 | driver.close(); // should not throw 53 | Mockito.verify(mButton, times(1)).close(); 54 | } 55 | 56 | @Test 57 | public void register_throwsIfClosed() throws IOException { 58 | ButtonInputDriver driver = new ButtonInputDriver(mButton, 0); 59 | driver.close(); 60 | mExpectedException.expect(IllegalStateException.class); 61 | driver.register(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /cap1xxx/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | 19 | android { 20 | compileSdkVersion DEFAULT_COMPILE_SDK_VERSION 21 | 22 | defaultConfig { 23 | minSdkVersion DEFAULT_MIN_SDK_VERSION 24 | targetSdkVersion DEFAULT_TARGET_SDK_VERSION 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | 28 | testOptions { 29 | unitTests.returnDefaultValues = true 30 | } 31 | 32 | sourceSets { 33 | String sharedTestDir = 'src/sharedTest/java' 34 | test { 35 | java.srcDir sharedTestDir 36 | } 37 | androidTest { 38 | java.srcDir sharedTestDir 39 | } 40 | } 41 | } 42 | 43 | dependencies { 44 | implementation 'com.android.support:support-annotations:27.1.0' 45 | compileOnly 'com.google.android.things:androidthings:1.0' 46 | 47 | testImplementation project(':testingutils') 48 | testImplementation 'com.google.android.things:androidthings:1.0' 49 | testImplementation 'org.powermock:powermock-module-junit4:1.6.6' 50 | testImplementation 'org.powermock:powermock-classloading-base:1.6.6' 51 | testImplementation 'org.powermock:powermock-classloading-xstream:1.6.6' 52 | testImplementation 'org.powermock:powermock-api-mockito:1.6.6' 53 | 54 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 55 | exclude group: 'com.android.support', module: 'support-annotations' 56 | }) 57 | androidTestImplementation 'com.google.android.things:androidthings:1.0' 58 | androidTestImplementation 'org.mockito:mockito-core:1.10.19' 59 | androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2' 60 | } 61 | -------------------------------------------------------------------------------- /tm1637/src/main/java/com/google/android/things/contrib/driver/tm1637/Font.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | // Font data from https://github.com/intel-iot-devkit/upm/blob/master/src/tm1637 18 | /* 19 | * Author: Mihai Tudor Panu 20 | * Copyright (c) 2015 Intel Corporation. 21 | * 22 | * Permission is hereby granted, free of charge, to any person obtaining 23 | * a copy of this software and associated documentation files (the 24 | * "Software"), to deal in the Software without restriction, including 25 | * without limitation the rights to use, copy, modify, merge, publish, 26 | * distribute, sublicense, and/or sell copies of the Software, and to 27 | * permit persons to whom the Software is furnished to do so, subject to 28 | * the following conditions: 29 | * 30 | * The above copyright notice and this permission notice shall be 31 | * included in all copies or substantial portions of the Software. 32 | * 33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 34 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 35 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 36 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 37 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 38 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 39 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | 42 | package com.google.android.things.contrib.driver.tm1637; 43 | 44 | class Font { 45 | static final byte DATA[] = 46 | {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; 47 | static final byte COLON = (byte) 0x80; 48 | static final byte HYPHEN = (byte) 0x40; 49 | } 50 | -------------------------------------------------------------------------------- /adc/src/test/java/com/google/android/things/contrib/driver/adc/mcp300x/Mcp300xTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. 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.google.android.things.contrib.driver.adc.mcp300x; 18 | 19 | import org.junit.Test; 20 | 21 | import java.io.IOException; 22 | 23 | import static junit.framework.Assert.assertEquals; 24 | 25 | public class Mcp300xTest { 26 | 27 | @Test 28 | public void readSingle_returnsCorrectValue() throws IOException { 29 | Mcp3008Device mockDevice = new Mcp3008Device(); 30 | mockDevice.setChannelValues(0, 256, 512, 1023); 31 | Mcp300x driver = new Mcp300x(mockDevice, Mcp300x.Configuration.MCP3008); 32 | 33 | int result = driver.readSingleEndedInput(0); 34 | assertEquals("Channel 0 should return 0", 0, result); 35 | result = driver.readSingleEndedInput(1); 36 | assertEquals("Channel 1 should return 256", 256, result); 37 | result = driver.readSingleEndedInput(2); 38 | assertEquals("Channel 2 should return 512", 512, result); 39 | result = driver.readSingleEndedInput(3); 40 | assertEquals("Channel 3 should return 1023", 1023, result); 41 | } 42 | 43 | @Test 44 | public void readDifferential_returnsCorrectValue() throws IOException { 45 | Mcp3008Device mockDevice = new Mcp3008Device(); 46 | mockDevice.setChannelValues(512, 256); 47 | Mcp300x driver = new Mcp300x(mockDevice, Mcp300x.Configuration.MCP3008); 48 | 49 | int result = driver.readDifferentialInput(Mcp300x.MODE_DIFF_0P_1N); 50 | assertEquals("Normal differential should return 256", 256, result); 51 | result = driver.readDifferentialInput(Mcp300x.MODE_DIFF_1P_0N); 52 | assertEquals("Inverted differential should return 0", 0, result); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /voicehat/src/androidTest/java/com/google/android/things/contrib/driver/voicehat/Max98357AInstrumentationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.voicehat; 18 | 19 | 20 | import android.support.test.filters.SmallTest; 21 | import android.support.test.runner.AndroidJUnit4; 22 | import java.io.IOException; 23 | import junit.framework.Assert; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | 28 | @RunWith(AndroidJUnit4.class) 29 | @SmallTest 30 | public class Max98357AInstrumentationTest { 31 | 32 | @Before 33 | public void createVoiceHat() throws IOException { 34 | InstrumentationTestUtils.assertRaspberryPiOnly(); 35 | } 36 | 37 | /** 38 | * Verify the existence of particular pins when the chip is constructed through the VoiceHat 39 | * driver. This means that {@code NOT_SD_MODE} exists, but {@code GAIN_SLOT} is {@code null}. 40 | * @throws IOException 41 | */ 42 | @Test 43 | public void testDefaultConstructor() throws IOException { 44 | Max98357A dac = VoiceHat.openDac(InstrumentationTestUtils.VOICE_HAT_TRIGGER_GPIO_RPI); 45 | Assert.assertNotNull(dac.getNotSdModePin()); 46 | Assert.assertNull(dac.getGainSlotPin()); 47 | } 48 | 49 | /** 50 | * Verify the functionality of this device when interfaced with directly instead of through the 51 | * VoiceHat. 52 | */ 53 | @Test 54 | public void testCustomInterface() throws Exception { 55 | Max98357A dac = new Max98357A(InstrumentationTestUtils.VOICE_HAT_BUTTON_GPIO_RPI, 56 | InstrumentationTestUtils.VOICE_HAT_LED_GPIO_RPI); 57 | Assert.assertNotNull(dac.getNotSdModePin()); 58 | Assert.assertNotNull(dac.getGainSlotPin()); 59 | dac.close(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /matrixkeypad/src/androidTest/java/com/google/android/things/contrib/driver/matrixkeypad/MatrixKeypadDriverInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.matrixkeypad; 17 | 18 | import static junit.framework.Assert.assertEquals; 19 | import static junit.framework.Assert.assertNotNull; 20 | 21 | import android.content.pm.PackageManager; 22 | import android.support.test.rule.ActivityTestRule; 23 | import android.view.KeyEvent; 24 | import org.junit.Rule; 25 | import org.junit.Test; 26 | 27 | public class MatrixKeypadDriverInstrumentedTest { 28 | 29 | @Rule 30 | public ActivityTestRule mActivityRule 31 | = new ActivityTestRule<>(MatrixKeypadActivity.class); 32 | 33 | @Test 34 | public void checkPermissionsGranted() { 35 | String MANAGE_INPUT_DRIVERS = "com.google.android.things.permission.MANAGE_INPUT_DRIVERS"; 36 | MatrixKeypadActivity activity = mActivityRule.getActivity(); 37 | 38 | assertEquals(PackageManager.PERMISSION_GRANTED, 39 | activity.checkSelfPermission(MANAGE_INPUT_DRIVERS)); 40 | } 41 | 42 | @Test 43 | public void keypadDriverInjectsKeyEvents() throws InterruptedException { 44 | MatrixKeypadActivity activity = mActivityRule.getActivity(); 45 | 46 | activity.sendMockKeyEvent(MatrixKeypadActivity.mKeyCodes[0], true); // press 47 | KeyEvent event = activity.getNextKeyDownEvent(); 48 | assertNotNull(event); 49 | assertEquals(MatrixKeypadActivity.mKeyCodes[0], event.getKeyCode()); 50 | 51 | activity.sendMockKeyEvent(MatrixKeypadActivity.mKeyCodes[0], false); // release 52 | event = activity.getNextKeyUpEvent(); 53 | assertNotNull(event); 54 | assertEquals(MatrixKeypadActivity.mKeyCodes[0], event.getKeyCode()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /apa102/README.md: -------------------------------------------------------------------------------- 1 | APA102 LED driver for Android Things 2 | ==================================== 3 | 4 | This driver supports RGB LED peripherals built on the APA102 SPI protocol. 5 | 6 | NOTE: these drivers are not production-ready. They are offered as sample 7 | implementations of Android Things user space drivers for common peripherals 8 | as part of the Developer Preview release. There is no guarantee 9 | of correctness, completeness or robustness. 10 | 11 | How to use the driver 12 | --------------------- 13 | 14 | ### Gradle dependency 15 | 16 | To use the `apa102` driver, simply add the line below to your project's `build.gradle`, 17 | where `` matches the last version of the driver available on [jcenter][jcenter]. 18 | 19 | ``` 20 | dependencies { 21 | compile 'com.google.android.things.contrib:driver-apa102:' 22 | } 23 | ``` 24 | 25 | ### Sample usage 26 | 27 | ```java 28 | import com.google.android.things.contrib.driver.apa102.Apa102; 29 | 30 | // Access the LED strip: 31 | 32 | Apa102 mApa102; 33 | 34 | try { 35 | mApa102 = new Apa102(spiBusName, Apa102.Mode.BGR); 36 | } catch (IOException e) { 37 | // couldn't configure the device... 38 | } 39 | 40 | // Light it up! 41 | 42 | int[] colors = new int[] {Color.RED, Color.GREEN, Color.BLUE}; 43 | try { 44 | mApa102.write(colors); 45 | } catch (IOException e) { 46 | // error setting LEDs 47 | } 48 | 49 | // Close the LED strip when finished: 50 | 51 | try { 52 | mApa102.close(); 53 | } catch (IOException e) { 54 | // error closing LED strip 55 | } 56 | ``` 57 | 58 | License 59 | ------- 60 | 61 | Copyright 2016 Google Inc. 62 | 63 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 64 | license agreements. See the NOTICE file distributed with this work for 65 | additional information regarding copyright ownership. The ASF licenses this 66 | file to you under the Apache License, Version 2.0 (the "License"); you may not 67 | use this file except in compliance with the License. You may obtain a copy of 68 | the License at 69 | 70 | http://www.apache.org/licenses/LICENSE-2.0 71 | 72 | Unless required by applicable law or agreed to in writing, software 73 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 74 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 75 | License for the specific language governing permissions and limitations under 76 | the License. 77 | 78 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-apa102/_latestVersion 79 | -------------------------------------------------------------------------------- /cap1xxx/src/test/java/com/google/android/things/contrib/driver/cap1xxx/ArrayFillingAnswerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.cap1xxx; 17 | 18 | import static junit.framework.Assert.assertEquals; 19 | import static junit.framework.Assert.assertNull; 20 | 21 | import org.junit.Rule; 22 | import org.junit.Test; 23 | import org.junit.rules.ExpectedException; 24 | import org.mockito.invocation.InvocationOnMock; 25 | 26 | import java.lang.reflect.Method; 27 | 28 | public class ArrayFillingAnswerTest { 29 | 30 | @Rule 31 | public ExpectedException mExpectedException = ExpectedException.none(); 32 | 33 | @Test 34 | public void fillsArrayAndReturnsNull() throws Throwable { 35 | final byte value = 42; 36 | ArrayFillingAnswer answer = new ArrayFillingAnswer(value); 37 | final byte[] toBeFilled = new byte[10]; 38 | 39 | InvocationOnMock invocation = new InvocationOnMock() { 40 | @Override 41 | public Object getMock() { 42 | return null; 43 | } 44 | 45 | @Override 46 | public Method getMethod() { 47 | return null; 48 | } 49 | 50 | @Override 51 | public Object[] getArguments() { 52 | return new Object[] { 53 | null, 54 | toBeFilled, 55 | null 56 | }; 57 | } 58 | 59 | @Override 60 | public T getArgumentAt(int index, Class clazz) { 61 | return (T) getArguments()[index]; 62 | } 63 | 64 | @Override 65 | public Object callRealMethod() throws Throwable { 66 | return null; 67 | } 68 | }; 69 | 70 | assertNull(answer.answer(invocation)); 71 | for (byte b : toBeFilled) { 72 | assertEquals(value, b); 73 | } 74 | } 75 | } 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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /pwmservo/README.md: -------------------------------------------------------------------------------- 1 | Servo driver for Android Things 2 | =================================== 3 | 4 | This driver supports servo motor peripherals using the PWM protocol. 5 | 6 | NOTE: these drivers are not production-ready. They are offered as sample 7 | implementations of Android Things user space drivers for common peripherals 8 | as part of the Developer Preview release. There is no guarantee 9 | of correctness, completeness or robustness. 10 | 11 | How to use the driver 12 | --------------------- 13 | 14 | ### Gradle dependency 15 | 16 | To use the `pwmservo` driver, simply add the line below to your project's `build.gradle`, 17 | where `` matches the last version of the driver available on [jcenter][jcenter]. 18 | 19 | ``` 20 | dependencies { 21 | compile 'com.google.android.things.contrib:driver-pwmservo:' 22 | } 23 | ``` 24 | 25 | ### Sample usage 26 | 27 | ```java 28 | import com.google.android.things.contrib.driver.pwmservo.Servo; 29 | 30 | // Access the servo: 31 | 32 | Servo mServo; 33 | 34 | try { 35 | mServo = new Servo(pwmPinName); 36 | mServo.setPulseDurationRange(1, 2); // according to your servo's specifications 37 | mServo.setAngleRange(0, 180); // according to your servo's specifications 38 | mServo.setEnabled(true); 39 | } catch (IOException e) { 40 | // couldn't configure the servo... 41 | } 42 | 43 | // Make the servo move: 44 | 45 | try { 46 | mServo.setAngle(90); 47 | } catch (IOException e) { 48 | // error setting servo 49 | } 50 | 51 | // Close the servo when finished: 52 | 53 | try { 54 | mServo.close(); 55 | } catch (IOException e) { 56 | // error closing servo 57 | } 58 | ``` 59 | 60 | License 61 | ------- 62 | 63 | Copyright 2016 Google Inc. 64 | 65 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 66 | license agreements. See the NOTICE file distributed with this work for 67 | additional information regarding copyright ownership. The ASF licenses this 68 | file to you under the Apache License, Version 2.0 (the "License"); you may not 69 | use this file except in compliance with the License. You may obtain a copy of 70 | the License at 71 | 72 | http://www.apache.org/licenses/LICENSE-2.0 73 | 74 | Unless required by applicable law or agreed to in writing, software 75 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 76 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 77 | License for the specific language governing permissions and limitations under 78 | the License. 79 | 80 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-pwmservo/_latestVersion 81 | -------------------------------------------------------------------------------- /pwmspeaker/README.md: -------------------------------------------------------------------------------- 1 | PWM Speaker driver for Android Things 2 | ===================================== 3 | 4 | This driver supports speaker and piezo buzzer peripherals using the PWM protocol. 5 | 6 | NOTE: these drivers are not production-ready. They are offered as sample 7 | implementations of Android Things user space drivers for common peripherals 8 | as part of the Developer Preview release. There is no guarantee 9 | of correctness, completeness or robustness. 10 | 11 | How to use the driver 12 | --------------------- 13 | 14 | ### Gradle dependency 15 | 16 | To use the `pwmspeaker` driver, simply add the line below to your project's `build.gradle`, 17 | where `` matches the last version of the driver available on [jcenter][jcenter]. 18 | 19 | ``` 20 | dependencies { 21 | compile 'com.google.android.things.contrib:driver-pwmspeaker:' 22 | } 23 | ``` 24 | 25 | ### Sample usage 26 | 27 | ```java 28 | import com.google.android.things.contrib.driver.pwmspeaker.Speaker; 29 | 30 | // Access the speaker: 31 | 32 | Speaker mSpeaker; 33 | 34 | try { 35 | mSpeaker = new Speaker(pwmPinName); 36 | } catch (IOException e) { 37 | // couldn't configure the speaker... 38 | } 39 | 40 | // Make it play: 41 | 42 | try { 43 | mSpeaker.play(440 /* tone */); 44 | } catch (IOException e) { 45 | // error setting speaker 46 | } 47 | 48 | // Stop a currently playing tone: 49 | 50 | try { 51 | mSpeaker.stop(); 52 | } catch (IOException e) { 53 | // error stopping speaker 54 | } 55 | 56 | // Close the speaker when finished: 57 | 58 | try { 59 | mSpeaker.close(); 60 | } catch (IOException e) { 61 | // error closing speaker 62 | } 63 | ``` 64 | 65 | License 66 | ------- 67 | 68 | Copyright 2016 Google Inc. 69 | 70 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 71 | license agreements. See the NOTICE file distributed with this work for 72 | additional information regarding copyright ownership. The ASF licenses this 73 | file to you under the Apache License, Version 2.0 (the "License"); you may not 74 | use this file except in compliance with the License. You may obtain a copy of 75 | the License at 76 | 77 | http://www.apache.org/licenses/LICENSE-2.0 78 | 79 | Unless required by applicable law or agreed to in writing, software 80 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 81 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 82 | License for the specific language governing permissions and limitations under 83 | the License. 84 | 85 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-pwmspeaker/_latestVersion 86 | -------------------------------------------------------------------------------- /zxgesturesensor/src/main/java/com/google/android/things/contrib/driver/zxgesturesensor/SimpleGestureDetector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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.google.android.things.contrib.driver.zxgesturesensor; 18 | 19 | import android.os.Handler; 20 | 21 | /** 22 | * Simple gesture detector (not really a detector) that relays gesture events from the sensor 23 | */ 24 | public class SimpleGestureDetector extends GestureDetector { 25 | private Handler mHandler; 26 | 27 | private final static int DEBOUNCE_DELAY_MS = 100; 28 | private boolean mSensorUpdated; 29 | private boolean mDebouncing; 30 | 31 | private ZXGestureSensor.Gesture mLastGesture; 32 | 33 | public SimpleGestureDetector(Handler handler) { 34 | mHandler = handler == null ? new Handler() : handler; 35 | } 36 | 37 | /** 38 | * Blocks immediate gesture event firings followed by a gesture event. 39 | */ 40 | private final Runnable bounceBack = new Runnable() { 41 | @Override 42 | public void run() { 43 | mDebouncing = false; 44 | } 45 | }; 46 | 47 | @Override 48 | protected void updateXpos(int xpos) { 49 | mSensorUpdated = true; 50 | } 51 | 52 | @Override 53 | protected void updateZpos(int zpos) { 54 | mSensorUpdated = true; 55 | } 56 | 57 | @Override 58 | protected void updateGesture(ZXGestureSensor.Gesture gesture, int gestureParams) { 59 | if (mLastGesture != null && mLastGesture != gesture) { 60 | mDebouncing = false; 61 | } 62 | mLastGesture = gesture; 63 | if(mListener != null) { 64 | if (mSensorUpdated && !mDebouncing) { 65 | mListener.onGestureEvent(mSensor, gesture, gestureParams); 66 | mDebouncing = true; 67 | mSensorUpdated = false; 68 | mHandler.postDelayed(bounceBack, DEBOUNCE_DELAY_MS); 69 | } 70 | } 71 | } 72 | 73 | @Override 74 | protected void updatePenUp() { 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /gps/src/androidTest/java/com/google/android/things/contrib/driver/gps/NmeaSampleData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. 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.google.android.things.contrib.driver.gps; 18 | 19 | public class NmeaSampleData { 20 | 21 | private static final String BLOCKED_NO_FIX = 22 | "$GPGGA,,,,,,0,00,99.99,,,,,,*48\r\n" + 23 | "$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n" + 24 | "$GPGSV,1,1,00*79\r\n" + 25 | "$GPRMC,,V,,,,,,,,,,N*53\r\n" + 26 | "$GPVTG,,,,,,,,,N*30\r\n"; 27 | public static byte[] SAMPLE_BLOCKED_NO_FIX = BLOCKED_NO_FIX.getBytes(); 28 | 29 | private static final String SAT_VIEW_NO_FIX = 30 | "$GPRMC,,V,,,,,,,,,,N*53\r\n"+ 31 | "$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D\r\n" + 32 | "$GPGSV,2,1,07,07,79,048,42,02,51,062,43,26,36,256,42,27,27,138,42*71\r\n" + 33 | "$GPGSV,2,2,07,09,23,313,42,04,19,159,41,15,12,041,42*41\r\n" + 34 | "$GPVTG,,T,,M,,N,,K,N*2C\r\n"+ 35 | "$GPGGA,,,,,,0,,,,,,,,*66\r\n"; 36 | public static byte[] SAMPLE_SAT_VIEW_NO_FIX = SAT_VIEW_NO_FIX.getBytes(); 37 | 38 | private static final String VALID_FIX = 39 | "$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n" + 40 | "$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D\r\n" + 41 | "$GPGSV,2,1,07,07,79,048,42,02,51,062,43,26,36,256,42,27,27,138,42*71\r\n" + 42 | "$GPGSV,2,2,07,09,23,313,42,04,19,159,41,15,12,041,42*41\r\n" + 43 | "$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n" + 44 | "$GPGLL,3907.360,N,12102.481,W,183730,A*33\r\n"; 45 | public static byte[] SAMPLE_VALID_FIX = VALID_FIX.getBytes(); 46 | 47 | /* 48 | * Expected parsed values for the above sample sentences 49 | */ 50 | public static int EXPECTED_SAT_COUNT = 7; 51 | public static long EXPECTED_TIMESTAMP = 984076649000L; 52 | public static double EXPECTED_LATITUDE = 39.1226; 53 | public static double EXPECTED_LONGITUDE = -121.0413; 54 | } 55 | -------------------------------------------------------------------------------- /apa102/src/test/java/com/google/android/things/contrib/driver/apa102/ColorMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.apa102; 18 | 19 | import android.graphics.Color; 20 | 21 | import org.mockito.Mockito; 22 | import org.mockito.invocation.InvocationOnMock; 23 | import org.mockito.stubbing.Answer; 24 | import org.powermock.api.mockito.PowerMockito; 25 | 26 | import static org.mockito.Matchers.anyInt; 27 | 28 | public class ColorMock { 29 | public static void mockStatic() { 30 | PowerMockito.mockStatic(Color.class); 31 | Mockito.when(Color.red(anyInt())).thenAnswer(new Answer() { 32 | @Override 33 | public Object answer(InvocationOnMock invocation) throws Throwable { 34 | int c = invocation.getArgumentAt(0, Integer.class); 35 | return (c >> 16) & 0xff; 36 | } 37 | }); 38 | Mockito.when(Color.green(anyInt())).thenAnswer(new Answer() { 39 | @Override 40 | public Object answer(InvocationOnMock invocation) throws Throwable { 41 | int c = invocation.getArgumentAt(0, Integer.class); 42 | return (c >> 8) & 0xff; 43 | } 44 | }); 45 | Mockito.when(Color.blue(anyInt())).thenAnswer(new Answer() { 46 | @Override 47 | public Object answer(InvocationOnMock invocation) throws Throwable { 48 | int c = invocation.getArgumentAt(0, Integer.class); 49 | return c & 0xff; 50 | } 51 | }); 52 | 53 | Mockito.when(Color.argb(anyInt(), anyInt(), anyInt(), anyInt())).thenAnswer(new Answer() { 54 | @Override 55 | public Integer answer(InvocationOnMock invocation) throws Throwable { 56 | int a = invocation.getArgumentAt(0, Integer.class); 57 | int r = invocation.getArgumentAt(1, Integer.class); 58 | int g = invocation.getArgumentAt(2, Integer.class); 59 | int b = invocation.getArgumentAt(3, Integer.class); 60 | return (a << 24) | (r << 16) | (g << 8) | b; 61 | } 62 | }); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ht16k33/README.md: -------------------------------------------------------------------------------- 1 | HT16K33 display driver for Android Things 2 | ========================================= 3 | 4 | This driver supports segment displays built on the HT16K33 LED driver 5 | 6 | NOTE: these drivers are not production-ready. They are offered as sample 7 | implementations of Android Things user space drivers for common peripherals 8 | as part of the Developer Preview release. There is no guarantee 9 | of correctness, completeness or robustness. 10 | 11 | How to use the driver 12 | --------------------- 13 | 14 | ### Gradle dependency 15 | 16 | To use the `ht16k33` driver, simply add the line below to your project's `build.gradle`, 17 | where `` matches the last version of the driver available on [jcenter][jcenter]. 18 | 19 | ``` 20 | dependencies { 21 | compile 'com.google.android.things.contrib:driver-ht16k33:' 22 | } 23 | ``` 24 | 25 | ### Sample usage 26 | 27 | Use the `AlphanumericDisplay` class to easily drive a 14-segment display. Use the `Ht16k33` class 28 | when driving other types of [HT16K33 led matrices][led_matrices]. 29 | ```java 30 | import com.google.android.things.contrib.driver.ht16k33.AlphanumericDisplay; 31 | 32 | // Access the display: 33 | 34 | AlphanumericDisplay mDisplay; 35 | 36 | try { 37 | mDisplay = new AlphanumericDisplay(i2cBusName); 38 | mDisplay.setEnabled(true); 39 | } catch (IOException e) { 40 | // couldn't configure the display... 41 | } 42 | 43 | // Display some text: 44 | 45 | try { 46 | mDisplay.display("XOXO"); 47 | } catch (IOException e) { 48 | // error setting display 49 | } 50 | 51 | // Close the display when finished: 52 | 53 | try { 54 | mDisplay.close(); 55 | } catch (IOException e) { 56 | // error closing display 57 | } 58 | ``` 59 | 60 | License 61 | ------- 62 | 63 | Copyright 2016 Google Inc. 64 | 65 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 66 | license agreements. See the NOTICE file distributed with this work for 67 | additional information regarding copyright ownership. The ASF licenses this 68 | file to you under the Apache License, Version 2.0 (the "License"); you may not 69 | use this file except in compliance with the License. You may obtain a copy of 70 | the License at 71 | 72 | http://www.apache.org/licenses/LICENSE-2.0 73 | 74 | Unless required by applicable law or agreed to in writing, software 75 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 76 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 77 | License for the specific language governing permissions and limitations under 78 | the License. 79 | 80 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-ht16k33/_latestVersion 81 | [led_matrices]: https://learn.adafruit.com/adafruit-led-backpack/connecting-multiple-backpacks?view=all 82 | -------------------------------------------------------------------------------- /ssd1306/README.md: -------------------------------------------------------------------------------- 1 | SSD1306 display driver for Android Things 2 | ========================================= 3 | 4 | This driver supports OLED screen peripherals built on the SSD1306 chip. 5 | 6 | NOTE: these drivers are not production-ready. They are offered as sample 7 | implementations of Android Things user space drivers for common peripherals 8 | as part of the Developer Preview release. There is no guarantee 9 | of correctness, completeness or robustness. 10 | 11 | How to use the driver 12 | --------------------- 13 | 14 | ### Gradle dependency 15 | 16 | To use the `ssd1306` driver, simply add the line below to your project's `build.gradle`, 17 | where `` matches the last version of the driver available on [jcenter][jcenter]. 18 | 19 | ``` 20 | dependencies { 21 | compile 'com.google.android.things.contrib:driver-ssd1306:' 22 | } 23 | ``` 24 | 25 | ### Sample usage 26 | 27 | ```java 28 | import com.google.android.things.contrib.driver.ssd1306.Ssd1306; 29 | 30 | // Access the display: 31 | 32 | Ssd1306 mDisplay; 33 | 34 | try { 35 | mDisplay = new Ssd1306(i2cBusName); 36 | } catch (IOException e) { 37 | // couldn't configure the display... 38 | } 39 | 40 | // Draw on the screen: 41 | 42 | try { 43 | for (int i = 0; i < mDisplay.getLcdWidth(); i++) { 44 | for (int j = 0; j < mDisplay.getLcdHeight(); j++) { 45 | // checkerboard 46 | mDisplay.setPixel(i, j, (i % 2) == (j % 2)); 47 | } 48 | } 49 | mDisplay.show(); // render the pixel data 50 | 51 | // You can also use BitmapHelper to render a bitmap instead of setting pixels manually 52 | } catch (IOException e) { 53 | // error setting display 54 | } 55 | 56 | // Close the display when finished: 57 | 58 | try { 59 | mDisplay.close(); 60 | } catch (IOException e) { 61 | // error closing display 62 | } 63 | ``` 64 | 65 | License 66 | ------- 67 | 68 | Copyright 2016 Google Inc. 69 | 70 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 71 | license agreements. See the NOTICE file distributed with this work for 72 | additional information regarding copyright ownership. The ASF licenses this 73 | file to you under the Apache License, Version 2.0 (the "License"); you may not 74 | use this file except in compliance with the License. You may obtain a copy of 75 | the License at 76 | 77 | http://www.apache.org/licenses/LICENSE-2.0 78 | 79 | Unless required by applicable law or agreed to in writing, software 80 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 81 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 82 | License for the specific language governing permissions and limitations under 83 | the License. 84 | 85 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-ssd1306/_latestVersion 86 | -------------------------------------------------------------------------------- /pwmspeaker/src/test/java/com/google/android/things/contrib/driver/pwmspeaker/SpeakerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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 | package com.google.android.things.contrib.driver.pwmspeaker; 17 | 18 | import com.google.android.things.pio.Pwm; 19 | 20 | import org.junit.Rule; 21 | import org.junit.Test; 22 | import org.junit.rules.ExpectedException; 23 | import org.mockito.Mock; 24 | import org.mockito.Mockito; 25 | import org.mockito.junit.MockitoJUnit; 26 | import org.mockito.junit.MockitoRule; 27 | 28 | import java.io.IOException; 29 | 30 | import static org.mockito.Mockito.times; 31 | 32 | public class SpeakerTest { 33 | 34 | @Mock 35 | Pwm mPwm; 36 | 37 | @Rule 38 | public MockitoRule mMockitoRule = MockitoJUnit.rule(); 39 | 40 | @Rule 41 | public ExpectedException mExpectedException = ExpectedException.none(); 42 | 43 | @Test 44 | public void dutyCycleIsSquareWave() throws IOException { 45 | Speaker speaker = new Speaker(mPwm); 46 | Mockito.verify(mPwm).setPwmDutyCycle(50); 47 | } 48 | 49 | @Test 50 | public void playStop() throws IOException { 51 | Speaker speaker = new Speaker(mPwm); 52 | 53 | speaker.play(440); 54 | Mockito.verify(mPwm).setPwmFrequencyHz(440); 55 | Mockito.verify(mPwm).setEnabled(true); 56 | 57 | speaker.stop(); 58 | Mockito.verify(mPwm).setEnabled(false); 59 | } 60 | 61 | @Test 62 | public void play_throwsIfClosed() throws IOException { 63 | Speaker speaker = new Speaker(mPwm); 64 | speaker.close(); 65 | 66 | mExpectedException.expect(IllegalStateException.class); 67 | speaker.play(440); 68 | } 69 | 70 | @Test 71 | public void stop_throwsIfClosed() throws IOException { 72 | Speaker speaker = new Speaker(mPwm); 73 | speaker.close(); 74 | 75 | mExpectedException.expect(IllegalStateException.class); 76 | speaker.stop(); 77 | } 78 | 79 | @Test 80 | public void close_safeToCallTwice() throws IOException { 81 | Speaker speaker = new Speaker(mPwm); 82 | speaker.close(); 83 | speaker.close(); // should not throw 84 | Mockito.verify(mPwm, times(1)).close(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sensehat/src/androidTest/java/com/google/android/things/contrib/driver/sensehat/SenseHatDeviceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.sensehat; 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.Canvas; 22 | import android.graphics.Color; 23 | import android.graphics.Paint; 24 | import android.graphics.RadialGradient; 25 | import android.graphics.Shader; 26 | import android.support.test.InstrumentationRegistry; 27 | import android.support.test.filters.SmallTest; 28 | import android.support.test.runner.AndroidJUnit4; 29 | 30 | import org.junit.Test; 31 | import org.junit.runner.RunWith; 32 | 33 | import java.io.IOException; 34 | 35 | @RunWith(AndroidJUnit4.class) 36 | @SmallTest 37 | public class SenseHatDeviceTest { 38 | @Test 39 | public void senseHat_DisplayColor() throws IOException { 40 | // Color the LED matrix. 41 | LedMatrix display = SenseHat.openDisplay(); 42 | 43 | display.draw(Color.MAGENTA); 44 | // Close the display when done. 45 | display.close(); 46 | } 47 | 48 | @Test 49 | public void senseHat_DisplayDrawable() throws IOException { 50 | Context context = InstrumentationRegistry.getTargetContext(); 51 | // Display a drawable on the LED matrix. 52 | LedMatrix display = SenseHat.openDisplay(); 53 | display.draw(context.getDrawable(android.R.drawable.ic_secure)); 54 | // Close the display when done. 55 | display.close(); 56 | } 57 | 58 | @Test 59 | public void senseHat_DisplayGradient() throws IOException { 60 | // Display a gradient on the LED matrix. 61 | LedMatrix display = SenseHat.openDisplay(); 62 | Bitmap bitmap = Bitmap.createBitmap(SenseHat.DISPLAY_WIDTH, SenseHat.DISPLAY_HEIGHT, Bitmap.Config.ARGB_8888); 63 | Canvas canvas = new Canvas(bitmap); 64 | Paint paint = new Paint(); 65 | paint.setShader(new RadialGradient(4, 4, 4, Color.RED, Color.BLUE, Shader.TileMode.CLAMP)); 66 | canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); 67 | display.draw(bitmap); 68 | // Close the display when done. 69 | display.close(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /sensehat/README.md: -------------------------------------------------------------------------------- 1 | Sense Hat driver for Android Things 2 | ===================================== 3 | 4 | This driver provides easy access to the peripherals available on the Raspberry Pi [Sense Hat][product]: 5 | - 8x8 LED matrix 6 | - TODO: 5 buttons joystick 7 | - TODO: Sensors 8 | 9 | 10 | NOTE: these drivers are not production-ready. They are offered as sample 11 | implementations of Android Things user space drivers for common peripherals 12 | as part of the Developer Preview release. There is no guarantee 13 | of correctness, completeness or robustness. 14 | 15 | How to use the driver 16 | --------------------- 17 | 18 | ### Gradle dependency 19 | 20 | To use the `sensehat` driver, simply add the line below to your project's `build.gradle`, 21 | where `` matches the last version of the driver available on [jcenter][jcenter]. 22 | 23 | ``` 24 | dependencies { 25 | compile 'com.google.android.things.contrib:driver-sensehat:' 26 | } 27 | ``` 28 | 29 | ### Sample usage 30 | 31 | ``` 32 | // import the SenseHat driver 33 | import com.google.android.things.contrib.driver.sensehat.SenseHat; 34 | ``` 35 | ``` 36 | // Color the LED matrix. 37 | LedMatrix display = SenseHat.openDisplay(); 38 | display.draw(Color.MAGENTA); 39 | ``` 40 | ``` 41 | // Display a drawable on the LED matrix. 42 | display.draw(context.getDrawable(android.R.drawable.ic_dialog_alert)); 43 | ``` 44 | ``` 45 | // Display a gradient on the LED matrix. 46 | Bitmap bitmap = Bitmap.createBitmap(SenseHat.DISPLAY_WIDTH, SenseHat.DISPLAY_HEIGHT, Bitmap.Config.ARGB_8888); 47 | Canvas canvas = new Canvas(bitmap); 48 | Paint paint = new Paint(); 49 | paint.setShader(new RadialGradient(4, 4, 4, Color.RED, Color.BLUE, Shader.TileMode.CLAMP)); 50 | canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); 51 | display.draw(bitmap); 52 | ``` 53 | ``` 54 | // Close the display when done. 55 | display.close(); 56 | ``` 57 | 58 | License 59 | ------- 60 | 61 | Copyright 2016 Google Inc. 62 | 63 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 64 | license agreements. See the NOTICE file distributed with this work for 65 | additional information regarding copyright ownership. The ASF licenses this 66 | file to you under the Apache License, Version 2.0 (the "License"); you may not 67 | use this file except in compliance with the License. You may obtain a copy of 68 | the License at 69 | 70 | http://www.apache.org/licenses/LICENSE-2.0 71 | 72 | Unless required by applicable law or agreed to in writing, software 73 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 74 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 75 | License for the specific language governing permissions and limitations under 76 | the License. 77 | 78 | [product]: https://www.raspberrypi.org/products/sense-hat/ 79 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-sensehat 80 | -------------------------------------------------------------------------------- /cap1xxx/src/test/java/com/google/android/things/contrib/driver/cap1xxx/BitwiseUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.cap1xxx; 17 | 18 | import org.junit.Rule; 19 | import org.junit.Test; 20 | import org.junit.rules.ExpectedException; 21 | 22 | import static junit.framework.Assert.assertEquals; 23 | import static junit.framework.Assert.assertFalse; 24 | import static junit.framework.Assert.assertTrue; 25 | 26 | public class BitwiseUtilTest { 27 | 28 | @Rule 29 | public ExpectedException mExpectedException = ExpectedException.none(); 30 | 31 | @Test 32 | public void setBit() { 33 | assertEquals((byte) 0b01, BitwiseUtil.setBit((byte) 0, 0)); 34 | assertEquals((byte) 0b10, BitwiseUtil.setBit((byte) 0, 1)); 35 | // bitIndex outside of byte range 36 | assertEquals((byte) 0, BitwiseUtil.setBit((byte) 0, 8)); 37 | } 38 | 39 | @Test 40 | public void clearBit() { 41 | assertEquals((byte) 0, BitwiseUtil.clearBit((byte) 0b01, 0)); 42 | assertEquals((byte) 0, BitwiseUtil.clearBit((byte) 0b10, 1)); 43 | // bitIndex outside of byte range 44 | assertEquals((byte) 0xFF, BitwiseUtil.clearBit((byte) 0xFF, 8)); 45 | } 46 | 47 | @Test 48 | public void isBitSet() { 49 | assertTrue(BitwiseUtil.isBitSet((byte) 0b01, 0)); 50 | assertTrue(BitwiseUtil.isBitSet((byte) 0b10, 1)); 51 | 52 | assertFalse(BitwiseUtil.isBitSet((byte) 0b11111110, 0)); 53 | assertFalse(BitwiseUtil.isBitSet((byte) 0b11111101, 1)); 54 | 55 | // bitIndex outside of byte range 56 | assertFalse(BitwiseUtil.isBitSet((byte) 0xFF, 8)); 57 | } 58 | 59 | @Test 60 | public void applyBitRange() { 61 | assertEquals((byte) 0b10101010, 62 | BitwiseUtil.applyBitRange((byte) 0b11111111, 0, 0b01010101)); 63 | 64 | assertEquals((byte) 0b11001100, 65 | BitwiseUtil.applyBitRange((byte) 0b11110000, 0b00001111, 0b00111100)); 66 | 67 | // empty mask, no change 68 | assertEquals((byte) 0b00001111, 69 | BitwiseUtil.applyBitRange((byte) 0b00001111, 0b11110000, 0)); 70 | 71 | // mask outside of byte range, no change 72 | assertEquals((byte) 1, BitwiseUtil.applyBitRange((byte) 1, -1, 0xFF00)); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tm1637/README.md: -------------------------------------------------------------------------------- 1 | TM1637 display driver for Android Things 2 | ======================================== 3 | 4 | This driver supports segment display peripherals built on the TM1637 chip. 5 | 6 | NOTE: these drivers are not production-ready. They are offered as sample 7 | implementations of Android Things user space drivers for common peripherals 8 | as part of the Developer Preview release. There is no guarantee 9 | of correctness, completeness or robustness. 10 | 11 | How to use the driver 12 | --------------------- 13 | 14 | ### Gradle dependency 15 | 16 | To use the `tm1637` driver, simply add the line below to your project's `build.gradle`, 17 | where `` matches the last version of the driver available on [jcenter][jcenter]. 18 | 19 | ``` 20 | dependencies { 21 | compile 'com.google.android.things.contrib:driver-tm1637:' 22 | } 23 | ``` 24 | 25 | ### Sample usage 26 | 27 | Use the `NumericDisplay` class to easily drive a 7-segment display. Use the `Tm1637` class when 28 | driving other types of [TM1637 led matrices][led_matrices] 29 | ```java 30 | import com.google.android.things.contrib.driver.tm1637.NumericDisplay; 31 | 32 | // Access the display: 33 | 34 | NumericDisplay mDisplay; 35 | 36 | try { 37 | mDisplay = new NumericDisplay(dataGpioPinName, clockGpioPinName); 38 | mDisplay.setEnabled(true); 39 | } catch (IOException e) { 40 | // couldn't configure the display... 41 | } 42 | 43 | // Display a number or a time: 44 | 45 | try { 46 | // displays "42" 47 | mDisplay.display(42); 48 | 49 | // displays "12:00" 50 | mDisplay.setColonEnabled(true); 51 | mDisplay.display("1200"); 52 | } catch (IOException e) { 53 | // error setting display 54 | } 55 | 56 | // Close the display when finished: 57 | 58 | try { 59 | mDisplay.close(); 60 | } catch (IOException e) { 61 | // error closing display 62 | } 63 | ``` 64 | 65 | License 66 | ------- 67 | 68 | Copyright 2016 Google Inc. 69 | 70 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 71 | license agreements. See the NOTICE file distributed with this work for 72 | additional information regarding copyright ownership. The ASF licenses this 73 | file to you under the Apache License, Version 2.0 (the "License"); you may not 74 | use this file except in compliance with the License. You may obtain a copy of 75 | the License at 76 | 77 | http://www.apache.org/licenses/LICENSE-2.0 78 | 79 | Unless required by applicable law or agreed to in writing, software 80 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 81 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 82 | License for the specific language governing permissions and limitations under 83 | the License. 84 | 85 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-tm1637/_latestVersion 86 | [led_matrices]: https://learn.adafruit.com/adafruit-led-backpack/connecting-multiple-backpacks?view=all 87 | -------------------------------------------------------------------------------- /ssd1306/src/test/java/com/google/android/things/contrib/driver/ssd1306/Ssd1306Test.java: -------------------------------------------------------------------------------- 1 | package com.google.android.things.contrib.driver.ssd1306; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import com.google.android.things.pio.I2cDevice; 6 | 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.rules.ExpectedException; 10 | import org.junit.runner.RunWith; 11 | import org.mockito.Mock; 12 | import org.mockito.Mockito; 13 | import org.mockito.junit.MockitoJUnit; 14 | import org.mockito.junit.MockitoRule; 15 | import org.powermock.core.classloader.annotations.PrepareForTest; 16 | import org.powermock.modules.junit4.PowerMockRunner; 17 | 18 | import java.io.IOException; 19 | 20 | import static org.mockito.Mockito.CALLS_REAL_METHODS; 21 | import static org.mockito.Mockito.withSettings; 22 | import static org.powermock.api.mockito.PowerMockito.mock; 23 | import static org.powermock.api.mockito.PowerMockito.mockStatic; 24 | 25 | @RunWith(PowerMockRunner.class) 26 | @PrepareForTest({BitmapHelper.class, Bitmap.class}) 27 | public class Ssd1306Test { 28 | 29 | @Mock 30 | I2cDevice mI2c; 31 | 32 | @Rule 33 | public MockitoRule mMokitoRule = MockitoJUnit.rule(); 34 | 35 | @Rule 36 | public ExpectedException mExpectedException = ExpectedException.none(); 37 | 38 | @Test 39 | public void setContrastValidValues() throws IOException { 40 | mockStatic(BitmapHelper.class); 41 | mockStatic(Bitmap.class); 42 | Ssd1306 ssd1306 = new Ssd1306(mI2c); 43 | 44 | int[] validValues = {0, 66, 255}; 45 | 46 | for (int validValue : validValues) { 47 | ssd1306.setContrast(validValue); 48 | Mockito.verify(mI2c).writeRegByte(0x00, (byte) 0x81); 49 | Mockito.verify(mI2c).writeRegByte(0x00, (byte) validValue); 50 | Mockito.reset(mI2c); 51 | } 52 | } 53 | 54 | @Test 55 | public void setContrastInValidValues() throws IOException { 56 | int[] invalidValues = {-777, -1, 256, 999}; 57 | mockStatic(BitmapHelper.class); 58 | mockStatic(Bitmap.class); 59 | Ssd1306 ssd1306 = new Ssd1306(mI2c); 60 | 61 | for (int invalidValue : invalidValues) { 62 | mExpectedException.expect(IllegalArgumentException.class); 63 | mExpectedException.expectMessage("Invalid contrast " + String.valueOf(invalidValue) + ", level must be between 0 and 255"); 64 | ssd1306.setContrast(invalidValue); 65 | Mockito.verify(mI2c, Mockito.never()).writeRegByte(0x00, (byte) 0x81); 66 | Mockito.verify(mI2c, Mockito.never()).writeRegByte(0x00, (byte) 66); 67 | Mockito.reset(mExpectedException); 68 | } 69 | } 70 | 71 | @Test 72 | public void nullmI2cDevice() throws IOException { 73 | Ssd1306 ssd1306 = mock(Ssd1306.class, withSettings().defaultAnswer(CALLS_REAL_METHODS)); 74 | mExpectedException.expect(IllegalStateException.class); 75 | mExpectedException.expectMessage("I2C Device not open"); 76 | ssd1306.setContrast(44); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /adc/README.md: -------------------------------------------------------------------------------- 1 | ADC Drivers for Android Things 2 | ==================================== 3 | 4 | This driver supports the following analog to digital converters (ADCs): 5 | 6 | | Driver | ADC | Module | 7 | | :----: | --- | ------ | 8 | | MCP3xxx | MCP3002 | [SparkFun](https://www.sparkfun.com/products/8636) 9 | | MCP3xxx | MCP3004 | 10 | | MCP3xxx | MCP3008 | [Adafruit](https://www.adafruit.com/product/856) 11 | | ADS1xxx | ADS1013, ADS1014, ADS1015 | [Adafruit](https://www.adafruit.com/product/1083) 12 | | ADS1xxx | ADS1113, ADS1114, ADS1115 | [Adafruit](https://www.adafruit.com/product/1085) 13 | 14 | NOTE: these drivers are not production-ready. They are offered as sample 15 | implementations of Android Things user space drivers for common peripherals 16 | as part of the Developer Preview release. There is no guarantee 17 | of correctness, completeness or robustness. 18 | 19 | How to use the driver 20 | --------------------- 21 | 22 | ### Gradle dependency 23 | 24 | To use the `adc` driver, simply add the line below to your project's `build.gradle`, 25 | where `` matches the last version of the driver available on [jcenter][jcenter]. 26 | 27 | ``` 28 | dependencies { 29 | compile 'com.google.android.things.contrib:driver-adc:' 30 | } 31 | ``` 32 | 33 | ### Sample usage 34 | 35 | ```java 36 | import com.google.android.things.contrib.driver.adc.ads1xxx.Ads1xxx; 37 | 38 | try { 39 | // Connect to an ADS1015 using the default I2C address 40 | mAdcDriver = new Ads1xxx(i2cBusName, Ads1xxx.Configuration.ADS1015); 41 | // Increase default range to fit +3.3V 42 | mAdcDriver.setInputRange(Ads1xxx.RANGE_4_096V); 43 | } catch (IOException e) { 44 | // couldn't configure the device... 45 | } 46 | 47 | // Elsewhere in a loop 48 | try { 49 | // Get the voltage difference between IN0+ and IN1- 50 | float voltage = mAdcDriver.readDifferentialVoltage(Ads1xxx.INPUT_DIFF_0P_1N); 51 | } catch (IOException e) { 52 | // error reading result 53 | } 54 | 55 | // Close the block when finished: 56 | try { 57 | mAdc.close() 58 | } catch (IOException e) { 59 | // error closing 60 | } 61 | 62 | ``` 63 | 64 | License 65 | ------- 66 | 67 | Copyright 2016 Google Inc. 68 | 69 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 70 | license agreements. See the NOTICE file distributed with this work for 71 | additional information regarding copyright ownership. The ASF licenses this 72 | file to you under the Apache License, Version 2.0 (the "License"); you may not 73 | use this file except in compliance with the License. You may obtain a copy of 74 | the License at 75 | 76 | http://www.apache.org/licenses/LICENSE-2.0 77 | 78 | Unless required by applicable law or agreed to in writing, software 79 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 80 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 81 | License for the specific language governing permissions and limitations under 82 | the License. 83 | 84 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-adc/_latestVersion 85 | -------------------------------------------------------------------------------- /adc/src/test/java/com/google/android/things/contrib/driver/adc/ads1xxx/Ads1xxxTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. 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.google.android.things.contrib.driver.adc.ads1xxx; 18 | 19 | import org.junit.Test; 20 | 21 | import java.io.IOException; 22 | 23 | import static junit.framework.Assert.assertEquals; 24 | 25 | public class Ads1xxxTest { 26 | 27 | @Test 28 | public void readSingle_returnsCorrectValue() throws IOException { 29 | // 12-bit ADC device 30 | Ads1015Device mockDevice = new Ads1015Device(); 31 | // Default voltage scale is 2.048V 32 | mockDevice.setChannelValue(2.048f); 33 | Ads1xxx driver = new Ads1xxx(mockDevice, Ads1xxx.Configuration.ADS1015); 34 | 35 | int result = driver.readSingleEndedInput(0); 36 | assertEquals(2047, result); 37 | } 38 | 39 | @Test 40 | public void readDifferential_returnsNegativeValue() throws IOException { 41 | // 12-bit ADC device 42 | Ads1015Device mockDevice = new Ads1015Device(); 43 | mockDevice.setChannelValue(-1f); 44 | Ads1xxx driver = new Ads1xxx(mockDevice, Ads1xxx.Configuration.ADS1015); 45 | 46 | double result = driver.readDifferentialVoltage(Ads1xxx.INPUT_DIFF_0P_1N); 47 | assertEquals(-1.0, result, 0.002); 48 | } 49 | 50 | @Test 51 | public void readScaled_returnsCorrectValue() throws IOException { 52 | // 12-bit ADC device 53 | Ads1015Device mockDevice = new Ads1015Device(); 54 | mockDevice.setChannelValue(3.3f); 55 | Ads1xxx driver = new Ads1xxx(mockDevice, Ads1xxx.Configuration.ADS1015); 56 | 57 | // Driver will max out at the default scale 58 | double result = driver.readSingleEndedVoltage(0); 59 | assertEquals(2.048, result, 0.002); 60 | // Increase the voltage scale 61 | driver.setInputRange(Ads1xxx.RANGE_4_096V); 62 | result = driver.readSingleEndedVoltage(0); 63 | assertEquals(3.3, result, 0.002); 64 | } 65 | 66 | @Test(expected = IOException.class) 67 | public void readTimeout_throwsException() throws IOException { 68 | // 12-bit ADC device 69 | Ads1015Device mockDevice = new Ads1015Device(); 70 | mockDevice.setChannelValue(3.3f); 71 | mockDevice.setClearOnRead(false); 72 | Ads1xxx driver = new Ads1xxx(mockDevice, Ads1xxx.Configuration.ADS1015); 73 | 74 | // This line should throw an exception, Ads1015 will never return complete flag 75 | driver.readDifferentialVoltage(0); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap12xx/Cap12xx.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.cap12xx; 18 | 19 | import android.content.Context; 20 | import android.os.Handler; 21 | 22 | import com.google.android.things.contrib.driver.cap1xxx.Cap1xxx; 23 | 24 | import java.io.IOException; 25 | 26 | /** 27 | * Driver for the Microchip CAP12xx Capacitive Touch Controller 28 | * e.g. http://www.microchip.com/wwwproducts/en/CAP1208 29 | * @deprecated Use {@link Cap1xxx} instead. 30 | */ 31 | @Deprecated 32 | @SuppressWarnings("WeakerAccess") 33 | public class Cap12xx extends Cap1xxx { 34 | private static final String TAG = "Cap12xx"; 35 | 36 | /** 37 | * @deprecated Use {@link #Cap12xx(String, String, Configuration)} instead. 38 | */ 39 | @Deprecated 40 | public Cap12xx(Context context, String i2cName, String alertName, Configuration chip) throws IOException { 41 | this(i2cName, alertName, chip, null); 42 | } 43 | 44 | /** 45 | * Create a new Cap1xxx controller. 46 | * 47 | * @param i2cName I2C port name where the controller is attached. Cannot be null. 48 | * @param alertName optional GPIO pin name connected to the controller's 49 | * alert interrupt signal. Can be null. 50 | * @param chip identifier for the connected controller device chip. 51 | * @throws IOException 52 | */ 53 | public Cap12xx(String i2cName, String alertName, Configuration chip) throws IOException { 54 | this(i2cName, alertName, chip, null); 55 | } 56 | 57 | /** 58 | * @deprecated Use {@link #Cap12xx(String, String, Configuration, Handler)} instead. 59 | */ 60 | @Deprecated 61 | public Cap12xx(Context context, String i2cName, String alertName, Configuration chip, 62 | Handler handler) throws IOException { 63 | this(i2cName, alertName, chip, handler); 64 | } 65 | 66 | /** 67 | * Create a new Cap1xxx controller. 68 | * 69 | * @param i2cName I2C port name where the controller is attached. Cannot be null. 70 | * @param alertName optional GPIO pin name connected to the controller's 71 | * alert interrupt signal. Can be null. 72 | * @param chip identifier for the connected controller device chip. 73 | * @param handler optional {@link Handler} for software polling and callback events. 74 | * @throws IOException 75 | */ 76 | public Cap12xx(String i2cName, String alertName, Configuration chip, Handler handler) 77 | throws IOException { 78 | super(i2cName, alertName, chip, handler); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /button/src/androidTest/java/com/google/android/things/contrib/driver/button/ButtonTestActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.button; 17 | 18 | import android.app.Activity; 19 | import android.os.Bundle; 20 | import android.util.Log; 21 | import android.view.KeyEvent; 22 | 23 | import com.google.android.things.contrib.driver.button.Button.LogicState; 24 | import com.google.android.things.pio.Gpio; 25 | 26 | import org.mockito.Mockito; 27 | 28 | import java.io.IOException; 29 | import java.util.concurrent.BlockingQueue; 30 | import java.util.concurrent.LinkedBlockingQueue; 31 | import java.util.concurrent.TimeUnit; 32 | 33 | public class ButtonTestActivity extends Activity { 34 | 35 | private static final String TAG = "ButtonTestActivity"; 36 | 37 | public static final int KEYCODE = KeyEvent.KEYCODE_ENTER; 38 | 39 | private Gpio mGpio; 40 | private Button mButton; 41 | private ButtonInputDriver mInputDriver; 42 | 43 | private BlockingQueue mKeyDownEvents; 44 | private BlockingQueue mKeyUpEvents; 45 | 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | 50 | mGpio = Mockito.mock(Gpio.class); 51 | try { 52 | mButton = new Button(mGpio, LogicState.PRESSED_WHEN_HIGH); 53 | } catch (IOException e) { 54 | throw new RuntimeException("Failed to initialize Button", e); 55 | } 56 | mInputDriver = new ButtonInputDriver(mButton, KEYCODE); 57 | mInputDriver.register(); 58 | 59 | mKeyDownEvents = new LinkedBlockingQueue<>(); 60 | mKeyUpEvents = new LinkedBlockingQueue<>(); 61 | } 62 | 63 | @Override 64 | protected void onDestroy() { 65 | super.onDestroy(); 66 | try { 67 | mInputDriver.close(); 68 | } catch (IOException e) { 69 | Log.e(TAG, "Error closing Button", e); 70 | } 71 | } 72 | 73 | void sendMockButtonEvent(boolean press) { 74 | mButton.performButtonEvent(press); 75 | } 76 | 77 | KeyEvent getNextKeyDownEvent() throws InterruptedException { 78 | return mKeyDownEvents.poll(1L, TimeUnit.SECONDS); 79 | } 80 | 81 | KeyEvent getNextKeyUpEvent() throws InterruptedException { 82 | return mKeyUpEvents.poll(1L, TimeUnit.SECONDS); 83 | } 84 | 85 | @Override 86 | public boolean onKeyDown(int keyCode, KeyEvent event) { 87 | mKeyDownEvents.offer(event); 88 | return super.onKeyDown(keyCode, event); 89 | } 90 | 91 | @Override 92 | public boolean onKeyUp(int keyCode, KeyEvent event) { 93 | mKeyUpEvents.offer(event); 94 | return super.onKeyUp(keyCode, event); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /pwmspeaker/src/main/java/com/google/android/things/contrib/driver/pwmspeaker/Speaker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.pwmspeaker; 18 | 19 | import android.support.annotation.VisibleForTesting; 20 | 21 | import com.google.android.things.pio.PeripheralManager; 22 | import com.google.android.things.pio.Pwm; 23 | 24 | import java.io.IOException; 25 | 26 | @SuppressWarnings({"unused", "WeakerAccess"}) 27 | public class Speaker implements AutoCloseable { 28 | 29 | private Pwm mPwm; 30 | 31 | /** 32 | * Create a Speaker connected to the given PWM pin name 33 | */ 34 | public Speaker(String pin) throws IOException { 35 | PeripheralManager pioService = PeripheralManager.getInstance(); 36 | Pwm device = pioService.openPwm(pin); 37 | try { 38 | connect(device); 39 | } catch (IOException|RuntimeException e) { 40 | try { 41 | close(); 42 | } catch (IOException|RuntimeException ignored) { 43 | } 44 | throw e; 45 | } 46 | } 47 | 48 | /** 49 | * Create a Speaker from a {@link Pwm} device 50 | */ 51 | @VisibleForTesting 52 | /*package*/ Speaker(Pwm device) throws IOException { 53 | connect(device); 54 | } 55 | 56 | private void connect(Pwm device) throws IOException { 57 | mPwm = device; 58 | mPwm.setPwmDutyCycle(50.0); // square wave 59 | } 60 | 61 | @Override 62 | public void close() throws IOException { 63 | if (mPwm != null) { 64 | try { 65 | mPwm.close(); 66 | } finally { 67 | mPwm = null; 68 | } 69 | } 70 | } 71 | 72 | /** 73 | * Play the specified frequency. Play continues until {@link #stop()} is called. 74 | * 75 | * @param frequency the frequency to play in Hz 76 | * @throws IOException 77 | * @throws IllegalStateException if the device is closed 78 | */ 79 | public void play(double frequency) throws IOException, IllegalStateException { 80 | if (mPwm == null) { 81 | throw new IllegalStateException("pwm device not opened"); 82 | } 83 | mPwm.setPwmFrequencyHz(frequency); 84 | mPwm.setEnabled(true); 85 | } 86 | 87 | /** 88 | * Stop a currently playing frequency 89 | * 90 | * @throws IOException 91 | * @throws IllegalStateException if the device is closed 92 | */ 93 | public void stop() throws IOException, IllegalStateException { 94 | if (mPwm == null) { 95 | throw new IllegalStateException("pwm device not opened"); 96 | } 97 | mPwm.setEnabled(false); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /gps/src/androidTest/java/com/google/android/things/contrib/driver/gps/LoopbackUartDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. 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.google.android.things.contrib.driver.gps; 18 | 19 | import android.os.Handler; 20 | 21 | import com.google.android.things.pio.UartDevice; 22 | import com.google.android.things.pio.UartDeviceCallback; 23 | 24 | import java.nio.ByteBuffer; 25 | 26 | /** 27 | * Fake UART device implementation that locally caches data 28 | * written to it, and returns the same buffer back to any 29 | * read requests. 30 | */ 31 | public class LoopbackUartDevice implements UartDevice { 32 | private UartDeviceCallback mCallback; 33 | private ByteBuffer mDataBuffer; 34 | 35 | @Override 36 | public void close() { 37 | // Do nothing...not a real device 38 | } 39 | 40 | @Override 41 | public void setBaudrate(int rate) { 42 | // Do nothing...not a real device 43 | } 44 | 45 | @Override 46 | public void setParity(int mode) { 47 | // Do nothing...not a real device 48 | } 49 | 50 | @Override 51 | public void setDataSize(int size) { 52 | // Do nothing...not a real device 53 | } 54 | 55 | @Override 56 | public void setStopBits(int bits) { 57 | // Do nothing...not a real device 58 | } 59 | 60 | @Override 61 | public void setHardwareFlowControl(int mode) { 62 | // Do nothing...not a real device 63 | } 64 | 65 | @Override 66 | public void setModemControl(int lines) { 67 | // Do nothing...not a real device 68 | } 69 | 70 | @Override 71 | public void clearModemControl(int lines) { 72 | // Do nothing...not a real device 73 | } 74 | 75 | @Override 76 | public void sendBreak(int duration) { 77 | // Do nothing...not a real device 78 | } 79 | 80 | @Override 81 | public void flush(int direction) { 82 | // Do nothing...not a real device 83 | } 84 | 85 | @Override 86 | public int read(byte[] buffer, int length) { 87 | int readLength = (mDataBuffer.remaining() < length) ? mDataBuffer.remaining() : length; 88 | mDataBuffer.get(buffer, 0, readLength); 89 | return readLength; 90 | } 91 | 92 | @Override 93 | public int write(byte[] buffer, int length) { 94 | mDataBuffer = ByteBuffer.wrap(buffer); 95 | mCallback.onUartDeviceDataAvailable(LoopbackUartDevice.this); 96 | return length; 97 | } 98 | 99 | @Override 100 | public void registerUartDeviceCallback(Handler handler, UartDeviceCallback callback) { 101 | mCallback = callback; 102 | } 103 | 104 | @Override 105 | public void unregisterUartDeviceCallback(UartDeviceCallback callback) { 106 | mCallback = null; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /motorhat/README.md: -------------------------------------------------------------------------------- 1 | Motor Hat driver for Android Things 2 | =================================== 3 | 4 | This driver provides access to and control of motor peripherals connected through the [Adafruit 5 | DC and Stepper Motor HAT][product]. 6 | 7 | NOTE: these drivers are not production-ready. They are offered as sample 8 | implementations of Android Things user space drivers for common peripherals 9 | as part of the Developer Preview release. There is no guarantee 10 | of correctness, completeness or robustness. 11 | 12 | How to use the driver 13 | --------------------- 14 | 15 | ### Gradle dependency 16 | 17 | To use the `motorhat` driver, simply add the line below to your project's `build.gradle`, 18 | where `` matches the last version of the driver available on [jcenter][jcenter]. 19 | 20 | ``` 21 | dependencies { 22 | compile 'com.google.android.things.contrib:driver-motorhat:' 23 | } 24 | ``` 25 | 26 | ### Sample usage 27 | 28 | Use the `MotorHat` class to easily control up to 4 DC motors. Motors are indexed from 0 to 3, 29 | corresponding to the ports of the Motor hat (`index = (port# - 1)`). Note: Support for Stepper 30 | motors is forthcoming, so the API is likely to change. 31 | ```java 32 | import com.google.android.things.contrib.driver.motorhat.MotorHat; 33 | 34 | // Access the Motor HAT: 35 | 36 | MotorHat mMotorHat; 37 | 38 | try { 39 | mMotorHat = new NumericDisplay(I2cBusName); 40 | } catch (IOException e) { 41 | // couldn't configure the display... 42 | } 43 | 44 | // Operate the motor: 45 | 46 | try { 47 | // Use a value between 0 and 255 48 | mMotorHat.setMotorSpeed(0, 100); 49 | // Turn clockwise 50 | mMotorHat.setMotorState(0, MotorHat.MOTOR_STATE_CW); 51 | // Turn counter-clockwise 52 | mMotorHat.setMotorState(0, MotorHat.MOTOR_STATE_CCW); 53 | // Stop the motor 54 | mMotorHat.setMotorState(0, MotorHat.MOTOR_STATE_RELEASE); 55 | } catch (IOException e) { 56 | // error setting motor 57 | } 58 | 59 | // Close when finished: 60 | 61 | try { 62 | mMotorHat.close(); 63 | } catch (IOException e) { 64 | // error closing Motor Hat 65 | } 66 | ``` 67 | 68 | Acknowledgments 69 | --------------- 70 | 71 | Inspired by the [Adafruit MotorHAT Python Library][pythonlib], and the [Android Robocar][robocar] 72 | Hackster project by Antonio Zugaldia and Halim Salameh. 73 | 74 | License 75 | ------- 76 | 77 | Copyright 2017 Google Inc. 78 | 79 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 80 | license agreements. See the NOTICE file distributed with this work for 81 | additional information regarding copyright ownership. The ASF licenses this 82 | file to you under the Apache License, Version 2.0 (the "License"); you may not 83 | use this file except in compliance with the License. You may obtain a copy of 84 | the License at 85 | 86 | http://www.apache.org/licenses/LICENSE-2.0 87 | 88 | Unless required by applicable law or agreed to in writing, software 89 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 90 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 91 | License for the specific language governing permissions and limitations under 92 | the License. 93 | 94 | [product]: https://www.adafruit.com/product/2348 95 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-motorhat/_latestVersion 96 | [pythonlib]: https://github.com/adafruit/Adafruit-Motor-HAT-Python-Library 97 | [robocar]: https://github.com/zugaldia/android-robocar 98 | -------------------------------------------------------------------------------- /motorhat/src/test/java/com/google/android/things/contrib/driver/motorhat/MotorHatTest.java: -------------------------------------------------------------------------------- 1 | package com.google.android.things.contrib.driver.motorhat; 2 | 3 | import static org.mockito.Mockito.times; 4 | import static org.mockito.Mockito.verify; 5 | 6 | import com.google.android.things.pio.I2cDevice; 7 | 8 | import org.junit.Before; 9 | import org.junit.Rule; 10 | import org.junit.Test; 11 | import org.junit.rules.ExpectedException; 12 | import org.mockito.Mock; 13 | import org.mockito.junit.MockitoJUnit; 14 | import org.mockito.junit.MockitoRule; 15 | 16 | import java.io.IOException; 17 | 18 | public class MotorHatTest { 19 | 20 | @Mock 21 | I2cDevice mI2c; 22 | 23 | @Rule 24 | public MockitoRule mMockitoRule = MockitoJUnit.rule(); 25 | 26 | @Rule 27 | public ExpectedException mExpectedException = ExpectedException.none(); 28 | 29 | private MotorHat mDriver; 30 | 31 | @Before 32 | public void setup() throws IOException { 33 | mDriver = new MotorHat(mI2c); 34 | } 35 | 36 | @Test 37 | public void close() throws IOException { 38 | mDriver.close(); 39 | verify(mI2c).close(); 40 | } 41 | 42 | @Test 43 | public void close_safeToCallTwice() throws IOException { 44 | mDriver.close(); 45 | mDriver.close(); // should not throw 46 | verify(mI2c, times(1)).close(); 47 | } 48 | 49 | @Test 50 | public void setMotorSpeed() throws IOException { 51 | final int speed = 100; 52 | final int speedCheck = speed << 4; 53 | mDriver.setMotorSpeed(0, speed); 54 | verifyPin(8, 0, speedCheck); 55 | mDriver.setMotorSpeed(1, speed); 56 | verifyPin(13, 0, speedCheck); 57 | mDriver.setMotorSpeed(2, speed); 58 | verifyPin(2, 0, speedCheck); 59 | mDriver.setMotorSpeed(3, speed); 60 | verifyPin(7, 0, speedCheck); 61 | } 62 | 63 | @Test 64 | public void setMotorSpeed_throwsIfClosed() throws IOException { 65 | mDriver.close(); 66 | mExpectedException.expect(IllegalStateException.class); 67 | mDriver.setMotorSpeed(0, 0); 68 | } 69 | 70 | @Test 71 | public void setMotorState() throws IOException { 72 | final int dcOn = 4096, dcOff = 0; 73 | mDriver.setMotorState(0, MotorHat.MOTOR_STATE_CW); 74 | verifyPin(9, dcOn, dcOff); 75 | verifyPin(10, dcOff, dcOn); 76 | mDriver.setMotorState(1, MotorHat.MOTOR_STATE_CCW); 77 | verifyPin(12, dcOff, dcOn); 78 | verifyPin(11, dcOn, dcOff); 79 | mDriver.setMotorState(2, MotorHat.MOTOR_STATE_RELEASE); 80 | verifyPin(3, dcOff, dcOn); 81 | verifyPin(4, dcOff, dcOn); 82 | } 83 | 84 | @Test 85 | public void setMotorState_throwsIfClosed() throws IOException { 86 | mDriver.close(); 87 | mExpectedException.expect(IllegalStateException.class); 88 | mDriver.setMotorState(0, MotorHat.MOTOR_STATE_RELEASE); 89 | } 90 | 91 | private void verifyPin(int pin, int on, int off) throws IOException { 92 | byte onLsb = (byte) (on & 0xFF); 93 | byte onMsb = (byte) (on >> 8); 94 | byte offLsb = (byte) (off & 0xFF); 95 | byte offMsb = (byte) (off >> 8); 96 | int offset = 4 * pin; 97 | verify(mI2c).writeRegByte(0x06 + offset, onLsb); 98 | verify(mI2c).writeRegByte(0x07 + offset, onMsb); 99 | verify(mI2c).writeRegByte(0x08 + offset, offLsb); 100 | verify(mI2c).writeRegByte(0x09 + offset, offMsb); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /lowpan/README.md: -------------------------------------------------------------------------------- 1 | LoWPAN driver for Android Things 2 | ================================= 3 | 4 | This driver supports UART-based LoWPAN peripherals that use the [Spinel][spinel] 5 | protocol with the [recommended UART framing mechanism][spinelframe]. This is the 6 | communications protocol supported by Network Co-Processor (NCP) devices running 7 | [OpenThread][openthread]. 8 | 9 | NOTE: these drivers are not production-ready. They are offered as sample 10 | implementations of Android Things user space drivers for common peripherals 11 | as part of the Developer Preview release. There is no guarantee 12 | of correctness, completeness or robustness. 13 | 14 | Hardware support 15 | ---------------- 16 | 17 | This driver has been tested with supported [OpenThread][openthread] developer 18 | boards running the [pre-built NCP firmware images][firmware]. We recommend the 19 | [Nordic nRF52840-PDK][nordic] to get started. 20 | 21 | For more details on building your own LoWPAN drivers to support additional 22 | hardware, see the [API guide][lowpan]. 23 | 24 | How to use the driver 25 | --------------------- 26 | 27 | ### Gradle dependency 28 | 29 | To use the `lowpan` driver, simply add the line below to your project's `build.gradle`, 30 | where `` matches the last version of the driver available on [jcenter][jcenter]. 31 | 32 | ``` 33 | dependencies { 34 | compile 'com.google.android.things.contrib:driver-lowpan:' 35 | } 36 | ``` 37 | 38 | ### Sample usage 39 | 40 | ```java 41 | import com.google.android.things.contrib.driver.lowpan.UartLowpanDriver; 42 | UartLowpanDriver mLowpanDriver; 43 | 44 | try { 45 | mLowpanDriver = new UartLowpanDriver( 46 | this, // context 47 | uartPortName, 48 | baudRate, 49 | hwFlowControl 50 | ); 51 | 52 | mLowpanDriver.register(); 53 | 54 | // At this point you can access the lowpan network through the APIs 55 | // provided by LowpanManager. 56 | } catch (IOException e) { 57 | // couldn't configure the lowpan driver... 58 | } 59 | 60 | // Unregister and close the input driver when finished: 61 | 62 | mLowpanDriver.unregister(); 63 | try { 64 | mLowpanDriver.close(); 65 | } catch (IOException e) { 66 | // error closing lowpan driver 67 | } 68 | ``` 69 | 70 | License 71 | ------- 72 | 73 | Copyright 2017 Google Inc. 74 | 75 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 76 | license agreements. See the NOTICE file distributed with this work for 77 | additional information regarding copyright ownership. The ASF licenses this 78 | file to you under the Apache License, Version 2.0 (the "License"); you may not 79 | use this file except in compliance with the License. You may obtain a copy of 80 | the License at 81 | 82 | http://www.apache.org/licenses/LICENSE-2.0 83 | 84 | Unless required by applicable law or agreed to in writing, software 85 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 86 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 87 | License for the specific language governing permissions and limitations under 88 | the License. 89 | 90 | [spinel]: https://tools.ietf.org/html/draft-rquattle-spinel-unified 91 | [spinelframe]: https://tools.ietf.org/html/draft-rquattle-spinel-unified-00#appendix-A.1.2 92 | [openthread]: https://openthread.io 93 | [firmware]: https://openthread.io/guides/ncp/firmware 94 | [nordic]: https://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK 95 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-lowpan/_latestVersion 96 | [lowpan]: https://developer.android.com/things/sdk/drivers/lowpan.html 97 | -------------------------------------------------------------------------------- /zxgesturesensor/src/main/java/com/google/android/things/contrib/driver/zxgesturesensor/GestureDetector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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.google.android.things.contrib.driver.zxgesturesensor; 18 | 19 | /** 20 | * A base gesture detector class. A gesture detector gets input from sensor and fires a callback 21 | * when a gesture is detected. 22 | */ 23 | public abstract class GestureDetector { 24 | protected ZXGestureSensor mSensor; 25 | protected ZXGestureSensor.OnGestureEventListener mListener; 26 | 27 | protected int mXpos; 28 | protected int mZpos; 29 | protected int[] mRanges = new int[2]; 30 | protected ZXGestureSensor.Gesture mGesture; 31 | protected int mGestureParams; 32 | 33 | public static final int POSITION_PENUP = 999; 34 | 35 | /** 36 | * Sets x position and puts it to gesture detector 37 | * @param xpos 38 | */ 39 | void setXpos(int xpos) { 40 | this.mXpos = xpos; 41 | updateXpos(xpos); 42 | } 43 | 44 | /** 45 | * Sets z position and puts it to gesture detector 46 | * @param zpos 47 | */ 48 | void setZpos(int zpos) { 49 | this.mZpos = zpos; 50 | updateZpos(zpos); 51 | } 52 | 53 | /** 54 | * Sets sensor in pen-up state (nothing is detected) 55 | */ 56 | void penUp() { 57 | mXpos = mZpos = POSITION_PENUP; 58 | updatePenUp(); 59 | } 60 | 61 | /** 62 | * Sets ranges of two IR LEDs on the sensor 63 | * @param rangeL left LED 64 | * @param rangeR right LED 65 | */ 66 | void setRanges(int rangeL, int rangeR) { 67 | this.mRanges[0] = rangeL; 68 | this.mRanges[1] = rangeR; 69 | } 70 | 71 | /** 72 | * Sets gesture and its parameter, puts them to gesture detector 73 | * @param gesture gesture to be set 74 | * @param gestureParams param associated with the gesture 75 | */ 76 | void setGesture(ZXGestureSensor.Gesture gesture, int gestureParams) { 77 | this.mGesture = gesture; 78 | this.mGestureParams = gestureParams; 79 | updateGesture(gesture, gestureParams); 80 | } 81 | 82 | public int getXpos() { 83 | return mXpos; 84 | } 85 | 86 | public int getZpos() { 87 | return mZpos; 88 | } 89 | 90 | public int[] getRanges() { 91 | return mRanges; 92 | } 93 | 94 | public int getGestureParams() { 95 | return mGestureParams; 96 | } 97 | 98 | public ZXGestureSensor.Gesture getGesture() { 99 | return mGesture; 100 | } 101 | 102 | protected abstract void updateXpos(int xpos); 103 | protected abstract void updateZpos(int zpos); 104 | protected abstract void updateGesture(ZXGestureSensor.Gesture gesture, int gestureParams); 105 | protected abstract void updatePenUp(); 106 | 107 | public void setListener(ZXGestureSensor.OnGestureEventListener listener) { 108 | mListener = listener; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /matrixkeypad/src/test/java/com/google/android/things/contrib/driver/matrixkeypad/MatrixKeypadTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 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 | package com.google.android.things.contrib.driver.matrixkeypad; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertFalse; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import android.os.Handler; 23 | import android.os.HandlerThread; 24 | import android.view.KeyEvent; 25 | import com.google.android.things.contrib.driver.matrixkeypad.MatrixKeypad.OnKeyEventListener; 26 | import com.google.android.things.pio.Gpio; 27 | import java.io.IOException; 28 | import org.junit.After; 29 | import org.junit.Test; 30 | import org.powermock.api.mockito.PowerMockito; 31 | 32 | public class MatrixKeypadTest { 33 | private static final Gpio[] mRowPins = new Gpio[] {PowerMockito.mock(Gpio.class)}; 34 | private static final Gpio[] mColPins = new Gpio[] {PowerMockito.mock(Gpio.class)}; 35 | private static final int[] mKeyCodes = new int[] {KeyEvent.KEYCODE_A}; 36 | 37 | private MatrixKeypad mMatrixKeypad; 38 | 39 | /** 40 | * Tests that the callback will retrieve the expected values. 41 | * @throws IOException 42 | */ 43 | @Test 44 | public void testCallbackKeyDown() throws IOException { 45 | final int[] index = {0}; 46 | final int[] testKeys = new int[] {KeyEvent.KEYCODE_A, KeyEvent.KEYCODE_NUMPAD_1, 47 | KeyEvent.KEYCODE_PERIOD}; 48 | 49 | mMatrixKeypad = new MatrixKeypad(mRowPins, mColPins, mKeyCodes, 50 | PowerMockito.mock(Handler.class)); 51 | mMatrixKeypad.setKeyCallback(new OnKeyEventListener() { 52 | @Override 53 | public void onKeyEvent(MatrixKey matrixKey) { 54 | assertEquals(testKeys[index[0]++], matrixKey.getKeyCode()); 55 | assertTrue(matrixKey.isPressed()); 56 | } 57 | }); 58 | 59 | for (int key : testKeys) { 60 | mMatrixKeypad.keyDown(key); 61 | } 62 | } 63 | 64 | /** 65 | * Tests that the callback will retrieve the expected values. 66 | * @throws IOException 67 | */ 68 | @Test 69 | public void testCallbackKeyUp() throws IOException { 70 | final int[] index = {0}; 71 | final int[] testKeys = new int[] {KeyEvent.KEYCODE_A, KeyEvent.KEYCODE_NUMPAD_1, 72 | KeyEvent.KEYCODE_PERIOD}; 73 | 74 | mMatrixKeypad = new MatrixKeypad(mRowPins, mColPins, mKeyCodes, 75 | PowerMockito.mock(Handler.class)); 76 | mMatrixKeypad.setKeyCallback(new OnKeyEventListener() { 77 | @Override 78 | public void onKeyEvent(MatrixKey matrixKey) { 79 | assertEquals(testKeys[index[0]++], matrixKey.getKeyCode()); 80 | assertFalse(matrixKey.isPressed()); 81 | } 82 | }); 83 | 84 | for (int key : testKeys) { 85 | mMatrixKeypad.keyUp(key); 86 | } 87 | } 88 | 89 | @After 90 | public void closeDriver() throws IOException { 91 | mMatrixKeypad.close(); 92 | } 93 | } -------------------------------------------------------------------------------- /button/README.md: -------------------------------------------------------------------------------- 1 | Button driver for Android Things 2 | ================================ 3 | 4 | This driver supports GPIO buttons. 5 | 6 | NOTE: these drivers are not production-ready. They are offered as sample 7 | implementations of Android Things user space drivers for common peripherals 8 | as part of the Developer Preview release. There is no guarantee 9 | of correctness, completeness or robustness. 10 | 11 | How to use the driver 12 | --------------------- 13 | 14 | ### Gradle dependency 15 | 16 | To use the `button` driver, simply add the line below to your project's `build.gradle`, 17 | where `` matches the last version of the driver available on [jcenter][jcenter]. 18 | 19 | ``` 20 | dependencies { 21 | compile 'com.google.android.things.contrib:driver-button:' 22 | } 23 | ``` 24 | 25 | ### Sample usage 26 | 27 | ```java 28 | import com.google.android.things.contrib.driver.button.Button; 29 | 30 | // Access the Button and listen for events: 31 | 32 | Button mButton; 33 | 34 | try { 35 | mButton = new Button(gpioPinName, 36 | // high signal indicates the button is pressed 37 | // use with a pull-down resistor 38 | Button.LogicState.PRESSED_WHEN_HIGH 39 | ); 40 | mButton.setOnButtonEventListener(new OnButtonEventListener() { 41 | @Override 42 | public void onButtonEvent(Button button, boolean pressed) { 43 | // do something awesome 44 | } 45 | }); 46 | } catch (IOException e) { 47 | // couldn't configure the button... 48 | } 49 | 50 | // Close the Button when finished: 51 | 52 | try { 53 | mButton.close(); 54 | } catch (IOException e) { 55 | // error closing button 56 | } 57 | ``` 58 | 59 | Alternatively, you can register a `ButtonInputDriver` with the system and receive `KeyEvent`s 60 | through the standard Android APIs: 61 | ```java 62 | ButtonInputDriver mInputDriver; 63 | 64 | try { 65 | mInputDriver = new ButtonInputDriver(gpioPinName, 66 | Button.LogicState.PRESSED_WHEN_HIGH, 67 | KeyEvent.KEYCODE_A // the keycode to send 68 | ); 69 | mInputDriver.register(); 70 | } catch (IOException e) { 71 | // error configuring button... 72 | } 73 | 74 | // Override key event callbacks in your Activity: 75 | 76 | @Override 77 | public boolean onKeyDown(int keyCode, KeyEvent event) { 78 | if (keyCode == KeyEvent.KEYCODE_A) { 79 | // do something awesome 80 | return true; // indicate we handled the event 81 | } 82 | return super.onKeyDown(keyCode, event); 83 | } 84 | 85 | // Unregister and close the input driver when finished: 86 | 87 | mInputDriver.unregister(); 88 | try { 89 | mInputDriver.close(); 90 | } catch (IOException e) { 91 | // error closing input driver 92 | } 93 | ``` 94 | 95 | License 96 | ------- 97 | 98 | Copyright 2016 Google Inc. 99 | 100 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 101 | license agreements. See the NOTICE file distributed with this work for 102 | additional information regarding copyright ownership. The ASF licenses this 103 | file to you under the Apache License, Version 2.0 (the "License"); you may not 104 | use this file except in compliance with the License. You may obtain a copy of 105 | the License at 106 | 107 | http://www.apache.org/licenses/LICENSE-2.0 108 | 109 | Unless required by applicable law or agreed to in writing, software 110 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 111 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 112 | License for the specific language governing permissions and limitations under 113 | the License. 114 | 115 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-button/_latestVersion 116 | -------------------------------------------------------------------------------- /tm1637/src/main/java/com/google/android/things/contrib/driver/tm1637/Tm1637.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 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.google.android.things.contrib.driver.tm1637; 18 | 19 | import android.support.annotation.VisibleForTesting; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | 24 | /** 25 | * Driver for a Tm1637 seven-segment display with 4 digits. Usually it's preferable to use a 26 | * {@link NumericDisplay} instead. 27 | */ 28 | public class Tm1637 implements Closeable { 29 | 30 | private static final int TM1637_ADDR = 0x40; 31 | private static final int TM1637_REG = 0xc0; 32 | private static final int TM1637_CMD = 0x88; 33 | 34 | /** 35 | * The maximum brightness of the display 36 | */ 37 | public static final int MAX_BRIGHTNESS = 0x07; 38 | 39 | /** 40 | * The maximum number of bytes that can be written at a time 41 | */ 42 | public static final int MAX_DATA_LENGTH = 4; 43 | 44 | I2cBitBangDevice mDevice; 45 | 46 | /** 47 | * Create a new driver for a TM1637 peripheral connected on the given GPIO pins. 48 | */ 49 | public Tm1637(String dataPin, String clockPin) throws IOException { 50 | mDevice = new I2cBitBangDevice(TM1637_ADDR, dataPin, clockPin); 51 | } 52 | 53 | @VisibleForTesting 54 | /* package */ Tm1637(I2cBitBangDevice device) throws IOException { 55 | mDevice = device; 56 | } 57 | 58 | /** 59 | * Close the device and the underlying device. 60 | */ 61 | @Override 62 | public void close() throws IOException { 63 | if (mDevice != null) { 64 | try { 65 | mDevice.close(); 66 | } finally { 67 | mDevice = null; 68 | } 69 | } 70 | } 71 | 72 | /** 73 | * Set LED display brightness. 74 | * @param value brigthness value between 0 and {@link #MAX_BRIGHTNESS} 75 | */ 76 | public void setBrightness(int value) throws IOException { 77 | if (mDevice == null) { 78 | throw new IllegalStateException("Device not opened"); 79 | } 80 | if (value < 0 || value > MAX_BRIGHTNESS) { 81 | throw new IllegalArgumentException("brightness must be between 0 and " + 82 | MAX_BRIGHTNESS); 83 | } 84 | mDevice.write(new byte[]{(byte) (TM1637_CMD | (byte) value)}, 1); 85 | } 86 | 87 | /** 88 | * Set LED display brightness. 89 | * @param value brigthness value between 0 and 1.0f 90 | */ 91 | public void setBrightness(float value) throws IOException { 92 | int val = Math.round(value * MAX_BRIGHTNESS); 93 | setBrightness(val); 94 | } 95 | 96 | /** 97 | * Write up to {@link #MAX_DATA_LENGTH} bytes of LED data. 98 | */ 99 | public void writeData(byte[] data) throws IOException { 100 | if (mDevice == null) { 101 | throw new IllegalStateException("Device not opened"); 102 | } 103 | if (data.length > MAX_DATA_LENGTH) { 104 | throw new IllegalArgumentException("data size should be less than " + MAX_DATA_LENGTH); 105 | } 106 | mDevice.writeRegBuffer(TM1637_REG, data, data.length); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /thermalprinter/README.md: -------------------------------------------------------------------------------- 1 | # Thermal Library driver for Android Things 2 | 3 | This driver exposes a [UART](https://developer.android.com/things/reference/com/google/android/things/pio/UartDevice.html) 4 | interface to a serial thermal printer. This printer can print text with a variety of text styles. Additionally, it 5 | can print bitmaps and barcodes. 6 | 7 | This driver works with the thermal printers from Adafruit, such as the 8 | [CsnA2 Mini Thermal Printer](https://www.adafruit.com/product/597). 9 | When you power on your device, press the button in order to get a printout of device information. Take 10 | note of the firmware version. This driver supports firmware v2.68 and above. 11 | 12 | The thermal printer requires an external power supply. It cannot be 13 | powered by the developer board. 14 | 15 | 16 | At this moment the driver has only been tested on the Raspberry Pi 3 and 17 | the imx7.d. 18 | 19 | NOTE: these drivers are not production-ready. They are offered as sample 20 | implementations of Android Things user space drivers for common peripherals 21 | as part of the Developer Preview release. There is no guarantee 22 | of correctness, completeness or robustness. 23 | 24 | 25 | ## How to use the driver 26 | 27 | ### Gradle dependency 28 | 29 | To use the `thermalprinter` driver, simply add the line below to your project's `build.gradle`, 30 | where `` matches the last version of the driver available on [jcenter][jcenter]. 31 | 32 | ``` 33 | dependencies { 34 | compile 'com.google.android.things.contrib:driver-thermalprinter:' 35 | } 36 | ``` 37 | 38 | ### Sample usage 39 | 40 | 41 | ```java 42 | // import the Thermal Printer driver 43 | import com.google.android.things.contrib.driver.thermalprinter.ThermalPrinter; 44 | ``` 45 | 46 | ```java 47 | // Start thermal printer. 48 | mThermalPrinter = new ThermalPrinter("UART0"); 49 | 50 | // Make sure to call mThermalPrinter.close() in the onDestroy() method in your activity 51 | ``` 52 | 53 | ```java 54 | // Start printing text. 55 | mThermalPrinter.enqueue(new TextJob().printText("Hello World")); 56 | ``` 57 | 58 | ```java 59 | // Print stylized text. 60 | mThermalPrinter.enqueue(new TextJob() 61 | .justify(CsnA2.JUSTIFY_CENTER) 62 | .setDoubleHeight(true) 63 | .printText("Hello World")); 64 | ``` 65 | 66 | ```java 67 | // Print a barcode. 68 | mThermalPrinter.enqueue(new BarcodeJob() 69 | .setBarcodeHeight(60) 70 | .printBarcode("GOOGLE", CsnA2.UPC_A)); 71 | ``` 72 | 73 | ```java 74 | // Print a bitmap 75 | mThermalPrinter.enqueue(new BitmapJob().printBitmap(bitmap)); 76 | // Feed several lines afterward 77 | mThermalPrinter.enqueue(PrinterJob.feedLines(3)); 78 | ``` 79 | 80 | ```java 81 | // Close Thermal Printer driver 82 | try { 83 | mThermalPrinter.close(); 84 | } catch (IOException e) { 85 | Log.e(TAG, "Unable to close thermal printer driver", e); 86 | } finally { 87 | mThermalPrinter = null; 88 | } 89 | ``` 90 | 91 | ## License 92 | 93 | Copyright 2018 Google Inc. 94 | 95 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 96 | license agreements. See the NOTICE file distributed with this work for 97 | additional information regarding copyright ownership. The ASF licenses this 98 | file to you under the Apache License, Version 2.0 (the "License"); you may not 99 | use this file except in compliance with the License. You may obtain a copy of 100 | the License at 101 | 102 | http://www.apache.org/licenses/LICENSE-2.0 103 | 104 | Unless required by applicable law or agreed to in writing, software 105 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 106 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 107 | License for the specific language governing permissions and limitations under 108 | the License. 109 | 110 | [jcenter]: https://bintray.com/google/androidthings/contrib-driver-thermalprinter --------------------------------------------------------------------------------