Added MultiAction, ChangeValueDisplay<wifi_auth_type_t>, TextWithValueHelper
This commit is contained in:
@ -7,6 +7,7 @@ set(headers
|
|||||||
src/changevaluedisplay_bool.h
|
src/changevaluedisplay_bool.h
|
||||||
src/changevaluedisplay_daylightsavingmode.h
|
src/changevaluedisplay_daylightsavingmode.h
|
||||||
src/changevaluedisplay_sntp_sync_mode_t.h
|
src/changevaluedisplay_sntp_sync_mode_t.h
|
||||||
|
src/changevaluedisplay_wifi_auth_mode_t.h
|
||||||
src/changevaluedisplay_wifi_mode_t.h
|
src/changevaluedisplay_wifi_mode_t.h
|
||||||
src/checkboxicon.h
|
src/checkboxicon.h
|
||||||
src/colorinterface.h
|
src/colorinterface.h
|
||||||
@ -24,8 +25,10 @@ set(headers
|
|||||||
src/splitgraphdisplay.h
|
src/splitgraphdisplay.h
|
||||||
src/tftinstance.h
|
src/tftinstance.h
|
||||||
src/textinterface.h
|
src/textinterface.h
|
||||||
|
src/textwithvaluehelper.h
|
||||||
src/actions/backproxyaction.h
|
src/actions/backproxyaction.h
|
||||||
src/actions/dummyaction.h
|
src/actions/dummyaction.h
|
||||||
|
src/actions/multiaction.h
|
||||||
src/actions/setvalueaction.h
|
src/actions/setvalueaction.h
|
||||||
src/actions/switchscreenaction.h
|
src/actions/switchscreenaction.h
|
||||||
src/actions/toggleboolaction.h
|
src/actions/toggleboolaction.h
|
||||||
@ -45,6 +48,7 @@ set(sources
|
|||||||
src/changevaluedisplay_bool.cpp
|
src/changevaluedisplay_bool.cpp
|
||||||
src/changevaluedisplay_daylightsavingmode.cpp
|
src/changevaluedisplay_daylightsavingmode.cpp
|
||||||
src/changevaluedisplay_sntp_sync_mode_t.cpp
|
src/changevaluedisplay_sntp_sync_mode_t.cpp
|
||||||
|
src/changevaluedisplay_wifi_auth_mode_t.cpp
|
||||||
src/changevaluedisplay_wifi_mode_t.cpp
|
src/changevaluedisplay_wifi_mode_t.cpp
|
||||||
src/display.cpp
|
src/display.cpp
|
||||||
src/displaywithtitle.cpp
|
src/displaywithtitle.cpp
|
||||||
@ -70,6 +74,7 @@ set(dependencies
|
|||||||
espchrono
|
espchrono
|
||||||
espcpputils
|
espcpputils
|
||||||
expected
|
expected
|
||||||
|
espwifistack
|
||||||
fmt
|
fmt
|
||||||
TFT_eSPI
|
TFT_eSPI
|
||||||
)
|
)
|
||||||
|
31
src/actions/multiaction.h
Normal file
31
src/actions/multiaction.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "actioninterface.h"
|
||||||
|
|
||||||
|
using namespace espgui;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template<typename ...T>
|
||||||
|
class MultiAction;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class MultiAction<T> : public virtual ActionInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void triggered() override
|
||||||
|
{
|
||||||
|
T{}.triggered();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T, typename ...Tmore>
|
||||||
|
class MultiAction<T, Tmore...> : public virtual MultiAction<Tmore...>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void triggered() override
|
||||||
|
{
|
||||||
|
T{}.triggered();
|
||||||
|
MultiAction<Tmore...>::triggered();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
65
src/changevaluedisplay_wifi_auth_mode_t.cpp
Normal file
65
src/changevaluedisplay_wifi_auth_mode_t.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include "changevaluedisplay_wifi_auth_mode_t.h"
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <futurecpp.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "actions/setvalueaction.h"
|
||||||
|
#include "actions/backproxyaction.h"
|
||||||
|
#include "icons/back.h"
|
||||||
|
|
||||||
|
namespace espgui {
|
||||||
|
namespace {
|
||||||
|
constexpr const char * const TAG = "ESPGUI";
|
||||||
|
|
||||||
|
constexpr char TEXT_OPEN[] = "OPEN";
|
||||||
|
constexpr char TEXT_WEP[] = "WEP";
|
||||||
|
constexpr char TEXT_WPA_PSK[] = "WPA_PSK";
|
||||||
|
constexpr char TEXT_WPA2_PSK[] = "WPA2_PSK";
|
||||||
|
constexpr char TEXT_WPA_WPA2_PSK[] = "WPA_WPA2_PSK";
|
||||||
|
constexpr char TEXT_WPA2_ENTERPRISE[] = "WPA2_ENTERPRISE";
|
||||||
|
constexpr char TEXT_WPA3_PSK[] = "WPA3_PSK";
|
||||||
|
constexpr char TEXT_WPA2_WPA3_PSK[] = "WPA2_WPA3_PSK";
|
||||||
|
constexpr char TEXT_WAPI_PSK[] = "WAPI_PSK";
|
||||||
|
constexpr char TEXT_BACK[] = "BACK";
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
ChangeValueDisplay<wifi_auth_mode_t>::ChangeValueDisplay()
|
||||||
|
{
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_OPEN>>>(WIFI_AUTH_OPEN, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_WEP>>>(WIFI_AUTH_WEP, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_WPA_PSK>>>(WIFI_AUTH_WPA_PSK, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_WPA2_PSK>>>(WIFI_AUTH_WPA2_PSK, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_WPA_WPA2_PSK>>>(WIFI_AUTH_WPA_WPA2_PSK, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_WPA2_ENTERPRISE>>>(WIFI_AUTH_WPA2_ENTERPRISE, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_WPA3_PSK>>>(WIFI_AUTH_WPA3_PSK, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_WPA2_WPA3_PSK>>>(WIFI_AUTH_WPA2_WPA3_PSK, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<wifi_auth_mode_t>, StaticText<TEXT_WAPI_PSK>>>(WIFI_AUTH_WAPI_PSK, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, BackProxyAction, StaticText<TEXT_BACK>, StaticMenuItemIcon<&espgui::icons::back>>>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeValueDisplay<wifi_auth_mode_t>::start()
|
||||||
|
{
|
||||||
|
Base::start();
|
||||||
|
|
||||||
|
switch (const auto value = getValue())
|
||||||
|
{
|
||||||
|
case WIFI_AUTH_OPEN: setSelectedIndex(0); break;
|
||||||
|
case WIFI_AUTH_WEP: setSelectedIndex(1); break;
|
||||||
|
case WIFI_AUTH_WPA_PSK: setSelectedIndex(2); break;
|
||||||
|
case WIFI_AUTH_WPA2_PSK: setSelectedIndex(3); break;
|
||||||
|
case WIFI_AUTH_WPA_WPA2_PSK: setSelectedIndex(4); break;
|
||||||
|
case WIFI_AUTH_WPA2_ENTERPRISE: setSelectedIndex(5); break;
|
||||||
|
case WIFI_AUTH_WPA3_PSK: setSelectedIndex(6); break;
|
||||||
|
case WIFI_AUTH_WPA2_WPA3_PSK: setSelectedIndex(7); break;
|
||||||
|
case WIFI_AUTH_WAPI_PSK: setSelectedIndex(8); break;
|
||||||
|
default:
|
||||||
|
ESP_LOGW(TAG, "Unknown wifi_auth_mode_t: %i", std::to_underlying(value));
|
||||||
|
setSelectedIndex(9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace espgui
|
27
src/changevaluedisplay_wifi_auth_mode_t.h
Normal file
27
src/changevaluedisplay_wifi_auth_mode_t.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_wifi_types.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "changevaluedisplay.h"
|
||||||
|
#include "menudisplay.h"
|
||||||
|
#include "actioninterface.h"
|
||||||
|
|
||||||
|
namespace espgui {
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class ChangeValueDisplay<wifi_auth_mode_t> :
|
||||||
|
public MenuDisplay,
|
||||||
|
public virtual AccessorInterface<wifi_auth_mode_t>,
|
||||||
|
public virtual ActionInterface
|
||||||
|
{
|
||||||
|
using Base = MenuDisplay;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ChangeValueDisplay();
|
||||||
|
|
||||||
|
void start() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace espgui
|
@ -3,6 +3,9 @@
|
|||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <futurecpp.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "actions/setvalueaction.h"
|
#include "actions/setvalueaction.h"
|
||||||
#include "actions/backproxyaction.h"
|
#include "actions/backproxyaction.h"
|
||||||
@ -39,7 +42,7 @@ void ChangeValueDisplay<wifi_mode_t>::start()
|
|||||||
case WIFI_MODE_AP: setSelectedIndex(2); break;
|
case WIFI_MODE_AP: setSelectedIndex(2); break;
|
||||||
case WIFI_MODE_APSTA: setSelectedIndex(3); break;
|
case WIFI_MODE_APSTA: setSelectedIndex(3); break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGW(TAG, "Unknown wifi_mode_t: %i", int(value));
|
ESP_LOGW(TAG, "Unknown wifi_mode_t: %i", std::to_underlying(value));
|
||||||
setSelectedIndex(4);
|
setSelectedIndex(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
// system includes
|
// system includes
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
// 3rdparty lib includes
|
|
||||||
#include <fmt/core.h>
|
|
||||||
|
|
||||||
namespace espgui {
|
namespace espgui {
|
||||||
|
|
||||||
class TextInterface {
|
class TextInterface {
|
||||||
public:
|
public:
|
||||||
virtual std::string text() const = 0;
|
virtual std::string text() const = 0;
|
||||||
@ -73,9 +72,4 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<const char *Tprefix, typename Taccessor>
|
|
||||||
struct TextWithValueHelper : public virtual TextInterface
|
|
||||||
{
|
|
||||||
std::string text() const override { return fmt::format("{} {}", Tprefix, Taccessor{}.getValue()); }
|
|
||||||
};
|
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
28
src/textwithvaluehelper.h
Normal file
28
src/textwithvaluehelper.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <strutils.h>
|
||||||
|
#include <espstrutils.h>
|
||||||
|
#include <espwifiutils.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "textinterface.h"
|
||||||
|
#include "richtextrenderer.h"
|
||||||
|
|
||||||
|
namespace espgui {
|
||||||
|
|
||||||
|
template<const char *Tprefix, typename Taccessor>
|
||||||
|
struct TextWithValueHelper : public virtual TextInterface
|
||||||
|
{
|
||||||
|
std::string text() const override
|
||||||
|
{
|
||||||
|
using cpputils::toString;
|
||||||
|
using espcpputils::toString;
|
||||||
|
using wifi_stack::toString;
|
||||||
|
|
||||||
|
return fmt::format("{} {}", Tprefix, richTextEscape(toString(Taccessor{}.getValue())));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace espgui
|
Reference in New Issue
Block a user