cleanup project config from unused observer code

This commit is contained in:
Lorow
2024-12-11 22:40:34 +01:00
parent fff9ce422f
commit 983c5fa473
6 changed files with 20 additions and 87 deletions
@@ -44,8 +44,7 @@ CommandResult updateCameraCommand::execute(std::string_view jsonPayload)
updatedConfig.framesize.has_value() ? updatedConfig.framesize.value() : oldConfig.framesize, updatedConfig.framesize.has_value() ? updatedConfig.framesize.value() : oldConfig.framesize,
updatedConfig.href.has_value() ? updatedConfig.href.value() : oldConfig.href, updatedConfig.href.has_value() ? updatedConfig.href.value() : oldConfig.href,
updatedConfig.quality.has_value() ? updatedConfig.quality.value() : oldConfig.quality, updatedConfig.quality.has_value() ? updatedConfig.quality.value() : oldConfig.quality,
updatedConfig.brightness.has_value() ? updatedConfig.brightness.value() : oldConfig.brightness, updatedConfig.brightness.has_value() ? updatedConfig.brightness.value() : oldConfig.brightness);
true);
return CommandResult::getSuccessResult("Config updated"); return CommandResult::getSuccessResult("Config updated");
} }
@@ -26,7 +26,7 @@ CommandResult setMDNSCommand::execute(std::string_view jsonPayload)
if (!payload.has_value()) if (!payload.has_value())
return CommandResult::getErrorResult("Invalid payload"); return CommandResult::getErrorResult("Invalid payload");
projectConfig->setMDNSConfig(payload.value().hostname, true); projectConfig->setMDNSConfig(payload.value().hostname);
return CommandResult::getSuccessResult("Config updated"); return CommandResult::getSuccessResult("Config updated");
} }
@@ -60,8 +60,7 @@ CommandResult setWiFiCommand::execute(std::string_view jsonPayload)
wifiConfig.ssid, wifiConfig.ssid,
wifiConfig.password, wifiConfig.password,
wifiConfig.channel, wifiConfig.channel,
wifiConfig.power, wifiConfig.power);
true);
return CommandResult::getSuccessResult("Config updated"); return CommandResult::getSuccessResult("Config updated");
} }
@@ -93,7 +92,7 @@ CommandResult deleteWifiCommand::execute(std::string_view jsonPayload)
if (!payload.has_value()) if (!payload.has_value())
return CommandResult::getErrorResult("Invalid payload"); return CommandResult::getErrorResult("Invalid payload");
projectConfig->deleteWifiConfig(payload.value().networkName, false); projectConfig->deleteWifiConfig(payload.value().networkName);
return CommandResult::getSuccessResult("Config updated"); return CommandResult::getSuccessResult("Config updated");
} }
@@ -164,8 +163,7 @@ CommandResult updateWifiCommand::execute(std::string_view jsonPayload)
updatedConfig.ssid.has_value() ? updatedConfig.ssid.value() : networkToUpdate->ssid, updatedConfig.ssid.has_value() ? updatedConfig.ssid.value() : networkToUpdate->ssid,
updatedConfig.password.has_value() ? updatedConfig.password.value() : networkToUpdate->password, updatedConfig.password.has_value() ? updatedConfig.password.value() : networkToUpdate->password,
updatedConfig.channel.has_value() ? updatedConfig.channel.value() : networkToUpdate->channel, updatedConfig.channel.has_value() ? updatedConfig.channel.value() : networkToUpdate->channel,
updatedConfig.power.has_value() ? updatedConfig.power.value() : networkToUpdate->power, updatedConfig.power.has_value() ? updatedConfig.power.value() : networkToUpdate->power);
false);
return CommandResult::getSuccessResult("Config updated"); return CommandResult::getSuccessResult("Config updated");
} }
@@ -7,7 +7,6 @@
#include "esp_log.h" #include "esp_log.h"
#include "mdns.h" #include "mdns.h"
// TODO add observer pattern here
class MDNSManager class MDNSManager
{ {
private: private:
@@ -221,8 +221,6 @@ void ProjectConfig::load()
this->config.camera.brightness = getInt("brightness", 2); this->config.camera.brightness = getInt("brightness", 2);
this->_already_loaded = true; this->_already_loaded = true;
// TODO add support for what's the pattern? Eh, the pattern
// this->notifyAll(ConfigState_e::configLoaded);
} }
//********************************************************************************************************************** //**********************************************************************************************************************
//* //*
@@ -231,36 +229,25 @@ void ProjectConfig::load()
//********************************************************************************************************************** //**********************************************************************************************************************
void ProjectConfig::setDeviceConfig(const std::string &OTALogin, void ProjectConfig::setDeviceConfig(const std::string &OTALogin,
const std::string &OTAPassword, const std::string &OTAPassword,
int OTAPort, int OTAPort)
bool shouldNotify)
{ {
ESP_LOGD(CONFIGURATION_TAG, "Updating device config"); ESP_LOGD(CONFIGURATION_TAG, "Updating device config");
this->config.device.OTALogin.assign(OTALogin); this->config.device.OTALogin.assign(OTALogin);
this->config.device.OTAPassword.assign(OTAPassword); this->config.device.OTAPassword.assign(OTAPassword);
this->config.device.OTAPort = OTAPort; this->config.device.OTAPort = OTAPort;
// TODO turn this on
// if (shouldNotify)
// this->notifyAll(ConfigState_e::deviceConfigUpdated);
} }
void ProjectConfig::setMDNSConfig(const std::string &hostname, void ProjectConfig::setMDNSConfig(const std::string &hostname)
bool shouldNotify)
{ {
ESP_LOGD(CONFIGURATION_TAG, "Updating MDNS config"); ESP_LOGD(CONFIGURATION_TAG, "Updating MDNS config");
this->config.mdns.hostname.assign(hostname); this->config.mdns.hostname.assign(hostname);
// TODO turn this on
// if (shouldNotify)
// this->notifyAll(ConfigState_e::mdnsConfigUpdated);
} }
void ProjectConfig::setCameraConfig(uint8_t vflip, void ProjectConfig::setCameraConfig(uint8_t vflip,
uint8_t framesize, uint8_t framesize,
uint8_t href, uint8_t href,
uint8_t quality, uint8_t quality,
uint8_t brightness, uint8_t brightness)
bool shouldNotify)
{ {
ESP_LOGD(CONFIGURATION_TAG, "Updating camera config"); ESP_LOGD(CONFIGURATION_TAG, "Updating camera config");
this->config.camera.vflip = vflip; this->config.camera.vflip = vflip;
@@ -270,20 +257,17 @@ void ProjectConfig::setCameraConfig(uint8_t vflip,
this->config.camera.brightness = brightness; this->config.camera.brightness = brightness;
ESP_LOGD(CONFIGURATION_TAG, "Updating Camera config"); ESP_LOGD(CONFIGURATION_TAG, "Updating Camera config");
// TODO turn this on
// if (shouldNotify)
// this->notifyAll(ConfigState_e::cameraConfigUpdated);
} }
void ProjectConfig::setWifiConfig(const std::string &networkName, void ProjectConfig::setWifiConfig(const std::string &networkName,
const std::string &ssid, const std::string &ssid,
const std::string &password, const std::string &password,
uint8_t channel, uint8_t channel,
uint8_t power, uint8_t power)
bool shouldNotify)
{ {
size_t size = this->config.networks.size(); size_t size = this->config.networks.size();
// rewrite it to std::find
for (auto it = this->config.networks.begin(); for (auto it = this->config.networks.begin();
it != this->config.networks.end();) it != this->config.networks.end();)
{ {
@@ -298,16 +282,6 @@ void ProjectConfig::setWifiConfig(const std::string &networkName,
it->channel = channel; it->channel = channel;
it->power = power; it->power = power;
if (shouldNotify)
{
// TODO port state managers
// wifiStateManager.setState(WiFiState_e::WiFiState_Disconnected);
// WiFi.disconnect();
this->wifiConfigSave();
// TODO turn this on
// this->notifyAll(ConfigState_e::networksConfigUpdated);
}
return; return;
} }
else else
@@ -333,20 +307,9 @@ void ProjectConfig::setWifiConfig(const std::string &networkName,
this->config.networks.emplace_back(networkName, ssid, password, channel, this->config.networks.emplace_back(networkName, ssid, password, channel,
power, false); power, false);
} }
if (shouldNotify)
{
// TODO port state managers
// wifiStateManager.setState(WiFiState_e::WiFiState_None);
// WiFi.disconnect();
this->wifiConfigSave();
// TODO turn this on
// this->notifyAll(ConfigState_e::networksConfigUpdated);
}
} }
void ProjectConfig::deleteWifiConfig(const std::string &networkName, void ProjectConfig::deleteWifiConfig(const std::string &networkName)
bool shouldNotify)
{ {
size_t size = this->config.networks.size(); size_t size = this->config.networks.size();
if (size == 0) if (size == 0)
@@ -368,43 +331,22 @@ void ProjectConfig::deleteWifiConfig(const std::string &networkName,
++it; ++it;
} }
} }
if (shouldNotify)
{
this->wifiConfigSave();
// TODO turn this on
// this->notifyAll(ConfigState_e::networksConfigUpdated);
}
} }
void ProjectConfig::setWiFiTxPower(uint8_t power, bool shouldNotify) void ProjectConfig::setWiFiTxPower(uint8_t power)
{ {
this->config.txpower.power = power; this->config.txpower.power = power;
ESP_LOGD(CONFIGURATION_TAG, "Updating wifi tx power"); ESP_LOGD(CONFIGURATION_TAG, "Updating wifi tx power");
// TODO turn this on
// if (shouldNotify)
// this->notifyAll(ConfigState_e::wifiTxPowerUpdated);
} }
void ProjectConfig::setAPWifiConfig(const std::string &ssid, void ProjectConfig::setAPWifiConfig(const std::string &ssid,
const std::string &password, const std::string &password,
uint8_t channel, uint8_t channel)
bool shouldNotify)
{ {
this->config.ap_network.ssid.assign(ssid); this->config.ap_network.ssid.assign(ssid);
this->config.ap_network.password.assign(password); this->config.ap_network.password.assign(password);
this->config.ap_network.channel = channel; this->config.ap_network.channel = channel;
ESP_LOGD(CONFIGURATION_TAG, "Updating access point config"); ESP_LOGD(CONFIGURATION_TAG, "Updating access point config");
if (shouldNotify)
{
// TODO port state managers
// wifiStateManager.setState(WiFiState_e::WiFiState_None);
// TODO Add some sort of signalling or IPC to tell the wifi manager to shut off
// WiFi.disconnect();
this->wifiConfigSave();
// TODO turn this on
// this->notifyAll(ConfigState_e::networksConfigUpdated);
}
} }
//********************************************************************************************************************** //**********************************************************************************************************************
@@ -112,30 +112,25 @@ public:
void setDeviceConfig(const std::string &OTALogin, void setDeviceConfig(const std::string &OTALogin,
const std::string &OTAPassword, const std::string &OTAPassword,
int OTAPort, int OTAPort);
bool shouldNotify); void setMDNSConfig(const std::string &hostname);
void setMDNSConfig(const std::string &hostname,
bool shouldNotify);
void setCameraConfig(uint8_t vflip, void setCameraConfig(uint8_t vflip,
uint8_t framesize, uint8_t framesize,
uint8_t href, uint8_t href,
uint8_t quality, uint8_t quality,
uint8_t brightness, uint8_t brightness);
bool shouldNotify);
void setWifiConfig(const std::string &networkName, void setWifiConfig(const std::string &networkName,
const std::string &ssid, const std::string &ssid,
const std::string &password, const std::string &password,
uint8_t channel, uint8_t channel,
uint8_t power, uint8_t power);
bool shouldNotify);
void deleteWifiConfig(const std::string &networkName, bool shouldNotify); void deleteWifiConfig(const std::string &networkName);
void setAPWifiConfig(const std::string &ssid, void setAPWifiConfig(const std::string &ssid,
const std::string &password, const std::string &password,
uint8_t channel, uint8_t channel);
bool shouldNotify); void setWiFiTxPower(uint8_t power);
void setWiFiTxPower(uint8_t power, bool shouldNotify);
private: private:
TrackerConfig_t config; TrackerConfig_t config;