Add debug info and fix rolling code startup
This commit is contained in:
@@ -26,7 +26,7 @@ namespace esphome::ratgdo {
|
|||||||
using namespace protocol;
|
using namespace protocol;
|
||||||
|
|
||||||
static const char* const TAG = "ratgdo";
|
static const char* const TAG = "ratgdo";
|
||||||
static constexpr int SYNC_DELAY = 1000;
|
static constexpr int SYNC_DELAY = 5000;
|
||||||
// Door state updates arrive over UART every ~200-400ms during movement.
|
// Door state updates arrive over UART every ~200-400ms during movement.
|
||||||
// 2 seconds gives ample margin for slow openers while still expiring
|
// 2 seconds gives ample margin for slow openers while still expiring
|
||||||
// stale callbacks before a user could reasonably trigger an unrelated
|
// stale callbacks before a user could reasonably trigger an unrelated
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public:
|
|||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void on_shutdown() override;
|
void on_shutdown() override;
|
||||||
|
|
||||||
|
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
|
||||||
|
|
||||||
void init_protocol();
|
void init_protocol();
|
||||||
|
|
||||||
float start_opening { -1 };
|
float start_opening { -1 };
|
||||||
|
|||||||
@@ -68,22 +68,21 @@ namespace secplus2 {
|
|||||||
|
|
||||||
void Secplus2::sync_helper(uint32_t start, uint32_t delay, uint8_t tries)
|
void Secplus2::sync_helper(uint32_t start, uint32_t delay, uint8_t tries)
|
||||||
{
|
{
|
||||||
bool synced = true;
|
|
||||||
if (*this->ratgdo_->door_state == DoorState::UNKNOWN) {
|
if (*this->ratgdo_->door_state == DoorState::UNKNOWN) {
|
||||||
|
ESP_LOGD(TAG, "Sync: querying status (attempt %d)...", tries);
|
||||||
this->query_status();
|
this->query_status();
|
||||||
synced = false;
|
} else if (*this->ratgdo_->openings == 0) {
|
||||||
}
|
ESP_LOGD(TAG, "Sync: querying openings (attempt %d)...", tries);
|
||||||
if (*this->ratgdo_->openings == 0) {
|
|
||||||
this->query_openings();
|
this->query_openings();
|
||||||
synced = false;
|
} else {
|
||||||
}
|
ESP_LOGD(TAG, "Sync successful!");
|
||||||
|
|
||||||
if (synced) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tries == 2 && *this->ratgdo_->door_state == DoorState::UNKNOWN) { // made a few attempts and no progress (door state is the first sync request)
|
if (tries == 10 && *this->ratgdo_->door_state == DoorState::UNKNOWN) {
|
||||||
// increment rolling code counter by some amount in case we crashed without writing to flash the latest value
|
// After 10 failed attempts to even get status, try jumping the rolling code.
|
||||||
|
// This handles cases where the device rolling code is way behind the GDO.
|
||||||
|
ESP_LOGW(TAG, "Sync: jumping rolling code counter...");
|
||||||
this->increment_rolling_code_counter(MAX_CODES_WITHOUT_FLASH_WRITE);
|
this->increment_rolling_code_counter(MAX_CODES_WITHOUT_FLASH_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,17 +91,18 @@ namespace secplus2 {
|
|||||||
ESP_LOGW(TAG, "Triggering sync failed actions.");
|
ESP_LOGW(TAG, "Triggering sync failed actions.");
|
||||||
this->ratgdo_->sync_failed = true;
|
this->ratgdo_->sync_failed = true;
|
||||||
} else {
|
} else {
|
||||||
if (tries % 3 == 0) {
|
// Use a slightly longer delay between queries during sync to avoid bus saturation
|
||||||
delay *= 1.5;
|
uint32_t next_delay = (tries < 5) ? 1000 : 2000;
|
||||||
}
|
this->scheduler_->set_timeout(this->ratgdo_, TIMEOUT_SYNC, next_delay, [this, start, next_delay, tries]() {
|
||||||
this->scheduler_->set_timeout(this->ratgdo_, TIMEOUT_SYNC, delay, [this, start, delay, tries]() {
|
this->sync_helper(start, next_delay, tries + 1);
|
||||||
this->sync_helper(start, delay, tries + 1);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Secplus2::sync()
|
void Secplus2::sync()
|
||||||
{
|
{
|
||||||
|
ESP_LOGD(TAG, "Starting sync...");
|
||||||
|
this->ratgdo_->sync_failed = false;
|
||||||
this->scheduler_->cancel_timeout(this->ratgdo_, TIMEOUT_SYNC);
|
this->scheduler_->cancel_timeout(this->ratgdo_, TIMEOUT_SYNC);
|
||||||
this->sync_helper(millis(), 500, 0);
|
this->sync_helper(millis(), 500, 0);
|
||||||
}
|
}
|
||||||
@@ -268,6 +268,8 @@ namespace secplus2 {
|
|||||||
|
|
||||||
void Secplus2::handle_command(const Command& cmd)
|
void Secplus2::handle_command(const Command& cmd)
|
||||||
{
|
{
|
||||||
|
ESP_LOGD(TAG, "Handle command: %s (nibble=%01x byte1=%02x byte2=%02x)", LOG_STR_ARG(CommandType_to_string(cmd.type)), cmd.nibble, cmd.byte1, cmd.byte2);
|
||||||
|
|
||||||
if (cmd.type == CommandType::STATUS) {
|
if (cmd.type == CommandType::STATUS) {
|
||||||
|
|
||||||
this->ratgdo_->received(to_DoorState(cmd.nibble, DoorState::UNKNOWN));
|
this->ratgdo_->received(to_DoorState(cmd.nibble, DoorState::UNKNOWN));
|
||||||
|
|||||||
Reference in New Issue
Block a user