Committer:
yxyang
Date:
Tue May 30 06:54:21 2017 +0000
Revision:
0:4e108bee7994

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yxyang 0:4e108bee7994 1 /*
yxyang 0:4e108bee7994 2 * An mbed library for the TSL1401CL line sensor.
yxyang 0:4e108bee7994 3 * Author: Galen Savidge
yxyang 0:4e108bee7994 4 */
yxyang 0:4e108bee7994 5
yxyang 0:4e108bee7994 6 #ifndef TSL1401CLh
yxyang 0:4e108bee7994 7 #define TSL1401CLh
yxyang 0:4e108bee7994 8
yxyang 0:4e108bee7994 9 #include "mbed.h"
yxyang 0:4e108bee7994 10
yxyang 0:4e108bee7994 11 #define TSL1401CL_PIXEL_COUNT 128
yxyang 0:4e108bee7994 12
yxyang 0:4e108bee7994 13 class TSL1401CL
yxyang 0:4e108bee7994 14 {
yxyang 0:4e108bee7994 15 public:
yxyang 0:4e108bee7994 16 /**
yxyang 0:4e108bee7994 17 * Parameters: binary pin connected to clock, binary pin connected to serial-
yxyang 0:4e108bee7994 18 * input (SI), adc pin connected to analog out (AO)
yxyang 0:4e108bee7994 19 */
yxyang 0:4e108bee7994 20 TSL1401CL(PinName pin_clk, PinName pin_si, PinName pin_adc);
yxyang 0:4e108bee7994 21
yxyang 0:4e108bee7994 22 /**
yxyang 0:4e108bee7994 23 * Returns whether enough time has passsed for integration to complete. The
yxyang 0:4e108bee7994 24 * sensor should not be read until integrationReady() returns true.
yxyang 0:4e108bee7994 25 */
yxyang 0:4e108bee7994 26 bool integrationReady();
yxyang 0:4e108bee7994 27
yxyang 0:4e108bee7994 28 /**
yxyang 0:4e108bee7994 29 * Reads from the sensor into private data storage.
yxyang 0:4e108bee7994 30 */
yxyang 0:4e108bee7994 31 void read();
yxyang 0:4e108bee7994 32
yxyang 0:4e108bee7994 33 /**
yxyang 0:4e108bee7994 34 * Sets the integration time of the sensor in microseconds. Can be called mid
yxyang 0:4e108bee7994 35 * integration.
yxyang 0:4e108bee7994 36 */
yxyang 0:4e108bee7994 37 void setIntegrationTime(uint32_t int_time_desired);
yxyang 0:4e108bee7994 38
yxyang 0:4e108bee7994 39 /**
yxyang 0:4e108bee7994 40 * Returns the dark-to-light edge of a line as an int between 0 and cam
yxyang 0:4e108bee7994 41 * resolution. Returns -1 when no line is found. Use higher precision value
yxyang 0:4e108bee7994 42 * for fewer samples, default is 1 (lowest, most precise). Ignores
yxyang 0:4e108bee7994 43 * crop_amount pixels on beginning/end of data. Set invert to true to instead
yxyang 0:4e108bee7994 44 * return the light-to-dark line edge (if found).
yxyang 0:4e108bee7994 45 */
yxyang 0:4e108bee7994 46 int findLineEdge (uint16_t threshold, uint8_t precision = 1,
yxyang 0:4e108bee7994 47 size_t crop_amount = 0, bool invert = false);
yxyang 0:4e108bee7994 48
yxyang 0:4e108bee7994 49 /**
yxyang 0:4e108bee7994 50 * Like FindLineEdge, but finds both edges of the line and returns their
yxyang 0:4e108bee7994 51 * midpoint. Returns -1 if either edge is not found.
yxyang 0:4e108bee7994 52 */
yxyang 0:4e108bee7994 53 int findLineCenter (uint16_t threshold, uint8_t precision = 1,
yxyang 0:4e108bee7994 54 size_t crop_amount = 0);
yxyang 0:4e108bee7994 55
yxyang 0:4e108bee7994 56 /**
yxyang 0:4e108bee7994 57 * Returns the value of the sensor's last read data at a specified index.
yxyang 0:4e108bee7994 58 */
yxyang 0:4e108bee7994 59 uint32_t getData(uint8_t index);
yxyang 0:4e108bee7994 60 protected:
yxyang 0:4e108bee7994 61 DigitalOut clk;
yxyang 0:4e108bee7994 62 DigitalOut si;
yxyang 0:4e108bee7994 63 AnalogIn adc;
yxyang 0:4e108bee7994 64
yxyang 0:4e108bee7994 65 uint32_t data[TSL1401CL_PIXEL_COUNT];
yxyang 0:4e108bee7994 66 uint32_t integration_time;
yxyang 0:4e108bee7994 67 Timer integration_timer;
yxyang 0:4e108bee7994 68 };
yxyang 0:4e108bee7994 69
yxyang 0:4e108bee7994 70 #endif