Implemented menu

This commit is contained in:
CommanderRedYT
2021-10-19 22:03:39 +02:00
committed by 0xFEEDC0DE64
parent aa9e5b2807
commit 4ea080e7f7
6 changed files with 81 additions and 14 deletions

View File

@ -77,7 +77,6 @@ set(headers
actions/multiaction.h
actions/rebootaction.h
actions/savesettingsaction.h
actions/selectbuildserveraction.h
actions/switchprofileaction.h
actions/tempomatmodeapplycurrentpeedaction.h
actions/updateswapfrontbackaction.h

View File

@ -1,4 +0,0 @@
#pragma once
#include "actioninterface.h"
#include "globals.h"

View File

@ -0,0 +1,45 @@
#pragma once
#include "globals.h"
#include "esp_log.h"
#include "fmt/core.h"
// esp-idf
#include "esp_http_client.h"
/*
* ToDo:
* - get_ota_decriptor_json_string => returns std::string, takes std::string url
*/
namespace {
std::string ota_descriptor_json = "";
std::string get_ota_url_from_index(uint16_t index)
{
if (index < stringSettings.otaServers.size())
{
auto otaServer = stringSettings.otaServers[index];
if (!otaServer.url.empty())
{
return otaServer.url;
}
else
{
ESP_LOGE("BOBBY", "Cannot get OTA url: otaServer.url is empty");
return "";
}
}
else
{
ESP_LOGE("BOBBY", "Cannot get OTA url: Invalid Index");
return "";
}
}
void get_ota_descriptor(std::string url)
{
auto descriptorUrl = fmt::format("{}/otaDescriptor", url);
// Make GET request to descriptorUrl and store json somewhere to be decoded when needed, for example in ota_descriptor_json (buildserver.h:16)
}
}

View File

@ -4,10 +4,14 @@
#include "menudisplay.h"
#include "utils.h"
#include "actions/dummyaction.h"
#include "actions/selectbuildserveraction.h"
#include "icons/back.h"
#include "texts.h"
#include "globals.h"
#include "buildserver.h"
// Debugging
#include "esp_log.h"
#include "fmt/core.h"
// forward declares
@ -19,6 +23,28 @@ using namespace espgui;
namespace {
class BuildserverMenuItem : public MenuItem
{
public:
std::string text() const override { return m_buildserver_name; }
void setBuildserverName(std::string &&buildserver_name) { m_buildserver_name = std::move(buildserver_name); }
void setBuildserverName(const std::string &buildserver_name) { m_buildserver_name = buildserver_name; }
void setBuildserverUrl(std::string &&buildserver_url) { m_buildserver_url = std::move(buildserver_url); }
void setBuildserverUrl(const std::string &buildserver_url) { m_buildserver_url = buildserver_url; }
void triggered() override
{
stringSettings.otaServerUrl = m_buildserver_url;
saveSettings();
}
private:
std::string m_buildserver_url;
std::string m_buildserver_name;
};
class SelectBuildServerMenu :
public MenuDisplay,
public StaticText<TEXT_SELECTBUILDSERVERMENU>,
@ -27,22 +53,19 @@ class SelectBuildServerMenu :
public:
SelectBuildServerMenu() {
auto numDisplayedServers = 0;
for (auto index = 0; index < stringSettings.otaServers.size(); index++)
for (const auto &otaServer : stringSettings.otaServers)
{
auto otaServer = stringSettings.otaServers[index];
std::string url = otaServer.url;
std::string name = (otaServer.name.empty()) ? url : otaServer.name;
if (!name.empty()) {
auto menuitem = constructMenuItem<makeComponent<MenuItem, ChangeableText, DummyAction>>();
menuitem.setTitle(name);
numDisplayedServers++;
auto &menuitem = constructMenuItem<BuildserverMenuItem>();
menuitem.setBuildserverName(name);
menuitem.setBuildserverUrl(url);
}
}
if (!numDisplayedServers)
if (menuItemCount() < 1)
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NOBUILDSERVERCONFIGURED>, DummyAction>>();
}

View File

@ -339,6 +339,7 @@ StringSettings makeDefaultStringSettings()
ConfiguredOtaServer { .name = {}, .url = {} },
ConfiguredOtaServer { .name = {}, .url = {} },*/
},
.otaServerUrl = {},
#endif
};
}

View File

@ -44,6 +44,7 @@ struct StringSettings
};
std::array<ConfiguredOtaServer, 2> otaServers;
std::string otaServerUrl;
#endif
};
@ -106,6 +107,8 @@ void StringSettings::executeForEveryCommonSetting(T &&callable)
callable("otaUrl8", otaServers[8].url);
callable("otaName9", otaServers[9].name);
callable("otaUrl9", otaServers[9].url);*/
callable("otaserver", otaServerUrl);
#endif
}