From 38cacdb4e4598dd6e78d56b66bda3dd63269d2aa Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 1 Apr 2012 14:01:28 +0200 Subject: add quick read --- src/k8055.c | 16 ++++++++++++---- src/k8055.h | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/k8055.c b/src/k8055.c index ccaa368..7fab664 100644 --- a/src/k8055.c +++ b/src/k8055.c @@ -285,7 +285,7 @@ static int writeData(int port) { * @return K8055_ERROR_INDEX if port is an invalid index * @return K8055_ERROR_CLOSED if the board associated to the given port is not open * @return K8055_ERROR_READ if another error occurred during the read process */ -static int readData(int port) { +static int readData(int port, int cycles) { int readStatus = 0; if (port < 0 || K8055_MAX_DEVICES < port) { @@ -302,7 +302,7 @@ static int readData(int port) { int transferred = 0; for(int i = 0; i < 3; ++i) { - for(int j = 0; j < 2; ++j) { /* read twice to get fresh data, (i.e. circumvent some kind of buffer) */ + for(int j = 0; j < cycles; ++j) { /* read twice to get fresh data, (i.e. circumvent some kind of buffer) */ readStatus = libusb_interrupt_transfer( device->deviceHandle, USB_IN_EP, @@ -416,8 +416,8 @@ int setDebounceTime(int port, int counter, int debounce) { return writeData(port); } -int getAll(int port, int *digitalBitmask, int *analog1, int *analog2, int *counter1, int *counter2) { - int r = readData(port); +static int getAllCycle(int port, int *digitalBitmask, int *analog1, int *analog2, int *counter1, int *counter2, int cycles) { + int r = readData(port, cycles); if (r != 0) return r; struct K8055Device *device = &devices[port]; @@ -437,3 +437,11 @@ int getAll(int port, int *digitalBitmask, int *analog1, int *analog2, int *count *counter2 = (int) device->dataIn[IN_COUNTER_2_OFFSET + 1] << 8 | device->dataIn[IN_COUNTER_2_OFFSET]; return 0; } + +int getAll(int port, int *digitalBitmask, int *analog1, int *analog2, int *counter1, int *counter2) { + return getAllCycle(port, digitalBitmask, analog1, analog2, counter1, counter2, 2); +} + +int quickGetAll(int port, int *digitalBitmask, int *analog1, int *analog2, int *counter1, int *counter2) { + return getAllCycle(port, digitalBitmask, analog1, analog2, counter1, counter2, 1); +} diff --git a/src/k8055.h b/src/k8055.h index d04c422..f288a7d 100644 --- a/src/k8055.h +++ b/src/k8055.h @@ -107,6 +107,7 @@ int resetCounter(int port, int counter); int setDebounceTime(int port, int counter, int debounce); /**Reads all current data of a given board into the passed parameters. NULL is a valid parameter. + * Data is read twice from the borad to circumvent some kind of buffer and get actual data. * @param port address of board * @param digitalBitmask bitmask value of digital inputs * @param analog1 value of first analog input @@ -119,4 +120,18 @@ int setDebounceTime(int port, int counter, int debounce); * @return K8055_ERROR_READ if another error occurred during the read process */ int getAll(int port, int *digitalBitMask, int *analog1, int *analog2, int *counter1, int *counter2); +/**Reads all current data of a given board into the passed parameters. NULL is a valid parameter. + * This function reads data once from the board and no guarantee of actuality is given. + * @param port address of board + * @param digitalBitmask bitmask value of digital inputs + * @param analog1 value of first analog input + * @param analog2 value of second analog input + * @param counter1 value of first counter + * @param counter2 value of second counter + * @return 0 on success + * @return K8055_ERROR_INDEX if port or counter are invalid indices + * @return K8055_ERROR_CLOSED if the board associated to the given port is not open + * @return K8055_ERROR_READ if another error occurred during the read process */ +int quickGetAll(int port, int *digitalBitMask, int *analog1, int *analog2, int *counter1, int *counter2); + #endif /* K8055_H_ */ -- cgit v1.2.3