mirror of
https://github.com/esphome/esphome.git
synced 2025-02-08 14:10:54 +00:00
some more compile result testing. Sorry all.
This commit is contained in:
parent
839ba8817b
commit
59c70f722d
@ -293,7 +293,10 @@ bool ESPNowComponent::write(const std::shared_ptr<ESPNowPacket> packet) {
|
|||||||
esp_err_t err = esp_now_send((uint8_t *) &mac, packet->content_bytes(), packet->get_size());
|
esp_err_t err = esp_now_send((uint8_t *) &mac, packet->content_bytes(), packet->get_size());
|
||||||
ESP_LOGVV(TAG, "S: 0x%04x.%d B: %d%s.", packet->get_sequents(), packet->attempts, this->send_queue_used(),
|
ESP_LOGVV(TAG, "S: 0x%04x.%d B: %d%s.", packet->get_sequents(), packet->attempts, this->send_queue_used(),
|
||||||
(err == ESP_OK) ? "" : " FAILED");
|
(err == ESP_OK) ? "" : " FAILED");
|
||||||
this->defer([this, packet, err]() { this->on_sent_(packet, err == ESP_OK); });
|
this->defer([this, packet, err]() {
|
||||||
|
packet->reload();
|
||||||
|
this->on_sent_(std::move(packet), err == ESP_OK);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,13 +313,19 @@ void ESPNowComponent::runner() {
|
|||||||
|
|
||||||
if (!esp_now_is_peer_exist(mac)) {
|
if (!esp_now_is_peer_exist(mac)) {
|
||||||
if (!this->auto_add_peer_) {
|
if (!this->auto_add_peer_) {
|
||||||
this->defer([this, packet]() { this->on_new_peer_(packet); });
|
this->defer([this, packet]() {
|
||||||
|
packet->reload();
|
||||||
|
this->on_new_peer_(std::move(packet));
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
this->add_peer(packet->peer);
|
this->add_peer(packet->peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->defer([this, packet]() { this->on_receive_(packet); });
|
this->defer([this, packet]() {
|
||||||
|
packet->reload();
|
||||||
|
this->on_receive_(std::move(packet));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
packet = std::make_shared<ESPNowPacket>();
|
packet = std::make_shared<ESPNowPacket>();
|
||||||
if (xQueueReceive(this->send_queue_, packet.get(), (TickType_t) 1) == pdTRUE) {
|
if (xQueueReceive(this->send_queue_, packet.get(), (TickType_t) 1) == pdTRUE) {
|
||||||
@ -366,7 +375,7 @@ void ESPNowComponent::on_data_sent(const uint8_t *mac_addr, esp_now_send_status_
|
|||||||
ESP_LOGV(TAG, "Confirm sent (0x%04x.%d)", packet->get_sequents(), packet->attempts);
|
ESP_LOGV(TAG, "Confirm sent (0x%04x.%d)", packet->get_sequents(), packet->attempts);
|
||||||
global_esp_now->defer([packet]() {
|
global_esp_now->defer([packet]() {
|
||||||
packet->reload();
|
packet->reload();
|
||||||
global_esp_now->on_sent_(packet, true);
|
global_esp_now->on_sent_(std::move(packet), true);
|
||||||
auto tmp = std::make_shared<ESPNowPacket>();
|
auto tmp = std::make_shared<ESPNowPacket>();
|
||||||
xQueueReceive(global_esp_now->send_queue_, tmp.get(), 10 / portTICK_PERIOD_MS);
|
xQueueReceive(global_esp_now->send_queue_, tmp.get(), 10 / portTICK_PERIOD_MS);
|
||||||
global_esp_now->unlock();
|
global_esp_now->unlock();
|
||||||
@ -374,7 +383,8 @@ void ESPNowComponent::on_data_sent(const uint8_t *mac_addr, esp_now_send_status_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
global_esp_now->defer([packet]() {
|
global_esp_now->defer([packet]() {
|
||||||
global_esp_now->on_sent_(packet, false);
|
packet->reload();
|
||||||
|
global_esp_now->on_sent_(std::move(packet), false);
|
||||||
global_esp_now->unlock();
|
global_esp_now->unlock();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -184,19 +184,19 @@ class ESPNowDefaultProtocol : public ESPNowProtocol {
|
|||||||
void add_on_receive_callback(std::function<void(const std::shared_ptr<ESPNowPacket>)> &&callback) {
|
void add_on_receive_callback(std::function<void(const std::shared_ptr<ESPNowPacket>)> &&callback) {
|
||||||
this->on_receive_.add(std::move(callback));
|
this->on_receive_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
void on_receive(const std::shared_ptr<ESPNowPacket> packet) override { this->on_receive_.call(packet); };
|
void on_receive(const std::shared_ptr<ESPNowPacket> packet) override { this->on_receive_.call(std::move(packet)); };
|
||||||
|
|
||||||
void add_on_sent_callback(std::function<void(const std::shared_ptr<ESPNowPacket>, bool status)> &&callback) {
|
void add_on_sent_callback(std::function<void(const std::shared_ptr<ESPNowPacket>, bool status)> &&callback) {
|
||||||
this->on_sent_.add(std::move(callback));
|
this->on_sent_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
void on_sent(const std::shared_ptr<ESPNowPacket> packet, bool status) override {
|
void on_sent(const std::shared_ptr<ESPNowPacket> packet, bool status) override {
|
||||||
this->on_sent_.call(packet, status);
|
this->on_sent_.call(std::move(packet), status);
|
||||||
};
|
};
|
||||||
|
|
||||||
void add_on_peer_callback(std::function<void(const std::shared_ptr<ESPNowPacket>)> &&callback) {
|
void add_on_peer_callback(std::function<void(const std::shared_ptr<ESPNowPacket>)> &&callback) {
|
||||||
this->on_new_peer_.add(std::move(callback));
|
this->on_new_peer_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
void on_new_peer(const std::shared_ptr<ESPNowPacket> packet) override { this->on_new_peer_.call(packet); };
|
void on_new_peer(const std::shared_ptr<ESPNowPacket> packet) override { this->on_new_peer_.call(std::move(packet)); };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CallbackManager<void(const std::shared_ptr<ESPNowPacket>, bool)> on_sent_;
|
CallbackManager<void(const std::shared_ptr<ESPNowPacket>, bool)> on_sent_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user