Merge branch 'wifi-cache-is-connected' into integration

This commit is contained in:
J. Nick Koston
2026-03-04 08:21:08 -10:00
12 changed files with 48 additions and 33 deletions
@@ -361,7 +361,7 @@ void FingerprintGrowComponent::aura_led_control(uint8_t state, uint8_t speed, ui
}
}
uint8_t FingerprintGrowComponent::transfer_(std::vector<uint8_t> *p_data_buffer) {
uint8_t FingerprintGrowComponent::transfer_(std::vector<uint8_t> &data_buffer) {
while (this->available())
this->read();
this->write((uint8_t) (START_CODE >> 8));
@@ -372,12 +372,12 @@ uint8_t FingerprintGrowComponent::transfer_(std::vector<uint8_t> *p_data_buffer)
this->write(this->address_[3]);
this->write(COMMAND);
uint16_t wire_length = p_data_buffer->size() + 2;
uint16_t wire_length = data_buffer.size() + 2;
this->write((uint8_t) (wire_length >> 8));
this->write((uint8_t) (wire_length & 0xFF));
uint16_t sum = (wire_length >> 8) + (wire_length & 0xFF) + COMMAND;
for (auto data : *p_data_buffer) {
for (auto data : data_buffer) {
this->write(data);
sum += data;
}
@@ -385,7 +385,7 @@ uint8_t FingerprintGrowComponent::transfer_(std::vector<uint8_t> *p_data_buffer)
this->write((uint8_t) (sum >> 8));
this->write((uint8_t) (sum & 0xFF));
p_data_buffer->clear();
data_buffer.clear();
uint8_t byte;
uint16_t idx = 0, length = 0;
@@ -431,9 +431,9 @@ uint8_t FingerprintGrowComponent::transfer_(std::vector<uint8_t> *p_data_buffer)
length |= byte;
break;
default:
p_data_buffer->push_back(byte);
data_buffer.push_back(byte);
if ((idx - 8) == length) {
switch ((*p_data_buffer)[0]) {
switch (data_buffer[0]) {
case OK:
case NO_FINGER:
case IMAGE_FAIL:
@@ -453,25 +453,26 @@ uint8_t FingerprintGrowComponent::transfer_(std::vector<uint8_t> *p_data_buffer)
ESP_LOGE(TAG, "Reader failed to process request");
break;
default:
ESP_LOGE(TAG, "Unknown response received from reader: 0x%.2X", (*p_data_buffer)[0]);
ESP_LOGE(TAG, "Unknown response received from reader: 0x%.2X", data_buffer[0]);
break;
}
this->last_transfer_ms_ = millis();
return (*p_data_buffer)[0];
return data_buffer[0];
}
break;
}
idx++;
}
ESP_LOGE(TAG, "No response received from reader");
(*p_data_buffer)[0] = TIMEOUT;
data_buffer.clear();
data_buffer.push_back(TIMEOUT);
this->last_transfer_ms_ = millis();
return TIMEOUT;
}
uint8_t FingerprintGrowComponent::send_command_() {
this->sensor_wakeup_();
return this->transfer_(&this->data_);
return this->transfer_(this->data_);
}
void FingerprintGrowComponent::sensor_wakeup_() {
@@ -517,7 +518,7 @@ void FingerprintGrowComponent::sensor_wakeup_() {
std::vector<uint8_t> buffer = {VERIFY_PASSWORD, (uint8_t) (this->password_ >> 24), (uint8_t) (this->password_ >> 16),
(uint8_t) (this->password_ >> 8), (uint8_t) (this->password_ & 0xFF)};
if (this->transfer_(&buffer) != OK) {
if (this->transfer_(buffer) != OK) {
ESP_LOGE(TAG, "Wrong password");
}
}
@@ -169,7 +169,7 @@ class FingerprintGrowComponent : public PollingComponent, public uart::UARTDevic
bool set_password_();
bool get_parameters_();
void get_fingerprint_count_();
uint8_t transfer_(std::vector<uint8_t> *p_data_buffer);
uint8_t transfer_(std::vector<uint8_t> &data_buffer);
uint8_t send_command_();
void sensor_wakeup_();
void sensor_sleep_();
@@ -190,7 +190,7 @@ class FingerprintGrowComponent : public PollingComponent, public uart::UARTDevic
bool is_sensor_awake_ = false;
uint32_t last_transfer_ms_ = 0;
uint32_t last_aura_led_control_ = 0;
uint16_t last_aura_led_duration_ = 0;
uint32_t last_aura_led_duration_ = 0;
uint16_t system_identifier_code_ = 0;
uint32_t idle_period_to_sleep_ms_ = UINT32_MAX;
sensor::Sensor *fingerprint_count_sensor_{nullptr};
@@ -99,7 +99,7 @@ bool PN532::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_to_6
uint8_t &message_start_index) {
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
if (!(page_3_to_6.size() > p4_offset + 5)) {
if (!(page_3_to_6.size() > p4_offset + 6)) {
return false;
}
@@ -134,7 +134,7 @@ bool PN532::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, nfc::NdefMessage *
} else {
encoded.insert(encoded.begin() + 1, 0xFF);
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
}
encoded.push_back(0xFE);
+3 -3
View File
@@ -562,9 +562,9 @@ optional<size_t> PN7150::find_tag_uid_(const nfc::NfcTagUid &uid) {
}
void PN7150::purge_old_tags_() {
for (size_t i = 0; i < this->discovered_endpoint_.size(); i++) {
if (millis() - this->discovered_endpoint_[i].last_seen > this->tag_ttl_) {
this->erase_tag_(i);
for (size_t i = this->discovered_endpoint_.size(); i > 0; i--) {
if (millis() - this->discovered_endpoint_[i - 1].last_seen > this->tag_ttl_) {
this->erase_tag_(i - 1);
}
}
}
@@ -100,7 +100,7 @@ uint8_t PN7150::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_
uint8_t &message_start_index) {
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
if (!(page_3_to_6.size() > p4_offset + 5)) {
if (!(page_3_to_6.size() > p4_offset + 6)) {
return nfc::STATUS_FAILED;
}
@@ -135,7 +135,7 @@ uint8_t PN7150::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, const std::sha
} else {
encoded.insert(encoded.begin() + 1, 0xFF);
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
}
encoded.push_back(0xFE);
+3 -3
View File
@@ -589,9 +589,9 @@ optional<size_t> PN7160::find_tag_uid_(const nfc::NfcTagUid &uid) {
}
void PN7160::purge_old_tags_() {
for (size_t i = 0; i < this->discovered_endpoint_.size(); i++) {
if (millis() - this->discovered_endpoint_[i].last_seen > this->tag_ttl_) {
this->erase_tag_(i);
for (size_t i = this->discovered_endpoint_.size(); i > 0; i--) {
if (millis() - this->discovered_endpoint_[i - 1].last_seen > this->tag_ttl_) {
this->erase_tag_(i - 1);
}
}
}
@@ -100,7 +100,7 @@ uint8_t PN7160::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_
uint8_t &message_start_index) {
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
if (!(page_3_to_6.size() > p4_offset + 5)) {
if (!(page_3_to_6.size() > p4_offset + 6)) {
return nfc::STATUS_FAILED;
}
@@ -135,7 +135,7 @@ uint8_t PN7160::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, const std::sha
} else {
encoded.insert(encoded.begin() + 1, 0xFF);
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
}
encoded.push_back(0xFE);
@@ -44,9 +44,13 @@ bool ProntoData::operator==(const ProntoData &rhs) const {
std::vector<uint16_t> data1 = encode_pronto(data);
std::vector<uint16_t> data2 = encode_pronto(rhs.data);
if (data1.size() != data2.size() || data1.empty()) {
return false;
}
uint32_t total_diff = 0;
// Don't need to check the last one, it's the large gap at the end.
for (std::vector<uint16_t>::size_type i = 0; i < data1.size() - 1; ++i) {
for (size_t i = 0; i < data1.size() - 1; ++i) {
int diff = data2[i] - data1[i];
diff *= diff;
if (rhs.delta == -1 && diff > 9)
@@ -106,7 +106,7 @@ void RemoteReceiverComponent::setup() {
this->store_.filter_symbols = this->filter_symbols_;
this->store_.receive_size = this->receive_symbols_ * sizeof(rmt_symbol_word_t);
this->store_.buffer_size = std::max((event_size + this->store_.receive_size) * 2, this->buffer_size_);
this->store_.buffer = new uint8_t[this->buffer_size_];
this->store_.buffer = new uint8_t[this->store_.buffer_size];
error = rmt_receive(this->channel_, (uint8_t *) this->store_.buffer + event_size, this->store_.receive_size,
&this->store_.config);
if (error != ESP_OK) {
+2 -2
View File
@@ -186,7 +186,7 @@ void SX127x::configure_fsk_ook_() {
} else {
this->write_register_(REG_PREAMBLE_DETECT, PREAMBLE_DETECTOR_OFF);
}
this->write_register_(REG_PREAMBLE_SIZE_MSB, this->preamble_size_ >> 16);
this->write_register_(REG_PREAMBLE_SIZE_MSB, this->preamble_size_ >> 8);
this->write_register_(REG_PREAMBLE_SIZE_LSB, this->preamble_size_ & 0xFF);
// config sync generation and setup ook threshold
@@ -214,7 +214,7 @@ void SX127x::configure_lora_() {
// config preamble
if (this->preamble_size_ >= 6) {
this->write_register_(REG_PREAMBLE_LEN_MSB, this->preamble_size_ >> 16);
this->write_register_(REG_PREAMBLE_LEN_MSB, this->preamble_size_ >> 8);
this->write_register_(REG_PREAMBLE_LEN_LSB, this->preamble_size_ & 0xFF);
}
+10 -3
View File
@@ -725,6 +725,7 @@ void WiFiComponent::restart_adapter() {
void WiFiComponent::loop() {
this->wifi_loop_();
const uint32_t now = App.get_loop_component_start_time();
this->update_connected_state_();
if (this->has_sta()) {
#if defined(USE_WIFI_CONNECT_TRIGGER) || defined(USE_WIFI_DISCONNECT_TRIGGER)
@@ -776,7 +777,7 @@ void WiFiComponent::loop() {
}
case WIFI_COMPONENT_STATE_STA_CONNECTED: {
if (!this->is_connected()) {
if (!this->is_connected_()) {
ESP_LOGW(TAG, "Connection lost; reconnecting");
this->state_ = WIFI_COMPONENT_STATE_STA_CONNECTING;
this->retry_connect();
@@ -2119,15 +2120,21 @@ bool WiFiComponent::can_proceed() {
if (!this->has_sta() || this->state_ == WIFI_COMPONENT_STATE_DISABLED || this->ap_setup_) {
return true;
}
return this->is_connected();
return this->is_connected_();
}
#endif
void WiFiComponent::set_reboot_timeout(uint32_t reboot_timeout) { this->reboot_timeout_ = reboot_timeout; }
bool WiFiComponent::is_connected() const {
bool WiFiComponent::is_connected_() const {
return this->state_ == WIFI_COMPONENT_STATE_STA_CONNECTED &&
this->wifi_sta_connect_status_() == WiFiSTAConnectStatus::CONNECTED && !this->error_from_callback_;
}
void WiFiComponent::update_connected_state_() {
bool connected = this->is_connected_();
if (connected != this->connected_) {
this->connected_ = connected;
}
}
void WiFiComponent::set_power_save_mode(WiFiPowerSaveMode power_save) {
this->power_save_ = power_save;
#if defined(USE_ESP32) && defined(USE_WIFI_RUNTIME_POWER_SAVE)
+4 -1
View File
@@ -443,7 +443,7 @@ class WiFiComponent : public Component {
void set_reboot_timeout(uint32_t reboot_timeout);
bool is_connected() const;
bool is_connected() const { return this->connected_; }
void set_power_save_mode(WiFiPowerSaveMode power_save);
void set_min_auth_mode(WifiMinAuthMode min_auth_mode) { min_auth_mode_ = min_auth_mode; }
@@ -678,6 +678,8 @@ class WiFiComponent : public Component {
bool wifi_sta_connect_(const WiFiAP &ap);
void wifi_pre_setup_();
WiFiSTAConnectStatus wifi_sta_connect_status_() const;
bool is_connected_() const;
void update_connected_state_();
bool wifi_scan_start_(bool passive);
#ifdef USE_WIFI_AP
@@ -854,6 +856,7 @@ class WiFiComponent : public Component {
bool has_completed_scan_after_captive_portal_start_{
false}; // Tracks if we've completed a scan after captive portal started
bool skip_cooldown_next_cycle_{false};
bool connected_{false};
bool post_connect_roaming_{true}; // Enabled by default
#if defined(USE_ESP32) && defined(USE_WIFI_RUNTIME_POWER_SAVE)
bool is_high_performance_mode_{false};