mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-26 08:39:09 +03:00
snapshot gpios in temporarly ram
This commit is contained in:
@@ -107,8 +107,6 @@ bool System::led_flash_timer_ = false;
|
||||
// GPIOs
|
||||
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::valid_system_gpios_;
|
||||
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::used_gpios_;
|
||||
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::snapshot_used_gpios_;
|
||||
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::snapshot_valid_system_gpios_;
|
||||
|
||||
// find the index of the language
|
||||
// 0 = EN, 1 = DE, etc...
|
||||
@@ -2923,37 +2921,26 @@ std::vector<uint8_t> System::available_gpios() {
|
||||
}
|
||||
|
||||
// make a snapshot of the current GPIOs
|
||||
void System::make_snapshot_gpios() {
|
||||
snapshot_used_gpios_.clear();
|
||||
void System::make_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios) {
|
||||
for (const auto & gpio : used_gpios_) {
|
||||
snapshot_used_gpios_.push_back(gpio);
|
||||
u_gpios.push_back(gpio);
|
||||
}
|
||||
|
||||
snapshot_valid_system_gpios_.clear();
|
||||
for (const auto & gpio : valid_system_gpios_) {
|
||||
snapshot_valid_system_gpios_.push_back(gpio);
|
||||
s_gpios.push_back(gpio);
|
||||
}
|
||||
}
|
||||
|
||||
// restore the GPIOs from the snapshot
|
||||
void System::restore_snapshot_gpios() {
|
||||
void System::restore_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios) {
|
||||
used_gpios_.clear();
|
||||
for (const auto & gpio : snapshot_used_gpios_) {
|
||||
for (const auto & gpio : u_gpios) {
|
||||
used_gpios_.push_back(gpio);
|
||||
}
|
||||
|
||||
valid_system_gpios_.clear();
|
||||
for (const auto & gpio : snapshot_valid_system_gpios_) {
|
||||
for (const auto & gpio : s_gpios) {
|
||||
valid_system_gpios_.push_back(gpio);
|
||||
}
|
||||
|
||||
// clear the snapshot
|
||||
clear_snapshot_gpios();
|
||||
}
|
||||
|
||||
void System::clear_snapshot_gpios() {
|
||||
snapshot_used_gpios_.clear();
|
||||
snapshot_valid_system_gpios_.clear();
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -163,9 +163,8 @@ class System {
|
||||
static bool add_gpio(uint8_t pin, const char * source_name);
|
||||
static std::vector<uint8_t> available_gpios();
|
||||
static bool load_board_profile(std::vector<int8_t> & data, const std::string & board_profile);
|
||||
static void make_snapshot_gpios();
|
||||
static void restore_snapshot_gpios();
|
||||
static void clear_snapshot_gpios();
|
||||
static void make_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios);
|
||||
static void restore_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios);
|
||||
|
||||
static bool readCommand(const char * data);
|
||||
|
||||
@@ -438,10 +437,8 @@ class System {
|
||||
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> string_range_to_vector(const std::string & range);
|
||||
|
||||
// GPIOs
|
||||
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used
|
||||
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> used_gpios_; // list of GPIOs used by the application
|
||||
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> snapshot_used_gpios_; // snapshot of the used GPIOs
|
||||
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> snapshot_valid_system_gpios_; // snapshot of the valid GPIOs
|
||||
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used
|
||||
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> used_gpios_; // list of GPIOs used by the application
|
||||
|
||||
int8_t wifi_quality(int8_t dBm);
|
||||
|
||||
|
||||
@@ -92,7 +92,9 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
|
||||
const WebSettings original_settings(settings);
|
||||
|
||||
// make a snapshot of the current GPIOs
|
||||
EMSESP::system_.make_snapshot_gpios();
|
||||
std::vector<int8_t> used_gpios;
|
||||
std::vector<int8_t> system_gpios;
|
||||
EMSESP::system_.make_snapshot_gpios(used_gpios, system_gpios);
|
||||
|
||||
reset_flags();
|
||||
|
||||
@@ -111,13 +113,6 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
|
||||
settings.eth_clock_mode = root["eth_clock_mode"];
|
||||
settings.led_type = root["led_type"]; // 1 = RGB-LED
|
||||
|
||||
#if defined(EMSESP_DEBUG)
|
||||
EMSESP::logger().debug("NVS boot value=[%s], current board_profile=[%s], new board_profile=[%s]",
|
||||
EMSESP::nvs_.getString("boot").c_str(),
|
||||
original_settings.board_profile.c_str(),
|
||||
settings.board_profile.c_str());
|
||||
#endif
|
||||
|
||||
// see if the user has changed the board profile
|
||||
// this will set: led_gpio, dallas_gpio, rx_gpio, tx_gpio, pbutton_gpio, phy_type, eth_power, eth_phy_addr, eth_clock_mode, led_type
|
||||
// this will always run when EMS-ESP starts since original_settings{} is empty
|
||||
@@ -315,16 +310,13 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
|
||||
// replace settings with original settings
|
||||
settings = original_settings; // the original settings are still valid
|
||||
// restore the GPIOs from the snapshot
|
||||
EMSESP::system_.restore_snapshot_gpios();
|
||||
EMSESP::system_.restore_snapshot_gpios(used_gpios, system_gpios);
|
||||
|
||||
// report the error to WebUI
|
||||
EMSESP::system_.systemStatus(SYSTEM_STATUS::SYSTEM_STATUS_INVALID_GPIO);
|
||||
return StateUpdateResult::ERROR; // don't save the settings if the GPIOs are invalid
|
||||
}
|
||||
|
||||
// clean up snapshot of the GPIOs
|
||||
EMSESP::system_.clear_snapshot_gpios();
|
||||
|
||||
// save the setting internally, for reference later
|
||||
EMSESP::system_.store_settings(settings);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user