forked from leinardi/androidthings-drivers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request leinardi#8 from leinardi/epaperdriverhat
E-Paper Driver HAT
- Loading branch information
Showing
30 changed files
with
1,179 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Change Log | ||
|
||
## [0.1] - 2018-01-19 | ||
- initial version | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# E-Paper Driver HAT display driver for Android Things | ||
|
||
[![Maven metadata URI](https://img.shields.io/maven-metadata/v/http/jcenter.bintray.com/com/leinardi/android/things/driver-epaperdriverhat/maven-metadata.xml.svg?style=plastic)](https://jcenter.bintray.com/com/leinardi/android/things/driver-epaperdriverhat/maven-metadata.xml) | ||
[![Build Status](https://img.shields.io/travis/leinardi/androidthings-drivers/master.svg?style=plastic)](https://travis-ci.org/leinardi/androidthings-drivers) | ||
[![GitHub license](https://img.shields.io/github/license/leinardi/androidthings-drivers.svg?style=plastic)](https://github.com/leinardi/androidthings-drivers/blob/master/LICENSE) | ||
|
||
This driver supports E-Paper screen peripherals connected with an E-Paper Driver HAT. | ||
|
||
## Supported displays | ||
|
||
<!-- DISPLAY_LIST_START --> | ||
Part Number | Class | Size | Color | Resolution | Interface | ||
:---:|:---:| --- | --- | --- | --- | ||
[GDEW075T8](https://www.waveshare.com/wiki/7.5inch_e-Paper_HAT) | `Gdew075t8Epd` | 7.5" | Black, White | 640x384 | SPI | ||
<!-- DISPLAY_LIST_END --> | ||
|
||
NOTE: these drivers are not production-ready. They are offered as sample | ||
implementations of Android Things user space drivers for common peripherals | ||
as part of the Developer Preview release. There is no guarantee | ||
of correctness, completeness or robustness. | ||
|
||
This driver is based on the [GxEPD driver from ZinggJM](https://github.com/ZinggJM/GxEPD) | ||
|
||
## How to use the driver | ||
|
||
### Gradle dependency | ||
|
||
To use the `epaperdriverhat` driver, simply add the line below to your project's `build.gradle`, | ||
where `<version>` matches the last version of the driver available on [jcenter][jcenter]. | ||
|
||
``` | ||
dependencies { | ||
implementation 'com.leinardi.android.things:driver-epaperdriverhat:<version>' | ||
} | ||
``` | ||
|
||
### Sample usage | ||
|
||
```java | ||
public class EpdScreenActivity extends Activity { | ||
private static final String TAG = EpdScreenActivity.class.getSimpleName(); | ||
Gdew075t8Epd mEpd; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
try { | ||
mEpd = new Gdew075t8Epd(); | ||
// Show checkerboard | ||
for (int i = 0; i < mEpd.getDisplayWidth(); i++) { | ||
for (int j = 0; j < mEpd.getDisplayHeight(); j++) { | ||
mEpd.setPixel(i, j, (i % 2) == (j % 2)); | ||
} | ||
} | ||
mEpd.show(); | ||
} catch (IOException e) { | ||
Log.e(TAG, "Error initializing EPD", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
try { | ||
mEpd.close(); | ||
} catch (IOException e) { | ||
Log.e(TAG, "Exception closing EPD", e); | ||
} finally { | ||
mEpd = null; | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
||
## License | ||
|
||
Copyright 2018 Roberto Leinardi | ||
|
||
Licensed to the Apache Software Foundation (ASF) under one or more contributor | ||
license agreements. See the NOTICE file distributed with this work for | ||
additional information regarding copyright ownership. The ASF licenses this | ||
file to you under the Apache License, Version 2.0 (the "License"); you may not | ||
use this file except in compliance with the License. You may obtain a copy of | ||
the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations under | ||
the License. | ||
|
||
[jcenter]: https://bintray.com/leinardi/androidthings/driver-epaperdriverhat/_latestVersion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2018 Roberto Leinardi. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
apply plugin: 'com.android.library' | ||
apply from: rootProject.file('checkstyle.gradle') | ||
|
||
android { | ||
compileSdkVersion build_versions.target_sdk | ||
buildToolsVersion build_versions.build_tools | ||
|
||
apply from: 'mavenConfig.gradle' | ||
|
||
defaultConfig { | ||
minSdkVersion build_versions.min_sdk | ||
targetSdkVersion build_versions.target_sdk | ||
versionCode build_versions.version_code | ||
versionName mvn_config.version as String | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility build_versions.java_version | ||
targetCompatibility build_versions.java_version | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
compileOnly deps.androidthings | ||
implementation deps.support.annotations | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2018 Roberto Leinardi. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
def mvn_config = [:] | ||
mvn_config.repository = 'androidthings' | ||
mvn_config.group_id = 'com.leinardi.android.things' | ||
mvn_config.artifact_id = 'driver-epaperdriverhat' | ||
mvn_config.version = '0.1' | ||
mvn_config.licenses = 'Apache-2.0' // Comma separated | ||
mvn_config.website = 'https://github.com/leinardi/androidthings-drivers' | ||
mvn_config.issue_tracker_url = 'https://github.com/leinardi/androidthings-drivers/issues' | ||
mvn_config.vcs_url = 'https://github.com/leinardi/androidthings-drivers.git' | ||
mvn_config.description = 'E-Paper Driver HAT driver for Android Things' | ||
mvn_config.tags = 'epaperdriverhat,gdew075t8,android-things,android,raspberry-pi' // Comma separated | ||
mvn_config.githubRepo = 'leinardi/androidthings-drivers' | ||
mvn_config.inception_year = '2018' | ||
mvn_config.dryRun = false | ||
mvn_config.publish = false | ||
mvn_config.override = true | ||
|
||
ext.mvn_config = mvn_config | ||
|
||
apply from: rootProject.file('maven.gradle') | ||
apply from: rootProject.file('bintray.gradle') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- | ||
~ Copyright 2018 Roberto Leinardi. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<manifest package="com.leinardi.android.things.driver.epd" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application> | ||
<uses-library | ||
android:name="com.google.android.things" | ||
android:required="false" /> | ||
</application> | ||
</manifest> |
61 changes: 61 additions & 0 deletions
61
...verhat/src/main/java/com/leinardi/android/things/driver/epaperdriverhat/BitmapHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2018 Roberto Leinardi. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.leinardi.android.things.driver.epaperdriverhat; | ||
|
||
import android.graphics.Bitmap; | ||
|
||
public class BitmapHelper { | ||
private static final int GRADIENT_CUTOFF = 85; // Tune for gradient picker on grayscale images. | ||
|
||
private BitmapHelper() { | ||
} | ||
|
||
/** | ||
* Converts a bitmap image to LCD screen data and sets it on the given screen at the specified | ||
* offset. | ||
* | ||
* @param mScreen The e-paper screen to write the bitmap data to. | ||
* @param xOffset The horizontal offset to draw the image at. | ||
* @param yOffset The vertical offset to draw the image at. | ||
* @param bmp The bitmap image that you want to convert to screen data. | ||
* @param drawWhite true for drawing only white pixels, false for drawing grayscale pixel | ||
* based on {@link #GRADIENT_CUTOFF}. | ||
*/ | ||
public static void setBmpData(Epd mScreen, int xOffset, int yOffset, Bitmap bmp, boolean drawWhite) { | ||
int width = bmp.getWidth(); | ||
int height = bmp.getHeight(); | ||
|
||
for (int y = 0; y < height; y++) { | ||
for (int x = 0; x < width; x++) { | ||
int pixel = bmp.getPixel(x, y); | ||
if (!drawWhite) { // Look at Alpha channel instead | ||
if ((pixel & 0xFF) <= GRADIENT_CUTOFF) { | ||
mScreen.setPixel(x + xOffset, y + yOffset, true); | ||
} else { | ||
mScreen.setPixel(x + xOffset, y + yOffset, false); | ||
} | ||
} else { | ||
if (pixel == -1) { // Only draw white pixels | ||
mScreen.setPixel(x + xOffset, y + yOffset, true); | ||
} else { | ||
mScreen.setPixel(x + xOffset, y + yOffset, false); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.