|
手册写明led的使用要跟demo里的包名一样,为了方便使用,我把led的部分写成了类。
- package com.embedsky.led;
- import android.util.Log;
- public class LedActivity {
- /** Called when the activity is first created. */
- //加载libled.so库,必须放在最前面
- static {
- System.loadLibrary("led");
- }
- //初始化led
- public static native boolean ledInit();
- //关闭led
- public static native boolean ledClose();
- //点亮led
- private static native boolean ledSetOn(int number);
- //灭掉led
- private static native boolean ledSetOff(int number);
- public LedActivity(){
- // led初始化
- if (!ledInit()) {
- //led初始化失败,则使控件不可点击
- Log.e("led", "init fail");
- }else{
- Log.e("led", "init ok");
- }
- }
- public void chickLed(final int idx,final int time){
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- // TODO Auto-generated method stub
- try {
- controlLed(idx, true);
- Thread.sleep(time);
- controlLed(idx, false);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- }).start();
- }
- /*******************************************/
- // 功能:LED亮/灭处理
- // 参数:
- // number :灯编号
- // on :true,亮;fase,灭
- /*******************************************/
- public void controlLed(int number, boolean on) {
- if (on) {
- ledSetOn(number);
- } else {
- ledSetOff(number);
- }
- }
- }
复制代码 使用:
private static LedActivity myled;
myled = new LedActivity();
myled.chickLed(1, 20); //第一个led闪烁一次
|
|