Initial Commit

This commit is contained in:
2012-01-22 13:53:19 -05:00
commit 2b3f9f8954
19 changed files with 1512 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
/**
* Debug.java
* @date Jan 7, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.IOIOTruck;
/**
* This class will hold constants used for debuging
* @author ricky barrette
*/
public class Debug {
/**
* Allows the application to print to the system log
*/
public static final boolean DEBUG = true;
/**
* Sets the size of the radius of a user selected point in km
*/
public static final float RADIUS = .010f;
/**
* Sets the amount of kilometers that a radius needs to be penetrated by an accuracy circle in km
*/
public static final float FUDGE_FACTOR = .005f;
}

View File

@@ -0,0 +1,203 @@
/**
* IOIOTruckThread.java
* @date Jan 11, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.IOIOTruck;
import ioio.lib.api.IOIO;
import ioio.lib.api.PwmOutput;
import ioio.lib.api.exception.ConnectionLostException;
import android.app.Activity;
import android.util.Log;
import com.TwentyCodes.android.IOIOTruck.R;
import com.TwentyCodes.android.ioio.IOIOManager;
/**
* This IOIO thread will be used to drive a rc truck
* @author ricky barrette
*/
public class IOIOTruckManager extends IOIOManager {
/**
* This listener will be used to notify the owner of this thread to update the onscreen log
* @author ricky barrette
*/
public interface IOIOTruckThreadListener{
public void onLogUpdate(String log);
}
private static final String TAG = "IOIOTruckThread";
private Activity mActivity;
private IOIOTruckThreadListener mListener;
private PwmOutput mDrive;
private PwmOutput mSteer;
private PwmOutput mShifter;
private int mDriveValue;
private int mSteerValue;
private int mShifterValue;
private boolean mStatLedValue;
private boolean isTank = false;
/**
* Creates a new IOIOTruckThread
* @param activity
* @param listener
* @author ricky barrette
*/
public IOIOTruckManager(Activity activity, IOIOTruckThreadListener listener){
super();
mActivity = activity;
mListener = listener;
updateLog(R.string.wait_ioio);
}
private void arcadeDrive() {
int left, right;
left = (mDriveValue + mSteerValue) /2;
right = (mDriveValue - mSteerValue) / 2;
mDriveValue = left;
mSteerValue = right + 1500;
Log.d(TAG, "left: "+ mDriveValue + " right: "+ mSteerValue);
}
/**
* @return the mDriveValue
*/
public synchronized int getDriveValue() {
return mDriveValue;
}
/**
* @return the mShifterValue
*/
public synchronized int getShifterValue() {
return mShifterValue;
}
/**
* @return the mSteerValue
*/
public synchronized int getSteerValue() {
return mSteerValue;
}
/**
* @return the mStatLedValue
*/
public synchronized boolean isStatLedValue() {
return mStatLedValue;
}
/**
* Here we register and initialize each port
* (non-Javadoc)
* @throws ConnectionLostException
* @see com.TwentyCodes.android.ioio.IOIOThread#onConnected()
*/
@Override
public void onConnected(IOIO ioio) throws ConnectionLostException {
updateLog(R.string.ioio_connected);
mDrive = ioio.openPwmOutput(IOIOTruckValues.DRIVE_PORT, IOIOTruckValues.RC_PWM_FRQ);
mSteer = ioio.openPwmOutput(IOIOTruckValues.STEER_PORT, IOIOTruckValues.RC_PWM_FRQ);
mShifter = ioio.openPwmOutput(IOIOTruckValues.SHIFTER_PORT, IOIOTruckValues.RC_PWM_FRQ);
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.ioio.IOIOThread#onDisconnect()
*/
@Override
public void onDisconnected() {
updateLog(R.string.wait_ioio);
}
/**
* (non-Javadoc)
* @throws ConnectionLostException
* @see com.TwentyCodes.android.ioio.IOIOThread#onUpdate()
*/
@Override
public void loop() throws ConnectionLostException {
this.setStatLedEnabled(mStatLedValue);
if(isTank){
arcadeDrive();
mSteer.setPulseWidth(mSteerValue);
mDrive.setPulseWidth(mDriveValue);
}
else {
/*
* if the autonomous routine is running
* then drive the truck
* else stop the truck
*/
if(mStatLedValue)
mDrive.setPulseWidth(mDriveValue);
else
mDrive.setPulseWidth(IOIOTruckValues.DRIVE_STOP);
}
mSteer.setPulseWidth(mSteerValue);
mShifter.setPulseWidth(mShifterValue);
}
/**
* @param mDriveValue the mDriveValue to set
*/
public synchronized void setDriveValue(int mDriveValue) {
this.mDriveValue = mDriveValue;
}
/**
* @param mShifterValue the mShifterValue to set
*/
public synchronized void setShifterValue(int mShifterValue) {
this.mShifterValue = mShifterValue;
}
/**
* @param mStatLedValue the mStatLedValue to set
*/
public synchronized void setStatLedValue(boolean mStatLedValue) {
this.mStatLedValue = mStatLedValue;
}
/**
* @param mSteerValue the mSteerValue to set
*/
public synchronized void setSteerValue(int mSteerValue) {
this.mSteerValue = mSteerValue;
}
/**
* @param isTankDrive
* @author ricky barrette
*/
public synchronized void setTankDrive(boolean isTankDrive){
isTank = isTankDrive;
}
/**
* updates the log listener in the UI thread
* @param resId
* @author ricky barrette
*/
private void updateLog(final int resId) {
if(mListener != null)
mActivity.runOnUiThread(new Runnable(){
@Override
public void run(){
mListener.onLogUpdate(mActivity.getString(resId));
}
});
}
}

View File

@@ -0,0 +1,88 @@
/**
* IOIOTruckValues.java
* @date Jan 21, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.IOIOTruck;
import com.TwentyCodes.android.ioio.IOIOValues;
/**
* This class is used to hold values for driving an RC truck
* @author ricky barrette
*/
public class IOIOTruckValues extends IOIOValues {
/**
* stop the truck
* PWM value
*/
public static final int DRIVE_STOP = 1500;
/**
* drive the truck forward
* PWM value
*/
public static final int DRIVE_FORWARD = 1300;
/**
* drive the truck in reverse
* PWM value
*/
public static final int DRIVE_REVERSE = 1700;
/**
* IOIO port to drive the speed controller
*/
public static final int DRIVE_PORT = 3;
/**
* IOIO port to drive the shifter servo
*/
public static final int SHIFTER_PORT = 4;
/**
* IOIO port to drive the steering servo
*/
public static final int STEER_PORT = 5;
/**
* steers the truck straight
* PWM value
*/
public static final int STEER_STRAIGHT = 1500;
/**
* steers the truck left
* PWM value
*/
public static final int STEER_LEFT = 1400;
/**
* steers the truck right
* PWM value
*/
public static final int STEER_RIGHT = 1600;
/**
*
* shifts truck into first
* PWM value
*/
public static final int SHIFT_FIRST = 1500;
/**
* shifts the truck into second
* TODO verify value
* PWM value
*/
public static final int SHIFT_SECOND = 1000;
/**
* shifts the truck into 3rd
* PWM value
*/
public static final int SHIFT_THRID = 2000;
}

View File

@@ -0,0 +1,66 @@
package com.TwentyCodes.android.IOIOTruck;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import com.TwentyCodes.android.exception.ExceptionHandler;
/**
* This is the main activity for this application
*
* It will be a simple menu of buttons that will start specific activitys based on the users needs
* @author ricky barrette
*/
public class Main extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
setContentView(R.layout.main);
findViewById(R.id.test_activity_button).setOnClickListener(this);
findViewById(R.id.nav_activity_button).setOnClickListener(this);
/*
* Version information textview
*/
TextView version = (TextView) findViewById(R.id.version_textview);
PackageManager pm = getPackageManager();
PackageInfo pi;
try {
pi = pm.getPackageInfo(getPackageName(), 0);
} catch (NameNotFoundException eNnf) {
//doubt this will ever run since we want info about our own package
pi = new PackageInfo();
pi.versionName = "unknown";
pi.versionCode = 1;
}
version.setText(getText(R.string.version)+" "+pi.versionName+" "+getString(R.string.build)+" "+pi.versionCode);
}
/**
* Called when a view has been clicked
* (non-Javadoc)
* @see android.view.View.OnClickListener#onClick(android.view.View)
*/
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.test_activity_button:
startActivity(new Intent(this, TestActivity.class));
break;
case R.id.nav_activity_button:
startActivity(new Intent(this, NavigationActivity.class));
break;
}
}
}

View File

@@ -0,0 +1,98 @@
/**
* MapFragment.java
* @date Jan 7, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.IOIOTruck;
import android.util.Log;
import com.TwentyCodes.android.location.LocationSelectedListener;
import com.TwentyCodes.android.location.MapView;
import com.TwentyCodes.android.location.RadiusOverlay;
import com.TwentyCodes.android.location.UserOverlayMapFragment;
import com.google.android.maps.GeoPoint;
/**
* This map fragment will maintain a map view and all its functions
*
* Specifically this map view will allow user to select a point on the map via RadiusOverlay
* @author ricky barrette
*/
public class MapFragment extends UserOverlayMapFragment implements LocationSelectedListener {
private final String TAG = "MapFragment";
private RadiusOverlay mRadiusOverlay;
private LocationSelectedListener mLocationSelectedListener;
/**
* Creates a new MapFragment
* @author ricky barrette
*/
public MapFragment() {
super();
}
/**
* Called when a point is selected on the map
* (non-Javadoc)
* @see com.TwentyCodes.android.location.LocationSelectedListener#onLocationSelected(com.google.android.maps.GeoPoint)
*/
@Override
public void onLocationSelected(GeoPoint point) {
setDestination(point);
if(mLocationSelectedListener != null)
mLocationSelectedListener.onLocationSelected(point);
if(point != null){
if(Debug.DEBUG)
Log.d(TAG, "onLocationSelected() "+ point.toString());
if(this.mRadiusOverlay != null)
this.mRadiusOverlay.setLocation(point);
} else if(Debug.DEBUG)
Log.d(TAG, "onLocationSelected() Location was null");
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.location.UserOverlayMapFragment#onMapViewCreate(com.TwentyCodes.android.location.MapView)
*/
@Override
public void onMapViewCreate(MapView map) {
mRadiusOverlay = new RadiusOverlay();
mRadiusOverlay.setLocationSelectedListener(this);
map.getOverlays().add(mRadiusOverlay);
super.onMapViewCreate(map);
}
/**
* @param listener
* @author ricky barrette
*/
public void setLocationSelectedListener(LocationSelectedListener listener){
mLocationSelectedListener = listener;
}
/**
* @param radius meters
* @author ricky barrette
*/
public void setRadius(int radius){
mRadiusOverlay.setRadius(radius);
}
/**
* @param color
* @author ricky barrette
*/
public void setRadiusColor(int color){
mRadiusOverlay.setColor(color);
}
}

View File

@@ -0,0 +1,379 @@
/**
* NavigationActivity.java
* @date Jan 7, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.IOIOTruck;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener;
import com.TwentyCodes.android.location.CompassListener;
import com.TwentyCodes.android.location.GeoPointLocationListener;
import com.TwentyCodes.android.location.GeoUtils;
import com.TwentyCodes.android.location.LocationSelectedListener;
import com.google.android.maps.GeoPoint;
/**
* This activity will be used to interact with the IOIO and setup autonomous routines
*
* The end goal of this activity is to:
* + have the user select a point on the map
* + have the IOIO drive the rc truck to the point on the map when the user starts the autonomous routine
*
* TODO
* + drive the truck forward or reverse to best navigate to the selected point
* @author ricky barrette
*/
public class NavigationActivity extends FragmentActivity implements CompassListener, GeoPointLocationListener, LocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener {
private IOIOTruckManager mIOIOManager;
private MapFragment mMap;
private TextView mLog;
private GeoPoint mPoint;
private ProgressBar mProgress;
private int mMaxDistance = 0; //meters
private boolean isRunning = false;
private Button mGoButton;
private float mBearing;
private ScrollView mScrollView;
private boolean isScrollingEnabled = true;
private int mDistance;
private LogUpdater mLoggerThread;
private TextView mAccuracyTextView;
private TextView mLastUpdateTextView;
private long mLast;
/**
* This thread will be used to update all the informational displays
* @author ricky barrette
*/
class LogUpdater extends Thread {
private boolean isAborted;
/**
* aborts the thread
* @author ricky barrette
*/
public void abort() {
isAborted = true;
}
@Override
public void run(){
while (true) {
if (isAborted)
break;
updateLog("\nDistance: "+ mDistance +getString(R.string.m)
+"\nDrive: "+mIOIOManager.getDriveValue()
+"\nSteering: "+mIOIOManager.getSteerValue()
+"\nBearing: "+mBearing
+"\nisRunning: "+isRunning);
updateLastUpdateTextView();
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/**
* updates the last update textview
* thread safe
* @author ricky barrette
*/
private void updateLastUpdateTextView() {
runOnUiThread( new Runnable(){
@Override
public void run(){
mLastUpdateTextView.setText((System.currentTimeMillis() - mLast) +getString(R.string.ms));
}
});
}
}
/**
* Called when the scrolling switch is checked
* (non-Javadoc)
* @see android.widget.CompoundButton.OnCheckedChangeListener#onCheckedChanged(android.widget.CompoundButton, boolean)
*/
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isScrollingEnabled = isChecked;
}
/**
* Called when a button is clicked
* (non-Javadoc)
* @see android.view.View.OnClickListener#onClick(android.view.View)
*/
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.go_button:
updateGoButton();
break;
case R.id.mark_my_lcoation_button:
GeoPoint point = mMap.getUserLocation();
if(point != null){
mMap.onLocationSelected(point);
} else
Toast.makeText(this, R.string.no_gps_signal, Toast.LENGTH_SHORT).show();
break;
case R.id.my_location_button:
GeoPoint user = mMap.getUserLocation();
if(user != null){
mMap.setMapCenter(user);
} else
break;
}
}
/**
* updates the go/stop button based on isRunning
* thread safe
* @author ricky barrette
*/
private void updateGoButton() {
updateGoButton(isRunning);
}
/**
* Sets the go/stop button to the provided value
* thread safe
* @param isRunnuing true = stop, false = go
* @author ricky barrette
*/
private void updateGoButton(final boolean isRun) {
mIOIOManager.setStatLedValue(!isRun);
runOnUiThread(new Runnable() {
@Override
public void run(){
if(isRun){
mGoButton.setText(R.string.go);
isRunning = false;
updateLog(R.string.stop);
if(mLoggerThread != null)
mLoggerThread.abort();
} else {
mGoButton.setText(R.string.stop);
isRunning = true;
updateLog(R.string.go);
mLoggerThread = new LogUpdater();
mLoggerThread.start();
}
}
});
}
/**
* Called when there is an update from the compass
* (non-Javadoc)
* @see com.TwentyCodes.android.location.CompassListener#onCompassUpdate(float)
*/
@Override
public void onCompassUpdate(float bearing) {
bearing = GeoUtils.calculateBearing(mMap.getUserLocation(), mPoint, bearing);
if(bearing > 355 || bearing < 5)
mIOIOManager.setSteerValue(IOIOTruckValues.STEER_STRAIGHT);
if(bearing < 355 && bearing > 180)
mIOIOManager.setSteerValue(IOIOTruckValues.STEER_RIGHT);
if(bearing < 180 && bearing > 5)
mIOIOManager.setSteerValue(IOIOTruckValues.STEER_LEFT);
mBearing = bearing;
}
/**
* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.nav_activity);
/*
* init UI
*/
mLog = (TextView) findViewById(R.id.log_textView);
mGoButton = (Button) findViewById(R.id.go_button);
mProgress = (ProgressBar) findViewById(R.id.progressBar);
mScrollView = (ScrollView) findViewById(R.id.scrollview);
Switch scrollSwitch = (Switch) findViewById(R.id.scrolling_switch);
mAccuracyTextView = (TextView) findViewById(R.id.accuracy_textview);
mLastUpdateTextView = (TextView) findViewById(R.id.time_textview);
/*
* init listeners
*/
scrollSwitch.setOnCheckedChangeListener(this);
mGoButton.setOnClickListener(this);
findViewById(R.id.mark_my_lcoation_button).setOnClickListener(this);
findViewById(R.id.my_location_button).setOnClickListener(this);
}
/**
* Called when android's location services have an update
* (non-Javadoc)
* @see com.TwentyCodes.android.location.GeoPointLocationListener#onLocationChanged(com.google.android.maps.GeoPoint, int)
*/
@Override
public void onLocationChanged(GeoPoint point, int accuracy) {
mLast = System.currentTimeMillis();
mAccuracyTextView.setText(accuracy+getString(R.string.m));
mDistance = updateProgress(point);
/*
* here we will update the progress bar
*
*/
if(mPoint != null)
if(GeoUtils.isIntersecting(point, (float) (accuracy / 1E3), mPoint, Debug.RADIUS, Debug.FUDGE_FACTOR)) {
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP);
updateGoButton(true);
updateLog(R.string.dest_reached);
} else
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_FORWARD);
else
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP);
}
/**
* Called when the user selects a point for the truck to drive to
* (non-Javadoc)
* @see com.TwentyCodes.android.location.LocationSelectedListener#onLocationSelected(com.google.android.maps.GeoPoint)
*/
@Override
public void onLocationSelected(GeoPoint point) {
mPoint = point;
mDistance = updateProgress(mMap.getUserLocation());
updateLog(getString(R.string.point_selected)+point.toString());
}
/**
* Called when the application is paused. We want to disconnect with the
* IOIO at this point, as the user is no longer interacting with our
* application.
* @author ricky barrette
*/
@Override
protected void onPause() {
try {
mIOIOManager.abort();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(mLoggerThread != null)
mLoggerThread.abort();
super.onPause();
}
/**
* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onResume()
*/
@Override
protected void onResume() {
super.onResume();
mMap = (MapFragment) this.getSupportFragmentManager().findFragmentById(R.id.map_fragment);
mMap.setCompassListener(this);
mMap.setGeoPointLocationListener(this);
mMap.setLocationSelectedListener(this);
mMap.setRadius((int) (Debug.RADIUS * 1E3));
mIOIOManager = new IOIOTruckManager(this, this);
mIOIOManager.start();
}
/**
* updates the log with the provided string res
* thread safe
* @param resId
*/
private void updateLog(final int resId) {
updateLog("\n"+getString(resId));
}
/**
* updates the log with the provided string
* thread safe
* @param id The string ID of the message to present.
*/
private void updateLog(final String log) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mLog.append("\n"+log);
/*
* Scroll the scroll view down
*/
if(isScrollingEnabled)
mScrollView.scrollTo(0, mLog.getHeight());
}
});
}
/**
* updates the progress bar
* it will roughly show the progress of the truck
*
* less = closer
* more = farther
* @param point dest
* @return distance meters
* @author ricky barrette
*/
private int updateProgress(GeoPoint point) {
int distance = (int) (GeoUtils.distanceKm(point, mPoint) * 1000);
if (distance > mMaxDistance) {
mMaxDistance = distance;
mProgress.setMax(distance);
}
mProgress.setProgress(distance);
return distance;
}
/**
* Called when the IOIOTruckThread has a log it wants to display
* (non-Javadoc)
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
*/
@Override
public void onLogUpdate(String log) {
updateLog(log);
}
}

View File

@@ -0,0 +1,172 @@
package com.TwentyCodes.android.IOIOTruck;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Switch;
import android.widget.TextView;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
import com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener;
import com.TwentyCodes.android.exception.ExceptionHandler;
/**
* This is a simple testing activity to test to main functions of the truck.
* These functions are:
* + drive forward /reverse
* + steer left / right
* + shift 1st, 2nd, 3rd
* + status LED on / off
* @author ricky barrette
*/
public class TestActivity extends Activity implements JoystickMovedListener, OnSeekBarChangeListener, OnCheckedChangeListener, IOIOTruckThreadListener {
private TextView mStatusTextView;
private TextView mDriveTextView;
private TextView mSteerTextView;
private TextView mShifterTextView;
private IOIOTruckManager mIOIOManager;
/**
* Called when the activity is first created
* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
setContentView(R.layout.test_activity);
mStatusTextView = (TextView) findViewById(R.id.title);
Switch ledSwitch = (Switch) findViewById(R.id.led_switch);
ledSwitch.setOnCheckedChangeListener(this);
SeekBar seekBar = (SeekBar) findViewById(R.id.skeekbar1);
seekBar.setOnSeekBarChangeListener(this);
JoystickView joyStick = (JoystickView) findViewById(R.id.joystick);
joyStick.setOnJostickMovedListener(this);
joyStick.setMovementRange(500);
mDriveTextView = (TextView) findViewById(R.id.tv_drive);
mSteerTextView = (TextView) findViewById(R.id.tv_steer);
mShifterTextView = (TextView) findViewById(R.id.tv_shifter);
mDriveTextView.setText(getString(R.string.drive)+1500);
mSteerTextView.setText(getString(R.string.steer)+1500);
mShifterTextView.setText(getString(R.string.shifter)+1500);
}
/**
* Called when the application is resumed (also when first started). Here is
* where we'll create our IOIO thread.
* @author ricky barrette
*/
@Override
protected void onResume() {
super.onResume();
mIOIOManager = new IOIOTruckManager(this, this);
mIOIOManager.start();
}
/**
* Called when the application is paused. We want to disconnect with the
* IOIO at this point, as the user is no longer interacting with our
* application.
* @author ricky barrette
*/
@Override
protected void onPause() {
super.onPause();
try {
mIOIOManager.abort();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* called when the joystick has been moved
* (non-Javadoc)
* @see com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener#OnMoved(int, int)
*/
@Override
public void OnMoved(int pan, int tilt) {
int drive = tilt + 1500;
int steer = pan + 1500;
mIOIOManager.setDriveValue(drive);
mIOIOManager.setSteerValue(steer);
mDriveTextView.setText(getString(R.string.drive)+mIOIOManager.getDriveValue());//drive);
mSteerTextView.setText(getString(R.string.steer)+mIOIOManager.getSteerValue());//steer);
}
/**
* Called when the joystick is released
* (non-Javadoc)
* @see com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener#OnReleased()
*/
@Override
public void OnReleased() {
//NOT USED
}
/**
* Called when the joystick ir returned to center
* (non-Javadoc)
* @see com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener#OnReturnedToCenter()
*/
@Override
public void OnReturnedToCenter() {
//All Stop
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP);
mIOIOManager.setSteerValue(IOIOTruckValues.STEER_STRAIGHT);
}
/**
* 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) {
int shifter = progress + 1000;
mIOIOManager.setShifterValue(shifter);
mShifterTextView.setText(getString(R.string.shifter)+shifter);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
//NOT USED
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
//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.setStatLedValue(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);
}
}