Triggered ADC readings
Dependents: rgb_sensor_buffer_example rgb_sensor_detection
rgb_sensor_buffer.h@2:8fbb1cd0c2d9, 2014-07-08 (annotated)
- Committer:
- meriac
- Date:
- Tue Jul 08 16:07:01 2014 +0000
- Revision:
- 2:8fbb1cd0c2d9
- Parent:
- 0:bbd86bfe6577
Reduce spurious filter to handle short pass-through-times
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
meriac | 0:bbd86bfe6577 | 1 | /* Discrete RGB color sensor (buffered) |
meriac | 0:bbd86bfe6577 | 2 | * |
meriac | 0:bbd86bfe6577 | 3 | * - uses single-channel light-dependent resistor (via ADC) |
meriac | 0:bbd86bfe6577 | 4 | * and a RGB LED. |
meriac | 0:bbd86bfe6577 | 5 | * - compensates background light |
meriac | 0:bbd86bfe6577 | 6 | * |
meriac | 0:bbd86bfe6577 | 7 | * Copyright (c) 2014 ARM Limited |
meriac | 0:bbd86bfe6577 | 8 | * |
meriac | 0:bbd86bfe6577 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
meriac | 0:bbd86bfe6577 | 10 | * you may not use this file except in compliance with the License. |
meriac | 0:bbd86bfe6577 | 11 | * You may obtain a copy of the License at |
meriac | 0:bbd86bfe6577 | 12 | * |
meriac | 0:bbd86bfe6577 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
meriac | 0:bbd86bfe6577 | 14 | * |
meriac | 0:bbd86bfe6577 | 15 | * Unless required by applicable law or agreed to in writing, software |
meriac | 0:bbd86bfe6577 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
meriac | 0:bbd86bfe6577 | 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
meriac | 0:bbd86bfe6577 | 18 | * See the License for the specific language governing permissions and |
meriac | 0:bbd86bfe6577 | 19 | * limitations under the License. |
meriac | 0:bbd86bfe6577 | 20 | */ |
meriac | 0:bbd86bfe6577 | 21 | |
meriac | 0:bbd86bfe6577 | 22 | #ifndef __RGB_SENSOR_BUFFER_H__ |
meriac | 0:bbd86bfe6577 | 23 | #define __RGB_SENSOR_BUFFER_H__ |
meriac | 0:bbd86bfe6577 | 24 | |
meriac | 0:bbd86bfe6577 | 25 | #include <rgb_sensor.h> |
meriac | 0:bbd86bfe6577 | 26 | |
meriac | 0:bbd86bfe6577 | 27 | #ifndef RGB_SENSOR_BUFFER_MIN |
meriac | 0:bbd86bfe6577 | 28 | #define RGB_SENSOR_BUFFER_MIN 32 |
meriac | 0:bbd86bfe6577 | 29 | #endif/*RGB_SENSOR_BUFFER_MIN*/ |
meriac | 0:bbd86bfe6577 | 30 | |
meriac | 0:bbd86bfe6577 | 31 | #ifndef RGB_SENSOR_BUFFER_SPURIOUS_COUNT |
meriac | 2:8fbb1cd0c2d9 | 32 | #define RGB_SENSOR_BUFFER_SPURIOUS_COUNT 32 |
meriac | 0:bbd86bfe6577 | 33 | #endif/*RGB_SENSOR_BUFFER_SPURIOUS_COUNT*/ |
meriac | 0:bbd86bfe6577 | 34 | |
meriac | 0:bbd86bfe6577 | 35 | class RGB_SensorBuffer: protected RGB_Sensor |
meriac | 0:bbd86bfe6577 | 36 | { |
meriac | 0:bbd86bfe6577 | 37 | public: |
meriac | 0:bbd86bfe6577 | 38 | RGB_SensorBuffer(PinName red, PinName green, PinName blue, PinName adc); |
meriac | 0:bbd86bfe6577 | 39 | int trigger(TRGB* rgb, int count, int treshold); |
meriac | 0:bbd86bfe6577 | 40 | |
meriac | 0:bbd86bfe6577 | 41 | private: |
meriac | 0:bbd86bfe6577 | 42 | TRGB* m_buffer; |
meriac | 0:bbd86bfe6577 | 43 | volatile int m_count, m_treshold, m_buffer_pos, m_buffer_spurious; |
meriac | 0:bbd86bfe6577 | 44 | bool m_initialized; |
meriac | 0:bbd86bfe6577 | 45 | static void __adc_irq(void); |
meriac | 0:bbd86bfe6577 | 46 | void adc_irq(void); |
meriac | 0:bbd86bfe6577 | 47 | static RGB_SensorBuffer* m_global; |
meriac | 0:bbd86bfe6577 | 48 | static bool __callback(const TRGB &color); |
meriac | 0:bbd86bfe6577 | 49 | bool callback(const TRGB &color); |
meriac | 0:bbd86bfe6577 | 50 | }; |
meriac | 0:bbd86bfe6577 | 51 | |
meriac | 0:bbd86bfe6577 | 52 | #endif/*__RGB_SENSOR_BUFFER_H__*/ |