From 68ab694d8a8f20e7176fa743993804243c4bb35b Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 16 Jun 2025 11:07:46 +0200 Subject: [PATCH] Fixes --- .gitignore | 2 ++ marlin2.cpp | 17 +++++++++++++++++ marlin2.h | 4 +++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1c3177 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +s +__pycache__/* diff --git a/marlin2.cpp b/marlin2.cpp index 83bd693..62ca4c2 100644 --- a/marlin2.cpp +++ b/marlin2.cpp @@ -218,6 +218,23 @@ namespace esphome { 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()); + + //reset string for next line + MarlinOutput=""; + return; + } + + ESP_LOGD(TAG, "#%s#",MarlinOutput.c_str()); MarlinOutput=""; return; diff --git a/marlin2.h b/marlin2.h index ea52446..170ad15 100644 --- a/marlin2.h +++ b/marlin2.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include "esphome/core/component.h" #include "esphome/components/uart/uart.h" #ifdef USE_SENSOR @@ -15,7 +17,6 @@ class Marlin2 : public PollingComponent, public uart::UARTDevice { public: Marlin2() = default; - #ifdef USE_SENSOR void add_sensor(const std::string& sName, sensor::Sensor *sens); sensor::Sensor* find_sensor(std::string key); @@ -55,6 +56,7 @@ class Marlin2 : public PollingComponent, public uart::UARTDevice { private: unsigned long millisProgress=0; + std::unordered_map file_table_; }; } // namespace esphome \ No newline at end of file