YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
gp2y1010au0f_drv.h
1/*
2 * gp2y1010au0fdrv.h
3 *
4 * Created on: 27.01.2017
5 * Author: aterstegge
6 */
7
8#ifndef _GP2Y1010AU0F_DRV_H_
9#define _GP2Y1010AU0F_DRV_H_
10
11#include "gpio_interface.h"
12#include "adc_interface.h"
13#include "timer_interface.h"
14
15void callback_helper(void *arg);
16
18public:
19
21 gpio_interface &led,
22 timer_interface &timer,
23 float voltage_factor = 1.0);
24
26
27 void start_measure(uint16_t measurements,
28 void (*callback)(gp2y1010au0f_drv *));
29
30 inline float get_volt() { return _volt; }
31
32 inline float get_volt_min() { return _volt_min; }
33
34 inline float get_volt_max() { return _volt_max; }
35
36 inline float get_dust() { return _dust; }
37
38private:
39
40 // Delay values in us. The pre-measurement delay should be 280us according
41 // to the data sheet, but the esp adc takes 90us to convert, so we align the
42 // _center_ of the adc 'window' to 280us and start 50us earlier...
43 static const uint16_t T = 10000; // T is 10ms according to data sheet
44 static const uint16_t DELAY = 230; // Delay before ADC measurement
45
46 void process_state();
47
48 float voltage_to_dust(float VO);
49
50 // HW members: ADC, LED and timer references
51 adc_channel &_adc;
52 gpio_interface &_ir_led;
53 timer_interface &_timer;
54
55 float _voltage_factor; // factor of voltage divider
56 uint32_t _raw_sum; // sum of all raw adc values
57 uint16_t _measurements; // Number of measurements to perform
58 uint16_t _counter; // Measurement counter
59 float _volt;
60 float _volt_min;
61 float _volt_max;
62 float _dust;
63
64 void (*_callback)(gp2y1010au0f_drv *);
65
66 enum sensor_state_t {
67 START_MEASURE, DO_MEASURE, STOP_MEASURE
68 };
69 sensor_state_t _state; // The current state of the sensor
70
71};
72
73#endif /* SRC_DRIVER_GP2Y1010AU0FDRV_H_ */
74