modified example accordingto latest version of irext-core
This commit is contained in:
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion "26.0.0"
|
||||
buildToolsVersion '26.0.2'
|
||||
defaultConfig {
|
||||
applicationId "net.irext.pi3sr"
|
||||
minSdkVersion 25
|
||||
@@ -21,6 +21,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
provided 'com.google.android.things:androidthings:0.5.1-devpreview'
|
||||
compile 'com.android.support:appcompat-v7:26.+'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<uses-library android:name="com.google.android.things" />
|
||||
|
||||
<activity android:name=".MainActivity">
|
||||
<activity android:name=".ui.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.irext.pi3sr;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
/**
|
||||
*
|
||||
* Pi3SRApplication
|
||||
*
|
||||
* created by strawmanbobi 2017-06-25
|
||||
*/
|
||||
public class Pi3SRApplication extends Application {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package net.irext.pi3sr.driver;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.things.pio.Gpio;
|
||||
import com.google.android.things.pio.GpioCallback;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* HC-SR501 driver
|
||||
*
|
||||
* created by strawmanbobi 2017-06-25
|
||||
*/
|
||||
public class HCSR501 implements MotionSensor {
|
||||
|
||||
private static final String TAG = HCSR501.class.getSimpleName();
|
||||
|
||||
private final Gpio bus;
|
||||
|
||||
private final MotionSensor.Listener listener;
|
||||
|
||||
public HCSR501(Gpio bus, Listener listener) {
|
||||
this.bus = bus;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startup() {
|
||||
try {
|
||||
bus.setDirection(Gpio.DIRECTION_IN);
|
||||
bus.setActiveType(Gpio.ACTIVE_HIGH);
|
||||
bus.setEdgeTriggerType(Gpio.EDGE_RISING);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Sensor can't start - App is foobar'd", e);
|
||||
}
|
||||
try {
|
||||
bus.registerGpioCallback(callback);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Sensor can't register callback", e);
|
||||
}
|
||||
}
|
||||
|
||||
private final GpioCallback callback = new GpioCallback() {
|
||||
@Override
|
||||
public boolean onGpioEdge(Gpio gpio) {
|
||||
listener.onMovement();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
bus.unregisterGpioCallback(callback);
|
||||
try {
|
||||
bus.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to shut down. You might get errors next time you try to start.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.irext.pi3sr.driver;
|
||||
|
||||
/**
|
||||
*
|
||||
* motion sensor interface
|
||||
*
|
||||
* created by strawmanbobi 2017-06-25
|
||||
*/
|
||||
public interface MotionSensor {
|
||||
|
||||
void startup();
|
||||
|
||||
void shutdown();
|
||||
|
||||
public interface Listener {
|
||||
void onMovement();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,16 @@
|
||||
package net.irext.pi3sr;
|
||||
package net.irext.pi3sr.ui;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import net.irext.pi3sr.R;
|
||||
|
||||
/**
|
||||
*
|
||||
* MainActivity
|
||||
*
|
||||
* created by strawmanbobi 2017-06-25
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="net.irext.pi3sr.MainActivity">
|
||||
tools:context="net.irext.pi3sr.ui.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user