開發板:TQ210
OS:Android 4.0.3
以下所有內容都是在TQ210開發板上實現,并且很多內容也是天嵌公司提供,我將一些內容進行了刪減、替換,然后加入了一些自己的理解,同時也是記錄自己學習的旅程。
LedUnderActivity.java
package com.unders.led;
import com.unders.led.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;
public class LedUnderActivity extends Activity implements OnCheckedChangeListener{
/** Called when the activity is first created. */
Switch led1,led2,all;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
led1=(Switch) findViewById(R.id.led1); //控制LED的開關
led2=(Switch) findViewById(R.id.led2);
all=(Switch) findViewById(R.id.led3); //控制兩個LED的開關
led1.setOnCheckedChangeListener(this); //開關的事件監聽
led2.setOnCheckedChangeListener(this);
all.setOnCheckedChangeListener(this);
if(!led_init()) //led初始化 加載庫 初始化led 打開led
{
new AlertDialog.Builder(LedUnderActivity.this).setTitle('error').setMessage('init led failn').setPositiveButton('確定', null).show();
}
}
//加載libledunders.so
static{
System.loadLibrary('ledunders');
}
//本地函數
public static native boolean led_init();
public static native boolean led_close();
public static native boolean led_setOn(int number);
public static native boolean led_setOff(int number);
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
switch (buttonView.getId()) {
case R.id.led1: //操縱LED1
//Toast.makeText(LedActivity.this, '1', 1).show();
//if (led1.isChecked()) {
controlLed(1,led1.isChecked());
Log.d('msg', '操作LED1,'+led1.isChecked());
//}
break;
case R.id.led2: //操縱LED2
//Toast.makeText(LedActivity.this, '2', 1).show();
controlLed(2,led2.isChecked());
Log.d('msg', '操作LED2,'+led2.isChecked());
break;
case R.id.led3: //同時操縱兩個LED
//Toast.makeText(LedActivity.this, '12', 1).show();
controlLed(1,all.isChecked());
controlLed(2,all.isChecked());
Log.d('msg', '操作LED1和LED2,'+all.isChecked());
break;
}
}
private void controlLed(int number,boolean on) //控制LED函數
{
if (on) {
led_setOn(number);
}else {
led_setOff(number);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) { //退出
// TODO Auto-generated method stub
menu.add(0, 1, 0, '退出');
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case 1:
this.finish();
break;
default:
break;
}
return true;
}
}
main.xml
android:layout_height='fill_parent' android:orientation='vertical' > android:layout_height='wrap_content' android:orientation='horizontal' > android:layout_height='wrap_content' android:text='@string/led1' /> android:layout_width='0dp' android:layout_weight='1' android:layout_height='wrap_content' /> android:layout_height='wrap_content' android:orientation='horizontal' > android:layout_height='wrap_content' android:text='@string/led2' /> android:layout_width='0dp' android:layout_weight='1' android:layout_height='wrap_content' /> android:layout_height='wrap_content' android:orientation='horizontal' > android:layout_height='wrap_content' android:text='@string/All' /> android:layout_width='0dp' android:layout_weight='1' android:layout_height='wrap_content' />
效果圖:
對于上層的應用開發 比較簡單 通過JNI調用本地方法 操縱LED的亮或者滅
上一篇:TQ210搭載Android4.0.3系統構建之LED從驅動到HAL到JNI到應用程序(JNI篇)
下一篇:TQ210搭載Android4.0.3系統構建之LED從驅動到HAL到JNI到應用程序(總結篇)
推薦閱讀最新更新時間:2025-04-07 10:42





設計資源 培訓 開發板 精華推薦
- 具有可編程 LDO 的 SC427 10A EcoSpeed 集成 FET 穩壓器的典型應用
- STM32F10xxx ADC應用電路使用STM32F10xxx ADC_IN14接口
- 示例工程_快速入門
- 使用 ams AG 的 AS1112 的參考設計
- SFP接口的千兆光電轉換器 copy
- 具有低電池電量指示的穩壓 3.3V、低紋波電荷泵的典型應用
- SI5338-EVB,使用 SI5335 系列任意頻率、任意輸出時鐘發生器和時鐘合成器的評估板
- 使用 Microchip Technology 的 LM385CZB-1.2 的參考設計
- RT9266B 大電流應用的典型應用 RT9266B 微型封裝、高效率、升壓 DC/DC 轉換器
- LTC3638EMSE 5V 至 140V 輸入至 5V 輸出、250mA 降壓型穩壓器的典型應用電路