Updated to meet api 3.22RC
Change-Id: I1577dedaef5b0267a6abdebcc1cf72eeb0b8d3db Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.IOIOTruck;
|
package com.TwentyCodes.android.IOIOTruck;
|
||||||
|
|
||||||
import com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener;
|
import com.TwentyCodes.android.IOIOTruck.IOIOTruckConnectionManager.IOIOTruckThreadListener;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -40,7 +40,7 @@ import android.widget.TextView;
|
|||||||
public class CameraActivity extends FragmentActivity implements IOIOTruckThreadListener {
|
public class CameraActivity extends FragmentActivity implements IOIOTruckThreadListener {
|
||||||
|
|
||||||
private static final String TAG = "CameraActivity";
|
private static final String TAG = "CameraActivity";
|
||||||
private IOIOTruckManager mIOIOManager;
|
private IOIOTruckConnectionManager mIOIOManager;
|
||||||
private WakeLock mWakeLock;
|
private WakeLock mWakeLock;
|
||||||
private TextView mLogTextView;
|
private TextView mLogTextView;
|
||||||
|
|
||||||
@@ -54,6 +54,28 @@ public class CameraActivity extends FragmentActivity implements IOIOTruckThreadL
|
|||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
setContentView(R.layout.camera_activity);
|
setContentView(R.layout.camera_activity);
|
||||||
mLogTextView = (TextView) findViewById(R.id.log_textView);
|
mLogTextView = (TextView) findViewById(R.id.log_textView);
|
||||||
|
mIOIOManager = new IOIOTruckConnectionManager(this, this);
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().create();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.FragmentActivity#onDestroy()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().destroy();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the IOIO Manager wants to log something
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckConnectionManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onLogUpdate(String log) {
|
||||||
|
mLogTextView.setText(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,15 +86,20 @@ public class CameraActivity extends FragmentActivity implements IOIOTruckThreadL
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
try {
|
|
||||||
mIOIOManager.abort();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if(mWakeLock.isHeld())
|
if(mWakeLock.isHeld())
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.app.Activity#onRestart()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onRestart() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().restart();
|
||||||
|
super.onRestart();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is resuming
|
* Called when the activity is resuming
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
@@ -80,8 +107,6 @@ public class CameraActivity extends FragmentActivity implements IOIOTruckThreadL
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
mIOIOManager = new IOIOTruckManager(this, this);
|
|
||||||
mIOIOManager.start();
|
|
||||||
|
|
||||||
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
|
||||||
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
|
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
|
||||||
@@ -90,13 +115,23 @@ public class CameraActivity extends FragmentActivity implements IOIOTruckThreadL
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the IOIO Manager wants to log something
|
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
|
* @see android.support.v4.app.FragmentActivity#onStart()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onLogUpdate(String log) {
|
protected void onStart() {
|
||||||
mLogTextView.setText(log);
|
mIOIOManager.getIOIOAndroidApplicationHelper().start();
|
||||||
|
super.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.FragmentActivity#onStop()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().stop();
|
||||||
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,15 +25,17 @@ import ioio.lib.api.DigitalOutput;
|
|||||||
import ioio.lib.api.IOIO;
|
import ioio.lib.api.IOIO;
|
||||||
import ioio.lib.api.PwmOutput;
|
import ioio.lib.api.PwmOutput;
|
||||||
import ioio.lib.api.exception.ConnectionLostException;
|
import ioio.lib.api.exception.ConnectionLostException;
|
||||||
|
import ioio.lib.util.IOIOLooper;
|
||||||
|
import ioio.lib.util.IOIOLooperProvider;
|
||||||
|
import ioio.lib.util.android.IOIOAndroidApplicationHelper;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.util.Log;
|
||||||
import com.TwentyCodes.android.ioio.IOIOManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This IOIO thread will be used to drive a rc truck
|
* This IOIO thread will be used to drive a rc truck
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class IOIOTruckManager extends IOIOManager {
|
public class IOIOTruckConnectionManager implements IOIOLooper, IOIOLooperProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This listener will be used to notify the owner of this thread to update the onscreen log
|
* This listener will be used to notify the owner of this thread to update the onscreen log
|
||||||
@@ -55,6 +57,10 @@ public class IOIOTruckManager extends IOIOManager {
|
|||||||
private DigitalOutput mMotorDriverStandBy;
|
private DigitalOutput mMotorDriverStandBy;
|
||||||
private DigitalInput mLeftFrontBumber;
|
private DigitalInput mLeftFrontBumber;
|
||||||
private DigitalInput mRightFrontBumber;
|
private DigitalInput mRightFrontBumber;
|
||||||
|
private boolean isStatLedEnabled;
|
||||||
|
private IOIOAndroidApplicationHelper mIOIOAndroidApplicationHelper;
|
||||||
|
private IOIO mIOIO;
|
||||||
|
private DigitalOutput mStatLed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new IOIOTruckThread
|
* Creates a new IOIOTruckThread
|
||||||
@@ -62,8 +68,9 @@ public class IOIOTruckManager extends IOIOManager {
|
|||||||
* @param listener
|
* @param listener
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public IOIOTruckManager(Activity activity, IOIOTruckThreadListener listener){
|
public IOIOTruckConnectionManager(Activity activity, IOIOTruckThreadListener listener){
|
||||||
super();
|
super();
|
||||||
|
mIOIOAndroidApplicationHelper = new IOIOAndroidApplicationHelper(activity, this);
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
updateLog(R.string.wait_ioio);
|
updateLog(R.string.wait_ioio);
|
||||||
@@ -111,9 +118,11 @@ public class IOIOTruckManager extends IOIOManager {
|
|||||||
* @see com.TwentyCodes.android.ioio.IOIOThread#onConnected()
|
* @see com.TwentyCodes.android.ioio.IOIOThread#onConnected()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(IOIO ioio) throws ConnectionLostException {
|
public void setup(IOIO ioio) throws ConnectionLostException,InterruptedException {
|
||||||
updateLog(R.string.ioio_connected);
|
updateLog(R.string.ioio_connected);
|
||||||
|
mIOIO = ioio;
|
||||||
|
|
||||||
|
mStatLed = ioio.openDigitalOutput(0, true);
|
||||||
mShifter = ioio.openPwmOutput(IOIOTruckValues.SHIFTER_PORT, IOIOTruckValues.RC_PWM_FRQ);
|
mShifter = ioio.openPwmOutput(IOIOTruckValues.SHIFTER_PORT, IOIOTruckValues.RC_PWM_FRQ);
|
||||||
mLeftMotor = new TB6612FNGMotorDriver(ioio, IOIOTruckValues.MOTOR_DRIVER_PWMA, IOIOTruckValues.MOTOR_DRIVER_A1, IOIOTruckValues.MOTOR_DRIVER_A2);
|
mLeftMotor = new TB6612FNGMotorDriver(ioio, IOIOTruckValues.MOTOR_DRIVER_PWMA, IOIOTruckValues.MOTOR_DRIVER_A1, IOIOTruckValues.MOTOR_DRIVER_A2);
|
||||||
mRightMotor = new TB6612FNGMotorDriver(ioio, IOIOTruckValues.MOTOR_DRIVER_PWMB, IOIOTruckValues.MOTOR_DRIVER_B1, IOIOTruckValues.MOTOR_DRIVER_B2);
|
mRightMotor = new TB6612FNGMotorDriver(ioio, IOIOTruckValues.MOTOR_DRIVER_PWMB, IOIOTruckValues.MOTOR_DRIVER_B1, IOIOTruckValues.MOTOR_DRIVER_B2);
|
||||||
@@ -133,7 +142,7 @@ public class IOIOTruckManager extends IOIOManager {
|
|||||||
* @see com.TwentyCodes.android.ioio.IOIOThread#onDisconnect()
|
* @see com.TwentyCodes.android.ioio.IOIOThread#onDisconnect()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnected() {
|
public void disconnected() {
|
||||||
updateLog(R.string.wait_ioio);
|
updateLog(R.string.wait_ioio);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,35 +154,40 @@ public class IOIOTruckManager extends IOIOManager {
|
|||||||
@Override
|
@Override
|
||||||
public void loop() throws ConnectionLostException, InterruptedException {
|
public void loop() throws ConnectionLostException, InterruptedException {
|
||||||
|
|
||||||
this.setStatLedEnabled(isStatLedEnabled());
|
|
||||||
|
|
||||||
mShifter.setPulseWidth(mShifterValue);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we need to check our sensors before we can make a move.
|
* we need to check our sensors before we can make a move.
|
||||||
*/
|
*/
|
||||||
if(mLeftFrontBumber.read()){
|
if(mLeftFrontBumber.read()){
|
||||||
//TODO backup, spin right, drive forward
|
//TODO backup, spin right, drive forward
|
||||||
setStatLedEnabled(false);
|
isStatLedEnabled = false;
|
||||||
} else if(mRightFrontBumber.read()){
|
} else if(mRightFrontBumber.read()){
|
||||||
//TODO backup, spin left, drive forward
|
//TODO backup, spin left, drive forward
|
||||||
setStatLedEnabled(false);
|
isStatLedEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mMotorDriverStandBy.write(isStatLedEnabled());
|
// mIOIO.beginBatch();
|
||||||
|
|
||||||
|
mStatLed.write(!isStatLedEnabled);
|
||||||
|
|
||||||
|
mShifter.setPulseWidth(mShifterValue);
|
||||||
|
|
||||||
|
|
||||||
|
mMotorDriverStandBy.write(isStatLedEnabled);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if the autonomous routine is running
|
* if the autonomous routine is running
|
||||||
* then drive the truck
|
* then drive the truck
|
||||||
* else stop the truck
|
* else stop the truck
|
||||||
*/
|
*/
|
||||||
if(isStatLedEnabled()){
|
if(isStatLedEnabled){
|
||||||
arcadeDrive();
|
arcadeDrive();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
mLeftMotor.setSpeed(0);
|
mLeftMotor.setSpeed(0);
|
||||||
mRightMotor.setSpeed(0);
|
mRightMotor.setSpeed(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mIOIO.endBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,4 +225,40 @@ public class IOIOTruckManager extends IOIOManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void incompatible() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IOIOLooper createIOIOLooper(String connectionType, Object extra) {
|
||||||
|
Log.v(TAG, connectionType);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the mIOIOAndroidApplicationHelper
|
||||||
|
*/
|
||||||
|
public IOIOAndroidApplicationHelper getIOIOAndroidApplicationHelper() {
|
||||||
|
return mIOIOAndroidApplicationHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the status of the led
|
||||||
|
* @param b
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public void setStatLedEnabled(boolean b) {
|
||||||
|
this.isStatLedEnabled = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return state of status led
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public boolean isStatLedEnabled(){
|
||||||
|
return this.isStatLedEnabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ import android.widget.Switch;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener;
|
import com.TwentyCodes.android.IOIOTruck.IOIOTruckConnectionManager.IOIOTruckThreadListener;
|
||||||
import com.TwentyCodes.android.location.CompassListener;
|
import com.TwentyCodes.android.location.CompassListener;
|
||||||
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
||||||
import com.TwentyCodes.android.location.GeoUtils;
|
import com.TwentyCodes.android.location.GeoUtils;
|
||||||
@@ -117,7 +117,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
|
|
||||||
}
|
}
|
||||||
private static final String TAG = "NavigationActivity";
|
private static final String TAG = "NavigationActivity";
|
||||||
private IOIOTruckManager mIOIOManager;
|
private IOIOTruckConnectionManager mIOIOManager;
|
||||||
private MapFragment mMap;
|
private MapFragment mMap;
|
||||||
private TextView mLog;
|
private TextView mLog;
|
||||||
private ProgressBar mProgress;
|
private ProgressBar mProgress;
|
||||||
@@ -214,6 +214,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
protected void onCreate(Bundle icicle) {
|
protected void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
setContentView(R.layout.nav_activity);
|
setContentView(R.layout.nav_activity);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* init UI
|
* init UI
|
||||||
*/
|
*/
|
||||||
@@ -233,6 +234,19 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
findViewById(R.id.mark_my_lcoation_button).setOnClickListener(this);
|
findViewById(R.id.mark_my_lcoation_button).setOnClickListener(this);
|
||||||
findViewById(R.id.my_location_button).setOnClickListener(this);
|
findViewById(R.id.my_location_button).setOnClickListener(this);
|
||||||
findViewById(R.id.map_button).setOnClickListener(this);
|
findViewById(R.id.map_button).setOnClickListener(this);
|
||||||
|
|
||||||
|
mIOIOManager = new IOIOTruckConnectionManager(this, this);
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().create();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.FragmentActivity#onDestroy()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().destroy();
|
||||||
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -358,7 +372,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
/**
|
/**
|
||||||
* Called when the IOIOTruckThread has a log it wants to display
|
* Called when the IOIOTruckThread has a log it wants to display
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
|
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckConnectionManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onLogUpdate(String log) {
|
public void onLogUpdate(String log) {
|
||||||
@@ -373,12 +387,6 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
try {
|
|
||||||
mIOIOManager.abort();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mLoggerThread != null)
|
if(mLoggerThread != null)
|
||||||
mLoggerThread.abort();
|
mLoggerThread.abort();
|
||||||
|
|
||||||
@@ -387,6 +395,16 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.app.Activity#onRestart()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onRestart() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().restart();
|
||||||
|
super.onRestart();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.support.v4.app.FragmentActivity#onResume()
|
* @see android.support.v4.app.FragmentActivity#onResume()
|
||||||
@@ -401,14 +419,32 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
mMap.setDirectionsCompleteListener(this);
|
mMap.setDirectionsCompleteListener(this);
|
||||||
mMap.setRadius((int) (Debug.RADIUS * 1E3));
|
mMap.setRadius((int) (Debug.RADIUS * 1E3));
|
||||||
mMap.enableGPSProgess();
|
mMap.enableGPSProgess();
|
||||||
mIOIOManager = new IOIOTruckManager(this, this);
|
|
||||||
mIOIOManager.start();
|
|
||||||
|
|
||||||
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
|
||||||
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
|
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.FragmentActivity#onStart()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().start();
|
||||||
|
super.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.FragmentActivity#onStop()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().stop();
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updates the go/stop button based on isRunning
|
* updates the go/stop button based on isRunning
|
||||||
* thread safe
|
* thread safe
|
||||||
@@ -465,6 +501,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
mLog.append("\n"+log);
|
mLog.append("\n"+log);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
|
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
|
||||||
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
|
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
|
||||||
import com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener;
|
import com.TwentyCodes.android.IOIOTruck.IOIOTruckConnectionManager.IOIOTruckThreadListener;
|
||||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +50,17 @@ public class TestActivity extends Activity implements JoystickMovedListener, OnS
|
|||||||
private TextView mDriveTextView;
|
private TextView mDriveTextView;
|
||||||
private TextView mSteerTextView;
|
private TextView mSteerTextView;
|
||||||
private TextView mShifterTextView;
|
private TextView mShifterTextView;
|
||||||
private IOIOTruckManager mIOIOManager;
|
private IOIOTruckConnectionManager mIOIOManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the led swich is toggled
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.widget.CompoundButton.OnCheckedChangeListener#onCheckedChanged(android.widget.CompoundButton, boolean)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
mIOIOManager.setStatLedEnabled(isChecked);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created
|
* Called when the activity is first created
|
||||||
@@ -82,34 +92,28 @@ public class TestActivity extends Activity implements JoystickMovedListener, OnS
|
|||||||
mDriveTextView.setText(getString(R.string.drive)+1500);
|
mDriveTextView.setText(getString(R.string.drive)+1500);
|
||||||
mSteerTextView.setText(getString(R.string.steer)+1500);
|
mSteerTextView.setText(getString(R.string.steer)+1500);
|
||||||
mShifterTextView.setText(getString(R.string.shifter)+1500);
|
mShifterTextView.setText(getString(R.string.shifter)+1500);
|
||||||
|
mIOIOManager = new IOIOTruckConnectionManager(this, this);
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().create();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the application is resumed (also when first started). Here is
|
* (non-Javadoc)
|
||||||
* where we'll create our IOIO thread.
|
* @see android.app.Activity#onDestroy()
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onDestroy() {
|
||||||
super.onResume();
|
mIOIOManager.getIOIOAndroidApplicationHelper().destroy();
|
||||||
mIOIOManager = new IOIOTruckManager(this, this);
|
super.onDestroy();
|
||||||
mIOIOManager.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the application is paused. We want to disconnect with the
|
* Called when the IOIOTruckThread has a log to publish
|
||||||
* IOIO at this point, as the user is no longer interacting with our
|
* (non-Javadoc)
|
||||||
* application.
|
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckConnectionManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
public void onLogUpdate(String log) {
|
||||||
super.onPause();
|
mStatusTextView.setText(log);
|
||||||
try {
|
|
||||||
mIOIOManager.abort();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,6 +131,19 @@ public class TestActivity extends Activity implements JoystickMovedListener, OnS
|
|||||||
mSteerTextView.setText(getString(R.string.steer)+mIOIOManager.getSteerValue());//steer);
|
mSteerTextView.setText(getString(R.string.steer)+mIOIOManager.getSteerValue());//steer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the shifter seekbar is adjusted
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.widget.SeekBar.OnSeekBarChangeListener#onProgressChanged(android.widget.SeekBar, int, boolean)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
float shifter = progress + 1000;
|
||||||
|
mIOIOManager.setShifterValue(progress + 1000);
|
||||||
|
|
||||||
|
mShifterTextView.setText(getString(R.string.shifter)+ shifter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the joystick is released
|
* Called when the joystick is released
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
@@ -137,6 +154,16 @@ public class TestActivity extends Activity implements JoystickMovedListener, OnS
|
|||||||
//NOT USED
|
//NOT USED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.app.Activity#onRestart()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onRestart() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().restart();
|
||||||
|
super.onRestart();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the joystick ir returned to center
|
* Called when the joystick ir returned to center
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
@@ -150,16 +177,13 @@ public class TestActivity extends Activity implements JoystickMovedListener, OnS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the shifter seekbar is adjusted
|
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.widget.SeekBar.OnSeekBarChangeListener#onProgressChanged(android.widget.SeekBar, int, boolean)
|
* @see android.app.Activity#onStart()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
protected void onStart() {
|
||||||
float shifter = progress + 1000;
|
mIOIOManager.getIOIOAndroidApplicationHelper().start();
|
||||||
mIOIOManager.setShifterValue(progress + 1000);
|
super.onStart();
|
||||||
|
|
||||||
mShifterTextView.setText(getString(R.string.shifter)+ shifter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -167,28 +191,18 @@ public class TestActivity extends Activity implements JoystickMovedListener, OnS
|
|||||||
//NOT USED
|
//NOT USED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.app.Activity#onStop()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
mIOIOManager.getIOIOAndroidApplicationHelper().stop();
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
//NOT USED
|
//NOT USED
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the led swich is toggled
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see android.widget.CompoundButton.OnCheckedChangeListener#onCheckedChanged(android.widget.CompoundButton, boolean)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
mIOIOManager.setStatLedEnabled(isChecked);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the IOIOTruckThread has a log to publish
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onLogUpdate(String log) {
|
|
||||||
mStatusTextView.setText(log);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user