Implemented menu
This commit is contained in:
@ -77,7 +77,6 @@ set(headers
|
|||||||
actions/multiaction.h
|
actions/multiaction.h
|
||||||
actions/rebootaction.h
|
actions/rebootaction.h
|
||||||
actions/savesettingsaction.h
|
actions/savesettingsaction.h
|
||||||
actions/selectbuildserveraction.h
|
|
||||||
actions/switchprofileaction.h
|
actions/switchprofileaction.h
|
||||||
actions/tempomatmodeapplycurrentpeedaction.h
|
actions/tempomatmodeapplycurrentpeedaction.h
|
||||||
actions/updateswapfrontbackaction.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 "menudisplay.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "actions/dummyaction.h"
|
#include "actions/dummyaction.h"
|
||||||
#include "actions/selectbuildserveraction.h"
|
|
||||||
#include "icons/back.h"
|
#include "icons/back.h"
|
||||||
#include "texts.h"
|
#include "texts.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "buildserver.h"
|
||||||
|
|
||||||
|
// Debugging
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "fmt/core.h"
|
||||||
|
|
||||||
|
|
||||||
// forward declares
|
// forward declares
|
||||||
@ -19,6 +23,28 @@ using namespace espgui;
|
|||||||
|
|
||||||
namespace {
|
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 :
|
class SelectBuildServerMenu :
|
||||||
public MenuDisplay,
|
public MenuDisplay,
|
||||||
public StaticText<TEXT_SELECTBUILDSERVERMENU>,
|
public StaticText<TEXT_SELECTBUILDSERVERMENU>,
|
||||||
@ -27,22 +53,19 @@ class SelectBuildServerMenu :
|
|||||||
public:
|
public:
|
||||||
SelectBuildServerMenu() {
|
SelectBuildServerMenu() {
|
||||||
|
|
||||||
auto numDisplayedServers = 0;
|
for (const auto &otaServer : stringSettings.otaServers)
|
||||||
|
|
||||||
for (auto index = 0; index < stringSettings.otaServers.size(); index++)
|
|
||||||
{
|
{
|
||||||
auto otaServer = stringSettings.otaServers[index];
|
|
||||||
std::string url = otaServer.url;
|
std::string url = otaServer.url;
|
||||||
std::string name = (otaServer.name.empty()) ? url : otaServer.name;
|
std::string name = (otaServer.name.empty()) ? url : otaServer.name;
|
||||||
|
|
||||||
if (!name.empty()) {
|
if (!name.empty()) {
|
||||||
auto menuitem = constructMenuItem<makeComponent<MenuItem, ChangeableText, DummyAction>>();
|
auto &menuitem = constructMenuItem<BuildserverMenuItem>();
|
||||||
menuitem.setTitle(name);
|
menuitem.setBuildserverName(name);
|
||||||
numDisplayedServers++;
|
menuitem.setBuildserverUrl(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!numDisplayedServers)
|
if (menuItemCount() < 1)
|
||||||
{
|
{
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NOBUILDSERVERCONFIGURED>, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NOBUILDSERVERCONFIGURED>, DummyAction>>();
|
||||||
}
|
}
|
||||||
|
@ -339,6 +339,7 @@ StringSettings makeDefaultStringSettings()
|
|||||||
ConfiguredOtaServer { .name = {}, .url = {} },
|
ConfiguredOtaServer { .name = {}, .url = {} },
|
||||||
ConfiguredOtaServer { .name = {}, .url = {} },*/
|
ConfiguredOtaServer { .name = {}, .url = {} },*/
|
||||||
},
|
},
|
||||||
|
.otaServerUrl = {},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ struct StringSettings
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::array<ConfiguredOtaServer, 2> otaServers;
|
std::array<ConfiguredOtaServer, 2> otaServers;
|
||||||
|
std::string otaServerUrl;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,6 +107,8 @@ void StringSettings::executeForEveryCommonSetting(T &&callable)
|
|||||||
callable("otaUrl8", otaServers[8].url);
|
callable("otaUrl8", otaServers[8].url);
|
||||||
callable("otaName9", otaServers[9].name);
|
callable("otaName9", otaServers[9].name);
|
||||||
callable("otaUrl9", otaServers[9].url);*/
|
callable("otaUrl9", otaServers[9].url);*/
|
||||||
|
|
||||||
|
callable("otaserver", otaServerUrl);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user