Commit d48405f5 authored by Pietro Saccardi's avatar Pietro Saccardi
Browse files

Improve user messages in examples.

Make sure colors are passed through. Test on real hw.
parent 011acaea
Pipeline #1499 passed with stages
in 22 minutes and 48 seconds
......@@ -211,5 +211,6 @@ extern "C" void app_main() {
print_card_info(tag);
list_apps(tag);
demo_app_and_file(tag);
ESP_LOGI(TAG, "Desfire demo complete.");
}
}
......@@ -41,5 +41,8 @@ extern "C" void app_main() {
// Now switch RF on, disable automatic field detection (used in target mode).
if (not pn532.rf_configuration_field(false, true)) {
ESP_LOGE(TAG, "Failed to switch RF field on");
return;
}
ESP_LOGI(TAG, "PN532 initialization successful.");
}
......@@ -2,6 +2,7 @@
platform = espressif32
framework = espidf
lib_deps = mittelab/libSpookyAction
monitor_flags = --raw
; Enable C++17
build_unflags = -std=gnu++11 -std=gnu++14 -std=c++11 -std=c++14 -std=c++17
......
#include <pn532/controller.hpp>
#include <pn532/esp32/hsu.hpp>
#include <thread>
#define TAG "EXAMPLE"
......@@ -9,9 +10,13 @@ using namespace std::chrono_literals;
* @note This is the new function introduced in this example
*/
void scan_uuids(pn532::controller &pn532) {
if (auto res = pn532.initiator_auto_poll(); res) {
for (std::size_t i = 0; i < res->size(); ++i) {
ESP_LOGI(TAG, "%u. %s", i + 1, pn532::to_string(res->at(i).type()));
if (const auto res = pn532.initiator_auto_poll(); res) {
if (res->empty()) {
ESP_LOGW(TAG, "No target found.");
} else {
for (std::size_t i = 0; i < res->size(); ++i) {
ESP_LOGI(TAG, "%u. %s", i + 1, pn532::to_string(res->at(i).type()));
}
}
} else {
ESP_LOGE(TAG, "Failed to scan for any target, error: %s", pn532::to_string(res.error()));
......@@ -47,5 +52,11 @@ extern "C" void app_main() {
ESP_LOGE(TAG, "Failed to switch RF field on");
return;
}
scan_uuids(pn532);
ESP_LOGI(TAG, "PN532 initialization successful.");
static constexpr auto retry_time = 3s;
while (true) {
scan_uuids(pn532);
ESP_LOGI(TAG, "Retrying in %lld seconds.", retry_time.count());
std::this_thread::sleep_for(retry_time);
}
}
#include <pn532/controller.hpp>
#include <pn532/esp32/hsu.hpp>
#include <thread>
#define TAG "EXAMPLE"
......@@ -9,10 +10,14 @@ using namespace std::chrono_literals;
* @note This is the new function introduced in this example
*/
void scan_uuids(pn532::controller &pn532) {
if (auto res = pn532.initiator_list_passive_kbps106_typea(); res) {
for (pn532::target_kbps106_typea const &target : *res) {
ESP_LOGI(TAG, "Logical index %u; NFC ID:", target.logical_index);
ESP_LOG_BUFFER_HEX_LEVEL(TAG, target.info.nfcid.data(), target.info.nfcid.size(), ESP_LOG_INFO);
if (const auto res = pn532.initiator_list_passive_kbps106_typea(); res) {
if (res->empty()) {
ESP_LOGW(TAG, "No target found.");
} else {
for (pn532::target_kbps106_typea const &target : *res) {
ESP_LOGI(TAG, "Logical index %u; NFC ID:", target.logical_index);
ESP_LOG_BUFFER_HEX_LEVEL(TAG, target.info.nfcid.data(), target.info.nfcid.size(), ESP_LOG_INFO);
}
}
} else {
ESP_LOGE(TAG, "Failed to scan for passive targets at 106kbps (type A), error: %s", pn532::to_string(res.error()));
......@@ -48,5 +53,11 @@ extern "C" void app_main() {
ESP_LOGE(TAG, "Failed to switch RF field on");
return;
}
scan_uuids(pn532);
ESP_LOGI(TAG, "PN532 initialization successful.");
static constexpr auto retry_time = 3s;
while (true) {
scan_uuids(pn532);
ESP_LOGI(TAG, "Retrying in %lld seconds.", retry_time.count());
std::this_thread::sleep_for(retry_time);
}
}
......@@ -5,12 +5,11 @@
using namespace std::chrono_literals;
const char *bool_to_ok_fail(bool result) {
return result ? "OK" : "FAIL";
}
const char *bool_to_yes_no(bool result) {
return result ? "YES" : "NO";
const char *bool_result_to_str(pn532::controller::result<bool> result, const char *success = "OK", const char *failure = "FAIL") {
if (not result) {
return pn532::to_string(result.error());
}
return *result ? success : failure;
}
/**
......@@ -18,28 +17,28 @@ const char *bool_to_yes_no(bool result) {
*/
void self_test(pn532::controller &pn532) {
// Autotest PN532 ROM firmware
ESP_LOGI(TAG, "ROM: %s", bool_to_ok_fail(bool(pn532.diagnose_rom())));
ESP_LOGI(TAG, "ROM: %s", bool_result_to_str(pn532.diagnose_rom()));
// Autotest PN532 RAM
ESP_LOGI(TAG, "RAM: %s", bool_to_ok_fail(bool(pn532.diagnose_ram())));
ESP_LOGI(TAG, "RAM: %s", bool_result_to_str(pn532.diagnose_ram()));
// Check card presence via ART or ISO/IEC14443-4 card presence detection
ESP_LOGI(TAG, "Card present: %s", bool_to_yes_no(bool(pn532.diagnose_attention_req_or_card_presence())));
ESP_LOGI(TAG, "Card present: %s", bool_result_to_str(pn532.diagnose_attention_req_or_card_presence(), "YES", "NO"));
// Test comunication line
ESP_LOGI(TAG, "Channel: %s", bool_to_ok_fail(bool(pn532.diagnose_comm_line())));
ESP_LOGI(TAG, "Channel: %s", bool_result_to_str(pn532.diagnose_comm_line()));
// Test target polling, this will search for FeliCa card with 212kbps or 424kbps baudrate, return number of failed attempt
ESP_LOGI(TAG, "Polling tag failures: ");
if (const auto poll_result = pn532.diagnose_poll_target(true, true); poll_result) {
ESP_LOGI(TAG, " %d@212kbps %d@424kbps", poll_result->first, poll_result->second);
} else {
ESP_LOGI(TAG, " Error: %s", pn532::to_string(poll_result.error()));
ESP_LOGW(TAG, " Error: %s", pn532::to_string(poll_result.error()));
}
// Check antenna for open circuit, or short circuit
const auto antenna_test_result = pn532.diagnose_self_antenna(pn532::bits::low_current_thr::mA_25, pn532::bits::high_current_thr::mA_150);
ESP_LOGI(TAG, "Antenna: %s", bool_to_ok_fail(bool(antenna_test_result)));
const auto antenna_test_result = pn532.diagnose_self_antenna(pn532::low_current_thr::mA_25, pn532::high_current_thr::mA_150);
ESP_LOGI(TAG, "Antenna: %s", bool_result_to_str(antenna_test_result));
// Get firmware version of the tag
ESP_LOGI(TAG, "PN532 info: ");
......@@ -48,7 +47,7 @@ void self_test(pn532::controller &pn532) {
ESP_LOGI(TAG, " Version: %#02x", fw_version_result->version);
ESP_LOGI(TAG, " Revision: %#02x", fw_version_result->revision);
} else {
ESP_LOGI(TAG, " Error: %s", pn532::to_string(fw_version_result.error()));
ESP_LOGW(TAG, " Error: %s", pn532::to_string(fw_version_result.error()));
}
}
......@@ -80,5 +79,7 @@ extern "C" void app_main() {
ESP_LOGE(TAG, "Failed to switch RF field on");
return;
}
ESP_LOGI(TAG, "PN532 initialization successful.");
self_test(pn532);
ESP_LOGI(TAG, "Self test complete.");
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment