From 6f7ccc267dff5cedaf07a783200e74c877b33519 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 10 Mar 2025 10:18:01 +0100 Subject: [PATCH] Progress --- __init__.py | 4 ++-- automation.h | 6 +++--- marlin2.cpp | 5 ++++- marlin2.h | 1 - 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/__init__.py b/__init__.py index a389cef..451369f 100644 --- a/__init__.py +++ b/__init__.py @@ -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, ) diff --git a/automation.h b/automation.h index 8ceb2ee..327979a 100644 --- a/automation.h +++ b/automation.h @@ -6,13 +6,13 @@ namespace esphome { -template class Marlin2WriteAction : public Action { +template class WriteAction : public Action { 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: diff --git a/marlin2.cpp b/marlin2.cpp index d37b2fb..1a7ba7c 100644 --- a/marlin2.cpp +++ b/marlin2.cpp @@ -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; diff --git a/marlin2.h b/marlin2.h index 770d29a..e34561e 100644 --- a/marlin2.h +++ b/marlin2.h @@ -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> sensors;