mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-29 01:59:08 +03:00
@@ -100,8 +100,6 @@ static void setup_commands(std::shared_ptr<Commands> const & commands) {
|
||||
EMSESP::show_sensor_values(shell);
|
||||
} else if (command == F_(mqtt)) {
|
||||
Mqtt::show_mqtt(shell);
|
||||
} else if (command == F_(gpio)) {
|
||||
EMSESP::system_.show_gpio(shell);
|
||||
} else {
|
||||
shell.printfln("Unknown show command");
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ MAKE_WORD_CUSTOM(deviceid_mandatory, "<deviceID>")
|
||||
MAKE_WORD_CUSTOM(device_type_optional, "[device]")
|
||||
MAKE_WORD_CUSTOM(invalid_log_level, "Invalid log level")
|
||||
MAKE_WORD_CUSTOM(log_level_optional, "[level]")
|
||||
MAKE_WORD_CUSTOM(show_commands, "[system | users | devices | log | ems | values | mqtt | commands | gpio]")
|
||||
MAKE_WORD_CUSTOM(show_commands, "[system | users | devices | log | ems | values | mqtt | commands]")
|
||||
MAKE_WORD_CUSTOM(name_mandatory, "<name>")
|
||||
MAKE_WORD_CUSTOM(name_optional, "[name]")
|
||||
MAKE_WORD_CUSTOM(new_password_prompt1, "Enter new password: ")
|
||||
|
||||
@@ -96,6 +96,8 @@ uint32_t System::max_alloc_mem_;
|
||||
uint32_t System::heap_mem_;
|
||||
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...
|
||||
@@ -1015,22 +1017,6 @@ void System::show_users(uuid::console::Shell & shell) {
|
||||
shell.println();
|
||||
}
|
||||
|
||||
// print GPIO available and used pins to console
|
||||
void System::show_gpio(uuid::console::Shell & shell) {
|
||||
shell.printfln("GPIO:");
|
||||
shell.printf(" In use (%d):", used_gpios_.size());
|
||||
for (const auto & gpio : used_gpios_) {
|
||||
shell.printf(" %d", gpio);
|
||||
}
|
||||
shell.println();
|
||||
auto available = available_gpios();
|
||||
shell.printf(" Available (%d):", available.size());
|
||||
for (const auto & gpio : available) {
|
||||
shell.printf(" %d", gpio);
|
||||
}
|
||||
shell.println();
|
||||
}
|
||||
|
||||
// shell command 'show system'
|
||||
void System::show_system(uuid::console::Shell & shell) {
|
||||
refreshHeapMem(); // refresh free heap and max alloc heap
|
||||
@@ -1068,8 +1054,20 @@ void System::show_system(uuid::console::Shell & shell) {
|
||||
} else {
|
||||
shell.printfln(" PSRAM: not available");
|
||||
}
|
||||
|
||||
// GPIOs
|
||||
shell.printf(" GPIO in use (%d):", used_gpios_.size());
|
||||
for (const auto & gpio : used_gpios_) {
|
||||
shell.printf(" %d", gpio);
|
||||
}
|
||||
shell.println();
|
||||
auto available = available_gpios();
|
||||
shell.printf(" GPIO available (%d):", available.size());
|
||||
for (const auto & gpio : available) {
|
||||
shell.printf(" %d", gpio);
|
||||
}
|
||||
shell.println();
|
||||
shell.println();
|
||||
|
||||
shell.println("Network:");
|
||||
|
||||
switch (WiFi.status()) {
|
||||
@@ -2241,10 +2239,9 @@ bool System::load_board_profile(std::vector<int8_t> & data, const std::string &
|
||||
|
||||
// format command - factory reset, removing all config files
|
||||
bool System::command_format(const char * value, const int8_t id) {
|
||||
LOG_INFO("Formatting FS, removing all config files");
|
||||
#ifndef EMSESP_STANDALONE
|
||||
if (LittleFS.format()) {
|
||||
LOG_INFO("FS formatted successfully");
|
||||
LOG_INFO("Filesystem formatted successfully. All config files removed.");
|
||||
} else {
|
||||
LOG_ERROR("Format failed");
|
||||
}
|
||||
@@ -2688,4 +2685,30 @@ std::vector<uint8_t> System::available_gpios() {
|
||||
return gpios;
|
||||
}
|
||||
|
||||
// make a snapshot of the current GPIOs
|
||||
void System::make_snapshot_gpios() {
|
||||
snapshot_used_gpios_.clear();
|
||||
for (const auto & gpio : used_gpios_) {
|
||||
snapshot_used_gpios_.push_back(gpio);
|
||||
}
|
||||
|
||||
snapshot_valid_system_gpios_.clear();
|
||||
for (const auto & gpio : valid_system_gpios_) {
|
||||
snapshot_valid_system_gpios_.push_back(gpio);
|
||||
}
|
||||
}
|
||||
|
||||
// restore the GPIOs from the snapshot
|
||||
void System::restore_snapshot_gpios() {
|
||||
used_gpios_.clear();
|
||||
for (const auto & gpio : snapshot_used_gpios_) {
|
||||
used_gpios_.push_back(gpio);
|
||||
}
|
||||
|
||||
valid_system_gpios_.clear();
|
||||
for (const auto & gpio : snapshot_valid_system_gpios_) {
|
||||
valid_system_gpios_.push_back(gpio);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -145,9 +145,12 @@ class System {
|
||||
static void extractSettings(const char * filename, const char * section, JsonObject output);
|
||||
static bool saveSettings(const char * filename, const char * section, JsonObject input);
|
||||
|
||||
// GPIOs
|
||||
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 bool readCommand(const char * data);
|
||||
|
||||
@@ -301,7 +304,6 @@ class System {
|
||||
|
||||
void show_system(uuid::console::Shell & shell);
|
||||
void show_users(uuid::console::Shell & shell);
|
||||
void show_gpio(uuid::console::Shell & shell);
|
||||
|
||||
void wifi_reconnect();
|
||||
|
||||
@@ -402,8 +404,10 @@ class System {
|
||||
|
||||
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> string_range_to_vector(const std::string & range);
|
||||
|
||||
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>> 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
|
||||
|
||||
int8_t wifi_quality(int8_t dBm);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user