-
Notifications
You must be signed in to change notification settings - Fork 0
linesensor.h
Go to the source code for linesensor.h
#include "time.h"#include "i2c.h"
InitializeI2CLineSensorInitializeGPIOLineSensorLineSensorReadLineSensorReadArrayLineSensorBackgroundReadLineSensorReadContinuouslyUSLineSensorReadContinuously
Initializes a line sensor with an address on an i2c bus
tLineSensor *InitializeI2CLineSensor(tI2C *i2c, unsigned int address);
Parameters:
-
i2cPointer to an initialized tI2C, returned by InitializeI2C -
address2-bit value determined by the solder jumpers on the board
Returns:
- Pointer to an initialized tLineSensor, can be used by the LineSensorRead functions
Initializes a GPIO line sensor on the provided pins
tLineSensor *InitializeGPIOLineSensor(tPin p0, tPin p1, tPin p2, tPin p3, tPin p4, tPin p5, tPin p6, tPin p7);
Parameters:
-
p0Pin plugged into sensor 0 -
p1Pin plugged into sensor 1 -
p2Pin plugged into sensor 2 -
p3Pin plugged into sensor 3 -
p4Pin plugged into sensor 4 -
p5Pin plugged into sensor 5 -
p6Pin plugged into sensor 6 -
p7Pin plugged into sensor 7
Returns:
- Pointer to an initialized tLineSensor, can be used by the LineSensorRead functions
Returns the line sensor value measured as a bit-packed byte
unsigned char LineSensorRead(tLineSensor *ls, float threshold);
Parameters:
-
lsPointer to an initialized tLineSensor, returned by InitializeLineSensor -
thresholdIf the value read from a single IR on the linesensor is above this threshold, it is converted to 1 and then packed into the byte
Returns:
- Value measured from the line sensors as a bit-packed byte, where each bit of the byte corresponds to the value of a single IR senor on the line sensor array
Notes:
- if the line sensor is not continously reading, then the function will busy wait for the results
- if there is an error in the I2C module, the returned value will be all ones
Puts the values read from the line sensor into an array of 8 floats
tBoolean LineSensorReadArray(tLineSensor *ls, float *array);
Parameters:
-
lsPointer to an initialized tLineSensor, returned by InitializeLineSensor -
arrayArray of 8 percentages, each corresponding to an IR sensor in the line sensor array
Returns:
- true if successful, otherwise it returns false and fills the array with infinities
Notes:
- if the line sensor is not continously reading, then the function will busy wait for the results
Sets up a line sensor to be run in the background
void LineSensorBackgroundRead(tLineSensor *ls, tCallback callback, void *data);
Parameters:
-
snrPointer to an initialized tLineSensor, returned by InitializeLineSensor -
callbackFunction called the next time the line sensor read completes, in which a call to LineSensorRead will return with the newly obtained value immediately -
dataArgument sent to the provided callback function whenever it is called
Sets up an line sensor to be read indefinitly
void LineSensorReadContinuouslyUS(tLineSensor *ls, tTime us);
Parameters:
-
snrPointer to an initialized tLineSensor, returned by InitializeLineSensor -
usTime between calls to read the line sensor in microseconds
Notes:
- Any following calls to LineSensorRead will return the most recent value
- If the passed time between calls is less than the time it takes for the line sensor read to complete, the line sensor will fire as fast as possible without overlap
Sets up an line sensor to be read indefinitly
void LineSensorReadContinuously(tLineSensor *ls, float s);
Parameters:
-
snrPointer to an initialized tLineSensor, returned by InitializeLineSensor -
sTime between calls to read the line sensor in seconds
Notes:
- Any following calls to LineSensorRead will return the most recent value
- If the passed time between calls is less than the time it takes for the line sensor read to complete, the line sensor will fire as fast as possible without overlap