diff --git a/esphome/components/pn532/pn532.cpp b/esphome/components/pn532/pn532.cpp index 1ab0da3df7..199a44dacc 100644 --- a/esphome/components/pn532/pn532.cpp +++ b/esphome/components/pn532/pn532.cpp @@ -308,13 +308,13 @@ void PN532::send_nack_() { enum PN532ReadReady PN532::read_ready_(bool block) { if (this->rd_ready_ == READY) { if (block) { - this->rd_start_time_ = 0; + this->rd_start_time_.reset(); this->rd_ready_ = WOULDBLOCK; } return READY; } - if (!this->rd_start_time_) { + if (!this->rd_start_time_.has_value()) { this->rd_start_time_ = millis(); } @@ -324,7 +324,7 @@ enum PN532ReadReady PN532::read_ready_(bool block) { break; } - if (millis() - this->rd_start_time_ > 100) { + if (millis() - *this->rd_start_time_ > 100) { ESP_LOGV(TAG, "Timed out waiting for readiness from PN532!"); this->rd_ready_ = TIMEOUT; break; @@ -340,7 +340,7 @@ enum PN532ReadReady PN532::read_ready_(bool block) { auto rdy = this->rd_ready_; if (block || rdy == TIMEOUT) { - this->rd_start_time_ = 0; + this->rd_start_time_.reset(); this->rd_ready_ = WOULDBLOCK; } return rdy; diff --git a/esphome/components/pn532/pn532.h b/esphome/components/pn532/pn532.h index f98c0f9322..e57ecd8104 100644 --- a/esphome/components/pn532/pn532.h +++ b/esphome/components/pn532/pn532.h @@ -99,7 +99,7 @@ class PN532 : public PollingComponent { std::vector triggers_ontagremoved_; nfc::NfcTagUid current_uid_; nfc::NdefMessage *next_task_message_to_write_; - uint32_t rd_start_time_{0}; + optional rd_start_time_{}; enum PN532ReadReady rd_ready_ { WOULDBLOCK }; enum NfcTask { READ = 0,