ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
dfrobot_sen0395.h
Go to the documentation of this file.
1#pragma once
2
6
7#ifdef USE_BINARY_SENSOR
9#endif
10#ifdef USE_SWITCH
12#endif
13
14#include "commands.h"
15
17
18const uint8_t MMWAVE_READ_BUFFER_LENGTH = 255;
19
20// forward declaration due to circular dependency
22
23static const uint8_t COMMAND_QUEUE_SIZE = 20;
24
26 public:
27 int8_t enqueue(std::unique_ptr<Command> cmd);
28 std::unique_ptr<Command> dequeue();
29 bool is_empty();
30 bool is_full();
31 uint8_t process(DfrobotSen0395Component *parent);
32
33 protected:
34 int front_{-1};
35 int rear_{-1};
36 std::unique_ptr<Command> commands_[COMMAND_QUEUE_SIZE];
37};
38
40#ifdef USE_SWITCH
41 SUB_SWITCH(sensor_active)
42 SUB_SWITCH(turn_on_led)
43 SUB_SWITCH(presence_via_uart)
44 SUB_SWITCH(start_after_boot)
45#endif
46
47 public:
48 void dump_config() override;
49 void loop() override;
50 void set_active(bool active) {
51 if (active != active_) {
52#ifdef USE_SWITCH
53 if (this->sensor_active_switch_ != nullptr)
54 this->sensor_active_switch_->publish_state(active);
55#endif
56 active_ = active;
57 }
58 }
59 bool is_active() { return active_; }
60
61 void set_led_active(bool active) {
62 if (led_active_ != active) {
63#ifdef USE_SWITCH
64 if (this->turn_on_led_switch_ != nullptr)
65 this->turn_on_led_switch_->publish_state(active);
66#endif
67 led_active_ = active;
68 }
69 }
70 bool is_led_active() { return led_active_; }
71
72 void set_uart_presence_active(bool active) {
73 uart_presence_active_ = active;
74#ifdef USE_SWITCH
75 if (this->presence_via_uart_switch_ != nullptr)
76 this->presence_via_uart_switch_->publish_state(active);
77#endif
78 }
79 bool is_uart_presence_active() { return uart_presence_active_; }
80
81 void set_start_after_boot(bool start) {
82 start_after_boot_ = start;
83#ifdef USE_SWITCH
84 if (this->start_after_boot_switch_ != nullptr)
85 this->start_after_boot_switch_->publish_state(start);
86#endif
87 }
88 bool does_start_after_boot() { return start_after_boot_; }
89
90#ifdef USE_BINARY_SENSOR
91 void set_detected_binary_sensor(binary_sensor::BinarySensor *detected_binary_sensor) {
92 detected_binary_sensor_ = detected_binary_sensor;
93 }
94#endif
95
96 int8_t enqueue(std::unique_ptr<Command> cmd);
97
98 protected:
99#ifdef USE_BINARY_SENSOR
101#endif
102
103 bool detected_{false};
104 bool active_{false};
105 bool led_active_{false};
107 bool start_after_boot_{false};
109 size_t read_pos_{0};
112
113 uint8_t read_message_();
114 uint8_t find_prompt_();
115 uint8_t send_cmd_(const char *cmd, uint32_t duration);
116
117 void set_detected_(bool detected);
118
119 friend class Command;
120 friend class ReadStateCommand;
121};
122
123} // namespace esphome::dfrobot_sen0395
virtual void dump_config()
Base class for all binary_sensor-type classes.
std::unique_ptr< Command > commands_[COMMAND_QUEUE_SIZE]
int8_t enqueue(std::unique_ptr< Command > cmd)
uint8_t process(DfrobotSen0395Component *parent)
binary_sensor::BinarySensor * detected_binary_sensor_
uint8_t send_cmd_(const char *cmd, uint32_t duration)
uint8_t duration
Definition msa3xx.h:0
const uint8_t MMWAVE_READ_BUFFER_LENGTH
static void uint32_t