diff --git a/mhz16/.gitignore b/mhz16/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/mhz16/.gitignore @@ -0,0 +1 @@ +/build diff --git a/mhz16/build.gradle b/mhz16/build.gradle new file mode 100644 index 0000000..bf77970 --- /dev/null +++ b/mhz16/build.gradle @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 Intel Corporation. + * + * 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.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + + defaultConfig { + applicationId "com.example.upm.androidthings.driversamples" + minSdkVersion 24 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + + jackOptions { + enabled true + } + + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile project(':driversupport') + compile 'io.mraa.at.upm:upm_mhz16:1.+' +} diff --git a/mhz16/proguard-rules.pro b/mhz16/proguard-rules.pro new file mode 100644 index 0000000..3ea928f --- /dev/null +++ b/mhz16/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/brillo/Android/Sdk/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 diff --git a/mhz16/src/main/AndroidManifest.xml b/mhz16/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6833938 --- /dev/null +++ b/mhz16/src/main/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mhz16/src/main/java/com/example/upm/androidthings/driversamples/MHZActivity.java b/mhz16/src/main/java/com/example/upm/androidthings/driversamples/MHZActivity.java new file mode 100644 index 0000000..be9c960 --- /dev/null +++ b/mhz16/src/main/java/com/example/upm/androidthings/driversamples/MHZActivity.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2017 Intel Corporation. + * + * 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.example.upm.androidthings.driversamples; + +import android.app.Activity; +import android.os.AsyncTask; +import android.os.Bundle; +import android.util.Log; +import android.widget.TextView; + +import com.example.upm.androidthings.driversupport.BoardDefaults; + +import mraa.mraa; + +public class MHZActivity extends Activity { + private static final String TAG = "MHZActivity"; + + upm_mhz16.MHZ16 mhz16; + TextView tv, tv1; + Runnable co2Task = new Runnable() { + + @Override + public void run() { + // Moves the current thread into the background + android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); + int i = 1; // iteration counter to defeat the chatty detector in Log.i + + if (mhz16.setupTty()) + { + try { + while (true) { + if (!mhz16.getData()) { + System.out.println("Failed to retrieve data"); + continue; + } + updateUI(i++, mhz16.getGas(), mhz16.getTemperature()); + + Thread.sleep(1000); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + mhz16.delete(); + MHZActivity.this.finish(); + } + } else { + MHZActivity.this.finish(); + } + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_mhz); + Log.d(TAG, "Starting MHZActivity"); + + int uartIndex = -1; + tv = (TextView) findViewById(R.id.text_value); + tv1 = (TextView) findViewById(R.id.textView); + BoardDefaults bd = new BoardDefaults(this.getApplicationContext()); + + switch (bd.getBoardVariant()) { + case BoardDefaults.DEVICE_EDISON_ARDUINO: + uartIndex = mraa.getUartLookup(getString(R.string.UART_Edison_Arduino)); + break; + case BoardDefaults.DEVICE_EDISON_SPARKFUN: + uartIndex = mraa.getUartLookup(getString(R.string.UART_Edison_Sparkfun)); + break; + case BoardDefaults.DEVICE_JOULE_TUCHUCK: + uartIndex = mraa.getUartLookup(getString(R.string.UART_Joule_Tuchuck)); + break; + default: + throw new IllegalStateException("Unknown Board Variant: " + bd.getBoardVariant()); + } + + mhz16 = new upm_mhz16.MHZ16(uartIndex); + AsyncTask.execute(co2Task); + } + + private void updateUI(int i, int gas, int Temp) { + this.runOnUiThread(new Runnable() { + @Override + public void run() { + tv.setText("Gas " + gas); + tv1.setText("Temp " + Temp); + Log.i(TAG, "iteration: " + i + ", " + "Gas value is " + gas + "Temp Value is" + Temp); + } + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + Log.d(TAG, "in onDestroy() call"); + Thread.currentThread().interrupt(); + mhz16.delete(); + } +} diff --git a/mhz16/src/main/res/layout/activity_mhz.xml b/mhz16/src/main/res/layout/activity_mhz.xml new file mode 100644 index 0000000..cfead24 --- /dev/null +++ b/mhz16/src/main/res/layout/activity_mhz.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/mhz16/src/main/res/mipmap-hdpi/ic_launcher.png b/mhz16/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/mhz16/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/mhz16/src/main/res/mipmap-hdpi/ic_launcher_round.png b/mhz16/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..9a078e3 Binary files /dev/null and b/mhz16/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/mhz16/src/main/res/mipmap-mdpi/ic_launcher.png b/mhz16/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/mhz16/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/mhz16/src/main/res/mipmap-mdpi/ic_launcher_round.png b/mhz16/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..efc028a Binary files /dev/null and b/mhz16/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/mhz16/src/main/res/mipmap-xhdpi/ic_launcher.png b/mhz16/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/mhz16/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/mhz16/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/mhz16/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..3af2608 Binary files /dev/null and b/mhz16/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/mhz16/src/main/res/mipmap-xxhdpi/ic_launcher.png b/mhz16/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/mhz16/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/mhz16/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/mhz16/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..9bec2e6 Binary files /dev/null and b/mhz16/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/mhz16/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/mhz16/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/mhz16/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/mhz16/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/mhz16/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..34947cd Binary files /dev/null and b/mhz16/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/mhz16/src/main/res/values/strings.xml b/mhz16/src/main/res/values/strings.xml new file mode 100644 index 0000000..45b01d1 --- /dev/null +++ b/mhz16/src/main/res/values/strings.xml @@ -0,0 +1,24 @@ + + + + + MHZ16 + + UART1 + UART1 + UART0 + diff --git a/settings.gradle b/settings.gradle index 8b67c1a..9cb4205 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,6 +15,7 @@ */ include ':accel_on_lcd' +include ':mhz16' include ':multisensor' include ':ads1015' include ':ssd1351'