Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

linesensor.h

Joseph Ryan edited this page Aug 19, 2017 · 5 revisions

Go to the source code for linesensor.h

Includes

  • #include "time.h"
  • #include "i2c.h"

Functions

Function Documention


InitializeI2CLineSensor

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

InitializeGPIOLineSensor

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

LineSensorRead

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

LineSensorReadArray

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

LineSensorBackgroundRead

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

LineSensorReadContinuouslyUS

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

LineSensorReadContinuously

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