ESPHome  2024.12.2
apds9960.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/defines.h"
6 #ifdef USE_SENSOR
8 #endif
9 #ifdef USE_BINARY_SENSOR
11 #endif
12 
13 namespace esphome {
14 namespace apds9960 {
15 
16 class APDS9960 : public PollingComponent, public i2c::I2CDevice {
17 #ifdef USE_SENSOR
18  SUB_SENSOR(red)
19  SUB_SENSOR(green)
20  SUB_SENSOR(blue)
21  SUB_SENSOR(clear)
22  SUB_SENSOR(proximity)
23 #endif
24 
25 #ifdef USE_BINARY_SENSOR
26  SUB_BINARY_SENSOR(up_direction)
27  SUB_BINARY_SENSOR(right_direction)
28  SUB_BINARY_SENSOR(down_direction)
29  SUB_BINARY_SENSOR(left_direction)
30 #endif
31 
32  public:
33  void setup() override;
34  void dump_config() override;
35  float get_setup_priority() const override;
36  void update() override;
37  void loop() override;
38 
39  void set_led_drive(uint8_t level) { this->led_drive_ = level; }
40  void set_proximity_gain(uint8_t gain) { this->proximity_gain_ = gain; }
41  void set_ambient_gain(uint8_t gain) { this->ambient_gain_ = gain; }
42  void set_gesture_led_drive(uint8_t level) { this->gesture_led_drive_ = level; }
43  void set_gesture_gain(uint8_t gain) { this->gesture_gain_ = gain; }
44  void set_gesture_wait_time(uint8_t wait_time) { this->gesture_wait_time_ = wait_time; }
45 
46  protected:
47  bool is_color_enabled_() const;
48  bool is_proximity_enabled_() const;
49  bool is_gesture_enabled_() const;
50  void read_color_data_(uint8_t status);
51  void read_proximity_data_(uint8_t status);
52  void read_gesture_data_();
53  void report_gesture_(int gesture);
54  void process_dataset_(int up, int down, int left, int right);
55 
56  uint8_t led_drive_;
57  uint8_t proximity_gain_;
58  uint8_t ambient_gain_;
60  uint8_t gesture_gain_;
62 
63  enum ErrorCode {
64  NONE = 0,
67  } error_code_{NONE};
68  bool gesture_up_started_{false};
69  bool gesture_down_started_{false};
70  bool gesture_left_started_{false};
72  uint32_t gesture_start_{0};
73 };
74 
75 } // namespace apds9960
76 } // namespace esphome
bool is_color_enabled_() const
Definition: apds9960.cpp:118
void read_color_data_(uint8_t status)
Definition: apds9960.cpp:174
void process_dataset_(int up, int down, int left, int right)
Definition: apds9960.cpp:315
This class simplifies creating components that periodically check a state.
Definition: component.h:283
AlsGain501 gain
enum esphome::apds9960::APDS9960::ErrorCode NONE
void read_proximity_data_(uint8_t status)
Definition: apds9960.cpp:208
virtual void setup()
Where the component's initialization should happen.
Definition: component.cpp:48
void report_gesture_(int gesture)
Definition: apds9960.cpp:277
uint8_t status
Definition: bl0942.h:74
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
bool is_gesture_enabled_() const
Definition: apds9960.cpp:398
bool is_proximity_enabled_() const
Definition: apds9960.cpp:389