ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ld6002b.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/gpio.h"
5
6namespace esphome::ld6002b {
7
8enum LD6002BButtonType : uint8_t {
9 BUTTON_WAKE = ld600x::LD600X_MODEL_KIND_BASE,
10};
11
13 public:
14 LD6002BComponent() : LD600XComponent(LOG_STR("ld6002b")) {}
15
16 void setup() override;
17
18 void set_wakeup_pin(GPIOPin *pin) { this->wakeup_pin_ = pin; }
20 void set_auto_wake(bool enable) { this->auto_wake_ = enable; }
21
22#ifdef USE_SWITCH
23 SUB_SWITCH(low_power)
24 bool set_switch_state(switch_::Switch *entity, bool state) override;
25#endif
26#ifdef USE_BUTTON
27 void press_button(uint8_t kind) override;
28#endif
29
30 protected:
31 bool handle_model_report(uint16_t type, const uint8_t *data, uint16_t len) override;
32 bool model_wants_target_stream() const override;
34 bool defer_frame_write(uint16_t type, const uint8_t *data, uint8_t len, bool track) override;
35 void setup_model() override;
36 void dump_model_config() override;
37
38 void handle_low_power_report_(const uint8_t *data, uint16_t len);
39 void handle_work_mode_report_(const uint8_t *data, uint16_t len);
41 void publish_work_mode_(bool low_power);
42 void wake_();
43
44 // Keyed so a repeated press replaces its own pending timeout instead of stacking
45 // another, and so the command path can cancel it when it takes the pin over.
47
50 // Frame a pending wake pulse will write, snapshotted because active_command_ may move on first.
51 std::array<uint8_t, ld600x::CMD_MAX_DATA_LEN> wake_scratch_{};
52 bool auto_wake_{true};
55 bool low_power_enabled_{false};
58};
59
60} // namespace esphome::ld6002b
Helper class to deduplicate items in a series of values.
Definition helpers.h:2132
bool defer_frame_write(uint16_t type, const uint8_t *data, uint8_t len, bool track) override
Definition ld6002b.cpp:139
std::array< uint8_t, ld600x::CMD_MAX_DATA_LEN > wake_scratch_
Definition ld6002b.h:51
void set_wakeup_pin(GPIOPin *pin)
Definition ld6002b.h:18
static constexpr uint32_t WAKE_BUTTON_TIMEOUT_ID
Definition ld6002b.h:46
bool handle_model_report(uint16_t type, const uint8_t *data, uint16_t len) override
Definition ld6002b.cpp:67
void set_auto_wake(bool enable)
Definition ld6002b.h:20
void handle_low_power_report_(const uint8_t *data, uint16_t len)
Definition ld6002b.cpp:80
void on_presence_update() override
Definition ld6002b.h:33
void publish_work_mode_(bool low_power)
Definition ld6002b.cpp:128
Deduplicator< bool > work_mode_low_power_
Definition ld6002b.h:57
void handle_work_mode_report_(const uint8_t *data, uint16_t len)
Definition ld6002b.cpp:92
SUB_SWITCH(low_power) bool set_switch_state(switch_ void press_button(uint8_t kind) override
Definition ld6002b.cpp:190
bool model_wants_target_stream() const override
Definition ld6002b.cpp:57
void set_wakeup_pulse_ms(uint32_t ms)
Definition ld6002b.h:19
LD600XComponent(const LogString *log_tag)
Definition ld600x.h:109
virtual bool set_switch_state(switch_::Switch *entity, bool state)
Definition ld600x.cpp:1391
static constexpr uint32_t MODEL_TIMEOUT_ID
Definition ld600x.h:317
Base class for all switches.
Definition switch.h:43
uint8_t type
bool state
Definition fan.h:2
const void size_t len
Definition hal.h:68
static void uint32_t