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 buttonintr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions buttonintr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Grove Button sample for Android Things using UPM
-----------------------------------------------

This example demonstrates a GPIO interrupts using UPM.

Pre-Requisites:
---------------
Use of the Grove Kit (for Joule or Edison) makes this easy. See the following links for getting
a starter kit.

* https://www.seeedstudio.com/Grove-Maker-Kit-for-Intel-Joule-p-2796.html
* https://www.seeedstudio.com/Grove-Starter-Kit-V3-p-1855.html


You will need:

1. Android Things compatible board.
2. Grove header or Breakout board.
3. A Grove push button.


Build and install:
------------------

On Android Studio, select the "buttonintr" module in select box by the "Run" button
and then click on the "Run" button.

Changing the GPIO pin
---------------------
This example uses a GPIO (digital input) to read the state of a button. The GPIO could be connected
via the shield to a Grove button... or it could be a button or wire on a breakout board directly
connected between a GPIO line and Vcc.

The GPIO line to be used is specified in the strings.xml file (src/res/values directory).

````
<resources>
<string name="app_name">ButtonIntr</string>

<string name="Button_Edison_Arduino">IO0</string>
<string name="Button_Edison_Sparkfun">GP20</string>
<string name="Button_Joule_Tuchuck">J7_64</string>
</resources>
````

The code will automatically determine the board type being run on (modify BoardDefaults.java
in the driver library to add another board) and select a string from this file for the GPIO line.
The above example uses IO0 on the Edison Arduino shield and J7_64 on the Joule Tuchuck
development board. These strings are programmed into the Peripheral Manager and read from their
into the UPM library to determine the GPIO pin to be used.

See the top level README.md for a table describing the available GPIO pins and where to find them
on the board.
51 changes: 51 additions & 0 deletions buttonintr/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_grove:1.+'
}
25 changes: 25 additions & 0 deletions buttonintr/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
36 changes: 36 additions & 0 deletions buttonintr/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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.
-->

<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=".ButtonIntrActivity">
<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,98 @@
/*
* 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.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.example.upm.androidthings.driversupport.BoardDefaults;

import mraa.mraa;
import mraa.Edge;

public class ButtonIntrActivity extends Activity {
private static final String TAG = "ButtonIntrActivity";
public static int counter = 0;
upm_grove.GroveButton button;
TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button_intr);

tv = (TextView) findViewById(R.id.text_value);

int gpioIndex = -1;
int level = Edge.EDGE_RISING.swigValue();
BoardDefaults bd = new BoardDefaults(this.getApplicationContext());

switch (bd.getBoardVariant()) {
case BoardDefaults.DEVICE_EDISON_ARDUINO:
gpioIndex = mraa.getGpioLookup(getString(R.string.Button_Edison_Arduino));
break;
case BoardDefaults.DEVICE_EDISON_SPARKFUN:
gpioIndex = mraa.getGpioLookup(getString(R.string.Button_Edison_Sparkfun));
break;
case BoardDefaults.DEVICE_JOULE_TUCHUCK:
gpioIndex = mraa.getGpioLookup(getString(R.string.Button_Joule_Tuchuck));
break;
default:
throw new IllegalStateException("Unknown Board Variant: " + bd.getBoardVariant());
}

button = new upm_grove.GroveButton(gpioIndex);
ButtonISR callback = new ButtonISR();
button.installISR(level, callback);
}

private void updateUI(int bv) {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
tv.setText(button.name() + " value is " + bv + " counter " + counter);
Log.i(TAG, "iteration: " + counter++ + ", " + button.name() + " value is " + bv);
}
});
}

@Override
protected void onDestroy() {
super.onDestroy();

Log.d(TAG, "in onDestroy() call");
button.delete();
}

class ButtonISR implements Runnable {

public void run() {
// Moves the current thread into the background
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);

try {
updateUI(button.value());
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
button.delete();
}
}
}
}
20 changes: 20 additions & 0 deletions buttonintr/src/main/res/layout/activity_button_intr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="64dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context="com.example.upm.androidthings.driversamples.ButtonIntrActivity">

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

</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.
23 changes: 23 additions & 0 deletions buttonintr/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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">ButtonIntr</string>

<string name="Button_Edison_Arduino">IO0</string>
<string name="Button_Edison_Sparkfun">GP20</string>
<string name="Button_Joule_Tuchuck">J7_64</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 ':buttonintr'
include ':multisensor'
include ':ads1015'
include ':ssd1351'
Expand Down