Added a way to check if the stat led is enabled from IOIOManager
This commit is contained in:
@@ -50,49 +50,7 @@ public abstract class IOIOManager implements IOIOListener{
|
||||
thread.abort();
|
||||
joinAllThreads();
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins all the threads
|
||||
* @throws InterruptedException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void joinAllThreads() throws InterruptedException {
|
||||
for (IOIOThread thread : mThreads)
|
||||
thread.join();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates all the required IOIO connectivity threads
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void createAllThreads() {
|
||||
mThreads.clear();
|
||||
Collection<IOIOConnectionSpec> specs = getConnectionSpecs();
|
||||
for (IOIOConnectionSpec spec : specs)
|
||||
mThreads.add(new IOIOThread(spec.className, spec.args, this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts IOIO connectivity threads
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void start() {
|
||||
createAllThreads();
|
||||
for (IOIOThread thread : mThreads)
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @author Ytai Ben-Tsvi
|
||||
*/
|
||||
private Collection<IOIOConnectionSpec> getConnectionSpecs() {
|
||||
Collection<IOIOConnectionSpec> result = new LinkedList<IOIOConnectionSpec>();
|
||||
addConnectionSpecs(SocketIOIOConnectionDiscovery.class.getName(),result);
|
||||
addConnectionSpecs(BluetoothIOIOConnectionDiscovery.class.getName(), result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param discoveryClassName
|
||||
* @param result
|
||||
@@ -108,6 +66,49 @@ public abstract class IOIOManager implements IOIOListener{
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG,"Exception caught while discovering connections - not adding connections of class "+ discoveryClassName, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates all the required IOIO connectivity threads
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void createAllThreads() {
|
||||
mThreads.clear();
|
||||
Collection<IOIOConnectionSpec> specs = getConnectionSpecs();
|
||||
for (IOIOConnectionSpec spec : specs)
|
||||
mThreads.add(new IOIOThread(spec.className, spec.args, this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @author Ytai Ben-Tsvi
|
||||
*/
|
||||
private Collection<IOIOConnectionSpec> getConnectionSpecs() {
|
||||
Collection<IOIOConnectionSpec> result = new LinkedList<IOIOConnectionSpec>();
|
||||
addConnectionSpecs(SocketIOIOConnectionDiscovery.class.getName(),result);
|
||||
addConnectionSpecs(BluetoothIOIOConnectionDiscovery.class.getName(), result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true is the stat led is enabled
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public boolean isStatLedEnabled() {
|
||||
for(IOIOThread thread : mThreads)
|
||||
if(thread.isConnected())
|
||||
return thread.isStatLedEnabled();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins all the threads
|
||||
* @throws InterruptedException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void joinAllThreads() throws InterruptedException {
|
||||
for (IOIOThread thread : mThreads)
|
||||
thread.join();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,4 +130,14 @@ public abstract class IOIOManager implements IOIOListener{
|
||||
thread.setUpdateInverval(ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts IOIO connectivity threads
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void start() {
|
||||
createAllThreads();
|
||||
for (IOIOThread thread : mThreads)
|
||||
thread.start();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,6 +50,7 @@ public class IOIOThread extends Thread{
|
||||
private IOIOListener mListener;
|
||||
private String mClassName;
|
||||
private Object[] mArgs;
|
||||
private boolean isConnected;
|
||||
|
||||
public IOIOThread(IOIOListener listener){
|
||||
super();
|
||||
@@ -70,20 +71,28 @@ public class IOIOThread extends Thread{
|
||||
* the case of abortion happening before the IOIO instance is created or
|
||||
* during its creation.
|
||||
*/
|
||||
synchronized public void abort() {
|
||||
public synchronized void abort() {
|
||||
isAborted = true;
|
||||
if (mIOIO != null) {
|
||||
mIOIO.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this tread is connected to a IOIO
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public synchronized boolean isConnected() {
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the isStatLedEnabled
|
||||
*/
|
||||
public boolean isStatLedEnabled() {
|
||||
public synchronized boolean isStatLedEnabled() {
|
||||
return isStatLedEnabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Thread Body
|
||||
@@ -105,7 +114,8 @@ public class IOIOThread extends Thread{
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
isConnected = true;
|
||||
try {
|
||||
/*
|
||||
* Here we will try to connect to the IOIO board.
|
||||
@@ -130,11 +140,13 @@ public class IOIOThread extends Thread{
|
||||
}
|
||||
} catch (ConnectionLostException e) {
|
||||
mListener.onDisconnected();
|
||||
isConnected = false;
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
e.printStackTrace();
|
||||
mIOIO.disconnect();
|
||||
mListener.onDisconnected();
|
||||
mListener.onDisconnected();
|
||||
isConnected = false;
|
||||
break;
|
||||
} catch (IncompatibilityException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
@@ -142,7 +154,8 @@ public class IOIOThread extends Thread{
|
||||
} finally {
|
||||
try {
|
||||
mIOIO.waitForDisconnect();
|
||||
mListener.onDisconnected();
|
||||
mListener.onDisconnected();
|
||||
isConnected = false;
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
@@ -155,8 +168,8 @@ public class IOIOThread extends Thread{
|
||||
*/
|
||||
public synchronized void setStatLedEnabled(boolean isStatLedEnabled) {
|
||||
this.isStatLedEnabled = isStatLedEnabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the update interval of the IOIO thread
|
||||
* @param ms
|
||||
|
||||
Reference in New Issue
Block a user