10static const char *
const TAG =
"he60r.cover";
11static const uint8_t QUERY_BYTE = 0x38;
12static const uint8_t TOGGLE_BYTE = 0x30;
19 if (restore.has_value()) {
33 traits.set_supports_stop(
true);
34 traits.set_supports_position(
true);
35 traits.set_supports_toggle(
true);
36 traits.set_is_assumed_state(
false);
41 LOG_COVER(
"",
"HE60R Cover",
this);
44 " Open Duration: %.1fs\n"
45 " Close Duration: %.1fs",
48 if (restore.has_value())
49 ESP_LOGCONFIG(TAG,
" Saved position %d%%", (
int) (restore->position * 100.f));
53 const uint32_t now =
millis();
62 ESP_LOGD(TAG,
"'%s' - %s endstop reached. Took %.1fs.", this->
name_.
c_str(),
78 ESP_LOGV(TAG,
"Process RX data %X", data);
82 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()) {
176 auto pos = *
call.get_position();
213 ESP_LOGD(TAG,
"'%s' - Direction '%s' requested.", this->
name_.
c_str(),
229 ESP_LOGD(TAG,
"'%s' - Reversing direction.", this->
name_.
c_str());
238 const uint32_t now =
millis();
255 ESP_LOGD(TAG,
"Recompute %ums, dir=%u, delta=%f, pos=%f", diff, this->
current_operation, delta, new_position);
257 if (this->
position != new_position) {
void set_interval(const std::string &name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
constexpr const char * c_str() const
const optional< bool > & get_toggle() const
const optional< float > & get_position() 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)
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
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)
@ UART_CONFIG_PARITY_EVEN
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT millis()
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)