This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
UART Application #42
Open
vintummala
wants to merge
1
commit into
intel-iot-devkit:master
Choose a base branch
from
vintummala:UART-Example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
UART Application #42
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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.+' | ||
| } |
This file contains hidden or 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,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 |
This file contains hidden or 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,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> |
114 changes: 114 additions & 0 deletions
114
mhz16/src/main/java/com/example/upm/androidthings/driversamples/MHZActivity.java
This file contains hidden or 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,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(); | ||
| } | ||
| } | ||
This file contains hidden or 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,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> |
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.
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.
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.
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.
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.
This file contains hidden or 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,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> |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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