diff --git a/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOListener.class b/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOListener.class deleted file mode 100644 index 76cb19a..0000000 Binary files a/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOListener.class and /dev/null differ diff --git a/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOManager.class b/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOManager.class deleted file mode 100644 index cb7b843..0000000 Binary files a/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOManager.class and /dev/null differ diff --git a/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOThread.class b/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOThread.class deleted file mode 100644 index 55f7630..0000000 Binary files a/IOIOLib/bin/classes/com/TwentyCodes/android/ioio/IOIOThread.class and /dev/null differ diff --git a/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOListener.java b/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOListener.java deleted file mode 100644 index 0400956..0000000 --- a/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOListener.java +++ /dev/null @@ -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(); - -} diff --git a/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOManager.java b/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOManager.java deleted file mode 100644 index fc027fb..0000000 --- a/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOManager.java +++ /dev/null @@ -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 mThreads = new LinkedList(); - - /** - * 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 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 specs = getConnectionSpecs(); - for (IOIOConnectionSpec spec : specs) - mThreads.add(new IOIOThread(spec.className, spec.args, this)); - } - - /** - * @return - * @author Ytai Ben-Tsvi - */ - private Collection getConnectionSpecs() { - Collection result = new LinkedList(); - 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(); - } - -} \ No newline at end of file diff --git a/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOThread.java b/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOThread.java deleted file mode 100644 index 15b7e6f..0000000 --- a/IOIOLib/src/com/TwentyCodes/android/ioio/IOIOThread.java +++ /dev/null @@ -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; - } - -} \ No newline at end of file