Dependents:   controller_with_imu controller_with_autostop ros_openroach

Committer:
yxyang
Date:
Tue May 30 06:41:58 2017 +0000
Revision:
0:57ff45e3cb20

        

Who changed what in which revision?

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