OpenIris/ESP/lib/src/data/config/project_config.hpp
DaOfficialWizard 17e3049be1
feat: Code cleanup and initial implementation of improv
* feat: add improv

- add version to build flags
- add improv
- remove byte pointers from config calls

* ´fix: improve not initilizing in ADHOC mode

* feat: add wifihandler to observers

* refactor: move improv handler to top of loop

* refactor: minor refactor to callback

* refactor: minor refactor to callback

* refactor: trying to weed out the timeout issue

* refactor: trying to weed out the timeout issue

* refactor: total refactor to clean up code

-  clean up statemanagers
- fix observer
- fix bugs introducted by fixing the observer

BREAKING CHANGES

* refactor: minor logging refactor

* fix: add config save to delete method

* fix: improv provisioning error

* refactor: simplify library interface

- implement pass by reference for all objects
- implement get by reference for all objects
- remove passing state to classes
- migrate to range based for loops

BREAKING CHANGES

* fix: esp crash on wifi updates

- figure out why esp crashes sometimes when wifi config changes

* fix: add warning about clang-format to baseAPI.hpp

* refactor: update improv

* ci(ci-test): setup prerelease

- use ci to merge binaries for testing in etvr app

* fix: compile time error

* fix: compile time error

* fix folder names

* fix folder names

* fix: compile time error

* fix: compile time error

* feat: remove improv from main

- keep improv code, incase we fix issue later on
- comment out improv includes

* fix: remove pre-release from release cycle

* fix: resolve wifiState manager state in config

* fix: file name casing

* fix: file name casing

* feat: add custom string_view header

- it is the intention to implement string_view
- vastly reduce heap allocations and improve performance of strings

* refactor: move improv class to new branch

* fix: file name casing

* feat: add newer esp cam driver

* Cleanup after merge

---------

Co-authored-by: lorow <smykupyka@gmail.com>
2023-04-02 17:44:38 +02:00

144 lines
3.9 KiB
C++

#pragma once
#ifndef PROJECT_CONFIG_HPP
#define PROJECT_CONFIG_HPP
#include <Arduino.h>
#include <Preferences.h>
#include <algorithm>
#include <string>
#include <vector>
#include "data/StateManager/StateManager.hpp"
#include "data/utilities/Observer.hpp"
#include "data/utilities/helpers.hpp"
#include "data/utilities/network_utilities.hpp"
#include "tasks/tasks.hpp"
class ProjectConfig : public Preferences, public ISubject<ConfigState_e> {
public:
ProjectConfig(const std::string& name = std::string(),
const std::string& mdnsName = std::string());
virtual ~ProjectConfig();
void load();
void save();
void wifiConfigSave();
void cameraConfigSave();
void deviceConfigSave();
void mdnsConfigSave();
void wifiTxPowerConfigSave();
bool reset();
void initConfig();
struct DeviceConfig_t {
std::string OTALogin;
std::string OTAPassword;
int OTAPort;
std::string toRepresentation();
};
struct MDNSConfig_t {
std::string hostname;
std::string service;
std::string toRepresentation();
};
struct CameraConfig_t {
uint8_t vflip;
uint8_t href;
uint8_t framesize;
uint8_t quality;
uint8_t brightness;
std::string toRepresentation();
};
struct WiFiConfig_t {
//! Constructor for WiFiConfig_t - allows us to use emplace_back
WiFiConfig_t(const std::string& name,
const std::string& ssid,
const std::string& password,
uint8_t channel,
uint8_t power,
bool adhoc)
: name(std::move(name)),
ssid(std::move(ssid)),
password(std::move(password)),
channel(channel),
adhoc(adhoc),
power(power) {}
std::string name;
std::string ssid;
std::string password;
uint8_t channel;
uint8_t power;
bool adhoc;
std::string toRepresentation();
};
struct AP_WiFiConfig_t {
std::string ssid;
std::string password;
uint8_t channel;
bool adhoc;
std::string toRepresentation();
};
struct WiFiTxPower_t {
uint8_t power;
std::string toRepresentation();
};
struct TrackerConfig_t {
DeviceConfig_t device;
CameraConfig_t camera;
std::vector<WiFiConfig_t> networks;
AP_WiFiConfig_t ap_network;
MDNSConfig_t mdns;
WiFiTxPower_t txpower;
};
DeviceConfig_t& getDeviceConfig();
CameraConfig_t& getCameraConfig();
std::vector<WiFiConfig_t>& getWifiConfigs();
AP_WiFiConfig_t& getAPWifiConfig();
MDNSConfig_t& getMDNSConfig();
WiFiTxPower_t& getWiFiTxPowerConfig();
void setDeviceConfig(const std::string& OTALogin,
const std::string& OTAPassword,
int OTAPort,
bool shouldNotify);
void setMDNSConfig(const std::string& hostname,
const std::string& service,
bool shouldNotify);
void setCameraConfig(uint8_t vflip,
uint8_t framesize,
uint8_t href,
uint8_t quality,
uint8_t brightness,
bool shouldNotify);
void setWifiConfig(const std::string& networkName,
const std::string& ssid,
const std::string& password,
uint8_t channel,
uint8_t power,
bool adhoc,
bool shouldNotify);
void setAPWifiConfig(const std::string& ssid,
const std::string& password,
uint8_t channel,
bool adhoc,
bool shouldNotify);
void setWiFiTxPower(uint8_t power, bool shouldNotify);
void deleteWifiConfig(const std::string& networkName, bool shouldNotify);
private:
TrackerConfig_t config;
std::string _name;
std::string _mdnsName;
bool _already_loaded;
};
#endif // PROJECT_CONFIG_HPP