test

Dependents:   controller_naive

Committer:
yxyang
Date:
Sat Feb 24 01:24:57 2018 +0000
Revision:
0:9c6145a1d114
avg intensity

Who changed what in which revision?

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