Mowing forward
This commit is contained in:
parent
9f9227cf53
commit
dce9c5d67d
@ -8,6 +8,15 @@ 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
|
||||||
|
24
automation.h
24
automation.h
@ -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
|
Loading…
x
Reference in New Issue
Block a user