mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-14 04:03:44 +02:00
Add PoC PWN duty cycle adjustment command for FaceFocus
This commit is contained in:
@@ -21,35 +21,39 @@ struct BaseConfigModel
|
||||
Preferences *pref;
|
||||
};
|
||||
|
||||
enum class StreamingMode {
|
||||
enum class StreamingMode
|
||||
{
|
||||
AUTO,
|
||||
UVC,
|
||||
WIFI,
|
||||
};
|
||||
|
||||
struct DeviceMode_t : BaseConfigModel {
|
||||
struct DeviceMode_t : BaseConfigModel
|
||||
{
|
||||
StreamingMode mode;
|
||||
explicit DeviceMode_t( Preferences *pref) : BaseConfigModel(pref), mode(StreamingMode::AUTO){}
|
||||
explicit DeviceMode_t(Preferences *pref) : BaseConfigModel(pref), mode(StreamingMode::AUTO) {}
|
||||
|
||||
void load() {
|
||||
void load()
|
||||
{
|
||||
int stored_mode = this->pref->getInt("mode", 0);
|
||||
this->mode = static_cast<StreamingMode>(stored_mode);
|
||||
ESP_LOGI("DeviceMode", "Loaded device mode: %d", stored_mode);
|
||||
}
|
||||
|
||||
void save() const {
|
||||
void save() const
|
||||
{
|
||||
this->pref->putInt("mode", static_cast<int>(this->mode));
|
||||
ESP_LOGI("DeviceMode", "Saved device mode: %d", static_cast<int>(this->mode));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct DeviceConfig_t : BaseConfigModel
|
||||
{
|
||||
DeviceConfig_t(Preferences *pref) : BaseConfigModel(pref) {}
|
||||
|
||||
std::string OTALogin;
|
||||
std::string OTAPassword;
|
||||
int led_external_pwm_duty_cycle;
|
||||
int OTAPort;
|
||||
|
||||
void load()
|
||||
@@ -57,20 +61,23 @@ struct DeviceConfig_t : BaseConfigModel
|
||||
this->OTALogin = this->pref->getString("OTALogin", "openiris");
|
||||
this->OTAPassword = this->pref->getString("OTAPassword", "openiris");
|
||||
this->OTAPort = this->pref->getInt("OTAPort", 3232);
|
||||
this->led_external_pwm_duty_cycle = this->pref->getInt("led_ext_pwm", CONFIG_LED_EXTERNAL_PWM_DUTY_CYCLE);
|
||||
};
|
||||
|
||||
void save() const {
|
||||
void save() const
|
||||
{
|
||||
this->pref->putString("OTALogin", this->OTALogin.c_str());
|
||||
this->pref->putString("OTAPassword", this->OTAPassword.c_str());
|
||||
this->pref->putInt("OTAPort", this->OTAPort);
|
||||
this->pref->putInt("led_ext_pwm", this->led_external_pwm_duty_cycle);
|
||||
};
|
||||
|
||||
std::string toRepresentation() const
|
||||
{
|
||||
return Helpers::format_string(
|
||||
"\"device_config\": {\"OTALogin\": \"%s\", \"OTAPassword\": \"%s\", "
|
||||
"\"OTAPort\": %u}",
|
||||
this->OTALogin.c_str(), this->OTAPassword.c_str(), this->OTAPort);
|
||||
"\"OTAPort\": %u, \"led_external_pwm_duty_cycle\": %u}",
|
||||
this->OTALogin.c_str(), this->OTAPassword.c_str(), this->OTAPort, this->led_external_pwm_duty_cycle);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -94,7 +101,8 @@ struct MDNSConfig_t : BaseConfigModel
|
||||
this->hostname = this->pref->getString("hostname", default_hostname);
|
||||
};
|
||||
|
||||
void save() const {
|
||||
void save() const
|
||||
{
|
||||
this->pref->putString("hostname", this->hostname.c_str());
|
||||
};
|
||||
|
||||
@@ -125,7 +133,8 @@ struct CameraConfig_t : BaseConfigModel
|
||||
this->brightness = this->pref->getInt("brightness", 2);
|
||||
};
|
||||
|
||||
void save() const {
|
||||
void save() const
|
||||
{
|
||||
this->pref->putInt("vflip", this->vflip);
|
||||
this->pref->putInt("href", this->href);
|
||||
this->pref->putInt("framesize", this->framesize);
|
||||
@@ -186,12 +195,13 @@ struct WiFiConfig_t : BaseConfigModel
|
||||
this->password = this->pref->getString(("password" + iter_str).c_str(), "");
|
||||
this->channel = this->pref->getUInt(("channel" + iter_str).c_str());
|
||||
this->power = this->pref->getUInt(("power" + iter_str).c_str());
|
||||
|
||||
ESP_LOGI("WiFiConfig", "Loaded network %d: name=%s, ssid=%s, channel=%d",
|
||||
|
||||
ESP_LOGI("WiFiConfig", "Loaded network %d: name=%s, ssid=%s, channel=%d",
|
||||
index, this->name.c_str(), this->ssid.c_str(), this->channel);
|
||||
};
|
||||
|
||||
void save() const {
|
||||
void save() const
|
||||
{
|
||||
char buffer[2];
|
||||
auto const iter_str = std::string(Helpers::itoa(this->index, buffer, 10));
|
||||
|
||||
@@ -200,8 +210,8 @@ struct WiFiConfig_t : BaseConfigModel
|
||||
this->pref->putString(("password" + iter_str).c_str(), this->password.c_str());
|
||||
this->pref->putUInt(("channel" + iter_str).c_str(), this->channel);
|
||||
this->pref->putUInt(("power" + iter_str).c_str(), this->power);
|
||||
|
||||
ESP_LOGI("WiFiConfig", "Saved network %d: name=%s, ssid=%s, channel=%d",
|
||||
|
||||
ESP_LOGI("WiFiConfig", "Saved network %d: name=%s, ssid=%s, channel=%d",
|
||||
this->index, this->name.c_str(), this->ssid.c_str(), this->channel);
|
||||
};
|
||||
|
||||
@@ -228,7 +238,8 @@ struct AP_WiFiConfig_t : BaseConfigModel
|
||||
this->password = this->pref->getString("apPassword", CONFIG_WIFI_AP_PASSWORD);
|
||||
};
|
||||
|
||||
void save() const {
|
||||
void save() const
|
||||
{
|
||||
this->pref->putString("apSSID", this->ssid.c_str());
|
||||
this->pref->putString("apPass", this->password.c_str());
|
||||
this->pref->putUInt("apChannel", this->channel);
|
||||
@@ -254,7 +265,8 @@ struct WiFiTxPower_t : BaseConfigModel
|
||||
this->power = this->pref->getUInt("txpower", 52);
|
||||
};
|
||||
|
||||
void save() const {
|
||||
void save() const
|
||||
{
|
||||
this->pref->putUInt("txpower", this->power);
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ ProjectConfig::ProjectConfig(Preferences *pref) : pref(pref),
|
||||
|
||||
ProjectConfig::~ProjectConfig() = default;
|
||||
|
||||
void ProjectConfig::save() const {
|
||||
void ProjectConfig::save() const
|
||||
{
|
||||
ESP_LOGD(CONFIGURATION_TAG, "Saving project config");
|
||||
this->config.device.save();
|
||||
this->config.device_mode.save();
|
||||
@@ -92,14 +93,22 @@ bool ProjectConfig::reset()
|
||||
//! DeviceConfig
|
||||
//*
|
||||
//**********************************************************************************************************************
|
||||
void ProjectConfig::setDeviceConfig(const std::string &OTALogin,
|
||||
const std::string &OTAPassword,
|
||||
const int OTAPort)
|
||||
void ProjectConfig::setOTAConfig(const std::string &OTALogin,
|
||||
const std::string &OTAPassword,
|
||||
const int OTAPort)
|
||||
{
|
||||
ESP_LOGD(CONFIGURATION_TAG, "Updating device config");
|
||||
this->config.device.OTALogin.assign(OTALogin);
|
||||
this->config.device.OTAPassword.assign(OTAPassword);
|
||||
this->config.device.OTAPort = OTAPort;
|
||||
this->config.device.save();
|
||||
}
|
||||
|
||||
void ProjectConfig::setLEDDUtyCycleConfig(int led_external_pwm_duty_cycle)
|
||||
{
|
||||
this->config.device.led_external_pwm_duty_cycle = led_external_pwm_duty_cycle;
|
||||
ESP_LOGI(CONFIGURATION_TAG, "Setting duty cycle to %d", led_external_pwm_duty_cycle);
|
||||
this->config.device.save();
|
||||
}
|
||||
|
||||
void ProjectConfig::setMDNSConfig(const std::string &hostname)
|
||||
@@ -120,6 +129,7 @@ void ProjectConfig::setCameraConfig(const uint8_t vflip,
|
||||
this->config.camera.framesize = framesize;
|
||||
this->config.camera.quality = quality;
|
||||
this->config.camera.brightness = brightness;
|
||||
this->config.camera.save();
|
||||
|
||||
ESP_LOGD(CONFIGURATION_TAG, "Updating Camera config");
|
||||
}
|
||||
@@ -133,8 +143,8 @@ void ProjectConfig::setWifiConfig(const std::string &networkName,
|
||||
const auto size = this->config.networks.size();
|
||||
|
||||
const auto it = std::ranges::find_if(this->config.networks,
|
||||
[&](const WiFiConfig_t &network)
|
||||
{ return network.name == networkName; });
|
||||
[&](const WiFiConfig_t &network)
|
||||
{ return network.name == networkName; });
|
||||
|
||||
if (it != this->config.networks.end())
|
||||
{
|
||||
@@ -191,8 +201,8 @@ void ProjectConfig::deleteWifiConfig(const std::string &networkName)
|
||||
}
|
||||
|
||||
const auto it = std::ranges::find_if(this->config.networks,
|
||||
[&](const WiFiConfig_t &network)
|
||||
{ return network.name == networkName; });
|
||||
[&](const WiFiConfig_t &network)
|
||||
{ return network.name == networkName; });
|
||||
|
||||
if (it != this->config.networks.end())
|
||||
{
|
||||
@@ -205,6 +215,7 @@ void ProjectConfig::deleteWifiConfig(const std::string &networkName)
|
||||
void ProjectConfig::setWiFiTxPower(uint8_t power)
|
||||
{
|
||||
this->config.txpower.power = power;
|
||||
this->config.txpower.save();
|
||||
ESP_LOGD(CONFIGURATION_TAG, "Updating wifi tx power");
|
||||
}
|
||||
|
||||
@@ -215,12 +226,14 @@ void ProjectConfig::setAPWifiConfig(const std::string &ssid,
|
||||
this->config.ap_network.ssid.assign(ssid);
|
||||
this->config.ap_network.password.assign(password);
|
||||
this->config.ap_network.channel = channel;
|
||||
this->config.ap_network.save();
|
||||
ESP_LOGD(CONFIGURATION_TAG, "Updating access point config");
|
||||
}
|
||||
|
||||
void ProjectConfig::setDeviceMode(const StreamingMode deviceMode) {
|
||||
void ProjectConfig::setDeviceMode(const StreamingMode deviceMode)
|
||||
{
|
||||
this->config.device_mode.mode = deviceMode;
|
||||
this->config.device_mode.save(); // Save immediately
|
||||
this->config.device_mode.save(); // Save immediately
|
||||
}
|
||||
|
||||
//**********************************************************************************************************************
|
||||
@@ -258,10 +271,12 @@ TrackerConfig_t &ProjectConfig::getTrackerConfig()
|
||||
return this->config;
|
||||
}
|
||||
|
||||
DeviceMode_t &ProjectConfig::getDeviceModeConfig() {
|
||||
DeviceMode_t &ProjectConfig::getDeviceModeConfig()
|
||||
{
|
||||
return this->config.device_mode;
|
||||
}
|
||||
|
||||
StreamingMode ProjectConfig::getDeviceMode() {
|
||||
StreamingMode ProjectConfig::getDeviceMode()
|
||||
{
|
||||
return this->config.device_mode.mode;
|
||||
}
|
||||
@@ -22,11 +22,6 @@ public:
|
||||
void load();
|
||||
void save() const;
|
||||
|
||||
void wifiConfigSave();
|
||||
void cameraConfigSave();
|
||||
void deviceConfigSave();
|
||||
void mdnsConfigSave();
|
||||
void wifiTxPowerConfigSave();
|
||||
bool reset();
|
||||
|
||||
DeviceConfig_t &getDeviceConfig();
|
||||
@@ -38,9 +33,10 @@ public:
|
||||
WiFiTxPower_t &getWiFiTxPowerConfig();
|
||||
TrackerConfig_t &getTrackerConfig();
|
||||
|
||||
void setDeviceConfig(const std::string &OTALogin,
|
||||
const std::string &OTAPassword,
|
||||
int OTAPort);
|
||||
void setOTAConfig(const std::string &OTALogin,
|
||||
const std::string &OTAPassword,
|
||||
int OTAPort);
|
||||
void setLEDDUtyCycleConfig(int led_external_pwm_duty_cycle);
|
||||
void setMDNSConfig(const std::string &hostname);
|
||||
void setCameraConfig(uint8_t vflip,
|
||||
uint8_t framesize,
|
||||
|
||||
Reference in New Issue
Block a user