From 155f56863ee424a4beb631ea39aa6a58b764569e Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Sat, 18 Dec 2021 22:21:55 +0100 Subject: [PATCH] Added new function --- main/qrimport.cpp | 18 +++++++++++++++--- main/qrimport.h | 6 ++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/main/qrimport.cpp b/main/qrimport.cpp index 81b46d2..6e84f7d 100644 --- a/main/qrimport.cpp +++ b/main/qrimport.cpp @@ -1,8 +1,8 @@ #include "qrimport.h" -// system includes // 3rd party includes +#include #include #include #include @@ -17,16 +17,28 @@ cpputils::DelayedConstruction http_request; } // namespace // nvs -tl::expected get_qr_code(std::string_view key) +tl::expected get_qr_code(std::string_view key) { return ""; } -tl::expected set_qr_code(std::string_view qrcode, std::string_view key) +tl::expected set_qr_code(std::string_view qrcode, std::string_view key) { return{}; } +bool has_qr_code(std::string_view key) +{ + if (const auto result = get_qr_code(key); !result) + { + return (result.error() == ESP_ERR_NVS_NOT_FOUND); + } + else + { + return true; + } +} + // web request void setup_request() { diff --git a/main/qrimport.h b/main/qrimport.h index 57da4a1..3bd0911 100644 --- a/main/qrimport.h +++ b/main/qrimport.h @@ -9,14 +9,16 @@ #include // 3rd party includes +#include #include // local includes namespace qrimport { // nvs - tl::expected get_qr_code(std::string_view key); - tl::expected set_qr_code(std::string_view qrcode, std::string_view key); + tl::expected get_qr_code(std::string_view key); + tl::expected set_qr_code(std::string_view qrcode, std::string_view key); + bool has_qr_code(std::string_view key); // web request void setup_request();