-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6eaabf3
commit ee7a13d
Showing
9 changed files
with
239 additions
and
1 deletion.
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
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,41 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
|
||
group='com.github.gradlman.SensorLib' | ||
version = '1.0' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
|
||
|
||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
api 'io.reactivex.rxjava2:rxandroid:2.1.0' | ||
api 'io.reactivex.rxjava2:rxjava:2.2.6' | ||
implementation 'com.android.support:appcompat-v7:27.1.1' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
api project(path: ':sensorlib') | ||
} |
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 |
28 changes: 28 additions & 0 deletions
28
SensorLib/rxsensorlib/src/androidTest/java/de/fau/sensorlib/rx/ExampleInstrumentedTest.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,28 @@ | ||
package de.fau.sensorlib.rx; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest | ||
{ | ||
@Test | ||
public void useAppContext() | ||
{ | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("de.fau.sensorlib.rx.test", appContext.getPackageName()); | ||
} | ||
} |
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,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="de.fau.sensorlib.rx"/> |
123 changes: 123 additions & 0 deletions
123
SensorLib/rxsensorlib/src/main/java/de/fau/sensorlib/rx/RxSensorDataProcessor.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,123 @@ | ||
package de.fau.sensorlib.rx; | ||
|
||
import de.fau.sensorlib.SensorDataProcessor; | ||
import de.fau.sensorlib.dataframe.SensorDataFrame; | ||
import de.fau.sensorlib.sensors.AbstractSensor; | ||
import io.reactivex.Observable; | ||
import io.reactivex.subjects.PublishSubject; | ||
|
||
public class RxSensorDataProcessor extends SensorDataProcessor | ||
{ | ||
|
||
public enum SensorState | ||
{ | ||
CREATED, CONNECTING, CONNECTED, DISCONNECTED, CONNECTION_LOST, STREAMING_STARTED, STREAMING_STOPPED | ||
} | ||
|
||
public static class SensorNotification<T> | ||
{ | ||
private final AbstractSensor sensor; | ||
private final T notification; | ||
|
||
public SensorNotification(AbstractSensor sensor, T notification) | ||
{ | ||
this.sensor = sensor; | ||
this.notification = notification; | ||
} | ||
|
||
public AbstractSensor getSensor() | ||
{ | ||
return sensor; | ||
} | ||
|
||
public T getNotification() | ||
{ | ||
return notification; | ||
} | ||
} | ||
|
||
private PublishSubject<SensorNotification<SensorState>> sensorStateSubject = PublishSubject.create(); | ||
private PublishSubject<SensorNotification<Double>> sensorSamplingRateSubject = PublishSubject.create(); | ||
private PublishSubject<SensorNotification<Object>> sensorNotificationSubject = PublishSubject.create(); | ||
private PublishSubject<SensorDataFrame> newDataSubject = PublishSubject.create(); | ||
|
||
|
||
@Override | ||
public void onSensorCreated(AbstractSensor sensor) | ||
{ | ||
sensorStateSubject.onNext(new SensorNotification<SensorState>(sensor, SensorState.CREATED)); | ||
} | ||
|
||
@Override | ||
public void onConnected(AbstractSensor sensor) | ||
{ | ||
sensorStateSubject.onNext(new SensorNotification<SensorState>(sensor, SensorState.CONNECTED)); | ||
} | ||
|
||
@Override | ||
public void onConnecting(AbstractSensor sensor) | ||
{ | ||
sensorStateSubject.onNext(new SensorNotification<SensorState>(sensor, SensorState.CONNECTING)); | ||
} | ||
|
||
@Override | ||
public void onDisconnected(AbstractSensor sensor) | ||
{ | ||
sensorStateSubject.onNext(new SensorNotification<SensorState>(sensor, SensorState.DISCONNECTED)); | ||
} | ||
|
||
@Override | ||
public void onConnectionLost(AbstractSensor sensor) | ||
{ | ||
sensorStateSubject.onNext(new SensorNotification<SensorState>(sensor, SensorState.CONNECTION_LOST)); | ||
} | ||
|
||
@Override | ||
public void onStartStreaming(AbstractSensor sensor) | ||
{ | ||
sensorStateSubject.onNext(new SensorNotification<SensorState>(sensor, SensorState.STREAMING_STARTED)); | ||
} | ||
|
||
@Override | ||
public void onStopStreaming(AbstractSensor sensor) | ||
{ | ||
sensorStateSubject.onNext(new SensorNotification<SensorState>(sensor, SensorState.STREAMING_STOPPED)); | ||
} | ||
|
||
@Override | ||
public void onSamplingRateChanged(AbstractSensor sensor, double newSamplingRate) | ||
{ | ||
sensorSamplingRateSubject.onNext(new SensorNotification<Double>(sensor, newSamplingRate)); | ||
} | ||
|
||
@Override | ||
public void onNotify(AbstractSensor sensor, Object notification) | ||
{ | ||
sensorNotificationSubject.onNext(new SensorNotification<Object>(sensor, notification)); | ||
} | ||
|
||
@Override | ||
public void onNewData(SensorDataFrame data) | ||
{ | ||
newDataSubject.onNext(data); | ||
} | ||
|
||
public Observable<SensorNotification<SensorState>> getSensorStateObservable() | ||
{ | ||
return sensorStateSubject; | ||
} | ||
|
||
public Observable<SensorNotification<Double>> getSensorSamplingRateObservable() | ||
{ | ||
return sensorSamplingRateSubject; | ||
} | ||
|
||
public Observable<SensorNotification<Object>> getSensorNotificationObservable() | ||
{ | ||
return sensorNotificationSubject; | ||
} | ||
|
||
public <T extends SensorDataFrame> Observable<T> getNewDataObservable() { | ||
return (Observable<T>) newDataSubject; | ||
} | ||
} |
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,3 @@ | ||
<resources> | ||
<string name="app_name">RxSensorLib</string> | ||
</resources> |
19 changes: 19 additions & 0 deletions
19
SensorLib/rxsensorlib/src/test/java/de/fau/sensorlib/rx/ExampleUnitTest.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,19 @@ | ||
package de.fau.sensorlib.rx; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
public class ExampleUnitTest | ||
{ | ||
@Test | ||
public void addition_isCorrect() | ||
{ | ||
assertEquals(4, 2 + 2); | ||
} | ||
} |
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