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:
@@ -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>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,4 +9,4 @@
|
||||
|
||||
android.library=true
|
||||
# Project target.
|
||||
target=android-15
|
||||
target=android-17
|
||||
|
||||
@@ -271,7 +271,7 @@ public class IOIOImpl implements IOIO, DisconnectListener {
|
||||
} else {
|
||||
incapAllocatorSingle_.releaseModule(incapNum);
|
||||
}
|
||||
protocol_.incapClose(incapNum);
|
||||
protocol_.incapClose(incapNum, doublePrecision);
|
||||
} catch (IOException e) {
|
||||
} catch (ConnectionLostException e) {
|
||||
}
|
||||
@@ -311,7 +311,7 @@ public class IOIOImpl implements IOIO, DisconnectListener {
|
||||
case APP_FIRMWARE_VER:
|
||||
return incomingState_.firmwareId_;
|
||||
case IOIOLIB_VER:
|
||||
return "IOIO0322";
|
||||
return "IOIO0326";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,10 @@ import ioio.lib.api.Uart;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import android.util.Log;
|
||||
@@ -258,11 +260,12 @@ class IOIOProtocol {
|
||||
endBatch();
|
||||
}
|
||||
|
||||
synchronized public void incapClose(int incapNum) throws IOException {
|
||||
synchronized public void incapClose(int incapNum, boolean double_prec)
|
||||
throws IOException {
|
||||
beginBatch();
|
||||
writeByte(INCAP_CONFIGURE);
|
||||
writeByte(incapNum);
|
||||
writeByte(0x00);
|
||||
writeByte(double_prec ? 0x80 : 0x00);
|
||||
endBatch();
|
||||
}
|
||||
|
||||
@@ -454,40 +457,40 @@ class IOIOProtocol {
|
||||
endBatch();
|
||||
}
|
||||
|
||||
public void icspOpen() throws IOException {
|
||||
synchronized public void icspOpen() throws IOException {
|
||||
beginBatch();
|
||||
writeByte(ICSP_CONFIG);
|
||||
writeByte(0x01);
|
||||
endBatch();
|
||||
}
|
||||
|
||||
public void icspClose() throws IOException {
|
||||
synchronized public void icspClose() throws IOException {
|
||||
beginBatch();
|
||||
writeByte(ICSP_CONFIG);
|
||||
writeByte(0x00);
|
||||
endBatch();
|
||||
}
|
||||
|
||||
public void icspEnter() throws IOException {
|
||||
synchronized public void icspEnter() throws IOException {
|
||||
beginBatch();
|
||||
writeByte(ICSP_PROG_ENTER);
|
||||
endBatch();
|
||||
}
|
||||
|
||||
public void icspExit() throws IOException {
|
||||
synchronized public void icspExit() throws IOException {
|
||||
beginBatch();
|
||||
writeByte(ICSP_PROG_EXIT);
|
||||
endBatch();
|
||||
}
|
||||
|
||||
public void icspSix(int instruction) throws IOException {
|
||||
synchronized public void icspSix(int instruction) throws IOException {
|
||||
beginBatch();
|
||||
writeByte(ICSP_SIX);
|
||||
writeThreeBytes(instruction);
|
||||
endBatch();
|
||||
}
|
||||
|
||||
public void icspRegout() throws IOException {
|
||||
synchronized public void icspRegout() throws IOException {
|
||||
beginBatch();
|
||||
writeByte(ICSP_REGOUT);
|
||||
endBatch();
|
||||
@@ -514,7 +517,8 @@ class IOIOProtocol {
|
||||
|
||||
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);
|
||||
|
||||
@@ -561,21 +565,18 @@ class IOIOProtocol {
|
||||
private int validBytes_ = 0;
|
||||
private byte[] inbuf_ = new byte[64];
|
||||
|
||||
private int[] analogFramePins_ = new int[0];
|
||||
private Set<Integer> removedPins_ = new HashSet<Integer>(
|
||||
Constants.NUM_ANALOG_PINS);
|
||||
private Set<Integer> addedPins_ = new HashSet<Integer>(
|
||||
Constants.NUM_ANALOG_PINS);
|
||||
private List<Integer> analogPinValues_ = new ArrayList<Integer>();
|
||||
private List<Integer> analogFramePins_ = new ArrayList<Integer>();
|
||||
private List<Integer> newFramePins_ = new ArrayList<Integer>();
|
||||
private Set<Integer> removedPins_ = new HashSet<Integer>();
|
||||
private Set<Integer> addedPins_ = new HashSet<Integer>();
|
||||
|
||||
private void findDelta(int[] newPins) {
|
||||
private void calculateAnalogFrameDelta() {
|
||||
removedPins_.clear();
|
||||
removedPins_.addAll(analogFramePins_);
|
||||
addedPins_.clear();
|
||||
for (int i : analogFramePins_) {
|
||||
removedPins_.add(i);
|
||||
}
|
||||
for (int i : newPins) {
|
||||
addedPins_.add(i);
|
||||
}
|
||||
addedPins_.addAll(newFramePins_);
|
||||
// Remove the intersection from both.
|
||||
for (Iterator<Integer> it = removedPins_.iterator(); it.hasNext();) {
|
||||
Integer current = it.next();
|
||||
if (addedPins_.contains(current)) {
|
||||
@@ -583,6 +584,10 @@ class IOIOProtocol {
|
||||
addedPins_.remove(current);
|
||||
}
|
||||
}
|
||||
// swap
|
||||
List<Integer> temp = analogFramePins_;
|
||||
analogFramePins_ = newFramePins_;
|
||||
newFramePins_ = temp;
|
||||
}
|
||||
|
||||
private void fillBuf() throws IOException {
|
||||
@@ -645,6 +650,7 @@ class IOIOProtocol {
|
||||
break;
|
||||
|
||||
case SOFT_RESET:
|
||||
analogFramePins_.clear();
|
||||
handler_.handleSoftReset();
|
||||
break;
|
||||
|
||||
@@ -670,33 +676,32 @@ class IOIOProtocol {
|
||||
|
||||
case REPORT_ANALOG_IN_FORMAT:
|
||||
numPins = readByte();
|
||||
int[] newFormat = new int[numPins];
|
||||
newFramePins_.clear();
|
||||
for (int i = 0; i < numPins; ++i) {
|
||||
newFormat[i] = readByte();
|
||||
newFramePins_.add(readByte());
|
||||
}
|
||||
findDelta(newFormat);
|
||||
calculateAnalogFrameDelta();
|
||||
for (Integer i : removedPins_) {
|
||||
handler_.handleAnalogPinStatus(i, false);
|
||||
}
|
||||
for (Integer i : addedPins_) {
|
||||
handler_.handleAnalogPinStatus(i, true);
|
||||
}
|
||||
analogFramePins_ = newFormat;
|
||||
break;
|
||||
|
||||
case REPORT_ANALOG_IN_STATUS:
|
||||
numPins = analogFramePins_.length;
|
||||
numPins = analogFramePins_.size();
|
||||
int header = 0;
|
||||
int[] values = new int[numPins];
|
||||
analogPinValues_.clear();
|
||||
for (int i = 0; i < numPins; ++i) {
|
||||
if (i % 4 == 0) {
|
||||
header = readByte();
|
||||
}
|
||||
values[i] = (readByte() << 2) | (header & 0x03);
|
||||
analogPinValues_.add((readByte() << 2) | (header & 0x03));
|
||||
header >>= 2;
|
||||
}
|
||||
handler_.handleReportAnalogInStatus(analogFramePins_,
|
||||
values);
|
||||
analogPinValues_);
|
||||
break;
|
||||
|
||||
case UART_REPORT_TX_STATUS:
|
||||
|
||||
@@ -32,6 +32,7 @@ import ioio.lib.api.exception.ConnectionLostException;
|
||||
import ioio.lib.impl.IOIOProtocol.IncomingHandler;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
@@ -395,10 +396,11 @@ class IncomingState implements IncomingHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReportAnalogInStatus(int pins[], int values[]) {
|
||||
public void handleReportAnalogInStatus(List<Integer> pins,
|
||||
List<Integer> values) {
|
||||
// logMethod("handleReportAnalogInStatus", pins, values);
|
||||
for (int i = 0; i < pins.length; ++i) {
|
||||
intputPinStates_[pins[i]].setValue(values[i]);
|
||||
for (int i = 0; i < pins.size(); ++i) {
|
||||
intputPinStates_[pins.get(i)].setValue(values.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ class TwiMasterImpl extends AbstractResource implements TwiMaster,
|
||||
synchronized (result) {
|
||||
result.ready_ = true;
|
||||
result.success_ = (size != 0xFF);
|
||||
if (result.success_) {
|
||||
if (result.success_ && size > 0) {
|
||||
System.arraycopy(data, 0, result.data_, 0, size);
|
||||
}
|
||||
result.notify();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ioio.lib.spi;
|
||||
|
||||
public class NoRuntimeSupportException extends Exception {
|
||||
public class NoRuntimeSupportException extends RuntimeException {
|
||||
private static final long serialVersionUID = -6559208663699429514L;
|
||||
|
||||
public NoRuntimeSupportException(String desc) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import ioio.lib.api.IOIOConnection;
|
||||
import ioio.lib.api.IOIOFactory;
|
||||
import ioio.lib.spi.IOIOConnectionBootstrap;
|
||||
import ioio.lib.spi.IOIOConnectionFactory;
|
||||
import ioio.lib.spi.NoRuntimeSupportException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
@@ -65,8 +66,8 @@ public class IOIOConnectionRegistry {
|
||||
* Get all available connection specifications. This is a list of all
|
||||
* currently available communication channels in which a IOIO may be
|
||||
* available. The client typically passes elements of this collection to
|
||||
* {@link IOIOFactory#create(IOIOConnection)}, possibly after filtering based on the
|
||||
* specification's properties.
|
||||
* {@link IOIOFactory#create(IOIOConnection)}, possibly after filtering
|
||||
* based on the specification's properties.
|
||||
*
|
||||
* @return A collection of specifications.
|
||||
*/
|
||||
@@ -118,13 +119,10 @@ public class IOIOConnectionRegistry {
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.d(TAG, "Bootstrap class not found: " + className
|
||||
+ ". Not adding.");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (NoRuntimeSupportException e) {
|
||||
Log.d(TAG, "No runtime support for: " + className + ". Not adding.");
|
||||
} catch (Throwable e) {
|
||||
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",
|
||||
e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user