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 | round(x) (int)(x + 0.5) |
Typedefs |
typedef ubyte | tByteArray [MAX_ARR_SIZE] |
typedef sbyte | tsByteArray [MAX_ARR_SIZE] |
typedef int | tIntArray [MAX_ARR_SIZE] |
Functions |
void | clearI2CError (tSensors link, ubyte address) |
bool | waitForI2CBus (tSensors link) |
bool | writeI2C (tSensors link, tByteArray &data, int replylen) |
bool | readI2C (tSensors link, tByteArray &data, int replylen) |
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 69 of file common.h.
#define clip |
( |
|
a, |
|
|
|
b, |
|
|
|
c |
|
) |
| min2(c, max2(b, a)) |
Returns x if it is between min and max. If outside the range, it returns min or max.
- Examples:
- MSLL-test3.c.
Definition at line 116 of file common.h.
#define max2 |
( |
|
a, |
|
|
|
b |
|
) |
| (a > b ? a : b) |
This function returns the bigger of the two numbers
Definition at line 103 of file common.h.
#define max3 |
( |
|
a, |
|
|
|
b, |
|
|
|
c |
|
) |
| (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c) |
This function returns the biggest of the three numbers
Definition at line 109 of file common.h.
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 85 of file common.h.
#define min2 |
( |
|
a, |
|
|
|
b |
|
) |
| (a < b ? a : b) |
This define returns the smaller of the two numbers
Definition at line 92 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 98 of file common.h.
#define round |
( |
|
x ) |
(int)(x + 0.5) |
Returns a rounded int from a float.
Definition at line 122 of file common.h.
Typedef Documentation
Array of ints as a struct, this is a work around for RobotC's inability to pass an array to a function.
- Examples:
- MSLL-test4.c.
Definition at line 136 of file common.h.
Function Documentation
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 150 of file common.h.
bool readI2C |
( |
tSensors |
link, |
|
|
tByteArray & |
data, |
|
|
int |
replylen |
|
) |
| |
Read from the I2C bus. This function will wait for the bus to be ready before reading from it.
- Parameters:
-
link | the port number |
data | holds the data from the reply |
replylen | the number of bytes in the reply |
- Returns:
- true if no error occured, false if it did
Definition at line 265 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 173 of file common.h.
bool writeI2C |
( |
tSensors |
link, |
|
|
tByteArray & |
data, |
|
|
int |
replylen |
|
) |
| |
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 |
data | the data to be sent |
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 210 of file common.h.