9static const char *
const TAG =
"he60r.cover";
10static const uint8_t QUERY_BYTE = 0x38;
11static const uint8_t TOGGLE_BYTE = 0x30;
18 if (restore.has_value()) {
32 traits.set_supports_stop(
true);
33 traits.set_supports_position(
true);
34 traits.set_supports_toggle(
true);
35 traits.set_is_assumed_state(
false);
40 LOG_COVER(
"",
"HE60R Cover",
this);
42 " Open Duration: %.1fs\n"
43 " Close Duration: %.1fs",
46 if (restore.has_value()) {
47 ESP_LOGCONFIG(TAG,
" Saved position %d%%", (
int) (restore->position * 100.f));
61 ESP_LOGD(TAG,
"'%s' - %s endstop reached. Took %.1fs.", this->
name_.
c_str(),
77 ESP_LOGV(TAG,
"Process RX data %X", data);
81 ESP_LOGD(TAG,
"RX Byte %02X", data);
131 if ((this->
counter_++ & 0x3) == 0) {
133 ESP_LOGD(TAG,
"Writing byte 0x30, still needed=%u", this->
toggles_needed_);
165 if (
call.get_stop()) {
175 auto pos_opt =
call.get_position();
176 if (!pos_opt.has_value())
216 ESP_LOGD(TAG,
"'%s' - Direction '%s' requested.", this->
name_.
c_str(),
219 : LOG_STR_LITERAL(
"STOP"));
232 ESP_LOGD(TAG,
"'%s' - Reversing direction.", this->
name_.
c_str());
257 auto new_position = clamp(delta + this->
position, COVER_CLOSED + 0.01f, COVER_OPEN - 0.01f);
258 ESP_LOGD(TAG,
"Recompute %ums, dir=%u, delta=%f, pos=%f", diff, this->
current_operation, delta, new_position);
260 if (this->
position != new_position) {
void set_interval(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a const char* name.
constexpr const char * c_str() const
const optional< bool > & get_toggle() const
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
optional< CoverRestoreState > restore_state_()
void publish_state(bool save=true)
Publish the current state of the cover.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
bool is_at_target_() const
Check if the cover has reached or passed the target position.
void control(const cover::CoverCall &call) override
cover::CoverOperation last_command_
cover::CoverTraits get_traits() override
void recompute_position_()
void endstop_reached_(cover::CoverOperation operation)
uint32_t last_recompute_time_
void set_current_operation_(cover::CoverOperation operation)
void process_rx_(uint8_t data)
cover::CoverOperation next_direction_
void dump_config() override
void start_direction_(cover::CoverOperation dir)
bool read_byte(uint8_t *data)
void write_byte(uint8_t data)
CoverOperation
Enum encoding the current operation of a cover.
@ COVER_OPERATION_OPENING
The cover is currently opening.
@ COVER_OPERATION_CLOSING
The cover is currently closing.
@ COVER_OPERATION_IDLE
The cover is currently idle (not moving)
uint32_t IRAM_ATTR HOT millis()