Browse Source

wifi: fix blocking-delay oopsie

blockingDelay uses inverse logic; passed function should return false
when the condition is satisfied
only broken on 2.7.x, 3.x.x skips the check
pull/2552/head
Maxim Prokhorov 1 year ago
parent
commit
af12762eb6
2 changed files with 12 additions and 9 deletions
  1. +5
    -5
      code/espurna/system.cpp
  2. +7
    -4
      code/espurna/wifi.cpp

+ 5
- 5
code/espurna/system.cpp View File

@ -306,13 +306,13 @@ namespace time {
// plus, another helper when there are no external blocking checker
bool tryDelay(CoreClock::time_point start, CoreClock::duration timeout, CoreClock::duration interval) {
auto expired = CoreClock::now() - start;
if (expired >= timeout) {
return true;
auto elapsed = CoreClock::now() - start;
if (elapsed < timeout) {
delay(std::min((timeout - elapsed), interval));
return false;
}
delay(std::min((timeout - expired), interval));
return false;
return true;
}
void blockingDelay(CoreClock::duration timeout, CoreClock::duration interval) {


+ 7
- 4
code/espurna/wifi.cpp View File

@ -266,7 +266,7 @@ uint8_t opmode() {
}
void ensure_opmode(uint8_t mode) {
auto is_set = [&]() {
const auto is_set = [&]() {
return (opmode() == mode);
};
@ -276,10 +276,13 @@ void ensure_opmode(uint8_t mode) {
if (!is_set()) {
wifi_set_opmode_current(mode);
espurna::time::blockingDelay(
espurna::duration::Seconds(1),
espurna::duration::Milliseconds(10),
is_set);
espurna::duration::Seconds(1),
espurna::duration::Milliseconds(10),
[&]() {
return !is_set();
});
if (!is_set()) {
abort();


Loading…
Cancel
Save