1 package de
.rmdir
.ms2debounce
;
3 import android
.app
.Activity
;
4 import android
.app
.Dialog
;
5 import android
.app
.AlertDialog
;
6 import android
.os
.Bundle
;
7 import android
.content
.Intent
;
8 import android
.content
.DialogInterface
;
9 import android
.widget
.TextView
;
10 import android
.widget
.EditText
;
11 import android
.widget
.Button
;
12 import android
.widget
.CheckBox
;
13 import android
.view
.View
;
14 import android
.view
.Menu
;
15 import android
.view
.MenuInflater
;
16 import android
.view
.MenuItem
;
17 import android
.text
.TextWatcher
;
18 import android
.text
.Editable
;
20 public class MS2Debounce
extends Activity
22 private DebounceModuleHelper module
;
24 // Calling these is expensive, so cache the result...
25 private boolean loaded
;
26 private boolean safe_to_load
;
27 private int debounce_delay
;
28 private int settle_time
;
29 private int poll_time
;
30 private boolean hw_debounce_en
;
31 private int hw_debounce_time
;
32 private boolean drive_inactive_en
;
37 module
= new DebounceModuleHelper(this);
41 public void onCreate(Bundle savedInstanceState
)
43 super.onCreate(savedInstanceState
);
45 setContentView(R
.layout
.main
);
47 EditText textDelay
= (EditText
)findViewById(R
.id
.debounce_delay
);
48 textDelay
.addTextChangedListener(new TextWatcher() {
50 public void afterTextChanged(Editable delay
) {
51 if (delay
.toString().length() > 0) {
52 module
.setSavedDelay(Integer
.parseInt(delay
.toString()));
57 public void beforeTextChanged(CharSequence s
, int start
, int count
, int after
) {
61 public void onTextChanged(CharSequence s
, int start
, int before
, int count
) {
65 EditText textSettle
= (EditText
)findViewById(R
.id
.settle_time
);
66 textSettle
.addTextChangedListener(new TextWatcher() {
68 public void afterTextChanged(Editable settle_time
) {
69 if (settle_time
.toString().length() > 0) {
70 module
.setSavedSettle(Integer
.parseInt(settle_time
.toString()));
75 public void beforeTextChanged(CharSequence s
, int start
, int count
, int after
) {
79 public void onTextChanged(CharSequence s
, int start
, int before
, int count
) {
83 EditText textPoll
= (EditText
)findViewById(R
.id
.poll_time
);
84 textPoll
.addTextChangedListener(new TextWatcher() {
86 public void afterTextChanged(Editable poll_time
) {
87 if (poll_time
.toString().length() > 0) {
88 module
.setSavedPoll(Integer
.parseInt(poll_time
.toString()));
93 public void beforeTextChanged(CharSequence s
, int start
, int count
, int after
) {
97 public void onTextChanged(CharSequence s
, int start
, int before
, int count
) {
101 EditText textHwDebounceTime
= (EditText
)findViewById(R
.id
.hw_debounce_time
);
102 textHwDebounceTime
.addTextChangedListener(new TextWatcher() {
104 public void afterTextChanged(Editable hw_debounce_time
) {
105 if (hw_debounce_time
.toString().length() > 0) {
106 module
.setSavedHwDebounceTime(Integer
.parseInt(hw_debounce_time
.toString()));
111 public void beforeTextChanged(CharSequence s
, int start
, int count
, int after
) {
115 public void onTextChanged(CharSequence s
, int start
, int before
, int count
) {
122 private void updateUI() {
125 // Calling these is expensive, so cache the result...
126 loaded
= module
.isLoaded();
127 safe_to_load
= module
.is_safe_to_load();
128 debounce_delay
= module
.getDelay();
129 settle_time
= module
.getSettle();
130 poll_time
= module
.getPoll();
131 hw_debounce_en
= module
.getHwDebounce();
132 hw_debounce_time
= module
.getHwDebounceTime();
133 drive_inactive_en
= module
.getDriveInactive();
135 TextView text
= (TextView
)findViewById(R
.id
.text
);
136 text
.setText("Module loaded: " + loaded
+ "\n" +
137 "debounce_delay: " + debounce_delay
+ "ms\n" +
138 "settle_time: " + settle_time
+ "us\n" +
139 "poll_time: " + poll_time
+ "ms\n" +
140 "safe_to_load: " + safe_to_load
+ " (module loaded by this app)\n" +
141 "hw_debounce: " + (hw_debounce_en?
"en":"dis") + "abled, " + ((hw_debounce_time
+1)*31) + "us (" + hw_debounce_time
+ "), drive inactive: " + (drive_inactive_en?
"en":"dis") + "abled");
143 EditText textDelay
= (EditText
)findViewById(R
.id
.debounce_delay
);
144 textDelay
.setText(Integer
.toString(module
.getSavedDelay()));
145 textDelay
.setEnabled(true);
147 EditText textSettle
= (EditText
)findViewById(R
.id
.settle_time
);
148 textSettle
.setText(Integer
.toString(module
.getSavedSettle()));
149 textSettle
.setEnabled(true);
151 EditText textPoll
= (EditText
)findViewById(R
.id
.poll_time
);
152 textPoll
.setText(Integer
.toString(module
.getSavedPoll()));
153 textPoll
.setEnabled(true);
155 EditText textHwDebounceTime
= (EditText
)findViewById(R
.id
.hw_debounce_time
);
156 textHwDebounceTime
.setText(Integer
.toString(module
.getSavedHwDebounceTime()));
157 textHwDebounceTime
.setEnabled(true);
159 Button set
= (Button
)findViewById(R
.id
.set
);
161 set
.setEnabled(true);
163 set
.setEnabled(false);
166 Button load
= (Button
)findViewById(R
.id
.load
);
168 load
.setEnabled(false);
170 load
.setEnabled(true);
173 Button unload
= (Button
)findViewById(R
.id
.unload
);
175 unload
.setEnabled(true);
177 unload
.setEnabled(false);
180 CheckBox on_boot
= (CheckBox
)findViewById(R
.id
.on_boot
);
181 on_boot
.setChecked(module
.get_on_boot());
183 on_boot
.setEnabled(true);
185 on_boot
.setEnabled(false);
188 CheckBox hw_debounce
= (CheckBox
)findViewById(R
.id
.hw_debounce
);
189 hw_debounce
.setChecked(module
.getSavedHwDebounce());
190 hw_debounce
.setEnabled(true);
192 CheckBox drive_inactive
= (CheckBox
)findViewById(R
.id
.drive_inactive
);
193 drive_inactive
.setChecked(module
.getSavedDriveInactive());
194 drive_inactive
.setEnabled(true);
197 private void disableUI() {
198 EditText textDelay
= (EditText
)findViewById(R
.id
.debounce_delay
);
199 textDelay
.setEnabled(false);
201 EditText textSettle
= (EditText
)findViewById(R
.id
.settle_time
);
202 textSettle
.setEnabled(false);
204 EditText textPoll
= (EditText
)findViewById(R
.id
.poll_time
);
205 textPoll
.setEnabled(false);
207 EditText textHwDebounceTime
= (EditText
)findViewById(R
.id
.hw_debounce_time
);
208 textHwDebounceTime
.setEnabled(false);
210 Button set
= (Button
)findViewById(R
.id
.set
);
211 set
.setEnabled(false);
213 Button load
= (Button
)findViewById(R
.id
.load
);
214 load
.setEnabled(false);
216 Button unload
= (Button
)findViewById(R
.id
.unload
);
217 unload
.setEnabled(false);
219 CheckBox on_boot
= (CheckBox
)findViewById(R
.id
.on_boot
);
220 on_boot
.setEnabled(false);
222 CheckBox hw_debounce
= (CheckBox
)findViewById(R
.id
.hw_debounce
);
223 hw_debounce
.setEnabled(false);
225 CheckBox drive_inactive
= (CheckBox
)findViewById(R
.id
.drive_inactive
);
226 drive_inactive
.setEnabled(false);
229 public void loadModule(View view
) {
231 if (!module
.isLoaded()) {
237 public void unloadModule(View view
) {
239 if (module
.isLoaded()) {
240 module
.unloadModule();
245 public void setValues(View view
) {
247 if (!module
.isLoaded()) {
250 module
.setAllValues();
254 public void toggle_on_boot(View view
) {
255 CheckBox on_boot
= (CheckBox
)view
;
257 module
.set_on_boot(on_boot
.isChecked());
260 public void toggle_hw_debounce(View view
) {
261 CheckBox hw_debounce
= (CheckBox
)view
;
263 module
.setSavedHwDebounce(hw_debounce
.isChecked());
266 public void toggle_drive_inactive(View view
) {
267 CheckBox drive_inactive
= (CheckBox
)view
;
269 module
.setSavedDriveInactive(drive_inactive
.isChecked());
273 public boolean onCreateOptionsMenu(Menu menu
) {
274 MenuInflater inflater
= getMenuInflater();
275 inflater
.inflate(R
.menu
.main
, menu
);
280 public boolean onOptionsItemSelected(MenuItem item
) {
281 switch (item
.getItemId()) {
286 return super.onOptionsItemSelected(item
);
290 protected Dialog
onCreateDialog(int id
) {
293 AlertDialog
.Builder about
= new AlertDialog
.Builder(this);
294 about
.setMessage("Milestone 2 Debounce\n\n(C) 2011 Michael Gernoth <michael@gernoth.net>\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA")
296 .setPositiveButton("Ok", new DialogInterface
.OnClickListener() {
297 public void onClick(DialogInterface dialog
, int id
) {
301 dlg
= about
.create();