Files |
file | common.h |
| Commonly used functions used by drivers.
|
Defines |
#define | __COMMON_H_SENSOR_CHECK__ 1 |
#define | MAX_ARR_SIZE 17 |
#define | min2(a, b) (a < b ? a : b) |
#define | min3(a, b, c) (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c) |
#define | max2(a, b) (a > b ? a : b) |
#define | max3(a, b, c) (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c) |
#define | clip(a, b, c) min2(c, max2(b, a)) |
#define | STRTOK_MAX_TOKEN_SIZE 20 |
#define | STRTOK_MAX_BUFFER_SIZE 50 |
Typedefs |
typedef ubyte | tByteArray [MAX_ARR_SIZE] |
typedef sbyte | tsByteArray [MAX_ARR_SIZE] |
typedef ubyte | tMassiveArray [128] |
typedef ubyte | tHugeByteArray [64] |
typedef ubyte | tBigByteArray [32] |
typedef ubyte | tIPaddr [4] |
typedef int | tIntArray [MAX_ARR_SIZE] |
Functions |
void | clearI2CError (tSensors link, ubyte address) |
void | clearI2Cbus (tSensors link) |
bool | waitForI2CBus (tSensors link) |
bool | writeI2C (tSensors link, tByteArray &request, tByteArray &reply, int replylen) |
bool | writeI2C (tSensors link, tByteArray &request) |
long | getUID () |
bool | strtok (char *buffer, char *token, char *seperator) |
Detailed Description
Commonly used functions used by drivers
Define Documentation
#define __COMMON_H_SENSOR_CHECK__ 1 |
< define this as 0 to remove the check
Definition at line 70 of file common.h.
#define clip |
( |
|
a, |
|
|
|
b, |
|
|
|
c |
|
) |
| min2(c, max2(b, a)) |
#define max2 |
( |
|
a, |
|
|
|
b |
|
) |
| (a > b ? a : b) |
#define max3 |
( |
|
a, |
|
|
|
b, |
|
|
|
c |
|
) |
| (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c) |
Maximum buffer size for byte_array, can be overridden in your own program. It's 17 bytes big because the max I2C buffer size is 16, plus 1 byte to denote packet length.
Definition at line 86 of file common.h.
#define min2 |
( |
|
a, |
|
|
|
b |
|
) |
| (a < b ? a : b) |
This define returns the smaller of the two numbers
Definition at line 93 of file common.h.
#define min3 |
( |
|
a, |
|
|
|
b, |
|
|
|
c |
|
) |
| (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c) |
This define returns the smallest of the three numbers
Definition at line 99 of file common.h.
#define STRTOK_MAX_BUFFER_SIZE 50 |
#define STRTOK_MAX_TOKEN_SIZE 20 |
Typedef Documentation
128 byte array for very large blobs of data
Definition at line 127 of file common.h.
Function Documentation
void clearI2Cbus |
( |
tSensors |
link ) |
|
void clearI2CError |
( |
tSensors |
link, |
|
|
ubyte |
address |
|
) |
| |
Clear out the error state on I2C bus by sending a bunch of dummy packets.
- Parameters:
-
link | the port number |
address | the I2C address we're sending to |
Definition at line 151 of file common.h.
Create a unique ID (UID) for an NXT. This based on the last 3 bytes of the Bluetooth address. The first 3 bytes are manufacturer specific and identical for all NXTs and are therefore not used.
- Returns:
- a unique ID for the NXT.
Definition at line 396 of file common.h.
bool strtok |
( |
char * |
buffer, |
|
|
char * |
token, |
|
|
char * |
seperator |
|
) |
| |
Tokenise an array of chars, using a seperator
- Parameters:
-
buffer | pointer to buffer we're parsing |
token | pointer to buffer to hold the tokens as we find them |
seperator | the seperator used between tokens |
- Returns:
- true if there are still tokens left, false if we're done
Definition at line 416 of file common.h.
bool waitForI2CBus |
( |
tSensors |
link ) |
|
Wait for the I2C bus to be ready for the next message
- Parameters:
-
- Returns:
- true if no error occured, false if it did
Definition at line 174 of file common.h.
Write to the I2C bus. This function will clear the bus and wait for it be ready before any bytes are sent.
- Parameters:
-
link | the port number |
request | the data to be sent |
reply | array to hold received data |
replylen | the number of bytes (if any) expected in reply to this command |
- Returns:
- true if no error occured, false if it did
Definition at line 271 of file common.h.
bool writeI2C |
( |
tSensors |
link, |
|
|
tByteArray & |
request |
|
) |
| |
Write to the I2C bus. This function will clear the bus and wait for it be ready before any bytes are sent.
- Parameters:
-
link | the port number |
request | the data to be sent |
- Returns:
- true if no error occured, false if it did
Definition at line 211 of file common.h.