Code Monkey home page Code Monkey logo

sample-pio-app's Introduction

Sample Peripheral I/O app (Kotlin)

This Android Things app uses the Android Things GPIO APIs in a multi-threaded environment.

Introduction

Building off the Simple PIO sample, this sample provides more detail on how you would integrate these APIs into your own application. It shows you how to:

  • Handle GPIO callbacks (button presses) off the main thread using Handlers and HandlerThreads

  • Report results back to the main UI thread once that work is complete

  • Make your Gpio components Lifecycle-Aware , so that each can shut down or re-initialize itself based on Android Lifecycle events, instead of writing overly complicated onDestroy() methods in your application's primary activity.

IMPORTANT: Please, note that these samples are not necessarily the easiest way to accomplish a task. In particular, they handle all low level I/O protocols directly, on purpose to showcase how to use the Peripheral APIs. In real world applications, you should use or develop a suitable driver that encapsulates the manipulation of low level APIs.

Pre-requisites

  • Android Things compatible board
  • Android Studio 3.0+

For the Button sample:

Build and install

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

If you prefer to run on the command line, type

./gradlew <module>:installDebug
adb shell am start com.example.androidthings.overview.MainActivity

If you have the Raspberry Pi Rainbow Hat for Android Things, just plug it onto your Raspberry Pi 3.

Schematics for Raspberry Pi 3

Enable auto-launch behavior

This sample app is currently configured to launch only when deployed from your development machine. To enable the main activity to launch automatically on boot, add the following intent-filter to the app's manifest file:

<activity ...>

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.HOME"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

</activity>

sample-pio-app's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.