Mowing forward

This commit is contained in:
Václav Španinger 2025-03-05 17:42:01 +01:00
parent 9f9227cf53
commit dce9c5d67d
2 changed files with 17 additions and 20 deletions

View File

@ -8,7 +8,16 @@ A configured uart is required.
Example: Example:
```yaml ```yaml
api:
actions:
- action: 'set_bed_temperature'
variables:
temperature: int
then:
- marlin2.write_g_code
gcode: !lampda "return temperature"
...
marlin2: marlin2:
uart_id: uart_bus uart_id: uart_bus

View File

@ -7,30 +7,18 @@
namespace esphome { namespace esphome {
template<typename... Ts> class Marlin2WriteAction : public Action<Ts...>, public Parented<Marlin2> { template<typename... Ts> class Marlin2WriteGCodeAction : public Action<Ts...> {
public: public:
void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) { explicit Marlin2WriteGCodeAction(Marlin2 *marlin2) : marlin2_(marlin2) {}
this->data_func_ = func; TEMPLATABLE_VALUE(std::string, gcode)
this->static_ = false;
}
void set_data_static(const std::vector<uint8_t> &data) {
this->data_static_ = data;
this->static_ = true;
}
void play(Ts... x) override { void play(Ts... x) override {
if (this->static_) { this->marlin2_->write_str("\r\n\r\nM117 Action Called!\r\n");;
this->parent_->write_array(this->data_static_);
} else {
auto val = this->data_func_(x...);
this->parent_->write_array(val);
}
} }
protected: protected:
bool static_{false}; Marlin2 *marlin2_;
std::function<std::vector<uint8_t>(Ts...)> data_func_{};
std::vector<uint8_t> data_static_{};
}; };
} // namespace esphome } // namespace esphome