This commit is contained in:
Václav Španinger 2025-06-26 14:01:31 +02:00
parent 68ab694d8a
commit 91f2dd54be
2 changed files with 163 additions and 135 deletions

View File

@ -86,10 +86,43 @@ namespace esphome {
} }
if(!MarlinOutput.compare("ok") || !MarlinOutput.compare(" ok")) { if(!MarlinOutput.compare("ok") || !MarlinOutput.compare(" ok")) {
listingFile = false;
MarlinOutput=""; MarlinOutput="";
return; return;
} }
if(!listingFile && MarlinOutput.compare("Begin file list") == 0) {
ESP_LOGD(TAG, "Listing of files started!");
listingFile = true;
//reset string for next line
MarlinOutput="";
return;
}
if(listingFile && MarlinOutput.compare(".GCO ")) {
int first_space = MarlinOutput.find(' ');
int second_space = MarlinOutput.find(' ', first_space + 1);
if(first_space > 0) {
std::string short_name = MarlinOutput.substr(0, first_space);
std::string long_name = short_name;
if (second_space > first_space){
long_name = MarlinOutput.substr(second_space + 1);
}
file_table_[long_name] = short_name;
ESP_LOGD(TAG, "Uloženo do tabulky: %s => %s", long_name.c_str(), short_name.c_str());
}
//reset string for next line
MarlinOutput="";
return;
}
//Parse periodic Temperature read out message //Parse periodic Temperature read out message
if( if(
MarlinOutput.find(" T:") == 0 || MarlinOutput.find(" T:") == 0 ||
@ -218,17 +251,11 @@ namespace esphome {
return; return;
} }
size_t first_space = MarlinOutput.find(' ');
size_t second_space = MarlinOutput.find(' ', first_space + 1);
if(second_space == std::string::npos && first_space == std::string::npos) {
std::string short_name = MarlinOutput.substr(0, first_space);
std::string long_name = MarlinOutput.substr(second_space + 1);
file_table_[long_name] = short_name;
ESP_LOGD(TAG, "Uloženo do tabulky: %s => %s", long_name.c_str(), short_name.c_str());
if(MarlinOutput.find("End file list") != std::string::npos) {
ESP_LOGD(TAG, "Listing of files stopped!");
listingFile = false;
//reset string for next line //reset string for next line
MarlinOutput=""; MarlinOutput="";
return; return;

View File

@ -57,6 +57,7 @@ class Marlin2 : public PollingComponent, public uart::UARTDevice {
private: private:
unsigned long millisProgress=0; unsigned long millisProgress=0;
std::unordered_map<std::string, std::string> file_table_; std::unordered_map<std::string, std::string> file_table_;
bool listingFile = false;
}; };
} // namespace esphome } // namespace esphome