Implemented enums for cloud

This commit is contained in:
CommanderRedYT
2022-06-12 19:37:13 +02:00
parent 1366f3fedb
commit 6c94b608fa
2 changed files with 20 additions and 4 deletions

View File

@ -2,9 +2,9 @@
// 3rdparty lib includes
#include <buttonsinterface.h>
#include <cpptypesafeenum.h>
// local includes
#include "bobbytypesafeenum.h"
#include "bobbybuttons.h"
#define BobbyQuickActionsValues(x) \
@ -18,7 +18,7 @@
x(HUPE) \
x(COMPRESSOR_TOGGLE)
DECLARE_TYPESAFE_ENUM(BobbyQuickActions, : uint8_t, BobbyQuickActionsValues)
DECLARE_BOBBYTYPESAFE_ENUM(BobbyQuickActions, : uint8_t, BobbyQuickActionsValues)
namespace quickactions {

View File

@ -148,8 +148,6 @@ toArduinoJson(std::string_view key, T value, T defaultValue, JsonObject &object)
template<typename T>
typename std::enable_if<
std::is_same_v<T, sntp_sync_mode_t> ||
std::is_same_v<T, espchrono::DayLightSavingMode> ||
std::is_same_v<T, OtaAnimationModes> ||
std::is_same_v<T, LedstripAnimation> ||
std::is_same_v<T, HandbremseMode> ||
@ -158,6 +156,24 @@ typename std::enable_if<
std::is_same_v<T, BatteryCellType>
, void>::type
toArduinoJson(std::string_view key, T value, T defaultValue, JsonObject &object)
{
object["n"] = key;
object["v"] = std::to_underlying(value);
object["d"] = std::to_underlying(defaultValue);
JsonArray enumObject = object.createNestedArray("e");
iterateEnum<T>::iterate([&](T enum_value, const auto &string_value){
enumObject.add(toString(enum_value));
});
}
template<typename T>
typename std::enable_if<
std::is_same_v<T, sntp_sync_mode_t> ||
std::is_same_v<T, espchrono::DayLightSavingMode>
, void>::type
toArduinoJson(std::string_view key, T value, T defaultValue, JsonObject &object)
{
object["n"] = key;
object["v"] = std::to_underlying(value);