-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves the WS2801 driver to a new module and add tests
- Loading branch information
Xavi Rigau
committed
Jan 12, 2017
1 parent
72e4f65
commit 30b9a30
Showing
12 changed files
with
395 additions
and
174 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
170 changes: 0 additions & 170 deletions
170
app/src/main/java/com/xavirigau/ledcontroller/Ws2801.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
include ':app' | ||
include ':app', ':ws2801-driver' |
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,29 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
|
||
defaultConfig { | ||
minSdkVersion 24 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
provided 'com.google.android.things:androidthings:0.1-devpreview' | ||
|
||
testCompile 'junit:junit:4.12' | ||
testCompile "org.mockito:mockito-core:1.10.19" | ||
} |
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 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /usr/local/Cellar/android-sdk/24.4.1_1/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# 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,11 @@ | ||
<manifest package="com.xrigau.driver.ws2801" | ||
|
||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application> | ||
|
||
<uses-library android:name="com.google.android.things" /> | ||
|
||
</application> | ||
|
||
</manifest> |
46 changes: 46 additions & 0 deletions
46
ws2801-driver/src/main/java/com/xrigau/driver/ws2801/ColorUnpacker.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,46 @@ | ||
package com.xrigau.driver.ws2801; | ||
|
||
import com.xrigau.driver.ws2801.Ws2801.Mode; | ||
|
||
import android.graphics.Color; | ||
|
||
class ColorUnpacker { | ||
|
||
// RGB LED strip configuration that must be provided by the caller. | ||
private final Mode ledMode; | ||
|
||
ColorUnpacker(Mode ledMode) { | ||
this.ledMode = ledMode; | ||
} | ||
|
||
/** | ||
* Returns an WS2801 packet corresponding to the current brightness and given {@link Color}. | ||
* | ||
* @param color The {@link Color} to retrieve the protocol packet for. | ||
* @return WS2801 packet corresponding to the current brightness and given {@link Color}. | ||
*/ | ||
byte[] unpack(int color) { | ||
int r = Color.red(color); | ||
int g = Color.green(color); | ||
int b = Color.blue(color); | ||
return getOrderedRgbBytes(ledMode, (byte) r, (byte) g, (byte) b); | ||
} | ||
|
||
static byte[] getOrderedRgbBytes(Mode ledMode, byte r, byte g, byte b) { | ||
switch (ledMode) { | ||
case RBG: | ||
return new byte[]{r, b, g}; | ||
case BGR: | ||
return new byte[]{b, g, r}; | ||
case BRG: | ||
return new byte[]{b, r, g}; | ||
case GRB: | ||
return new byte[]{g, r, b}; | ||
case GBR: | ||
return new byte[]{g, b, r}; | ||
default: | ||
throw new IllegalArgumentException(ledMode.name() + " is an unknown " + Mode.class.getSimpleName()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.