Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mhz16/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
51 changes: 51 additions & 0 deletions mhz16/build.gradle
Original file line number Diff line number Diff line change
@@ -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.+'
}
25 changes: 25 additions & 0 deletions mhz16/proguard-rules.pro
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 /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
17 changes: 17 additions & 0 deletions mhz16/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.upm.androidthings.driversamples">

<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
<activity android:name=".MHZActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does getData block() ?
A blocking call to the data fetch routine or a poll() would be much better than a read/sleep for the uart. Bonus points if we can do this with interrupts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are few UART drivers which do open(), read() etc., calls for uart from UPM rather than calling MRAA api's.
This gas sensor is doing the same because of which i see open of /dev/tty1 failed: Permission denied. Out of 13 UAR sensor drivers, there are 7 drivers in UPM which does the same. Will have to talk to UPM team about this and fix it accordingly.
Meanwhile, i will try to get another sensor and write an example with it

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();
}
}
30 changes: 30 additions & 0 deletions mhz16/src/main/res/layout/activity_mhz.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/activity_mhz"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="64dp"
android:paddingRight="64dp"
android:paddingTop="16dp"
tools:context="com.example.upm.androidthings.driversamples.MHZActivity">

<TextView
android:id="@+id/text_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/text_value"
android:layout_alignEnd="@id/text_value"
android:layout_below="@+id/text_value"
android:layout_marginTop="100dp"
android:text="TextView" />

</RelativeLayout>
Binary file added mhz16/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mhz16/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mhz16/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mhz16/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mhz16/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions mhz16/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->

<resources>
<string name="app_name">MHZ16</string>

<string name="UART_Edison_Arduino">UART1</string>
<string name="UART_Edison_Sparkfun">UART1</string>
<string name="UART_Joule_Tuchuck">UART0</string>
</resources>
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

include ':accel_on_lcd'
include ':mhz16'
include ':multisensor'
include ':ads1015'
include ':ssd1351'
Expand Down