mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 23:48:11 +01:00
fix formatting
This commit is contained in:
parent
6705f3b898
commit
0c0f2bf58e
2 changed files with 124 additions and 127 deletions
|
@ -60,8 +60,8 @@ bool TimeBasedTiltCover::is_at_target_tilt_() const {
|
|||
}
|
||||
|
||||
void TimeBasedTiltCover::loop() {
|
||||
|
||||
if ( this->fsm_state_ == STATE_IDLE && this->target_position_ == TARGET_NONE && this->target_tilt_ == TARGET_NONE ) return;
|
||||
if (this->fsm_state_ == STATE_IDLE && this->target_position_ == TARGET_NONE && this->target_tilt_ == TARGET_NONE)
|
||||
return;
|
||||
|
||||
const uint32_t now = millis();
|
||||
|
||||
|
@ -78,7 +78,8 @@ void TimeBasedTiltCover::loop() {
|
|||
this->stop_trigger_->trigger();
|
||||
if (this->current_operation != COVER_OPERATION_IDLE) {
|
||||
this->interlocked_time = millis();
|
||||
this->interlocked_direction = this->current_operation == COVER_OPERATION_CLOSING ? COVER_OPERATION_OPENING : COVER_OPERATION_CLOSING;
|
||||
this->interlocked_direction =
|
||||
this->current_operation == COVER_OPERATION_CLOSING ? COVER_OPERATION_OPENING : COVER_OPERATION_CLOSING;
|
||||
} else {
|
||||
this->interlocked_direction = COVER_OPERATION_IDLE;
|
||||
}
|
||||
|
@ -91,15 +92,15 @@ void TimeBasedTiltCover::loop() {
|
|||
|
||||
// if the cover is not moving, check whether the new targets are set and if they are, compute move direction
|
||||
if (this->fsm_state_ == STATE_IDLE && (this->target_position_ != TARGET_NONE || this->target_tilt_ != TARGET_NONE)) {
|
||||
|
||||
if (this->target_position_ != TARGET_NONE) {
|
||||
this->current_operation = this->compute_direction(this->target_position_, this->position);
|
||||
} else {
|
||||
this->current_operation = this->compute_direction(this->target_tilt_, this->tilt);
|
||||
}
|
||||
// interlocking support
|
||||
if ( this->current_operation == this->interlocked_direction
|
||||
&& now - this->interlocked_time < this->interlock_wait_time_ ) return;
|
||||
if (this->current_operation == this->interlocked_direction &&
|
||||
now - this->interlocked_time < this->interlock_wait_time_)
|
||||
return;
|
||||
|
||||
Trigger<> *trig = this->current_operation == COVER_OPERATION_CLOSING ? this->close_trigger_ : this->open_trigger_;
|
||||
|
||||
|
@ -112,12 +113,12 @@ void TimeBasedTiltCover::loop() {
|
|||
|
||||
// moving state
|
||||
if (this->fsm_state_ == STATE_MOVING) {
|
||||
|
||||
auto travel_time = now - this->last_recompute_time_;
|
||||
this->last_recompute_time_ = now;
|
||||
|
||||
float dir_factor = this->current_operation == COVER_OPERATION_CLOSING ? -1.0 : 1.0;
|
||||
auto inertia_time = this->current_operation == COVER_OPERATION_CLOSING ? this->inertia_close_time_ : this->inertia_open_time_ ;
|
||||
auto inertia_time =
|
||||
this->current_operation == COVER_OPERATION_CLOSING ? this->inertia_close_time_ : this->inertia_open_time_;
|
||||
|
||||
if (inertia_time > 0 && this->inertia * dir_factor < 0.5f) { // inertia before movement
|
||||
auto inertia_step = dir_factor * travel_time / inertia_time;
|
||||
|
@ -125,11 +126,13 @@ void TimeBasedTiltCover::loop() {
|
|||
auto rest = this->inertia - clamp(this->inertia, -0.5f, 0.5f);
|
||||
this->inertia = clamp(this->inertia, -0.5f, 0.5f);
|
||||
|
||||
if ( ! rest ) return; // the movement has not yet actually started
|
||||
if (!rest)
|
||||
return; // the movement has not yet actually started
|
||||
travel_time = dir_factor * rest * inertia_time; // actual movement time taking inertia into account
|
||||
}
|
||||
|
||||
auto tilt_time = this->current_operation == COVER_OPERATION_CLOSING ? this->tilt_close_duration_ : this->tilt_open_duration_;
|
||||
auto tilt_time =
|
||||
this->current_operation == COVER_OPERATION_CLOSING ? this->tilt_close_duration_ : this->tilt_open_duration_;
|
||||
|
||||
if (tilt_time > 0 && (this->tilt - 0.5f) * dir_factor < 0.5f) { // tilting before movement
|
||||
auto tilt_step = dir_factor * travel_time / tilt_time;
|
||||
|
@ -145,8 +148,7 @@ void TimeBasedTiltCover::loop() {
|
|||
// If the cover is in extreme positions, run recalibration
|
||||
if (this->recalibration_time_ > 0 &&
|
||||
(((this->position == COVER_CLOSED && (tilt_time == 0 || this->tilt == COVER_CLOSED)) ||
|
||||
(this->position == COVER_OPEN && (tilt_time == 0 || this->tilt == COVER_OPEN)))))
|
||||
{
|
||||
(this->position == COVER_OPEN && (tilt_time == 0 || this->tilt == COVER_OPEN))))) {
|
||||
this->fsm_state_ = STATE_CALIBRATING;
|
||||
this->publish_state(false);
|
||||
} else {
|
||||
|
@ -161,7 +163,8 @@ void TimeBasedTiltCover::loop() {
|
|||
this->last_publish_time_ = now;
|
||||
}
|
||||
|
||||
if ( ! rest ) return; // the movement has not yet actually started
|
||||
if (!rest)
|
||||
return; // the movement has not yet actually started
|
||||
|
||||
travel_time = dir_factor * rest * tilt_time; // actual movement time taking tilt into account
|
||||
}
|
||||
|
@ -182,8 +185,7 @@ void TimeBasedTiltCover::loop() {
|
|||
// If the cover is in extreme positions, run recalibration
|
||||
if (this->recalibration_time_ > 0 &&
|
||||
(((this->position == COVER_CLOSED && (tilt_time == 0 || this->tilt == COVER_CLOSED)) ||
|
||||
(this->position == COVER_OPEN && (tilt_time == 0 || this->tilt == COVER_OPEN)))))
|
||||
{
|
||||
(this->position == COVER_OPEN && (tilt_time == 0 || this->tilt == COVER_OPEN))))) {
|
||||
this->fsm_state_ = STATE_CALIBRATING;
|
||||
this->publish_state(false);
|
||||
} else {
|
||||
|
@ -196,7 +198,6 @@ void TimeBasedTiltCover::loop() {
|
|||
this->last_publish_time_ = now;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float TimeBasedTiltCover::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
@ -236,8 +237,7 @@ void TimeBasedTiltCover::control(const CoverCall &call) {
|
|||
direction = this->compute_direction(this->target_tilt_, this->tilt);
|
||||
}
|
||||
|
||||
if (direction != this->current_operation )
|
||||
{
|
||||
if (direction != this->current_operation) {
|
||||
this->fsm_state_ = STATE_STOPPING;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@ class TimeBasedTiltCover : public cover::Cover, public Component {
|
|||
void set_recalibration_time(uint32_t recalibration_time) { this->recalibration_time_ = recalibration_time; }
|
||||
void set_inertia_open_time(uint32_t inertia_time) { this->inertia_open_time_ = inertia_time; }
|
||||
void set_inertia_close_time(uint32_t inertia_time) { this->inertia_close_time_ = inertia_time; }
|
||||
cover::CoverOperation compute_direction(float target, float current) { return target < current ? cover::COVER_OPERATION_CLOSING : cover::COVER_OPERATION_OPENING ; };
|
||||
cover::CoverOperation compute_direction(float target, float current) {
|
||||
return target < current ? cover::COVER_OPERATION_CLOSING : cover::COVER_OPERATION_OPENING;
|
||||
};
|
||||
float round_position(float pos) { return round(100 * pos) / 100; };
|
||||
cover::CoverTraits get_traits() override;
|
||||
void set_assumed_state(bool value) { this->assumed_state_ = value; }
|
||||
|
@ -51,12 +53,7 @@ class TimeBasedTiltCover : public cover::Cover, public Component {
|
|||
uint32_t inertia_close_time_;
|
||||
|
||||
const static float TARGET_NONE;
|
||||
enum State : uint8_t {
|
||||
STATE_IDLE,
|
||||
STATE_MOVING,
|
||||
STATE_STOPPING,
|
||||
STATE_CALIBRATING
|
||||
};
|
||||
enum State : uint8_t { STATE_IDLE, STATE_MOVING, STATE_STOPPING, STATE_CALIBRATING };
|
||||
|
||||
uint32_t last_recompute_time_{0};
|
||||
uint32_t last_publish_time_{0};
|
||||
|
|
Loading…
Reference in a new issue