Android from hardware to application: step by step to step 6, android step by step

Source: Internet
Author: User

Android from hardware to application: step by step to step 6, android step by step

Create an Android Application Project: Use the Android plug-in ADT of Eclipse to create an Android project named Gpio. After the project is created, copy the project directory to the packages/apps/folder, and delete the gen folder under the project directory. If you do not delete it, duplicate class errors will occur.

Src/com/android/gpio/Gpio. java:

package com.android.gpio;  import com.android.gpio.R;  import android.app.Activity;  import android.os.ServiceManager;  import android.os.Bundle;  import android.os.IGpioService;  import android.os.RemoteException;  import android.util.Log;  import android.view.View;  import android.view.View.OnClickListener;  import android.widget.Button;  public class Gpio extends Activity implements OnClickListener {  private final static String LOG_TAG = "com.android.Gpio";  private IGpioService gpioService = null;  private Button setButton = null;  private Button clearButton = null;    /** Called when the activity is first created. */  @Override  public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.main);  gpioService = IGpioService.Stub.asInterface(  ServiceManager.getService("gpio"));  setButton = (Button)findViewById(R.id.button_set);  clearButton = (Button)findViewById(R.id.button_clear);  setButton.setOnClickListener(this);  clearButton.setOnClickListener(this);  }    @Override  public void onClick(View v) {  if(v.equals(setButton)) {   try{int val='1';gpioService.setVal(val);} catch (RemoteException e){Log.e(LOG_TAG,"setting value");}} else if(v.equals(clearButton)) {try{int val='0';gpioService.setVal(val);   } catch (RemoteException e){Log.e(LOG_TAG,"setting value");   }   }  }  }  
Layout res/layout/main. xml:

<?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent">     <Button       android:id="@+id/button_clear"       android:layout_width="match_parent"       android:layout_height="wrap_content"       android:text="@string/clear"       android:textStyle="bold"       android:layout_marginTop="140dp"/>   <Button       android:id="@+id/button_set"       android:layout_width="match_parent"       android:layout_height="wrap_content"       android:text="@string/set"       android:textStyle="bold"        android:layout_marginTop="0dp"/></LinearLayout>  
String res/values/strings. xml:

<?xml version="1.0" encoding="utf-8"?>  <resources>     <string name="app_name">GPIO</string>     <string name="set">Set</string>     <string name="clear">Clear</string>  </resources>  
AndroidManifest. xml:

<?xml version="1.0" encoding="utf-8"?>  <manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.android.gpio"    android:versionCode="1"    android:versionName="1.0">    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">      <activity android:name=".Gpio"                android:label="@string/app_name">          <intent-filter>              <action android:name="android.intent.action.MAIN" />              <category android:name="android.intent.category.LAUNCHER" />          </intent-filter>      </activity>    </application>  </manifest>   
Edit Android. mk in the project directory:

LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optionalLOCAL_SRC_FILES := $(call all-subdir-java-files)LOCAL_PACKAGE_NAME := GpioLOCAL_CERTIFICATE := platforminclude $(BUILD_PACKAGE)include $(call all-makefiles-under,$(LOCAL_PATH))
Edit build/target/product/generic_no_telephony.mk:

Add Gpio \ After PRODUCT_PACKAGES := \

The compilation project will generate gpio.apk

make TARGET_PRODUCT=am335xevm_sk -j8 OMAPES=4.x 
At this step, all preparations are ready. Start to update the file system of the target board am335evm: (host on the left and evm on the right)

out/target/product/am335xevm_sk/system/app/Gpio.apk                 ==>   rootfs/out/target/product/am335xevm_sk/system/framework/services.jar       ==>   rootfs/system/framework/out/target/product/am335xevm_sk/system/framework/framework.jar      ==>   rootfs/system/framework/out/target/product/am335xevm_sk/obj/lib/libandroid_servers.so       ==>   rootfs/system/lib/out/target/product/am335xevm_sk/obj/lib/gpio.default.so             ==>   rootfs/system/lib/hw/

Make sure that ueventd. rc under rootfs has been added: (Android from hardware to application: Step by Step climb 3 -- Hardware Abstraction Layer access hardware driver mentioned)

/dev/AdrIO                0666   root       root
Start, install gpio.apk, and enable GPIO:

Symptom:

Click "Set" button: D1 light on and click "Clear" button: D1 light off

It can be seen that the written APP has successfully operated the AM335 register by calling the hardware service, changed the AM335X_GPIO_LED4 level, and controlled the LED D1 light-off through the ngou MOS device.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.