Compare commits

..

10 Commits

Author SHA1 Message Date
22ecc8f1e6 Removed bin directory 2012-12-11 12:12:02 -05:00
efb63070a2 Updated ioio library to the lastest code
Orignal code pulled from git://github.com/ytai/ioio.git

Please note that built in Android Open Accessory support is included in
Android 3.1 (API Level 12). If you want to use Android 2.3.4 (API Level
10) amd higher, you will need to use the Add-On Support Library.
2012-12-11 11:06:07 -05:00
b8a55682d4 I removed IOIOManager, IOIOThread, and IOIOListener
Thier functionality have been replaced by IOIOAndroidApplicationHelper

Change-Id: I8a4d7a647e7e78a078c08929be93a1dd18cbf70f
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
2012-03-12 11:44:22 -04:00
5f51c1caa1 Started to update the library to API 3.22 RC
Change-Id: I8eaf3151b1d405799eb582564f0e1e8fbcb7744c
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
2012-03-12 00:53:13 -04:00
2b1ee23cff Removed Tracking for generated files
Change-Id: Ic035613089de15141acf6e1270a70aa97480769e
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
2012-03-04 23:15:35 -05:00
e510b09138 Removed the word "test"
Change-Id: I85dd6035b75f704719f8ac5678b4a2711bf3e23a
2012-02-01 11:01:53 -05:00
40c2ec2e9b yet another test commit
Change-Id: I43372c0508f4ca2b7160b6123b46d7331edb1ada
2012-02-01 01:33:47 -05:00
c04832c94e Added a way to check if the stat led is enabled from IOIOManager 2012-01-28 18:09:01 -05:00
8633e303bf Reduced Logging from error to verbose. 2012-01-28 15:27:15 -05:00
aef0901a07 IOIOListener.java
added throws InterruptedException to loop()

IOIOThread.java
added a catch for InterruptedException in run()
removed catch for Exception in run()
added a catch for IncompatibilityException in run()
added Loging
2012-01-28 15:24:52 -05:00
141 changed files with 1912 additions and 745 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

2
IOIOLib/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/gen
/bin

Binary file not shown.

View File

@@ -9,4 +9,4 @@
android.library=true
# Project target.
target=android-15
target=android-17

View File

@@ -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;
/**
* Called when the IOIO is disconnected.
* @author ricky barrette
*/
public void onDisconnected();
}

View File

@@ -1,132 +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();
}
/**
* 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
* @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);
}
}
/**
* @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);
}
}

View File

@@ -1,161 +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 ioio.lib.api.DigitalOutput;
import ioio.lib.api.IOIO;
import ioio.lib.api.IOIOFactory;
import ioio.lib.api.exception.ConnectionLostException;
/**
* 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 IOIO mIOIO;
private boolean isAborted = false;
private long mUpdateInterval = 10;
private boolean isStatLedEnabled = false;
private IOIOListener mListener;
private String mClassName;
private Object[] mArgs;
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.
*/
synchronized public void abort() {
isAborted = true;
if (mIOIO != null) {
mIOIO.disconnect();
}
}
/**
* @return the isStatLedEnabled
*/
public 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();
}
}
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();
} catch (Exception e) {
e.printStackTrace();
mIOIO.disconnect();
mListener.onDisconnected();
break;
} finally {
try {
mIOIO.waitForDisconnect();
mListener.onDisconnected();
} 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;
}
}

View File

@@ -52,10 +52,42 @@ import ioio.lib.api.exception.ConnectionLostException;
* Typical usage:
*
* <pre>
* {@code
* AnalogInput potentiometer = ioio.openAnalogInput(40);
* float value = potentiometer.read();
* ...
* potentiometer.close(); // pin 40 can now be used for something else.
* }
* </pre>
* <p>
* An alternate usage allows reading periodically sampled data without missing
* samples. The {@link #setBuffer(int)} method must first be called, for setting
* up an internal buffer for queuing samples. Then, samples can be obtained by
* calling {@link #readBuffered()} or {@link #getVoltageBuffered()}. These
* methods will block until a sample is available. If this is undesirable, the
* {@link #available()} method can be called first to check how many samples are
* ready in the buffer. In case the buffer overflows, as result of the client
* not reading fast enough, old samples will be dropped, and the client can
* check {@link #getOverflowCount()} to determine how many samples have been
* lost. The sample rate used for capturing samples can be obtained by calling
* {@link #getSampleRate()}.
* <p>
* The non-buffered versions of the read methods will still behave normally when
* buffering is enabled. The {@link #read()} and {@link #getVoltage()} methods
* will always return the most recent value, regardless of the buffer state.
* <p>
* Typical usage:
*
* <pre>
* AnalogInput potentiometer = ioio.openAnalogInput(40);
* potentiometer.setBuffer(256);
* for (int i = 0; i < 1024; ++i) {
* // next line will block until at least one sample is available
* float sample = potentiometer.readBuffered();
* ...
* }
* ...
* potentiometer.close(); // pin 40 can now be used for something else.
* </pre>
*
* @see IOIO#openAnalogInput(int)
@@ -69,11 +101,13 @@ public interface AnalogInput extends Closeable {
* may block shortly. If this is a problem, the calling thread can be
* interrupted.
* <p>
* If a scaled value is desired, consider using {@link #read()}.
* If a scaled value is desired, consider using {@link #read()}.
*
* @return The voltage, in Volt units.
* @throws InterruptedException The calling thread has been interrupted.
* @throws ConnectionLostException The connection with the IOIO is lost.
* @throws InterruptedException
* The calling thread has been interrupted.
* @throws ConnectionLostException
* The connection with the IOIO is lost.
* @see #read()
*/
public float getVoltage() throws InterruptedException,
@@ -81,6 +115,7 @@ public interface AnalogInput extends Closeable {
/**
* Gets the maximum value against which {@link #read()} values are scaled.
*
* @return The voltage, in Volts.
*/
public float getReference();
@@ -96,9 +131,95 @@ public interface AnalogInput extends Closeable {
* If an absolute value is desired, consider using {@link #getVoltage()}.
*
* @return The voltage, in scaled units.
* @throws InterruptedException The calling thread has been interrupted.
* @throws ConnectionLostException The connection with the IOIO is lost.
* @throws InterruptedException
* The calling thread has been interrupted.
* @throws ConnectionLostException
* The connection with the IOIO is lost.
* @see #getVoltage()
*/
public float read() throws InterruptedException, ConnectionLostException;
/**
* Initializes or destroys an internal buffer, used for queuing sampled
* data. When called with a positive argument, an internal buffer will be
* created, and start storing sampled data. The client can then call
* {@link #readBuffered()} or {@link #getVoltageBuffered()} for obtaining
* buffered samples.
* <p>
* When called with argument of 0, the internal buffer is destroyed.
*
* @param capacity
* The maximum number of unread samples that can be buffered
* before overflow occurs.
* @throws ConnectionLostException
* The connection with the IOIO is lost.
*/
public void setBuffer(int capacity) throws ConnectionLostException;
/**
* Gets the number of samples that have been dropped as result of overflow,
* since {@link #setBuffer(int)} has been called.
*
* @return The number of dropped samples.
* @throws ConnectionLostException
* The connection with the IOIO is lost.
*/
public int getOverflowCount() throws ConnectionLostException;
/**
* Gets the number of samples currently in the buffer. Reading that many
* samples is guaranteed not to block.
*
* @return The number of samples available in the buffer.
* @throws ConnectionLostException
* The connection with the IOIO is lost.
*/
public int available() throws ConnectionLostException;
/**
* Read a sample from the internal buffer. This method will block until at
* least one sample is available, the instance is closed (via
* {@link #close()}), the thread is interrupted (via
* {@link Thread#interrupt()} or connection is lost. {@link #setBuffer(int)}
* must be called prior to this method for setting up an internal buffer for
* storing samples.
*
* @see #getVoltageBuffered()
* @return The earliest (oldest) sample available in the buffer, scaled to
* the range [0,1].
* @throws InterruptedException
* The calling thread has been interrupted.
* @throws ConnectionLostException
* The connection with the IOIO is lost.
*/
public float readBuffered() throws InterruptedException,
ConnectionLostException;
/**
* Read a sample from the internal buffer. This method will block until at
* least one sample is available, the instance is closed (via
* {@link #close()}), the thread is interrupted (via
* {@link Thread#interrupt()} or connection is lost. {@link #setBuffer(int)}
* must be called prior to this method for setting up an internal buffer for
* storing samples.
*
* @see #readBuffered()
* @return The earliest (oldest) sample available in the buffer, in Volt
* units.
* @throws InterruptedException
* The calling thread has been interrupted.
* @throws ConnectionLostException
* The connection with the IOIO is lost.
*/
public float getVoltageBuffered() throws InterruptedException,
ConnectionLostException;
/**
* Gets the sample rate used for obtaining buffered samples.
*
* @return The sample rate, in Hz units.
* @throws ConnectionLostException
* The connection with the IOIO is lost.
*/
public float getSampleRate() throws ConnectionLostException;
}

View File

@@ -34,7 +34,7 @@ import ioio.lib.api.exception.ConnectionLostException;
* A pin used for digital input.
* <p>
* A digital input pin can be used to read logic-level signals. DigitalInput
* instances are obtained by calling {@link IOIO#openDigitalInput(Spec)}.
* instances are obtained by calling {@link IOIO#openDigitalInput(DigitalInput.Spec)}.
* <p>
* The value of the pin is obtained by calling {@link #read()}. It is also
* possible for the client to block until a certain level is sensed, by using

View File

@@ -35,7 +35,7 @@ import ioio.lib.api.exception.ConnectionLostException;
* <p>
* A digital input pin can be used to generate logic-level signals.
* DigitalOutput instances are obtained by calling
* {@link IOIO#openDigitalOutput(Spec, boolean)}.
* {@link IOIO#openDigitalOutput(DigitalOutput.Spec, boolean)}.
* <p>
* The value of the pin is set by calling {@link #write(boolean)}.
* <p>
@@ -101,7 +101,7 @@ public interface DigitalOutput extends Closeable {
/**
* Shorthand for Spec(pin, Mode.NORMAL).
*
* @see #Spec(int, Mode)
* @see DigitalOutput.Spec#Spec(int, DigitalOutput.Spec.Mode)
*/
public Spec(int pin) {
this(pin, Mode.NORMAL);

View File

@@ -109,6 +109,20 @@ public interface IOIO {
IOIOLIB_VER
}
/**
* A state of a IOIO instance.
*/
public enum State {
/** Connection not yet established. */
INIT,
/** Connected. */
CONNECTED,
/** Connection established, incompatible firmware detected. */
INCOMPATIBLE,
/** Disconnected. Instance is useless. */
DEAD
}
/**
* Establishes connection with the IOIO board.
* <p>
@@ -157,6 +171,13 @@ public interface IOIO {
*/
public void waitForDisconnect() throws InterruptedException;
/**
* Gets the connections state.
*
* @return The connection state.
*/
public State getState();
/**
* Resets the entire state (returning to initial state), without dropping
* the connection.
@@ -420,7 +441,8 @@ public interface IOIO {
* with the given mode.
*
* @see #openPulseInput(ioio.lib.api.DigitalInput.Spec,
* ioio.lib.api.PulseInput.ClockRate, PulseMode, boolean)
* ioio.lib.api.PulseInput.ClockRate,
* ioio.lib.api.PulseInput.PulseMode, boolean)
*/
public PulseInput openPulseInput(int pin, PulseMode mode)
throws ConnectionLostException;
@@ -478,12 +500,12 @@ public interface IOIO {
/**
* Shorthand for
* {@link #openUart(ioio.lib.api.DigitalInput.Spec, ioio.lib.api.DigitalOutput.Spec, int, Parity, StopBits)}
* {@link #openUart(DigitalInput.Spec, DigitalOutput.Spec, int, Uart.Parity, Uart.StopBits)}
* , where the input pins use their default specs. {@link #INVALID_PIN} can
* be used on either pin if a TX- or RX-only UART is needed.
*
* @see #openUart(ioio.lib.api.DigitalInput.Spec,
* ioio.lib.api.DigitalOutput.Spec, int, Parity, StopBits)
* @see #openUart(DigitalInput.Spec, DigitalOutput.Spec, int, Uart.Parity,
* Uart.StopBits)
*/
public Uart openUart(int rx, int tx, int baud, Parity parity,
StopBits stopbits) throws ConnectionLostException;
@@ -552,9 +574,12 @@ public interface IOIO {
DigitalOutput.Spec[] slaveSelect, SpiMaster.Config config)
throws ConnectionLostException;
/**
* Shorthand for {@link #openSpiMaster(ioio.lib.api.DigitalInput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec[], ioio.lib.api.SpiMaster.Config),
* where the pins are all open with the default modes and default configuration values are used.
/**
* Shorthand for
* {@link #openSpiMaster(ioio.lib.api.DigitalInput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec[], ioio.lib.api.SpiMaster.Config)}
* , where the pins are all open with the default modes and default
* configuration values are used.
*
* @see #openSpiMaster(ioio.lib.api.DigitalInput.Spec,
* ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec,
* ioio.lib.api.DigitalOutput.Spec[], ioio.lib.api.SpiMaster.Config)
@@ -564,10 +589,12 @@ public interface IOIO {
throws ConnectionLostException;
/**
* Shorthand for {@link #openSpiMaster(ioio.lib.api.DigitalInput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec[], ioio.lib.api.SpiMaster.Config),
* where the MISO pins is opened with pull up, and the other pins are open
* with the default modes and default configuration values are used.
* In this version, a single slave is used.
* Shorthand for
* {@link #openSpiMaster(ioio.lib.api.DigitalInput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec[], ioio.lib.api.SpiMaster.Config)}
* , where the MISO pins is opened with pull up, and the other pins are open
* with the default modes and default configuration values are used. In this
* version, a single slave is used.
*
* @see #openSpiMaster(ioio.lib.api.DigitalInput.Spec,
* ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec,
* ioio.lib.api.DigitalOutput.Spec[], ioio.lib.api.SpiMaster.Config)
@@ -635,4 +662,35 @@ public interface IOIO {
* method.
*/
public IcspMaster openIcspMaster() throws ConnectionLostException;
}
/**
* Start a batch of operations. This is strictly an optimization and will
* not change functionality: if the client knows that a sequence of several
* IOIO operations are going to be performed immediately following each
* other, a call to {@link #beginBatch()} before the sequence and
* {@link #endBatch()} after the sequence will cause the operations to be
* grouped into one transfer to the IOIO, thus reducing latency. A matching
* {@link #endBatch()} operation must always follow, or otherwise no
* operation will ever be actually executed. {@link #beginBatch()} /
* {@link #endBatch()} blocks may be nested - the transfer will occur when
* the outermost {@link #endBatch()} is invoked. Note that it is not
* guaranteed that no transfers will happen while inside a batch - it should
* be treated as a hint. Code running inside the block must be quick as it
* blocks <b>all</b> transfers to the IOIO, including those performed from
* other threads.
*
* @throws ConnectionLostException
* Connection was lost before or during the execution of this
* method.
*/
public void beginBatch() throws ConnectionLostException;
/**
* End a batch of operations. For explanation, see {@link #beginBatch()}.
*
* @throws ConnectionLostException
* Connection was lost before or during the execution of this
* method.
*/
public void endBatch() throws ConnectionLostException;
}

0
IOIOLib/src/ioio/lib/api/IOIOConnection.java Executable file → Normal file
View File

View File

@@ -28,10 +28,14 @@
*/
package ioio.lib.api;
import java.lang.reflect.Constructor;
import ioio.lib.impl.IOIOImpl;
import ioio.lib.impl.SocketIOIOConnection;
import ioio.lib.spi.IOIOConnectionFactory;
import ioio.lib.util.IOIOConnectionRegistry;
import java.util.Collection;
import java.util.NoSuchElementException;
import android.util.Log;
/**
* Factory class for creating instances of the IOIO interface.
@@ -55,22 +59,21 @@ import ioio.lib.impl.SocketIOIOConnection;
* </pre>
*/
public class IOIOFactory {
/** The TCP port used for communicating with the IOIO board. */
public static final int IOIO_PORT = 4545;
/**
* Create a IOIO instance. This specific implementation creates a IOIO
* instance which works with the actual IOIO board connected via a TCP
* connection (typically over a wired USB connection).
*
*
* @return The IOIO instance.
*/
public static IOIO create() {
Collection<IOIOConnectionFactory> factories = IOIOConnectionRegistry
.getConnectionFactories();
try {
return create(SocketIOIOConnection.class.getName(), IOIO_PORT);
} catch (ClassNotFoundException e) {
// we shouldn't get here - this class must always exist.
throw new RuntimeException("Something is very wrong here");
return create(factories.iterator().next().createConnection());
} catch (NoSuchElementException e) {
Log.e(TAG, "No connection is available. This shouldn't happen.");
throw e;
}
}
@@ -78,44 +81,15 @@ public class IOIOFactory {
* Create a IOIO instance with a user-provided underlying connection class.
* This method should be used for establishing a non-standard connection to
* the IOIO board.
*
* @param connectionClassName
* The name of the connection class. Must have a public default
* constructor.
*
*
* @param connection
* An instance of a IOIO connection.
*
* @return The IOIO instance.
* @throws ClassNotFoundException The given class name was not found.
*/
public static IOIO create(String connectionClassName, Object... args) throws ClassNotFoundException {
IOIOConnection connection = createConnectionDynamically(connectionClassName, args);
return create(connection);
}
public static IOIO create(IOIOConnection connection) {
return new IOIOImpl(connection);
}
public static IOIOConnection createConnectionDynamically(
String connectionClassName, Object... args)
throws ClassNotFoundException {
Class<?> cls;
cls = Class.forName(connectionClassName);
Object instance;
try {
Class<?>[] argTypes = new Class<?>[args.length];
for (int i = 0; i < args.length; ++i) {
argTypes[i] = args[i].getClass();
}
Constructor<?> constructor = cls.getConstructor(argTypes);
instance = constructor.newInstance(args);
} catch (Exception e) {
throw new IllegalArgumentException(
"Provided class does not have a public ctor with the right signature", e);
}
if (!(instance instanceof IOIOConnection)) {
throw new IllegalArgumentException(
"Provided class does not implement IOIOConnection");
}
return (IOIOConnection) instance;
}
private static final String TAG = "IOIOFactory";
}

0
IOIOLib/src/ioio/lib/api/IcspMaster.java Executable file → Normal file
View File

2
IOIOLib/src/ioio/lib/api/PulseInput.java Executable file → Normal file
View File

@@ -46,7 +46,7 @@ import ioio.lib.api.exception.ConnectionLostException;
* for measuring a turning shaft's speed.
* <p>
* {@link PulseInput} instances are obtained by calling
* {@link IOIO#openPulseInput(ioio.lib.api.DigitalInput.Spec, ClockRate, PulseMode, boolean)}
* {@link IOIO#openPulseInput(ioio.lib.api.DigitalInput.Spec, ioio.lib.api.PulseInput.ClockRate, ioio.lib.api.PulseInput.PulseMode, boolean)}
* . When created, some important configuration decisions have to be made: the
* precision (single or double), the clock rate and the mode of operation. Modes
* are straightforward: {@link PulseMode#POSITIVE} is used for measuring a

13
IOIOLib/src/ioio/lib/api/SpiMaster.java Executable file → Normal file
View File

@@ -28,7 +28,6 @@
*/
package ioio.lib.api;
import ioio.lib.api.DigitalInput.Spec;
import ioio.lib.api.exception.ConnectionLostException;
/**
@@ -41,7 +40,7 @@ import ioio.lib.api.exception.ConnectionLostException;
* between this slave and a respective pin on the master. The MISO line should
* operate in pull-up mode, using either the internal pull-up or an external
* resistor. SpiMaster instances are obtained by calling
* {@link IOIO#openSpiMaster(Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec[], Config)}.
* {@link IOIO#openSpiMaster(DigitalInput.Spec, DigitalOutput.Spec, DigitalOutput.Spec, DigitalOutput.Spec[], SpiMaster.Config)}.
* <p>
* The SPI protocol is comprised of simultaneous sending and receiving of data
* between the bus master and a single slave. By the very nature of this
@@ -90,9 +89,11 @@ import ioio.lib.api.exception.ConnectionLostException;
* spi.writeRead(request, 2, 4, response, 3);
* ...
* spi.close(); // free SPI module and pins
* }</pre>
* }
* </pre>
*
* @see IOIO#openSpiMaster(Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec[], Config)
* @see IOIO#openSpiMaster(DigitalInput.Spec, DigitalOutput.Spec,
* DigitalOutput.Spec, DigitalOutput.Spec[], SpiMaster.Config)
*/
public interface SpiMaster extends Closeable {
/** Possible data rates for SPI, in Hz. */
@@ -148,7 +149,7 @@ public interface SpiMaster extends Closeable {
* Constructor with common defaults. Equivalent to Config(rate, false,
* false)
*
* @see #Config(Rate, boolean, boolean)
* @see SpiMaster.Config#Config(SpiMaster.Config.Rate, boolean, boolean)
*/
public Config(Rate rate) {
this(rate, false, false);
@@ -165,7 +166,7 @@ public interface SpiMaster extends Closeable {
* @param slave
* The slave index. It is determined by the index of its
* slave-select pin, as per the array passed to
* {@link IOIO#openSpiMaster(Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec, ioio.lib.api.DigitalOutput.Spec[], Config)}
* {@link IOIO#openSpiMaster(DigitalInput.Spec, DigitalOutput.Spec, DigitalOutput.Spec, DigitalOutput.Spec[], SpiMaster.Config)}
* .
* @param writeData
* A byte array of data to write. May be null if writeSize is 0.

4
IOIOLib/src/ioio/lib/api/TwiMaster.java Executable file → Normal file
View File

@@ -39,7 +39,7 @@ import ioio.lib.api.exception.ConnectionLostException;
* requires a physical connection of two lines (SDA, SCL) shared by all the bus
* nodes, where the SDA is open-drain and externally pulled-up. TwiMaster
* instances are obtained by calling
* {@link IOIO#openTwiMaster(int, Rate, boolean)}.
* {@link IOIO#openTwiMaster(int, ioio.lib.api.TwiMaster.Rate, boolean)}.
* <p>
* TWI is the generic name for the specific I2C and SMBus protocols, differing
* mostly by the voltage levels they require. This module supports both.
@@ -79,7 +79,7 @@ import ioio.lib.api.exception.ConnectionLostException;
* twi.close(); // free TWI module and pins
* }</pre>
*
* @see IOIO#openTwiMaster(int, Rate, boolean)
* @see IOIO#openTwiMaster(int, ioio.lib.api.TwiMaster.Rate, boolean)
*/
public interface TwiMaster extends Closeable {
enum Rate {

View File

@@ -28,7 +28,6 @@
*/
package ioio.lib.api;
import ioio.lib.api.DigitalInput.Spec;
import ioio.lib.api.exception.ConnectionLostException;
import java.io.InputStream;
@@ -41,7 +40,7 @@ import java.io.OutputStream;
* asynchronous point-to-point data transfer. It typically serves for opening
* consoles or as a basis for higher-level protocols, such as MIDI, RS-232 and
* RS-485. Uart instances are obtained by calling
* {@link IOIO#openUart(Spec, ioio.lib.api.DigitalOutput.Spec, int, Parity, StopBits)}.
* {@link IOIO#openUart(DigitalInput.Spec, DigitalOutput.Spec, int, Uart.Parity, Uart.StopBits)}.
* <p>
* The UART protocol is completely symmetric - there is no "master" and "slave"
* at this layer. Each end may send any number of bytes at arbitrary times,
@@ -70,8 +69,8 @@ import java.io.OutputStream;
* uart.close(); // free UART module and pins
* </pre>
*
* @see IOIO#openUart(Spec, ioio.lib.api.DigitalOutput.Spec, int, Parity,
* StopBits)
* @see IOIO#openUart(DigitalInput.Spec, DigitalOutput.Spec, int, Uart.Parity,
* Uart.StopBits)
*/
public interface Uart extends Closeable {
/** Parity-bit mode. */

Some files were not shown because too many files have changed in this diff Show More