Added a GPIO to power on/off for external I2C sensor(s) (with LEDs)
Dependencies: UniGraphic mbed vt100
edge_color.h
00001 #ifndef _EDGE_COLOR_H_ 00002 #define _EDGE_COLOR_H_ 00003 #include "mbed.h" 00004 #include "edge_sensor.h" 00005 #include "VEML6040.h" 00006 00007 /** 00008 * edge_color edge_sensor which manages LED and color sensor (VEML6040) 00009 */ 00010 00011 class edge_color : public edge_sensor { 00012 public: 00013 /** 00014 * constructor 00015 * @param *sensor VEML6040 object 00016 * @param *led[] PwmOuts for LEDs 00017 * @param *pwm[] uint16_t pwm duty values 00018 */ 00019 edge_color(VEML6040 *sensor, PwmOut *led[], uint16_t *pwm) ; 00020 00021 /** 00022 * destructor 00023 */ 00024 ~edge_color(void) ; 00025 00026 /** 00027 * reset and clear internal values 00028 */ 00029 virtual void reset(void) ; 00030 00031 /** 00032 * prepare at first this was planned to set LEDs 00033 * before sampling, but turned out to be not neccesarry 00034 */ 00035 virtual void prepare(void) ; 00036 00037 /** 00038 * sample sampling the color value(s) is some what complicated. 00039 * At first leds are turned on using the pwm values _pwm[]. 00040 * then VEML6040 is triggered with config value, which includes 00041 * the trigger method and integration time. 00042 * Wait for the integration time (actually x 1.25 of the value) 00043 * then acquire the color values from VEML6040 and turn the leds off. 00044 */ 00045 virtual int sample(void) ; 00046 00047 /** 00048 * Deliver the sampled value to the afero cloud. 00049 */ 00050 virtual int deliver(void) ; 00051 00052 /** 00053 * Show the value(s) in the display (TFT) 00054 */ 00055 virtual void show(void) ; 00056 00057 /** 00058 * calibrate: caribrate the led pwm values trying to adjust the measured 00059 * values to the values given in target[]. Measurements are repeated 00060 * num_ave+2 times and the minimum and maximum values will be discarded 00061 * then average values are calculated using the remaining values. 00062 * @param target[] uint16_t target values for R, G, B measurement 00063 * @param result[] uint16_t calibrated pwm R,G,B values 00064 * @param num_ave repeat time for averaging the measurement data 00065 */ 00066 void calibrate(uint16_t target[], uint16_t result[], int num_ave) ; 00067 00068 /** 00069 * request_calibration: set the flag to calibrate next avilable time slot 00070 */ 00071 void request_calibration(void) { _calibration_request = 1 ; } 00072 00073 /** 00074 * calibration_requested 00075 * @returns if the calibration is due 00076 */ 00077 int calibration_requested(void) { return _calibration_request ; } 00078 00079 /** 00080 * getAveColor 00081 * @param led[] uint16_t pwm values for R,G,B 00082 * @param v[] uint16_t averaged measurement value 00083 * @param num_ave int measurment repeat time for averaging 00084 */ 00085 void getAveColor(uint16_t led[], uint16_t v[], int num_ave) ; 00086 00087 /** 00088 * getRGB 00089 * @param v[] uint16_t measured R,G,B values 00090 * @returns 0: success non-0: failure 00091 */ 00092 int getRGB(uint16_t v[]) ; 00093 00094 /** 00095 * getConfig 00096 * @returns config this value is used to trigger VEML6040 measurement 00097 */ 00098 uint8_t getConfig(void) { return _sensor_config ; } 00099 00100 /** 00101 * setConfig 00102 * @param config uint8_t 8bit value to use trigger VEML6040 measurement 00103 */ 00104 void setConfig(uint8_t config) { _sensor_config = config ; } 00105 00106 /** 00107 * get_pwm_period 00108 * @returns pwm_period in us 00109 */ 00110 uint16_t get_pwm_period(void) { return _pwm_period ; } 00111 00112 /** 00113 * set_pwm_period 00114 * @param pwm_period uint16_t pwm period in us 00115 */ 00116 void set_pwm_period(uint16_t period) { _pwm_period = period ; } 00117 00118 /** 00119 * get_pwm_target 00120 * @returns measurment target value controlled by the pwm 00121 */ 00122 uint16_t get_pwm_target(void) { return _pwm_target ; } 00123 00124 /** 00125 * set_pwm_target 00126 * @param target uint16_t measurement target value 00127 */ 00128 void set_pwm_target(uint16_t target) { _pwm_target = target ; } 00129 00130 /** 00131 * getR 00132 * @returns measured value of R 00133 */ 00134 uint16_t getR(void) { return _value[0] ; } 00135 00136 /** 00137 * getG 00138 * @returns measured value of G 00139 */ 00140 uint16_t getG(void) { return _value[1] ; } 00141 00142 /** 00143 * getB 00144 * @returns measured value of B 00145 */ 00146 uint16_t getB(void) { return _value[2] ; } 00147 00148 /** 00149 * getPwmR 00150 * @returns PWM value of R LED 00151 */ 00152 uint16_t getPwmR(void) { return _pwm[0] ; } 00153 00154 /** 00155 * setPwmR 00156 * @param pwm_r 00157 */ 00158 void setPwmR(uint16_t pwm_r) { _pwm[0] = pwm_r ; } 00159 00160 /** 00161 * getPwmG 00162 * @returns PWM value of G LED 00163 */ 00164 uint16_t getPwmG(void) { return _pwm[1] ; } 00165 00166 /** 00167 * setPwmG 00168 * @param pwm_g 00169 */ 00170 void setPwmG(uint16_t pwm_g) { _pwm[1] = pwm_g ; } 00171 00172 /** 00173 * getPwmB 00174 * @returns PWM value of B LED 00175 */ 00176 uint16_t getPwmB(void) { return _pwm[2] ; } 00177 00178 /** 00179 * setPwmB 00180 * @param pwm_b 00181 */ 00182 void setPwmB(uint16_t pwm_b) { _pwm[2] = pwm_b ; } 00183 00184 /** 00185 * setLEDs set pwm values to PwmOut pins to drive LEDS 00186 * @param led_value[] uint16_t pwm values for R, G, B 00187 */ 00188 void setLEDs(uint16_t led_value[]) ; 00189 00190 /** 00191 * setLEDs set pwm values to PwmOut pins to drive LEDS 00192 * @param r uint16_t pwm value of R LED 00193 * @param g uint16_t pwm value of G LED 00194 * @param b uint16_t pwm value of B LED 00195 */ 00196 void setLEDs(uint16_t r, uint16_t g, uint16_t b) ; 00197 00198 protected: 00199 VEML6040 *_sensor ; 00200 uint8_t _sensor_config ; 00201 PwmOut *_led[3] ; 00202 uint16_t _pwm_period ; 00203 uint16_t _pwm_target ; 00204 uint16_t _value[3] ; /* r, g, b */ 00205 uint16_t _pwm[3] ; /* r, g, b */ 00206 uint16_t _probe ; /* probing value for calibration */ 00207 uint8_t _calibration_request ; 00208 } ; 00209 00210 extern uint16_t color0_pwm[3] ; 00211 extern uint16_t color1_pwm[3] ; 00212 extern uint16_t color0_target[3] ; 00213 extern uint16_t color1_target[3] ; 00214 00215 #endif /* _EDGE_COLOR_H_ */
Generated on Wed Jul 13 2022 12:25:10 by
1.7.2
La Suno