Files
ESPHomeMarlin2/automation.h
JonatanRek 270a92ba06 Refactor Marlin2 component and add new features
- Updated __init__.py to include max_sd_files configuration option.
- Refactored Marlin2 class to use new namespaces and improved structure.
- Added support for binary sensors and select components in binary_sensor.py and select.py.
- Enhanced sensor.py and text_sensor.py to include new configuration options for SD card file count and selected file.
- Improved code readability and organization across multiple files.
2026-04-07 08:19:25 +02:00

40 lines
1.1 KiB
C++

#pragma once
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "marlin2.h"
namespace esphome::marlin2 {
template<typename... Ts> class WriteAction : public Action<Ts...> {
public:
explicit WriteAction(Marlin2 *marlin2) : marlin2_(marlin2) {}
TEMPLATABLE_VALUE(std::string, value)
void play(Ts... x) override {
this->marlin2_->write(this->value_.value(x...));
}
protected:
Marlin2 *marlin2_;
};
template<typename... Ts> class PrintFileAction : public Action<Ts...> {
public:
explicit PrintFileAction(Marlin2 *marlin2) : marlin2_(marlin2) {}
TEMPLATABLE_VALUE(std::string, value)
void play(Ts... x) override {
static const char *const TAG = "marlin2";
std::string file_name = this->marlin2_->to_dos_name(this->value_.value(x...));
ESP_LOGD(TAG, "->FILE: %s", file_name.c_str());
this->marlin2_->write(str_sprintf("M32 P !%s#", file_name.c_str()));
}
protected:
Marlin2 *marlin2_;
};
} // namespace esphome::marlin2