Permalink
Browse files

Threading finally correct. TachoCount as seperate class. USBSend as m…

…ethod. No hangs.
  • Loading branch information...
1 parent 442a7e5 commit f796147fe783cdba70e5644499686cb4876651b0 Shawn-in-Tokyo committed Jan 11, 2010
Binary file not shown.
@@ -7,46 +7,49 @@
import lejos.nxt.Sound;
import lejos.nxt.remote.NXTCommand;
import lejos.pc.comm.NXTConnector;
-import android.os.AsyncTask;
import android.util.Log;
-public class TachoCount extends AsyncTask {
-
-
-
- @Override
- protected Object doInBackground(Object... params) {
- NXTConnector conn;
- conn = test.connect(test.TACHO_COUNT, CONN_TYPE.LEGO);
- NXTCommand.getSingleton().setNXTComm(conn.getNXTComm());
-
- Log.i(test.TACHO_COUNT, "Tachometer A: " + Motor.A.getTachoCount());
- Log.i(test.TACHO_COUNT, "Tachometer C: " + Motor.C.getTachoCount());
- Motor.A.rotate(5000);
- Motor.C.rotate(-5000);
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- Sound.playTone(1000, 1000);
- Log.i(test.TACHO_COUNT, "Tachometer A: " + Motor.A.getTachoCount());
- Log.i(test.TACHO_COUNT, "Tachometer C: " + Motor.C.getTachoCount());
+public class TachoCount {
+
+ public void countThoseTachos(){
- if( conn != null ){
- try {
- conn.close();
- } catch (IOException e) {
- Log.e(test.TACHO_COUNT,"Error closing connection",e);
- }
- }
-
+ Thread ctt= new Thread(){
+
+ public void run(){
+
+ NXTConnector conn = test.connect(test.TACHO_COUNT, CONN_TYPE.LEGO);
+ NXTCommand.getSingleton().setNXTComm(conn.getNXTComm());
+
+ Log.i(test.TACHO_COUNT, "Tachometer A1: " + Motor.A.getTachoCount());
+ //only have one moment one hand for the moment to test!
+ //Log.i(test.TACHO_COUNT, "Tachometer C1: " + Motor.C.getTachoCount());
+ Motor.A.rotate(500);
+ //Motor.C.rotate(-5000);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ Log.e(test.TACHO_COUNT,"Thread.sleep error",e); }
+ Sound.playTone(1000, 1000);
+ Log.i(test.TACHO_COUNT, "Tachometer A2: " + Motor.A.getTachoCount());
+ //Log.i(test.TACHO_COUNT, "Tachometer C2: " + Motor.C.getTachoCount());
+
+ if( conn != null ){
+ try {
+ conn.close();
+ } catch (IOException e) {
+ Log.e(test.TACHO_COUNT,"Error closing connection",e);
+ }
+ }
+ Log.i(test.TACHO_COUNT, "run finished");
+ }
+
+
+ };
+
+ ctt.start();
- return null; //alter to send feedback to ui via onPostExecute
}
-
- protected void onPostExecute(Object result) {//executes back on UI thread
-
- }
+
+
}
Oops, something went wrong.

0 comments on commit f796147

Please sign in to comment.