From dce9c5d67da85b368b0978fbc0bf2621f8fded23 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 5 Mar 2025 17:42:01 +0100 Subject: [PATCH] Mowing forward --- README.md | 11 ++++++++++- automation.h | 26 +++++++------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index bbfb79e..3c91b41 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,16 @@ A configured uart is required. Example: ```yaml - +api: + actions: + - action: 'set_bed_temperature' + variables: + temperature: int + then: + - marlin2.write_g_code + gcode: !lampda "return temperature" + ... + marlin2: uart_id: uart_bus diff --git a/automation.h b/automation.h index ccaab7b..d456348 100644 --- a/automation.h +++ b/automation.h @@ -7,30 +7,18 @@ namespace esphome { -template class Marlin2WriteAction : public Action, public Parented { +template class Marlin2WriteGCodeAction : public Action { public: - void set_data_template(std::function(Ts...)> func) { - this->data_func_ = func; - this->static_ = false; - } - void set_data_static(const std::vector &data) { - this->data_static_ = data; - this->static_ = true; - } + explicit Marlin2WriteGCodeAction(Marlin2 *marlin2) : marlin2_(marlin2) {} + TEMPLATABLE_VALUE(std::string, gcode) void play(Ts... x) override { - if (this->static_) { - this->parent_->write_array(this->data_static_); - } else { - auto val = this->data_func_(x...); - this->parent_->write_array(val); - } + this->marlin2_->write_str("\r\n\r\nM117 Action Called!\r\n");; } - + + protected: - bool static_{false}; - std::function(Ts...)> data_func_{}; - std::vector data_static_{}; + Marlin2 *marlin2_; }; } // namespace esphome \ No newline at end of file