Use received door state for 2nd door toggle in sec+1.0
This commit is contained in:
parent
9a4cfe3c56
commit
02319d49a5
|
@ -13,15 +13,17 @@ namespace ratgdo {
|
||||||
class OnceCallbacks<void(Ts...)> {
|
class OnceCallbacks<void(Ts...)> {
|
||||||
public:
|
public:
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
void then(Callback&& callback) { this->callbacks_.push_back(std::forward<Callback>(callback)); }
|
void operator()(Callback&& callback) { this->callbacks_.push_back(std::forward<Callback>(callback)); }
|
||||||
|
|
||||||
void operator()(Ts... args)
|
void trigger(Ts... args)
|
||||||
{
|
{
|
||||||
for (auto& cb : this->callbacks_)
|
for (auto& cb : this->callbacks_)
|
||||||
cb(args...);
|
cb(args...);
|
||||||
this->callbacks_.clear();
|
this->callbacks_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::function<void(Ts...)>> callbacks_;
|
std::vector<std::function<void(Ts...)>> callbacks_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -187,7 +187,7 @@ namespace ratgdo {
|
||||||
}
|
}
|
||||||
|
|
||||||
this->door_state = door_state;
|
this->door_state = door_state;
|
||||||
this->door_state_received(door_state);
|
this->on_door_state_.trigger(door_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::received(const LearnState learn_state)
|
void RATGDOComponent::received(const LearnState learn_state)
|
||||||
|
@ -442,7 +442,7 @@ namespace ratgdo {
|
||||||
if (*this->door_state == DoorState::OPENING) {
|
if (*this->door_state == DoorState::OPENING) {
|
||||||
// have to stop door first, otherwise close command is ignored
|
// have to stop door first, otherwise close command is ignored
|
||||||
this->door_action(DoorAction::STOP);
|
this->door_action(DoorAction::STOP);
|
||||||
this->door_state_received.then([=](DoorState s) {
|
this->on_door_state_([=](DoorState s) {
|
||||||
if (s == DoorState::STOPPED) {
|
if (s == DoorState::STOPPED) {
|
||||||
this->door_action(DoorAction::CLOSE);
|
this->door_action(DoorAction::CLOSE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -487,7 +487,7 @@ namespace ratgdo {
|
||||||
ESP_LOGW(TAG, "It's not recommended to use ensure_door_action with non-idempotent commands such as DOOR_TOGGLE");
|
ESP_LOGW(TAG, "It's not recommended to use ensure_door_action with non-idempotent commands such as DOOR_TOGGLE");
|
||||||
}
|
}
|
||||||
auto prev_door_state = *this->door_state;
|
auto prev_door_state = *this->door_state;
|
||||||
this->door_state_received.then([=](DoorState s) {
|
this->on_door_state_([=](DoorState s) {
|
||||||
if ((action == DoorAction::STOP) && (s != DoorState::STOPPED) && !(prev_door_state == DoorState::OPENING && s == DoorState::OPEN) && !(prev_door_state == DoorState::CLOSING && s == DoorState::CLOSED)) {
|
if ((action == DoorAction::STOP) && (s != DoorState::STOPPED) && !(prev_door_state == DoorState::OPENING && s == DoorState::OPEN) && !(prev_door_state == DoorState::CLOSING && s == DoorState::CLOSED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -512,7 +512,7 @@ namespace ratgdo {
|
||||||
{
|
{
|
||||||
if (*this->door_state == DoorState::OPENING || *this->door_state == DoorState::CLOSING) {
|
if (*this->door_state == DoorState::OPENING || *this->door_state == DoorState::CLOSING) {
|
||||||
this->door_action(DoorAction::STOP);
|
this->door_action(DoorAction::STOP);
|
||||||
this->door_state_received.then([=](DoorState s) {
|
this->on_door_state_([=](DoorState s) {
|
||||||
if (s == DoorState::STOPPED) {
|
if (s == DoorState::STOPPED) {
|
||||||
this->door_move_to_position(position);
|
this->door_move_to_position(position);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace ratgdo {
|
||||||
observable<MotionState> motion_state { MotionState::UNKNOWN };
|
observable<MotionState> motion_state { MotionState::UNKNOWN };
|
||||||
observable<LearnState> learn_state { LearnState::UNKNOWN };
|
observable<LearnState> learn_state { LearnState::UNKNOWN };
|
||||||
|
|
||||||
OnceCallbacks<void(DoorState)> door_state_received;
|
OnceCallbacks<void(DoorState)> on_door_state_;
|
||||||
|
|
||||||
observable<bool> sync_failed { false };
|
observable<bool> sync_failed { false };
|
||||||
|
|
||||||
|
|
|
@ -154,8 +154,10 @@ namespace secplus1 {
|
||||||
} else if (this->door_state == DoorState::STOPPED) {
|
} else if (this->door_state == DoorState::STOPPED) {
|
||||||
this->toggle_door(); // this starts closing door
|
this->toggle_door(); // this starts closing door
|
||||||
// this changes direction of door
|
// this changes direction of door
|
||||||
this->scheduler_->set_timeout(this->ratgdo_, "", double_toggle_delay, [=] {
|
this->on_door_state_([=](DoorState s) {
|
||||||
this->toggle_door();
|
if (s==DoorState::CLOSING) {
|
||||||
|
this->toggle_door();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (action == DoorAction::CLOSE) {
|
} else if (action == DoorAction::CLOSE) {
|
||||||
|
@ -164,8 +166,10 @@ namespace secplus1 {
|
||||||
} else if (this->door_state == DoorState::OPENING) {
|
} else if (this->door_state == DoorState::OPENING) {
|
||||||
this->toggle_door(); // this switches to stopped
|
this->toggle_door(); // this switches to stopped
|
||||||
// another toggle needed to close
|
// another toggle needed to close
|
||||||
this->scheduler_->set_timeout(this->ratgdo_, "", double_toggle_delay, [=] {
|
this->on_door_state_([=](DoorState s) {
|
||||||
this->toggle_door();
|
if (s==DoorState::STOPPED) {
|
||||||
|
this->toggle_door();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else if (this->door_state == DoorState::STOPPED) {
|
} else if (this->door_state == DoorState::STOPPED) {
|
||||||
this->toggle_door();
|
this->toggle_door();
|
||||||
|
@ -175,9 +179,12 @@ namespace secplus1 {
|
||||||
this->toggle_door();
|
this->toggle_door();
|
||||||
} else if (this->door_state == DoorState::CLOSING) {
|
} else if (this->door_state == DoorState::CLOSING) {
|
||||||
this->toggle_door(); // this switches to opening
|
this->toggle_door(); // this switches to opening
|
||||||
|
|
||||||
// another toggle needed to stop
|
// another toggle needed to stop
|
||||||
this->scheduler_->set_timeout(this->ratgdo_, "", double_toggle_delay, [=] {
|
this->on_door_state_([=](DoorState s) {
|
||||||
this->toggle_door();
|
if (s==DoorState::OPENING) {
|
||||||
|
this->toggle_door();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +203,7 @@ namespace secplus1 {
|
||||||
void Secplus1::toggle_door()
|
void Secplus1::toggle_door()
|
||||||
{
|
{
|
||||||
this->enqueue_transmit(CommandType::TOGGLE_DOOR_PRESS);
|
this->enqueue_transmit(CommandType::TOGGLE_DOOR_PRESS);
|
||||||
this->enqueue_transmit(CommandType::QUERY_DOOR_STATUS);
|
// this->enqueue_transmit(CommandType::QUERY_DOOR_STATUS);
|
||||||
if (this->door_state == DoorState::STOPPED || this->door_state == DoorState::OPEN || this->door_state == DoorState::CLOSED) {
|
if (this->door_state == DoorState::STOPPED || this->door_state == DoorState::OPEN || this->door_state == DoorState::CLOSED) {
|
||||||
this->door_moving_ = true;
|
this->door_moving_ = true;
|
||||||
}
|
}
|
||||||
|
@ -319,9 +326,14 @@ namespace secplus1 {
|
||||||
door_state = DoorState::UNKNOWN;
|
door_state = DoorState::UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->maybe_door_state != door_state) {
|
||||||
|
this->on_door_state_.trigger(door_state);
|
||||||
|
}
|
||||||
|
|
||||||
if (!this->is_0x37_panel_ && door_state != this->maybe_door_state) {
|
if (!this->is_0x37_panel_ && door_state != this->maybe_door_state) {
|
||||||
this->maybe_door_state = door_state;
|
this->maybe_door_state = door_state;
|
||||||
} else {
|
} else {
|
||||||
|
this->maybe_door_state = door_state;
|
||||||
this->door_state = door_state;
|
this->door_state = door_state;
|
||||||
if (this->door_state == DoorState::STOPPED || this->door_state == DoorState::OPEN || this->door_state == DoorState::CLOSED) {
|
if (this->door_state == DoorState::STOPPED || this->door_state == DoorState::OPEN || this->door_state == DoorState::CLOSED) {
|
||||||
this->door_moving_ = false;
|
this->door_moving_ = false;
|
||||||
|
|
|
@ -115,6 +115,8 @@ namespace secplus1 {
|
||||||
LockState maybe_lock_state { LockState::UNKNOWN };
|
LockState maybe_lock_state { LockState::UNKNOWN };
|
||||||
DoorState maybe_door_state { DoorState::UNKNOWN };
|
DoorState maybe_door_state { DoorState::UNKNOWN };
|
||||||
|
|
||||||
|
OnceCallbacks<void(DoorState)> on_door_state_;
|
||||||
|
|
||||||
bool door_moving_ { false };
|
bool door_moving_ { false };
|
||||||
|
|
||||||
bool wall_panel_starting_ { false };
|
bool wall_panel_starting_ { false };
|
||||||
|
|
|
@ -471,7 +471,7 @@ namespace secplus2 {
|
||||||
|
|
||||||
void Secplus2::send_command(Command command, IncrementRollingCode increment, std::function<void()>&& on_sent)
|
void Secplus2::send_command(Command command, IncrementRollingCode increment, std::function<void()>&& on_sent)
|
||||||
{
|
{
|
||||||
this->command_sent_.then(on_sent);
|
this->on_command_sent_(on_sent);
|
||||||
this->send_command(command, increment);
|
this->send_command(command, increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,7 +521,7 @@ namespace secplus2 {
|
||||||
|
|
||||||
this->transmit_pending_ = false;
|
this->transmit_pending_ = false;
|
||||||
this->transmit_pending_start_ = 0;
|
this->transmit_pending_start_ = 0;
|
||||||
this->command_sent_();
|
this->on_command_sent_.trigger();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ namespace secplus2 {
|
||||||
bool transmit_pending_ { false };
|
bool transmit_pending_ { false };
|
||||||
uint32_t transmit_pending_start_ { 0 };
|
uint32_t transmit_pending_start_ { 0 };
|
||||||
WirePacket tx_packet_;
|
WirePacket tx_packet_;
|
||||||
OnceCallbacks<void()> command_sent_;
|
OnceCallbacks<void()> on_command_sent_;
|
||||||
|
|
||||||
ProtocolTraits traits_;
|
ProtocolTraits traits_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue