友善之臂Mini6410之Android开发学习笔记(2)-PWM Demo
git clone https://code.google.com/p/androiddemoformini6410/
git clone https://code.google.com/p/androiddemoformini6410/
PWMActivity.java
[java] package com.mini6410.PWM;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ToggleButton;
import com.friendlyarm.AndroidSDK.HardwareControler;
import com.mini6410.R;
/**
*
* ClassName:PWMActivity
* Reason: PWM Demo
*
* @author snowdream
* @version
* @since Ver 1.1
* @Date 2011 2012-03-11 17:21
*
* @see
*/
public class PWMActivity extends Activity implements Button.OnClickListener,ToggleButton.OnCheckedChangeListener{
public static final String TAG = "PWMActivity";
/*PWM频率*/
public static final int PWM_FREQUENCY_1 = 1;
public static final int PWM_FREQUENCY_100 = 100;
public static final int PWM_FREQUENCY_200 = 200;
public static final int PWM_FREQUENCY_500 = 500;
public static final int PWM_FREQUENCY_1000 = 1000;
public static final int PWM_FREQUENCY_2000 = 2000;
public static final int PWM_FREQUENCY_5000 = 5000;
public static final int PWM_FREQUENCY_10000 = 10000;
/*PWM播放时长*/
public static final int PWM_PLAY_PERIOD_FOR_EVER = -1;
public static final int PWM_PLAY_PERIOD_100 = 100;
public static final int PWM_PLAY_PERIOD_200 = 200;
public static final int PWM_PLAY_PERIOD_300 = 300;
public static final int PWM_PLAY_PERIOD_500 = 500;
public static final int PWM_PLAY_PERIOD_1000 = 1000;
/*PWM播放间隔*/
public static final int PWM_WAIT_PERIOD_100 = 100;
public static final int PWM_WAIT_PERIOD_200 = 200;
public static final int PWM_WAIT_PERIOD_300 = 300;
public static final int PWM_WAIT_PERIOD_500 = 500;
public static final int PWM_WAIT_PERIOD_1000 = 1000;
/*播放频率*/
public int mfrequency = PWM_FREQUENCY_1000;
/*频率改变步长Step*/
public int mfrequencystep = 100;
/*播放时长*/
public int mplayperiod = PWM_PLAY_PERIOD_1000;
/*播放间隔*/
public int mwaitperiod = PWM_WAIT_PERIOD_1000;
/*播放次数*/
public int mplaynum = 20;
private boolean mStop = false;
private Button mButtonSub = null;
private Button mButtonAdd = null;
private ToggleButton mToggleButtonStartForEver= null;
private ToggleButton mToggleButtonStartForTimes = null;
private EditText mEditTextFrequency = null;
private EditText mEditTextPlayPeriod = null;
private EditText mTextViewWaitPeriod = null;
private EditText mEditTextPlayNum = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pwmdemo);
initUI();
initData();
}
@Override
protected void onDestroy() {
mStop = true;
super.onDestroy();
}
/**
*
* initUI: 初始化UI
*
* @param
* @return
* @throws
*/
public void initUI(){
mButtonSub = (Button)findViewById(R.id.ButtonSUB);
mButtonAdd = (Button)findViewById(R.id.ButtonADD);
/*按钮易做图,具体实现参考下面的函数:onClick*/
mButtonSub.setOnClickListener(this);
mButtonAdd.setOnClickListener(this);
mToggleButtonStartForEver= (ToggleButton)findViewById(R.id.ToggleButtonStartForEver);
mToggleButtonStartForTimes = (ToggleButton)findViewById(R.id.ToggleButtonStartForTimes);
/*开关按钮易做图,具体实现参考下面的函数:onCheckedChanged*/
mToggleButtonStartForEver.setOnCheckedChangeListener(this);
mToggleButtonStartForTimes.setOnCheckedChangeListener(this);
mEditTextFrequency = (EditText)findViewById(R.id.EditTextFrequency);
mEditTextPlayPeriod = (EditText)findViewById(R.id.EditTextPlayPeriod);
mTextViewWaitPeriod = (EditText)findViewById(R.id.EditTextWaitPeriod);
mEditTextPlayNum = (EditText)findViewById(R.id.EditTextPlayNum);
/*EditText易做图,具体实现参考下面的函数:onTextChanged
* 主要用于获取更改后最新的数值,下同。
* */
mEditTextFrequency.addTextChangedListener(new TextWatcher() {&nbs
补充:移动开发 , Android ,