mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-03 19:38:30 +02:00
Use standard version of make_unique when available (#2292)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include "pn532.h"
|
||||
|
||||
#include <memory>
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
// Based on:
|
||||
@@ -104,7 +106,7 @@ void PN532::loop() {
|
||||
if (!success) {
|
||||
// Something failed
|
||||
if (!this->current_uid_.empty()) {
|
||||
auto tag = std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(this->current_uid_)};
|
||||
auto tag = make_unique<nfc::NfcTag>(this->current_uid_);
|
||||
for (auto *trigger : this->triggers_ontagremoved_)
|
||||
trigger->process(tag);
|
||||
}
|
||||
@@ -117,7 +119,7 @@ void PN532::loop() {
|
||||
if (num_targets != 1) {
|
||||
// no tags found or too many
|
||||
if (!this->current_uid_.empty()) {
|
||||
auto tag = std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(this->current_uid_)};
|
||||
auto tag = make_unique<nfc::NfcTag>(this->current_uid_);
|
||||
for (auto *trigger : this->triggers_ontagremoved_)
|
||||
trigger->process(tag);
|
||||
}
|
||||
@@ -281,9 +283,9 @@ std::unique_ptr<nfc::NfcTag> PN532::read_tag_(std::vector<uint8_t> &uid) {
|
||||
return this->read_mifare_ultralight_tag_(uid);
|
||||
} else if (type == nfc::TAG_TYPE_UNKNOWN) {
|
||||
ESP_LOGV(TAG, "Cannot determine tag type");
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid)};
|
||||
return make_unique<nfc::NfcTag>(uid);
|
||||
} else {
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid)};
|
||||
return make_unique<nfc::NfcTag>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <memory>
|
||||
|
||||
#include "pn532.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
@@ -15,15 +17,15 @@ std::unique_ptr<nfc::NfcTag> PN532::read_mifare_classic_tag_(std::vector<uint8_t
|
||||
std::vector<uint8_t> data;
|
||||
if (this->read_mifare_classic_block_(current_block, data)) {
|
||||
if (!nfc::decode_mifare_classic_tlv(data, message_length, message_start_index)) {
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::ERROR)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::ERROR);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to read block %d", current_block);
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::MIFARE_CLASSIC);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGV(TAG, "Tag is not NDEF formatted");
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::MIFARE_CLASSIC);
|
||||
}
|
||||
|
||||
uint32_t index = 0;
|
||||
@@ -51,7 +53,7 @@ std::unique_ptr<nfc::NfcTag> PN532::read_mifare_classic_tag_(std::vector<uint8_t
|
||||
}
|
||||
}
|
||||
buffer.erase(buffer.begin(), buffer.begin() + message_start_index);
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC, buffer)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::MIFARE_CLASSIC, buffer);
|
||||
}
|
||||
|
||||
bool PN532::read_mifare_classic_block_(uint8_t block_num, std::vector<uint8_t> &data) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <memory>
|
||||
|
||||
#include "pn532.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
@@ -9,25 +11,25 @@ static const char *const TAG = "pn532.mifare_ultralight";
|
||||
std::unique_ptr<nfc::NfcTag> PN532::read_mifare_ultralight_tag_(std::vector<uint8_t> &uid) {
|
||||
if (!this->is_mifare_ultralight_formatted_()) {
|
||||
ESP_LOGD(TAG, "Not NDEF formatted");
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
}
|
||||
|
||||
uint8_t message_length;
|
||||
uint8_t message_start_index;
|
||||
if (!this->find_mifare_ultralight_ndef_(message_length, message_start_index)) {
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
}
|
||||
ESP_LOGVV(TAG, "message length: %d, start: %d", message_length, message_start_index);
|
||||
|
||||
if (message_length == 0) {
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
}
|
||||
std::vector<uint8_t> data;
|
||||
for (uint8_t page = nfc::MIFARE_ULTRALIGHT_DATA_START_PAGE; page < nfc::MIFARE_ULTRALIGHT_MAX_PAGE; page++) {
|
||||
std::vector<uint8_t> page_data;
|
||||
if (!this->read_mifare_ultralight_page_(page, page_data)) {
|
||||
ESP_LOGE(TAG, "Error reading page %d", page);
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
}
|
||||
data.insert(data.end(), page_data.begin(), page_data.end());
|
||||
|
||||
@@ -38,7 +40,7 @@ std::unique_ptr<nfc::NfcTag> PN532::read_mifare_ultralight_tag_(std::vector<uint
|
||||
data.erase(data.begin(), data.begin() + message_start_index);
|
||||
data.erase(data.begin() + message_length, data.end());
|
||||
|
||||
return std::unique_ptr<nfc::NfcTag>{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2, data)};
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2, data);
|
||||
}
|
||||
|
||||
bool PN532::read_mifare_ultralight_page_(uint8_t page_num, std::vector<uint8_t> &data) {
|
||||
|
||||
Reference in New Issue
Block a user