This commit is contained in:
Václav Španinger 2025-03-10 10:18:01 +01:00
parent ebef6ce886
commit 6f7ccc267d
4 changed files with 9 additions and 7 deletions

View File

@ -26,7 +26,7 @@ DEPENDENCIES = ['uart']
CONF_MARLIN2_ID = "marlin2_id"
Marlin2 = cg.esphome_ns.class_('Marlin2', cg.Component)
Marlin2WriteAction = Marlin2.class_("Marlin2WriteAction", automation.Action)
WriteAction = cg.esphome_ns.class_("WriteAction", automation.Action)
CONFIG_SCHEMA = cv.All(
cv.Schema({
@ -58,7 +58,7 @@ OPERATION_BASE_SCHEMA = cv.Schema({
@automation.register_action(
"marlin2.write",
Marlin2WriteAction,
WriteAction,
OPERATION_BASE_SCHEMA,
)

View File

@ -6,13 +6,13 @@
namespace esphome {
template<typename... Ts> class Marlin2WriteAction : public Action<Ts...> {
template<typename... Ts> class WriteAction : public Action<Ts...> {
public:
explicit Marlin2WriteAction(Marlin2 *marlin2) : marlin2_(marlin2) {}
explicit WriteAction(Marlin2 *marlin2) : marlin2_(marlin2) {}
TEMPLATABLE_VALUE(std::string, value)
void play(Ts... x) override {
this->marlin2_->write("M117 Action Called!");
this->marlin2_->write(this->value_.value(x...));
}
protected:

View File

@ -52,7 +52,8 @@ namespace esphome {
void Marlin2::write(std::string gcode) {
ESP_LOGD(TAG, "->GCODE: %s", gcode.c_str());
write_str(gcode.c_str());
write_str((std::string("\r\n\r\n") + gcode + std::string("\r\n")).c_str());
flush();
}
@ -77,6 +78,8 @@ namespace esphome {
}
void Marlin2::process_line() {
ESP_LOGD(TAG, "#%s#",MarlinOutput.c_str());
if(MarlinOutput.size() < 3) {
MarlinOutput="";
return;

View File

@ -37,7 +37,6 @@ class Marlin2 : public PollingComponent, public uart::UARTDevice {
float print_progress = 0;
double print_time_offset = 0;
#ifdef USE_SENSOR
std::vector<std::pair<std::string, sensor::Sensor *>> sensors;