package cn.hyc.led;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.widget.Button;public class MainActivity extends Activity { private Button led1, led2, led3, led4; private boolean led1OnOFF = false; private boolean led2OnOFF = false; private boolean led3OnOFF = false; private boolean led4OnOFF = false; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); led1 = (Button)this.findViewById(R.id.led1); led2 = (Button)this.findViewById(R.id.led2); led3 = (Button)this.findViewById(R.id.led3); led4 = (Button)this.findViewById(R.id.led4); led1.setOnClickListener(new OnClickLed()); led2.setOnClickListener(new OnClickLed()); led3.setOnClickListener(new OnClickLed()); led4.setOnClickListener(new OnClickLed()); } public class OnClickLed implements View.OnClickListener{ public void onClick(View v) { switch (v.getId()) { case R.id.led1: if(led1OnOFF){ cmdLeds(0, 0); led1OnOFF = false; } else{ cmdLeds(1, 0); led1OnOFF = true; } break; case R.id.led2: if(led2OnOFF){ cmdLeds(0, 1); led2OnOFF = false; } else{ cmdLeds(1, 1); led2OnOFF = true; } break; case R.id.led3: if(led3OnOFF){ cmdLeds(0, 2); led3OnOFF = false; } else{ cmdLeds(1, 2); led3OnOFF = true; } break; case R.id.led4: if(led4OnOFF){ cmdLeds(0, 3); led4OnOFF = false; } else{ cmdLeds(1, 3); led4OnOFF = true; } break; default: break; } } }
public native void cmdLeds(int cmd, int arg); static { System.loadLibrary("leds"); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
#include#include #include #include #include #include #include void Java_cn_hyc_led_MainActivity_cmdLeds( JNIEnv* env, jobject thiz, jint cmd, jint arg){ int dev; dev = open("/dev/leds", O_WRONLY); ioctl(dev, cmd, arg); close(dev);}
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := ledsLOCAL_SRC_FILES := leds.cinclude $(BUILD_SHARED_LIBRARY)
posted on 2013-11-24 14:40 阅读( ...) 评论( ...) 收藏