I removed IOIOManager, IOIOThread, and IOIOListener
Thier functionality have been replaced by IOIOAndroidApplicationHelper Change-Id: I8a4d7a647e7e78a078c08929be93a1dd18cbf70f Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* IOIOListener.java
|
||||
* @date Jan 24, 2012
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*
|
||||
* Copyright 2012 Richard Barrette
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.TwentyCodes.android.ioio;
|
||||
|
||||
import ioio.lib.api.IOIO;
|
||||
import ioio.lib.api.exception.ConnectionLostException;
|
||||
|
||||
/**
|
||||
* This is a simple interface used to pass information from the IOIO thread to the manager
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public interface IOIOListener {
|
||||
|
||||
/**
|
||||
* Called when a IOIO is connected.
|
||||
* here is a good time to init ports
|
||||
* @param ioio
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void onConnected(IOIO ioio) throws ConnectionLostException;
|
||||
|
||||
/**
|
||||
* Called when the IOIO thread loops.
|
||||
* Here you want to update the ports
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void loop() throws ConnectionLostException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Called when the IOIO is disconnected.
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void onDisconnected();
|
||||
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/**
|
||||
* IOIOManager.java
|
||||
* @date Jan 21, 2012
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*
|
||||
* Copyright 2012 Richard Barrette
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.TwentyCodes.android.ioio;
|
||||
|
||||
import ioio.lib.bluetooth.BluetoothIOIOConnectionDiscovery;
|
||||
import ioio.lib.util.IOIOConnectionDiscovery;
|
||||
import ioio.lib.util.SocketIOIOConnectionDiscovery;
|
||||
import ioio.lib.util.IOIOConnectionDiscovery.IOIOConnectionSpec;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* This class manages the IOIO connectivity threads. It is based on the AbstractIOIOActivity
|
||||
* Remember that onConnected(), loop(), and onDisconnected() are called from the one of the IOIO threads
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public abstract class IOIOManager implements IOIOListener{
|
||||
|
||||
private static final String TAG = "IOIOManager";
|
||||
private Collection<IOIOThread> mThreads = new LinkedList<IOIOThread>();
|
||||
|
||||
/**
|
||||
* Aborts the IOIO connectivity threads and joins them
|
||||
* @throws InterruptedException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void abort() throws InterruptedException {
|
||||
for (IOIOThread thread : mThreads)
|
||||
thread.abort();
|
||||
joinAllThreads();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param discoveryClassName
|
||||
* @param result
|
||||
* @author Ytai Ben-Tsvi
|
||||
*/
|
||||
private void addConnectionSpecs(String discoveryClassName, Collection<IOIOConnectionSpec> result) {
|
||||
try {
|
||||
Class<?> cls = Class.forName(discoveryClassName);
|
||||
IOIOConnectionDiscovery discovery = (IOIOConnectionDiscovery) cls.newInstance();
|
||||
discovery.getSpecs(result);
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.d(TAG, "Discovery class not found: " + discoveryClassName+ ". Not adding.");
|
||||
} 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isStatLedEnabled the isStatLedEnabled to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setStatLedEnabled(boolean isStatLedEnabled) {
|
||||
for(IOIOThread thread : mThreads)
|
||||
thread.setStatLedEnabled(isStatLedEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the update interval of the IOIO thread
|
||||
* @param ms
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setUpdateInverval(long ms){
|
||||
for(IOIOThread thread : mThreads)
|
||||
thread.setUpdateInverval(ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts IOIO connectivity threads
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void start() {
|
||||
createAllThreads();
|
||||
for (IOIOThread thread : mThreads)
|
||||
thread.start();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
/**
|
||||
* IOIOThread.java
|
||||
* @date Jan 11, 2012
|
||||
* @author ricky barrette
|
||||
* @author Ytai Ben-Tsvi
|
||||
* @author Twenty Codes, LLC
|
||||
*
|
||||
* Copyright 2012 Richard Barrette
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.TwentyCodes.android.ioio;
|
||||
|
||||
import android.util.Log;
|
||||
import ioio.lib.api.DigitalOutput;
|
||||
import ioio.lib.api.IOIO;
|
||||
import ioio.lib.api.IOIOFactory;
|
||||
import ioio.lib.api.exception.ConnectionLostException;
|
||||
import ioio.lib.api.exception.IncompatibilityException;
|
||||
|
||||
/**
|
||||
* This is the thread that maintains the IOIO interaction.
|
||||
*
|
||||
* It first creates a IOIO instance and wait for a connection to be
|
||||
* established.
|
||||
*
|
||||
* Whenever a connection drops, it tries to reconnect, unless this is a
|
||||
* result of abort().
|
||||
*
|
||||
* @author Ytai Ben-Tsvi
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class IOIOThread extends Thread{
|
||||
|
||||
private static final String TAG = "IOIOThread";
|
||||
private IOIO mIOIO;
|
||||
private boolean isAborted = false;
|
||||
private long mUpdateInterval = 10;
|
||||
private boolean isStatLedEnabled = false;
|
||||
private IOIOListener mListener;
|
||||
private String mClassName;
|
||||
private Object[] mArgs;
|
||||
private boolean isConnected;
|
||||
|
||||
public IOIOThread(IOIOListener listener){
|
||||
super();
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public IOIOThread(String className, Object[] args, IOIOListener listener) {
|
||||
super();
|
||||
mListener = listener;
|
||||
mClassName = className;
|
||||
mArgs = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort the connection.
|
||||
*
|
||||
* This is a little tricky synchronization-wise: we need to be handle
|
||||
* the case of abortion happening before the IOIO instance is created or
|
||||
* during its creation.
|
||||
*/
|
||||
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 synchronized boolean isStatLedEnabled() {
|
||||
return isStatLedEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread Body
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Thread#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
synchronized (this) {
|
||||
if (isAborted) {
|
||||
break;
|
||||
}
|
||||
if(mClassName == null || mArgs == null)
|
||||
mIOIO = IOIOFactory.create();
|
||||
else
|
||||
try {
|
||||
mIOIO = IOIOFactory.create(mClassName, mArgs);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
isConnected = true;
|
||||
try {
|
||||
/*
|
||||
* Here we will try to connect to the IOIO board.
|
||||
*
|
||||
* the waitForConnect() is blocking until it can connect
|
||||
*/
|
||||
mIOIO.waitForConnect();
|
||||
|
||||
/*
|
||||
* Here we register and initialize each port
|
||||
*/
|
||||
DigitalOutput statLed = mIOIO.openDigitalOutput(IOIOValues.STAT_LED_PORT, true);
|
||||
mListener.onConnected(mIOIO);
|
||||
|
||||
/*
|
||||
* Here we will update the ports every 10 ms (default)
|
||||
*/
|
||||
while (true) {
|
||||
mListener.loop();
|
||||
statLed.write(!isStatLedEnabled);
|
||||
sleep(mUpdateInterval );
|
||||
}
|
||||
} 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());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
mIOIO.waitForDisconnect();
|
||||
mListener.onDisconnected();
|
||||
isConnected = false;
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stat led on / off
|
||||
* @param isStatLedEnabled the isStatLedEnabled to set
|
||||
*/
|
||||
public synchronized void setStatLedEnabled(boolean isStatLedEnabled) {
|
||||
this.isStatLedEnabled = isStatLedEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the update interval of the IOIO thread
|
||||
* @param ms
|
||||
*/
|
||||
public synchronized void setUpdateInverval(long ms){
|
||||
mUpdateInterval = ms;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user