Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 2363ce9

Browse files
author
Bruce j Beare
authored
Merge pull request #19 from intel-iot-devkit/BME280
Example Application for BME280 Temperature, Pressure and Humidity Sen…
2 parents ffce887 + d0527f2 commit 2363ce9

File tree

15 files changed

+192
-0
lines changed

15 files changed

+192
-0
lines changed

bme280/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

bme280/build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.2"
6+
7+
defaultConfig {
8+
applicationId "com.example.upm.androidthings.driversamples"
9+
minSdkVersion 24
10+
targetSdkVersion 25
11+
versionCode 1
12+
versionName "1.0"
13+
14+
jackOptions {
15+
enabled true
16+
}
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
}
29+
30+
dependencies {
31+
compile fileTree(dir: 'libs', include: ['*.jar'])
32+
compile project(':driverlibrary')
33+
compile 'io.mraa.at.upm:upm_bmp280:1.2.0'
34+
}

bme280/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/brillo/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+
#}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.upm.androidthings.driversamples">
4+
5+
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
6+
android:label="@string/app_name" android:supportsRtl="true">
7+
<activity android:name=".BMETempActivity">
8+
<intent-filter>
9+
<action android:name="android.intent.action.MAIN" />
10+
11+
<category android:name="android.intent.category.LAUNCHER" />
12+
</intent-filter>
13+
</activity>
14+
</application>
15+
16+
</manifest>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.example.upm.androidthings.driversamples;
2+
3+
import android.app.Activity;
4+
import android.os.AsyncTask;
5+
import android.os.Bundle;
6+
import android.util.Log;
7+
8+
import com.example.upm.androidthings.driverlibrary.BoardDefaults;
9+
import mraa.mraa;
10+
11+
public class BMETempActivity extends Activity {
12+
13+
private static final String TAG = "BMETempActivity";
14+
15+
upm_bmp280.BME280 tphSensor;
16+
17+
@Override
18+
protected void onCreate(Bundle savedInstanceState) {
19+
super.onCreate(savedInstanceState);
20+
setContentView(R.layout.activity_bmetemp);
21+
22+
BoardDefaults bd = new BoardDefaults(this.getApplicationContext());
23+
int i2cIndex = -1;
24+
25+
switch (bd.getBoardVariant()) {
26+
case BoardDefaults.DEVICE_EDISON_ARDUINO:
27+
i2cIndex = mraa.getI2cLookup(getString(R.string.Bme_Edison_Arduino));
28+
break;
29+
case BoardDefaults.DEVICE_EDISON_SPARKFUN:
30+
i2cIndex = mraa.getI2cLookup(getString(R.string.Bme_Edison_Sparkfun));
31+
break;
32+
case BoardDefaults.DEVICE_JOULE_TUCHUCK:
33+
i2cIndex = mraa.getI2cLookup(getString(R.string.Bme_Joule_Tuchuck));
34+
break;
35+
default:
36+
throw new IllegalStateException("Unknown Board Variant: " + bd.getBoardVariant());
37+
}
38+
39+
tphSensor = new upm_bmp280.BME280(i2cIndex);
40+
AsyncTask.execute(tphSensorTask);
41+
}
42+
43+
Runnable tphSensorTask = new Runnable() {
44+
45+
@Override
46+
public void run() {
47+
// Moves the current thread into the background
48+
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
49+
50+
try {
51+
while (true)
52+
{
53+
// update our values from the sensor
54+
tphSensor.update();
55+
56+
Log.i(TAG,"Compensation Temperature: " + tphSensor.getTemperature()
57+
+ " C / "
58+
+ tphSensor.getTemperature(true)
59+
+ " F");
60+
61+
Log.i(TAG,"Pressure: "
62+
+ tphSensor.getPressure()
63+
+ " Pa");
64+
65+
Log.i(TAG,"Computed Altitude: "
66+
+ tphSensor.getAltitude()
67+
+ " m");
68+
69+
Log.i(TAG,"Humidity: "
70+
+ tphSensor.getHumidity()
71+
+ " %RH");
72+
Thread.sleep(1000);
73+
}
74+
75+
} catch (InterruptedException e) {
76+
Thread.currentThread().interrupt();
77+
} finally {
78+
tphSensor.reset();
79+
BMETempActivity.this.finish();
80+
81+
}
82+
}
83+
};
84+
85+
@Override
86+
protected void onDestroy() {
87+
super.onDestroy();
88+
89+
Thread.currentThread().interrupt();
90+
tphSensor.reset();
91+
}
92+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_bmetemp"
4+
android:layout_width="match_parent" android:layout_height="match_parent"
5+
android:paddingBottom="@dimen/activity_vertical_margin"
6+
android:paddingLeft="@dimen/activity_horizontal_margin"
7+
android:paddingRight="@dimen/activity_horizontal_margin"
8+
android:paddingTop="@dimen/activity_vertical_margin"
9+
tools:context="com.example.upm.androidthings.driversamples.BMETempActivity">
10+
11+
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
12+
android:text="Hello World!" />
13+
</RelativeLayout>
3.34 KB
Loading
2.15 KB
Loading
4.73 KB
Loading
7.54 KB
Loading

0 commit comments

Comments
 (0)