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:
```yaml
api:
actions:
- action: 'set_bed_temperature'
variables:
temperature: int
then:
- marlin2.write_g_code
gcode: !lampda "return temperature"
...
marlin2:
uart_id: uart_bus

View File

@ -7,30 +7,18 @@
namespace esphome {
template<typename... Ts> class Marlin2WriteAction : public Action<Ts...>, public Parented<Marlin2> {
template<typename... Ts> class Marlin2WriteGCodeAction : public Action<Ts...> {
public:
void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) {
this->data_func_ = func;
this->static_ = false;
}
void set_data_static(const std::vector<uint8_t> &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<std::vector<uint8_t>(Ts...)> data_func_{};
std::vector<uint8_t> data_static_{};
Marlin2 *marlin2_;
};
} // namespace esphome