Android平台读写i2c设备开发笔记三
来源:互联网 发布:乐视电视mac码怎么查 编辑:程序博客网 时间:2024/05/18 18:46
三、app调用服务接口访问硬件
上主要代码EEPROMActivity.java
package com.zkgd.eeprom;import android.app.Activity;import android.os.Bundle;import android.os.ServiceManager;import android.os.IIICService;import android.os.RemoteException;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class EEPROMActivity extends Activity implements OnClickListener{private final static String LOG_TAG = "com.zkgd.eeprom"; private IIICService iicService = null; private EditText valueText = null; private Button readButton = null; private Button writeButton = null; private Button clearButton = null; int len = 1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); iicService = IIICService.Stub.asInterface( ServiceManager.getService("iic")); valueText = (EditText)findViewById(R.id.edit_value); readButton = (Button)findViewById(R.id.button_read); writeButton = (Button)findViewById(R.id.button_write); clearButton = (Button)findViewById(R.id.button_clear); readButton.setOnClickListener(this); writeButton.setOnClickListener(this); clearButton.setOnClickListener(this); Log.i(LOG_TAG, "Activity Created"); } public void onClick(View v) { if(v.equals(readButton)) { try { len = 1; //在从设备中读取数据 String val = iicService.getVal(0x50,len); valueText.setText(val); } catch (RemoteException e) { Log.e(LOG_TAG, "Remote Exception while reading value from device."); } } else if(v.equals(writeButton)) { try { String val = valueText.getText().toString(); len = val.length(); //在从设备的子地址处开始写入数据 iicService.setVal(val,0x50,0x10,len); } catch (RemoteException e) { Log.e(LOG_TAG, "Remote Exception while writing value to device."); } } else if(v.equals(clearButton)) { String text = ""; valueText.setText(text); } } }工程eeprom放置在源码目录package/app/下
编译命令:mmm package/app/eeprom
打包,烧写固件至开发板,启动就可以看到该应用的图标了。
小结:
整个调用流程为:app<---AIDL访问服务<---JNI本地方法实现<---HALso文件<---硬件
一个问题,这种方法改动了android原生api,毕竟是访问了硬件。如果想做通用app又想使用c/c++提高效率,直接进行NDK开发,功能编译成库文件打进app应用的工程中。
另一个问题,硬件访问会遭遇到权限问题。如果做通用app,需要设备root了,然后在代码里添加权限修改操作,例如:"chmod 777 "+getPackageCodePath(); "chmod 777 /dev/i2c-1";
- Android平台读写i2c设备开发笔记三
- Android平台读写i2c设备开发笔记
- Android平台读写i2c设备开发笔记
- Android平台读写i2c设备开发笔记一
- Android平台读写i2c设备开发笔记二
- android NDK平台搭建 && Android平台读写i2c设备
- MTK android平台添加读写i2c设备工具
- MTK android平台添加读写i2c设备工具
- amlogic平台android uboot中添加i2c设备实现i2c的读写
- amlogic平台android 系统linux内核中添加i2c设备实现i2c的读写
- Linux I2C设备读写应用程序
- Linux I2C设备读写应用程序
- Linux I2C设备读写应用程序
- I2C设备,读写地址换算
- i2c 设备读写 与驱动
- I2C设备应用层读写
- Linux I2C设备读写应用程序
- linux设备驱动开发详解 通过O_RDWR IOCTL 读写i2c设备
- 对X window 全面分析的文章
- hduoj 题目分类
- 关于audio各结构说明摘录
- xlib协议概要
- Handler基础
- Android平台读写i2c设备开发笔记三
- 四种强制转换
- POSTFIX SASL 验证配置,经过测试
- 修改XML
- X是协议,不是具体的某个软件
- subversion的安装各种文章
- 抽象类和接口的区别
- 数据库中NCHAR 、CHAR等的区别
- 用Xlib库进行基本图形编程