11static const char *
const TAG =
"tormatic.cover";
15static constexpr uint32_t DRAIN_TIMEOUT_MS = 15;
21 if (restore.has_value()) {
32 traits.set_supports_stop(
true);
33 traits.set_supports_position(
true);
34 traits.set_is_assumed_state(
false);
39 LOG_COVER(
"",
"Tormatic Cover",
this);
43 " Open Duration: %.1fs\n"
44 " Close Duration: %.1fs",
48 if (restore.has_value()) {
49 ESP_LOGCONFIG(TAG,
" Saved position %d%%", (
int) (restore->position * 100.f));
58 auto status = o_status.value();
69 if (
call.get_stop()) {
74 auto pos_val =
call.get_position();
75 if (pos_val.has_value()) {
108 ESP_LOGD(TAG,
"Gate paused, clearing direction start time");
116 ESP_LOGD(TAG,
"Gate started moving from fully open or closed state");
128 ESP_LOGI(TAG,
"Recalibrated the gate's open duration to %" PRIu32
"ms", this->
open_duration_);
132 ESP_LOGI(TAG,
"Recalibrated the gate's close duration to %" PRIu32
"ms", this->
close_duration_);
198 this->last_recompute_time_ = now;
209 if (target == COVER_OPEN) {
210 ESP_LOGI(TAG,
"Fully opening gate");
214 if (target == COVER_CLOSED) {
215 ESP_LOGI(TAG,
"Fully closing gate");
225 ESP_LOGI(TAG,
"Opening gate towards %.1f", target);
231 ESP_LOGI(TAG,
"Closing gate towards %.1f", target);
278 ESP_LOGW(TAG,
"Unexpected payload size %" PRIu32
", flushing rx buffer", this->
pending_hdr_->payload_size());
296 ESP_LOGE(TAG,
"Header specifies payload size %" PRIu32
" but size of StatusReply is %zu", hdr.payload_size(),
307 return o_status->state;
321 ESP_LOGE(TAG,
"Reading remaining %" PRIu32
" payload bytes of unknown type 0x%x", hdr.payload_size(), hdr.type);
333 ESP_LOGV(TAG,
"Requesting gate status");
350 out.insert(out.end(), reqv.begin(), reqv.end());
359 auto ok = this->
read_array((uint8_t *) &obj,
sizeof(obj));
366 ESP_LOGV(TAG,
"Read %s in %" PRIu32
" ms", obj.print().c_str(),
millis() - start);
377 for (uint16_t i = 0; i < n; i++) {
384 while (
millis() - start < DRAIN_TIMEOUT_MS) {
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).
optional< GateStatus > read_gate_status_()
void dump_config() override
void send_message_(MessageType t, T r)
GateStatus current_status_
void recalibrate_duration_(GateStatus s)
uint32_t direction_start_time_
optional< MessageHeader > pending_hdr_
void drain_rx_(uint16_t n=0)
void request_gate_status_()
optional< float > target_position_
void recompute_position_()
void send_gate_command_(GateStatus s)
void control(const cover::CoverCall &call) override
optional< T > read_data_()
void control_position_(float target)
void handle_gate_status_(GateStatus s)
uint32_t last_publish_time_
uint32_t last_recompute_time_
cover::CoverTraits get_traits() override
void publish_state(bool save=true, uint32_t ratelimit=0)
optional< std::array< uint8_t, N > > read_array()
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_array(const uint8_t *data, size_t len)
@ 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)
CoverOperation gate_status_to_cover_operation(GateStatus s)
std::vector< uint8_t > serialize(T obj)
const char * gate_status_to_str(GateStatus s)
@ UART_CONFIG_PARITY_NONE
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT millis()