Implemented menu
This commit is contained in:
@ -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
|
||||
|
@ -1,4 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "actioninterface.h"
|
||||
#include "globals.h"
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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>>();
|
||||
}
|
||||
|
@ -339,6 +339,7 @@ StringSettings makeDefaultStringSettings()
|
||||
ConfiguredOtaServer { .name = {}, .url = {} },
|
||||
ConfiguredOtaServer { .name = {}, .url = {} },*/
|
||||
},
|
||||
.otaServerUrl = {},
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user