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();
|
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 discoveryClassName
|
||||||
* @param result
|
* @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
|
* @param isStatLedEnabled the isStatLedEnabled to set
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -129,4 +130,14 @@ public abstract class IOIOManager implements IOIOListener{
|
|||||||
thread.setUpdateInverval(ms);
|
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 IOIOListener mListener;
|
||||||
private String mClassName;
|
private String mClassName;
|
||||||
private Object[] mArgs;
|
private Object[] mArgs;
|
||||||
|
private boolean isConnected;
|
||||||
|
|
||||||
public IOIOThread(IOIOListener listener){
|
public IOIOThread(IOIOListener listener){
|
||||||
super();
|
super();
|
||||||
@@ -70,21 +71,29 @@ public class IOIOThread extends Thread{
|
|||||||
* the case of abortion happening before the IOIO instance is created or
|
* the case of abortion happening before the IOIO instance is created or
|
||||||
* during its creation.
|
* during its creation.
|
||||||
*/
|
*/
|
||||||
synchronized public void abort() {
|
public synchronized void abort() {
|
||||||
isAborted = true;
|
isAborted = true;
|
||||||
if (mIOIO != null) {
|
if (mIOIO != null) {
|
||||||
mIOIO.disconnect();
|
mIOIO.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this tread is connected to a IOIO
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public synchronized boolean isConnected() {
|
||||||
|
return isConnected;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the isStatLedEnabled
|
* @return the isStatLedEnabled
|
||||||
*/
|
*/
|
||||||
public boolean isStatLedEnabled() {
|
public synchronized boolean isStatLedEnabled() {
|
||||||
return isStatLedEnabled;
|
return isStatLedEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread Body
|
* Thread Body
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
@@ -106,6 +115,7 @@ public class IOIOThread extends Thread{
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isConnected = true;
|
||||||
try {
|
try {
|
||||||
/*
|
/*
|
||||||
* Here we will try to connect to the IOIO board.
|
* Here we will try to connect to the IOIO board.
|
||||||
@@ -130,11 +140,13 @@ public class IOIOThread extends Thread{
|
|||||||
}
|
}
|
||||||
} catch (ConnectionLostException e) {
|
} catch (ConnectionLostException e) {
|
||||||
mListener.onDisconnected();
|
mListener.onDisconnected();
|
||||||
|
isConnected = false;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.e(TAG, e.getMessage());
|
Log.e(TAG, e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
mIOIO.disconnect();
|
mIOIO.disconnect();
|
||||||
mListener.onDisconnected();
|
mListener.onDisconnected();
|
||||||
|
isConnected = false;
|
||||||
break;
|
break;
|
||||||
} catch (IncompatibilityException e) {
|
} catch (IncompatibilityException e) {
|
||||||
Log.e(TAG, e.getMessage());
|
Log.e(TAG, e.getMessage());
|
||||||
@@ -143,6 +155,7 @@ public class IOIOThread extends Thread{
|
|||||||
try {
|
try {
|
||||||
mIOIO.waitForDisconnect();
|
mIOIO.waitForDisconnect();
|
||||||
mListener.onDisconnected();
|
mListener.onDisconnected();
|
||||||
|
isConnected = false;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user