-
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"
InitializeI2CLineSensor
InitializeGPIOLineSensor
LineSensorRead
LineSensorReadArray
LineSensorBackgroundRead
LineSensorReadContinuouslyUS
LineSensorReadContinuously
Initializes a line sensor with an address on an i2c bus
tLineSensor *InitializeI2CLineSensor(tI2C *i2c, unsigned int address);
Parameters:
-
i2c
Pointer to an initialized tI2C, returned by InitializeI2C -
address
2-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:
-
p0
Pin plugged into sensor 0 -
p1
Pin plugged into sensor 1 -
p2
Pin plugged into sensor 2 -
p3
Pin plugged into sensor 3 -
p4
Pin plugged into sensor 4 -
p5
Pin plugged into sensor 5 -
p6
Pin plugged into sensor 6 -
p7
Pin 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:
-
ls
Pointer to an initialized tLineSensor, returned by InitializeLineSensor -
threshold
If 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:
-
ls
Pointer to an initialized tLineSensor, returned by InitializeLineSensor -
array
Array 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:
-
snr
Pointer to an initialized tLineSensor, returned by InitializeLineSensor -
callback
Function called the next time the line sensor read completes, in which a call to LineSensorRead will return with the newly obtained value immediately -
data
Argument 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:
-
snr
Pointer to an initialized tLineSensor, returned by InitializeLineSensor -
us
Time 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:
-
snr
Pointer to an initialized tLineSensor, returned by InitializeLineSensor -
s
Time 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