From 53d9c6273218947487c20c1977f48cbbab2eec6d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 9 Jun 2023 18:43:43 -0500 Subject: [PATCH] button --- components/ratgdo/ratgdo.cpp | 5 ++++- components/ratgdo/ratgdo.h | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 6af39b1..ab9ebfc 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -477,7 +477,10 @@ namespace ratgdo { { transmit(command); this->pref_.save(&this->rollingCodeCounter); - global_preferences->sync(); + if (!this->lastSyncedRollingCodeCounter || this->rollingCodeCounter - this->lastSyncedRollingCodeCounter > 2) { + this->lastSyncedRollingCodeCounter = this->rollingCodeCounter; + global_preferences->sync(); + } } void RATGDOComponent::register_child(RATGDOClient* obj) diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 00a4552..0de83a9 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -82,9 +82,11 @@ namespace ratgdo { void loop() override; void dump_config() override; - uint32_t rollingCodeCounter; + uint32_t rollingCodeCounter{ 0}; + uint32_t lastSyncedRollingCodeCounter{ 0}; + uint16_t previousOpenings { 0 }; // number of times the door has been opened - uint16_t openings; // number of times the door has been opened + uint16_t openings{0}; // number of times the door has been opened uint8_t txRollingCode[CODE_LENGTH]; uint8_t rxRollingCode[CODE_LENGTH];