ESPHome  2022.12.8
apds9960.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace esphome {
9 namespace apds9960 {
10 
11 class APDS9960 : public PollingComponent, public i2c::I2CDevice {
12  public:
13  void setup() override;
14  void dump_config() override;
15  float get_setup_priority() const override;
16  void update() override;
17  void loop() override;
18 
19  void set_led_drive(uint8_t level) { this->led_drive_ = level; }
20  void set_proximity_gain(uint8_t gain) { this->proximity_gain_ = gain; }
21  void set_ambient_gain(uint8_t gain) { this->ambient_gain_ = gain; }
22  void set_gesture_led_drive(uint8_t level) { this->gesture_led_drive_ = level; }
23  void set_gesture_gain(uint8_t gain) { this->gesture_gain_ = gain; }
24  void set_gesture_wait_time(uint8_t wait_time) { this->gesture_wait_time_ = wait_time; }
25 
26  void set_red_channel(sensor::Sensor *red_channel) { red_channel_ = red_channel; }
27  void set_green_channel(sensor::Sensor *green_channel) { green_channel_ = green_channel; }
28  void set_blue_channel(sensor::Sensor *blue_channel) { blue_channel_ = blue_channel; }
29  void set_clear_channel(sensor::Sensor *clear_channel) { clear_channel_ = clear_channel; }
30  void set_up_direction(binary_sensor::BinarySensor *up_direction) { up_direction_ = up_direction; }
31  void set_right_direction(binary_sensor::BinarySensor *right_direction) { right_direction_ = right_direction; }
32  void set_down_direction(binary_sensor::BinarySensor *down_direction) { down_direction_ = down_direction; }
33  void set_left_direction(binary_sensor::BinarySensor *left_direction) { left_direction_ = left_direction; }
34  void set_proximity(sensor::Sensor *proximity) { proximity_ = proximity; }
35 
36  protected:
37  bool is_color_enabled_() const;
38  bool is_proximity_enabled_() const;
39  bool is_gesture_enabled_() const;
40  void read_color_data_(uint8_t status);
41  void read_proximity_data_(uint8_t status);
42  void read_gesture_data_();
43  void report_gesture_(int gesture);
44  void process_dataset_(int up, int down, int left, int right);
45 
46  uint8_t led_drive_;
47  uint8_t proximity_gain_;
48  uint8_t ambient_gain_;
50  uint8_t gesture_gain_;
52 
62  enum ErrorCode {
63  NONE = 0,
66  } error_code_{NONE};
67  bool gesture_up_started_{false};
68  bool gesture_down_started_{false};
69  bool gesture_left_started_{false};
71  uint32_t gesture_start_{0};
72 };
73 
74 } // namespace apds9960
75 } // namespace esphome
void set_down_direction(binary_sensor::BinarySensor *down_direction)
Definition: apds9960.h:32
void set_proximity_gain(uint8_t gain)
Definition: apds9960.h:20
void set_gesture_gain(uint8_t gain)
Definition: apds9960.h:23
binary_sensor::BinarySensor * down_direction_
Definition: apds9960.h:59
bool is_color_enabled_() const
Definition: apds9960.cpp:118
sensor::Sensor * blue_channel_
Definition: apds9960.h:55
sensor::Sensor * red_channel_
Definition: apds9960.h:53
void set_up_direction(binary_sensor::BinarySensor *up_direction)
Definition: apds9960.h:30
void set_red_channel(sensor::Sensor *red_channel)
Definition: apds9960.h:26
void read_color_data_(uint8_t status)
Definition: apds9960.cpp:161
void process_dataset_(int up, int down, int left, int right)
Definition: apds9960.cpp:294
This class simplifies creating components that periodically check a state.
Definition: component.h:267
void set_right_direction(binary_sensor::BinarySensor *right_direction)
Definition: apds9960.h:31
void dump_config() override
Definition: apds9960.cpp:123
enum esphome::apds9960::APDS9960::ErrorCode NONE
void read_proximity_data_(uint8_t status)
Definition: apds9960.cpp:193
void set_gesture_led_drive(uint8_t level)
Definition: apds9960.h:22
void set_left_direction(binary_sensor::BinarySensor *left_direction)
Definition: apds9960.h:33
void setup() override
Definition: apds9960.cpp:17
sensor::Sensor * clear_channel_
Definition: apds9960.h:56
void report_gesture_(int gesture)
Definition: apds9960.cpp:258
void set_blue_channel(sensor::Sensor *blue_channel)
Definition: apds9960.h:28
binary_sensor::BinarySensor * right_direction_
Definition: apds9960.h:58
float get_setup_priority() const override
Definition: apds9960.cpp:367
void set_clear_channel(sensor::Sensor *clear_channel)
Definition: apds9960.h:29
void set_led_drive(uint8_t level)
Definition: apds9960.h:19
uint8_t status
Definition: bl0942.h:23
void set_green_channel(sensor::Sensor *green_channel)
Definition: apds9960.h:27
void update() override
Definition: apds9960.cpp:150
Definition: a4988.cpp:4
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:28
Base-class for all sensors.
Definition: sensor.h:50
void set_gesture_wait_time(uint8_t wait_time)
Definition: apds9960.h:24
bool is_gesture_enabled_() const
Definition: apds9960.cpp:369
binary_sensor::BinarySensor * up_direction_
Definition: apds9960.h:57
bool is_proximity_enabled_() const
Definition: apds9960.cpp:368
binary_sensor::BinarySensor * left_direction_
Definition: apds9960.h:60
sensor::Sensor * proximity_
Definition: apds9960.h:61
void set_ambient_gain(uint8_t gain)
Definition: apds9960.h:21
sensor::Sensor * green_channel_
Definition: apds9960.h:54
void set_proximity(sensor::Sensor *proximity)
Definition: apds9960.h:34