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.
This commit is contained in:
2012-12-11 11:06:07 -05:00
parent b8a55682d4
commit efb63070a2
41 changed files with 3235 additions and 3230 deletions

View File

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

View File

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

View File

@@ -271,7 +271,7 @@ public class IOIOImpl implements IOIO, DisconnectListener {
} else { } else {
incapAllocatorSingle_.releaseModule(incapNum); incapAllocatorSingle_.releaseModule(incapNum);
} }
protocol_.incapClose(incapNum); protocol_.incapClose(incapNum, doublePrecision);
} catch (IOException e) { } catch (IOException e) {
} catch (ConnectionLostException e) { } catch (ConnectionLostException e) {
} }
@@ -311,7 +311,7 @@ public class IOIOImpl implements IOIO, DisconnectListener {
case APP_FIRMWARE_VER: case APP_FIRMWARE_VER:
return incomingState_.firmwareId_; return incomingState_.firmwareId_;
case IOIOLIB_VER: case IOIOLIB_VER:
return "IOIO0322"; return "IOIO0326";
} }
return null; return null;
} }

View File

@@ -37,8 +37,10 @@ import ioio.lib.api.Uart;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Set; import java.util.Set;
import android.util.Log; import android.util.Log;
@@ -258,11 +260,12 @@ class IOIOProtocol {
endBatch(); endBatch();
} }
synchronized public void incapClose(int incapNum) throws IOException { synchronized public void incapClose(int incapNum, boolean double_prec)
throws IOException {
beginBatch(); beginBatch();
writeByte(INCAP_CONFIGURE); writeByte(INCAP_CONFIGURE);
writeByte(incapNum); writeByte(incapNum);
writeByte(0x00); writeByte(double_prec ? 0x80 : 0x00);
endBatch(); endBatch();
} }
@@ -454,40 +457,40 @@ class IOIOProtocol {
endBatch(); endBatch();
} }
public void icspOpen() throws IOException { synchronized public void icspOpen() throws IOException {
beginBatch(); beginBatch();
writeByte(ICSP_CONFIG); writeByte(ICSP_CONFIG);
writeByte(0x01); writeByte(0x01);
endBatch(); endBatch();
} }
public void icspClose() throws IOException { synchronized public void icspClose() throws IOException {
beginBatch(); beginBatch();
writeByte(ICSP_CONFIG); writeByte(ICSP_CONFIG);
writeByte(0x00); writeByte(0x00);
endBatch(); endBatch();
} }
public void icspEnter() throws IOException { synchronized public void icspEnter() throws IOException {
beginBatch(); beginBatch();
writeByte(ICSP_PROG_ENTER); writeByte(ICSP_PROG_ENTER);
endBatch(); endBatch();
} }
public void icspExit() throws IOException { synchronized public void icspExit() throws IOException {
beginBatch(); beginBatch();
writeByte(ICSP_PROG_EXIT); writeByte(ICSP_PROG_EXIT);
endBatch(); endBatch();
} }
public void icspSix(int instruction) throws IOException { synchronized public void icspSix(int instruction) throws IOException {
beginBatch(); beginBatch();
writeByte(ICSP_SIX); writeByte(ICSP_SIX);
writeThreeBytes(instruction); writeThreeBytes(instruction);
endBatch(); endBatch();
} }
public void icspRegout() throws IOException { synchronized public void icspRegout() throws IOException {
beginBatch(); beginBatch();
writeByte(ICSP_REGOUT); writeByte(ICSP_REGOUT);
endBatch(); endBatch();
@@ -514,7 +517,8 @@ class IOIOProtocol {
public void handleAnalogPinStatus(int pin, boolean open); public void handleAnalogPinStatus(int pin, boolean open);
public void handleReportAnalogInStatus(int pins[], int values[]); public void handleReportAnalogInStatus(List<Integer> pins,
List<Integer> values);
public void handleUartOpen(int uartNum); public void handleUartOpen(int uartNum);
@@ -561,21 +565,18 @@ class IOIOProtocol {
private int validBytes_ = 0; private int validBytes_ = 0;
private byte[] inbuf_ = new byte[64]; private byte[] inbuf_ = new byte[64];
private int[] analogFramePins_ = new int[0]; private List<Integer> analogPinValues_ = new ArrayList<Integer>();
private Set<Integer> removedPins_ = new HashSet<Integer>( private List<Integer> analogFramePins_ = new ArrayList<Integer>();
Constants.NUM_ANALOG_PINS); private List<Integer> newFramePins_ = new ArrayList<Integer>();
private Set<Integer> addedPins_ = new HashSet<Integer>( private Set<Integer> removedPins_ = new HashSet<Integer>();
Constants.NUM_ANALOG_PINS); private Set<Integer> addedPins_ = new HashSet<Integer>();
private void findDelta(int[] newPins) { private void calculateAnalogFrameDelta() {
removedPins_.clear(); removedPins_.clear();
removedPins_.addAll(analogFramePins_);
addedPins_.clear(); addedPins_.clear();
for (int i : analogFramePins_) { addedPins_.addAll(newFramePins_);
removedPins_.add(i); // Remove the intersection from both.
}
for (int i : newPins) {
addedPins_.add(i);
}
for (Iterator<Integer> it = removedPins_.iterator(); it.hasNext();) { for (Iterator<Integer> it = removedPins_.iterator(); it.hasNext();) {
Integer current = it.next(); Integer current = it.next();
if (addedPins_.contains(current)) { if (addedPins_.contains(current)) {
@@ -583,6 +584,10 @@ class IOIOProtocol {
addedPins_.remove(current); addedPins_.remove(current);
} }
} }
// swap
List<Integer> temp = analogFramePins_;
analogFramePins_ = newFramePins_;
newFramePins_ = temp;
} }
private void fillBuf() throws IOException { private void fillBuf() throws IOException {
@@ -645,6 +650,7 @@ class IOIOProtocol {
break; break;
case SOFT_RESET: case SOFT_RESET:
analogFramePins_.clear();
handler_.handleSoftReset(); handler_.handleSoftReset();
break; break;
@@ -670,33 +676,32 @@ class IOIOProtocol {
case REPORT_ANALOG_IN_FORMAT: case REPORT_ANALOG_IN_FORMAT:
numPins = readByte(); numPins = readByte();
int[] newFormat = new int[numPins]; newFramePins_.clear();
for (int i = 0; i < numPins; ++i) { for (int i = 0; i < numPins; ++i) {
newFormat[i] = readByte(); newFramePins_.add(readByte());
} }
findDelta(newFormat); calculateAnalogFrameDelta();
for (Integer i : removedPins_) { for (Integer i : removedPins_) {
handler_.handleAnalogPinStatus(i, false); handler_.handleAnalogPinStatus(i, false);
} }
for (Integer i : addedPins_) { for (Integer i : addedPins_) {
handler_.handleAnalogPinStatus(i, true); handler_.handleAnalogPinStatus(i, true);
} }
analogFramePins_ = newFormat;
break; break;
case REPORT_ANALOG_IN_STATUS: case REPORT_ANALOG_IN_STATUS:
numPins = analogFramePins_.length; numPins = analogFramePins_.size();
int header = 0; int header = 0;
int[] values = new int[numPins]; analogPinValues_.clear();
for (int i = 0; i < numPins; ++i) { for (int i = 0; i < numPins; ++i) {
if (i % 4 == 0) { if (i % 4 == 0) {
header = readByte(); header = readByte();
} }
values[i] = (readByte() << 2) | (header & 0x03); analogPinValues_.add((readByte() << 2) | (header & 0x03));
header >>= 2; header >>= 2;
} }
handler_.handleReportAnalogInStatus(analogFramePins_, handler_.handleReportAnalogInStatus(analogFramePins_,
values); analogPinValues_);
break; break;
case UART_REPORT_TX_STATUS: case UART_REPORT_TX_STATUS:

View File

@@ -32,6 +32,7 @@ import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.impl.IOIOProtocol.IncomingHandler; import ioio.lib.impl.IOIOProtocol.IncomingHandler;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
@@ -395,10 +396,11 @@ class IncomingState implements IncomingHandler {
} }
@Override @Override
public void handleReportAnalogInStatus(int pins[], int values[]) { public void handleReportAnalogInStatus(List<Integer> pins,
List<Integer> values) {
// logMethod("handleReportAnalogInStatus", pins, values); // logMethod("handleReportAnalogInStatus", pins, values);
for (int i = 0; i < pins.length; ++i) { for (int i = 0; i < pins.size(); ++i) {
intputPinStates_[pins[i]].setValue(values[i]); intputPinStates_[pins.get(i)].setValue(values.get(i));
} }
} }

View File

@@ -137,7 +137,7 @@ class TwiMasterImpl extends AbstractResource implements TwiMaster,
synchronized (result) { synchronized (result) {
result.ready_ = true; result.ready_ = true;
result.success_ = (size != 0xFF); result.success_ = (size != 0xFF);
if (result.success_) { if (result.success_ && size > 0) {
System.arraycopy(data, 0, result.data_, 0, size); System.arraycopy(data, 0, result.data_, 0, size);
} }
result.notify(); result.notify();

View File

@@ -1,6 +1,6 @@
package ioio.lib.spi; package ioio.lib.spi;
public class NoRuntimeSupportException extends Exception { public class NoRuntimeSupportException extends RuntimeException {
private static final long serialVersionUID = -6559208663699429514L; private static final long serialVersionUID = -6559208663699429514L;
public NoRuntimeSupportException(String desc) { public NoRuntimeSupportException(String desc) {

View File

@@ -32,6 +32,7 @@ import ioio.lib.api.IOIOConnection;
import ioio.lib.api.IOIOFactory; import ioio.lib.api.IOIOFactory;
import ioio.lib.spi.IOIOConnectionBootstrap; import ioio.lib.spi.IOIOConnectionBootstrap;
import ioio.lib.spi.IOIOConnectionFactory; import ioio.lib.spi.IOIOConnectionFactory;
import ioio.lib.spi.NoRuntimeSupportException;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
@@ -65,8 +66,8 @@ public class IOIOConnectionRegistry {
* Get all available connection specifications. This is a list of all * Get all available connection specifications. This is a list of all
* currently available communication channels in which a IOIO may be * currently available communication channels in which a IOIO may be
* available. The client typically passes elements of this collection to * available. The client typically passes elements of this collection to
* {@link IOIOFactory#create(IOIOConnection)}, possibly after filtering based on the * {@link IOIOFactory#create(IOIOConnection)}, possibly after filtering
* specification's properties. * based on the specification's properties.
* *
* @return A collection of specifications. * @return A collection of specifications.
*/ */
@@ -118,13 +119,10 @@ public class IOIOConnectionRegistry {
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Log.d(TAG, "Bootstrap class not found: " + className Log.d(TAG, "Bootstrap class not found: " + className
+ ". Not adding."); + ". Not adding.");
} catch (RuntimeException e) { } catch (NoRuntimeSupportException e) {
Log.d(TAG, "No runtime support for: " + className + ". Not adding.");
} catch (Throwable e) {
Log.e(TAG, Log.e(TAG,
"Runtime exception caught while attempting to initialize accessory connection factory",
e);
throw e;
} catch (Exception e) {
Log.w(TAG,
"Exception caught while attempting to initialize accessory connection factory", "Exception caught while attempting to initialize accessory connection factory",
e); e);
} }