mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-18 20:23:27 +02:00
6682c43dfa
## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
63 lines
2.4 KiB
C++
63 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/components/i2c/i2c.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
|
|
|
namespace esphome {
|
|
namespace apds9960 {
|
|
|
|
class APDS9960 : public PollingComponent, public i2c::I2CDevice {
|
|
public:
|
|
APDS9960(uint32_t update_interval) : PollingComponent(update_interval) {}
|
|
void setup() override;
|
|
void dump_config() override;
|
|
float get_setup_priority() const override;
|
|
void update() override;
|
|
void loop() override;
|
|
|
|
void set_red_channel(sensor::Sensor *red_channel) { red_channel_ = red_channel; }
|
|
void set_green_channel(sensor::Sensor *green_channel) { green_channel_ = green_channel; }
|
|
void set_blue_channel(sensor::Sensor *blue_channel) { blue_channel_ = blue_channel; }
|
|
void set_clear_channel(sensor::Sensor *clear_channel) { clear_channel_ = clear_channel; }
|
|
void set_up_direction(binary_sensor::BinarySensor *up_direction) { up_direction_ = up_direction; }
|
|
void set_right_direction(binary_sensor::BinarySensor *right_direction) { right_direction_ = right_direction; }
|
|
void set_down_direction(binary_sensor::BinarySensor *down_direction) { down_direction_ = down_direction; }
|
|
void set_left_direction(binary_sensor::BinarySensor *left_direction) { left_direction_ = left_direction; }
|
|
void set_proximity(sensor::Sensor *proximity) { proximity_ = proximity; }
|
|
|
|
protected:
|
|
bool is_color_enabled_() const;
|
|
bool is_proximity_enabled_() const;
|
|
bool is_gesture_enabled_() const;
|
|
void read_color_data_(uint8_t status);
|
|
void read_proximity_data_(uint8_t status);
|
|
void read_gesture_data_();
|
|
void report_gesture_(int gesture);
|
|
void process_dataset_(int up, int down, int left, int right);
|
|
|
|
sensor::Sensor *red_channel_{nullptr};
|
|
sensor::Sensor *green_channel_{nullptr};
|
|
sensor::Sensor *blue_channel_{nullptr};
|
|
sensor::Sensor *clear_channel_{nullptr};
|
|
binary_sensor::BinarySensor *up_direction_{nullptr};
|
|
binary_sensor::BinarySensor *right_direction_{nullptr};
|
|
binary_sensor::BinarySensor *down_direction_{nullptr};
|
|
binary_sensor::BinarySensor *left_direction_{nullptr};
|
|
sensor::Sensor *proximity_{nullptr};
|
|
enum ErrorCode {
|
|
NONE = 0,
|
|
COMMUNICATION_FAILED,
|
|
WRONG_ID,
|
|
} error_code_{NONE};
|
|
bool gesture_up_started_{false};
|
|
bool gesture_down_started_{false};
|
|
bool gesture_left_started_{false};
|
|
bool gesture_right_started_{false};
|
|
uint32_t gesture_start_{0};
|
|
};
|
|
|
|
} // namespace apds9960
|
|
} // namespace esphome
|