Made some modifications to qr functions
This commit is contained in:
@ -32,7 +32,6 @@ private:
|
||||
std::string m_msg;
|
||||
};
|
||||
|
||||
template<typename TMenu>
|
||||
class PushQrImportDisplayAction : public virtual espgui::ActionInterface
|
||||
{
|
||||
public:
|
||||
@ -41,7 +40,7 @@ public:
|
||||
|
||||
void triggered() override
|
||||
{
|
||||
espgui::pushScreen<QrImportDisplay<TMenu>>(std::move(m_nvskey));
|
||||
espgui::pushScreen<QrImportDisplay>(std::move(m_nvskey));
|
||||
}
|
||||
private:
|
||||
std::string m_nvskey;
|
||||
|
@ -81,7 +81,7 @@ GreenPassMenu::GreenPassMenu()
|
||||
}
|
||||
else
|
||||
{
|
||||
constructMenuItem<makeComponentArgs<MenuItem, PushQrImportDisplayAction<GreenPassMenu>, StaticText<TEXT_ADDCERT>>>(std::move(nvs_key));
|
||||
constructMenuItem<makeComponentArgs<MenuItem, PushQrImportDisplayAction, StaticText<TEXT_ADDCERT>>>(std::move(nvs_key));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,92 @@
|
||||
#include "qrimportdisplay.h"
|
||||
|
||||
namespace {
|
||||
constexpr const char * const TAG = "qrimport";
|
||||
}
|
||||
|
||||
void QrImportDisplay::start()
|
||||
{
|
||||
using namespace espgui;
|
||||
Base::start();
|
||||
|
||||
m_statuslabel.start();
|
||||
|
||||
qrimport::setup_request();
|
||||
|
||||
if (const auto result = qrimport::start_qr_request(); result)
|
||||
{
|
||||
ESP_LOGI(TAG, "started request, waiting for result");
|
||||
m_waitingForResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "could not start request: %.*s", result.error().size(), result.error().data());
|
||||
m_result = tl::make_unexpected(std::move(result).error());
|
||||
}
|
||||
}
|
||||
|
||||
void QrImportDisplay::update()
|
||||
{
|
||||
using namespace espgui;
|
||||
Base::update();
|
||||
|
||||
if (!m_waitingForResult)
|
||||
return;
|
||||
|
||||
if (qrimport::get_request_running())
|
||||
return;
|
||||
|
||||
m_waitingForResult = false;
|
||||
|
||||
m_result = qrimport::check_request();
|
||||
if (m_result)
|
||||
{
|
||||
ESP_LOGI(TAG, "%.*s => %.*s", m_nvs_key.size(), m_nvs_key.data(), m_result->size(), m_result->data());
|
||||
if (const auto result = qrimport::set_qr_code(m_nvs_key, *m_result); !result)
|
||||
m_result = tl::make_unexpected(fmt::format("saving qr failed: {}", esp_err_to_name(result.error())));
|
||||
}
|
||||
else
|
||||
ESP_LOGW(TAG, "failed %.*s => %.*s", m_nvs_key.size(), m_nvs_key.data(), m_result.error().size(), m_result.error().data());
|
||||
}
|
||||
|
||||
void QrImportDisplay::redraw()
|
||||
{
|
||||
using namespace espgui;
|
||||
Base::redraw();
|
||||
|
||||
if (m_waitingForResult)
|
||||
{
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
m_statuslabel.redraw("In progress");
|
||||
}
|
||||
else if (!m_result && !m_result.error().empty())
|
||||
{
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
BobbyErrorHandler{}.errorOccurred(fmt::format("Error: {}", m_result.error()));
|
||||
m_result.error().clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
m_statuslabel.redraw("OK");
|
||||
popScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void QrImportDisplay::buttonPressed(espgui::Button button)
|
||||
{
|
||||
using namespace espgui;
|
||||
Base::buttonPressed(button);
|
||||
|
||||
switch (button)
|
||||
{
|
||||
using espgui::Button;
|
||||
case Button::Left:
|
||||
if (!m_waitingForResult)
|
||||
popScreen();
|
||||
else
|
||||
ESP_LOGW(TAG, "tried to leave while waiting for result");
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
constexpr const char * const TAG = "qrimport";
|
||||
|
||||
// 3rd party includes
|
||||
#include <esp_log.h>
|
||||
#include <widgets/label.h>
|
||||
#include <fmt/core.h>
|
||||
#include <tftinstance.h>
|
||||
#include <tl/expected.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <widgets/label.h>
|
||||
|
||||
// local includes
|
||||
#include "bobbydisplay.h"
|
||||
@ -14,7 +13,6 @@ constexpr const char * const TAG = "qrimport";
|
||||
#include "qrimport.h"
|
||||
#include "screenmanager.h"
|
||||
|
||||
template<typename TMenu>
|
||||
class QrImportDisplay : public BobbyDisplay
|
||||
{
|
||||
using Base = BobbyDisplay;
|
||||
@ -23,92 +21,10 @@ public:
|
||||
explicit QrImportDisplay(const std::string &nvs_key) : m_nvs_key{nvs_key} {}
|
||||
explicit QrImportDisplay(std::string &&nvs_key) : m_nvs_key{std::move(nvs_key)} {}
|
||||
|
||||
void start() override
|
||||
{
|
||||
using namespace espgui;
|
||||
Base::start();
|
||||
|
||||
m_statuslabel.start();
|
||||
|
||||
qrimport::setup_request();
|
||||
|
||||
if (const auto result = qrimport::start_qr_request(); result)
|
||||
{
|
||||
ESP_LOGI(TAG, "started request, waiting for result");
|
||||
m_waitingForResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "could not start request: %.*s", result.error().size(), result.error().data());
|
||||
m_result = tl::make_unexpected(std::move(result).error());
|
||||
}
|
||||
}
|
||||
|
||||
void update() override
|
||||
{
|
||||
using namespace espgui;
|
||||
Base::update();
|
||||
|
||||
if (!m_waitingForResult)
|
||||
return;
|
||||
|
||||
if (qrimport::get_request_running())
|
||||
return;
|
||||
|
||||
m_waitingForResult = false;
|
||||
|
||||
m_result = qrimport::check_request();
|
||||
if (m_result)
|
||||
{
|
||||
ESP_LOGI(TAG, "%.*s => %.*s", m_nvs_key.size(), m_nvs_key.data(), m_result->size(), m_result->data());
|
||||
if (const auto result = qrimport::set_qr_code(m_nvs_key, *m_result); !result)
|
||||
m_result = tl::make_unexpected(fmt::format("saving qr failed: {}", esp_err_to_name(result.error())));
|
||||
}
|
||||
else
|
||||
ESP_LOGW(TAG, "failed %.*s => %.*s", m_nvs_key.size(), m_nvs_key.data(), m_result.error().size(), m_result.error().data());
|
||||
}
|
||||
|
||||
void redraw() override
|
||||
{
|
||||
using namespace espgui;
|
||||
Base::redraw();
|
||||
|
||||
if (m_waitingForResult)
|
||||
{
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
m_statuslabel.redraw("In progress");
|
||||
}
|
||||
else if (!m_result && !m_result.error().empty())
|
||||
{
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
BobbyErrorHandler{}.errorOccurred(fmt::format("Error: {}", m_result.error()));
|
||||
m_result.error().clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
m_statuslabel.redraw("OK");
|
||||
popScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void buttonPressed(espgui::Button button) override
|
||||
{
|
||||
using namespace espgui;
|
||||
Base::buttonPressed(button);
|
||||
|
||||
switch (button)
|
||||
{
|
||||
using espgui::Button;
|
||||
case Button::Left:
|
||||
if (!m_waitingForResult)
|
||||
popScreen();
|
||||
else
|
||||
ESP_LOGW(TAG, "tried to leave while waiting for result");
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
void start() override;
|
||||
void update() override;
|
||||
void redraw() override;
|
||||
void buttonPressed(espgui::Button button) override;
|
||||
|
||||
private:
|
||||
bool m_waitingForResult{false};
|
||||
|
Reference in New Issue
Block a user