diff --git a/arduino/cover/cover.ino b/arduino/cover/cover.ino index a79c798..acb8c83 100644 --- a/arduino/cover/cover.ino +++ b/arduino/cover/cover.ino @@ -64,6 +64,7 @@ class Cover { } void reset() { + InterruptGuard _{}; m_position.position = 0; m_position.close = 0; m_position.open = 0; @@ -184,21 +185,23 @@ class Cover { m_set_limits = SetLimit::CLOSE; break; case Direction::STOP: - switch (m_set_limits) { - case SetLimit::OPEN: - m_position.open = position; - break; - case SetLimit::CLOSE: - m_position.close = position; - break; - case SetLimit::NONE: - break; + { + InterruptGuard _{}; + switch (m_set_limits) { + case SetLimit::OPEN: + m_position.open = position; + break; + case SetLimit::CLOSE: + m_position.close = position; + break; + case SetLimit::NONE: + break; + } + m_set_limits = SetLimit::NONE; + // Save settings to EEPROM. Update will not touch the EEPROM if the data is the same so + // it's safe to put it here. + EEPROM.updateBlock(0, m_position); } - m_set_limits = SetLimit::NONE; - // Save settings to EEPROM. Update will not touch the EEPROM if the data is the same so - // it's safe to put it here. - InterruptGuard _{}; - EEPROM.updateBlock(0, m_position); break; } } @@ -231,7 +234,7 @@ class Cover { void debug() const { Serial.print(F("position=")); - Serial.println(m_position.position); + Serial.println(get_position()); Serial.print(F("open=")); Serial.println(m_position.open); Serial.print(F("close="));