Added a way to check if the stat led is enabled from IOIOManager
This commit is contained in:
@@ -51,48 +51,6 @@ public abstract class IOIOManager implements IOIOListener{
|
||||
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
|
||||
@@ -110,6 +68,49 @@ public abstract class IOIOManager implements IOIOListener{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isStatLedEnabled the isStatLedEnabled to set
|
||||
* @author ricky barrette
|
||||
@@ -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,21 +71,29 @@ 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
|
||||
* (non-Javadoc)
|
||||
@@ -106,6 +115,7 @@ public class IOIOThread extends Thread{
|
||||
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();
|
||||
isConnected = false;
|
||||
break;
|
||||
} catch (IncompatibilityException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
@@ -143,6 +155,7 @@ public class IOIOThread extends Thread{
|
||||
try {
|
||||
mIOIO.waitForDisconnect();
|
||||
mListener.onDisconnected();
|
||||
isConnected = false;
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user