Library for the ADJD-S371, Avago Colour Sensor
ADJDColourSensor.h@0:47465be3223d, 2010-10-01 (annotated)
- Committer:
- MichaelW
- Date:
- Fri Oct 01 13:39:51 2010 +0000
- Revision:
- 0:47465be3223d
Supports reading from the sensors and writing to the configuration registers. Doesn\t have built in optimisation yet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MichaelW | 0:47465be3223d | 1 | /** |
MichaelW | 0:47465be3223d | 2 | * @section LICENSE |
MichaelW | 0:47465be3223d | 3 | *Copyright (c) 2010 ARM Ltd. |
MichaelW | 0:47465be3223d | 4 | * |
MichaelW | 0:47465be3223d | 5 | *Permission is hereby granted, free of charge, to any person obtaining a copy |
MichaelW | 0:47465be3223d | 6 | *of this software and associated documentation files (the "Software"), to deal |
MichaelW | 0:47465be3223d | 7 | *in the Software without restriction, including without limitation the rights |
MichaelW | 0:47465be3223d | 8 | *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
MichaelW | 0:47465be3223d | 9 | *copies of the Software, and to permit persons to whom the Software is |
MichaelW | 0:47465be3223d | 10 | *furnished to do so, subject to the following conditions: |
MichaelW | 0:47465be3223d | 11 | * |
MichaelW | 0:47465be3223d | 12 | *The above copyright notice and this permission notice shall be included in |
MichaelW | 0:47465be3223d | 13 | *all copies or substantial portions of the Software. |
MichaelW | 0:47465be3223d | 14 | * |
MichaelW | 0:47465be3223d | 15 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
MichaelW | 0:47465be3223d | 16 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
MichaelW | 0:47465be3223d | 17 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
MichaelW | 0:47465be3223d | 18 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
MichaelW | 0:47465be3223d | 19 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MichaelW | 0:47465be3223d | 20 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
MichaelW | 0:47465be3223d | 21 | *THE SOFTWARE. |
MichaelW | 0:47465be3223d | 22 | * |
MichaelW | 0:47465be3223d | 23 | * |
MichaelW | 0:47465be3223d | 24 | * @section DESCRIPTION |
MichaelW | 0:47465be3223d | 25 | * |
MichaelW | 0:47465be3223d | 26 | * |
MichaelW | 0:47465be3223d | 27 | */ |
MichaelW | 0:47465be3223d | 28 | |
MichaelW | 0:47465be3223d | 29 | #ifndef ADJDCOLOURSENS_H_ |
MichaelW | 0:47465be3223d | 30 | #define ADJDCOLOURSENS_H_ |
MichaelW | 0:47465be3223d | 31 | |
MichaelW | 0:47465be3223d | 32 | /** |
MichaelW | 0:47465be3223d | 33 | * |
MichaelW | 0:47465be3223d | 34 | * Includes |
MichaelW | 0:47465be3223d | 35 | * |
MichaelW | 0:47465be3223d | 36 | */ |
MichaelW | 0:47465be3223d | 37 | #include "mbed.h" |
MichaelW | 0:47465be3223d | 38 | /** |
MichaelW | 0:47465be3223d | 39 | * A class to interface with an Avago ADJD-S371-QR999. |
MichaelW | 0:47465be3223d | 40 | * The class allows you to read the light levels setected by the sensor for each colour and to set the gain settings. |
MichaelW | 0:47465be3223d | 41 | */ |
MichaelW | 0:47465be3223d | 42 | class ADJDColourSensor{ |
MichaelW | 0:47465be3223d | 43 | public: |
MichaelW | 0:47465be3223d | 44 | ADJDColourSensor(PinName sda, PinName scl, PinName LED); |
MichaelW | 0:47465be3223d | 45 | |
MichaelW | 0:47465be3223d | 46 | /** |
MichaelW | 0:47465be3223d | 47 | * Read the colour sensor channels. |
MichaelW | 0:47465be3223d | 48 | * The red, green and blue values are |
MichaelW | 0:47465be3223d | 49 | * |
MichaelW | 0:47465be3223d | 50 | * @returns The clear result, ie the overall brightness |
MichaelW | 0:47465be3223d | 51 | */ |
MichaelW | 0:47465be3223d | 52 | float read(); |
MichaelW | 0:47465be3223d | 53 | |
MichaelW | 0:47465be3223d | 54 | /** |
MichaelW | 0:47465be3223d | 55 | * Read the offsets from the device and into the corresponding members. |
MichaelW | 0:47465be3223d | 56 | * |
MichaelW | 0:47465be3223d | 57 | * @returns The value of the clear offset |
MichaelW | 0:47465be3223d | 58 | */ |
MichaelW | 0:47465be3223d | 59 | int readOffset(); |
MichaelW | 0:47465be3223d | 60 | |
MichaelW | 0:47465be3223d | 61 | float red, green, blue; |
MichaelW | 0:47465be3223d | 62 | |
MichaelW | 0:47465be3223d | 63 | signed int redOffset, greenOffset, blueOffset, clearOffset; |
MichaelW | 0:47465be3223d | 64 | |
MichaelW | 0:47465be3223d | 65 | /** |
MichaelW | 0:47465be3223d | 66 | * Set the number of capacitors for each channel of the ADC. |
MichaelW | 0:47465be3223d | 67 | * |
MichaelW | 0:47465be3223d | 68 | * The values of the parameters must be between 0x00 and 0x0F |
MichaelW | 0:47465be3223d | 69 | * @param redCap The number of capacitors for the red channel |
MichaelW | 0:47465be3223d | 70 | */ |
MichaelW | 0:47465be3223d | 71 | void setCapacitors(int redCap, int greenCap, int blueCap, int clearCap); |
MichaelW | 0:47465be3223d | 72 | |
MichaelW | 0:47465be3223d | 73 | /** |
MichaelW | 0:47465be3223d | 74 | * Set the integration time slot for each of the ADCs. |
MichaelW | 0:47465be3223d | 75 | * |
MichaelW | 0:47465be3223d | 76 | * All the values are as a 12 bit number |
MichaelW | 0:47465be3223d | 77 | * @param redInt The integration time slot for the red channel |
MichaelW | 0:47465be3223d | 78 | * @param greenInt The integration time slot for the green channel |
MichaelW | 0:47465be3223d | 79 | * @param blueInt The integration time slot for the blue channel |
MichaelW | 0:47465be3223d | 80 | * @param clearInt The integration time slot for the clear channel |
MichaelW | 0:47465be3223d | 81 | */ |
MichaelW | 0:47465be3223d | 82 | void setIntegrationTimeSlot(int redInt, int greenInt, int blueInt, int ClearInt); |
MichaelW | 0:47465be3223d | 83 | |
MichaelW | 0:47465be3223d | 84 | void optimise(); |
MichaelW | 0:47465be3223d | 85 | void optimise(int optimum); |
MichaelW | 0:47465be3223d | 86 | void optimise(int redTarget, int blueTarget, int greenTarget, int clearTarget); |
MichaelW | 0:47465be3223d | 87 | |
MichaelW | 0:47465be3223d | 88 | |
MichaelW | 0:47465be3223d | 89 | private: |
MichaelW | 0:47465be3223d | 90 | I2C _sensor; |
MichaelW | 0:47465be3223d | 91 | DigitalOut _LED; |
MichaelW | 0:47465be3223d | 92 | int _red, _green, _blue, _clear; |
MichaelW | 0:47465be3223d | 93 | int _address; |
MichaelW | 0:47465be3223d | 94 | }; |
MichaelW | 0:47465be3223d | 95 | #endif |