Tweaks And Fixes
This commit is contained in:
parent
dce9c5d67d
commit
ebef6ce886
33
__init__.py
33
__init__.py
@ -16,8 +16,10 @@ from esphome.const import (
|
|||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
DEVICE_CLASS_DURATION,
|
DEVICE_CLASS_DURATION,
|
||||||
CONF_DATA,
|
CONF_DATA,
|
||||||
|
CONF_VALUE
|
||||||
)
|
)
|
||||||
from esphome import pins, automation
|
from esphome import pins, automation
|
||||||
|
from esphome.core import CORE, coroutine_with_priority
|
||||||
|
|
||||||
CODEOWNERS = ["@jonatanrek"]
|
CODEOWNERS = ["@jonatanrek"]
|
||||||
DEPENDENCIES = ['uart']
|
DEPENDENCIES = ['uart']
|
||||||
@ -43,19 +45,26 @@ def validate_raw_data(value):
|
|||||||
return cv.Schema([cv.hex_uint8_t])(value)
|
return cv.Schema([cv.hex_uint8_t])(value)
|
||||||
raise cv.Invalid("data must either be a string wrapped in quotes or a list of bytes")
|
raise cv.Invalid("data must either be a string wrapped in quotes or a list of bytes")
|
||||||
|
|
||||||
@automation.register_action(
|
@coroutine_with_priority(100.0)
|
||||||
"marlin2.write",
|
|
||||||
Marlin2WriteAction,
|
|
||||||
cv.maybe_simple_value(
|
|
||||||
{
|
|
||||||
cv.GenerateID(): cv.declare_id(Marlin2),
|
|
||||||
cv.Required(CONF_DATA): cv.templatable(validate_raw_data),
|
|
||||||
},
|
|
||||||
key=CONF_DATA,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
await uart.register_uart_device(var, config)
|
await uart.register_uart_device(var, config)
|
||||||
|
|
||||||
|
OPERATION_BASE_SCHEMA = cv.Schema({
|
||||||
|
cv.GenerateID(): cv.use_id(Marlin2),
|
||||||
|
cv.Required(CONF_VALUE): cv.templatable(cv.string_strict),
|
||||||
|
})
|
||||||
|
|
||||||
|
@automation.register_action(
|
||||||
|
"marlin2.write",
|
||||||
|
Marlin2WriteAction,
|
||||||
|
OPERATION_BASE_SCHEMA,
|
||||||
|
)
|
||||||
|
|
||||||
|
async def marlin2_write_to_code(config, action_id, template_arg, args):
|
||||||
|
paren = await cg.get_variable(config[CONF_ID])
|
||||||
|
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||||
|
template_ = await cg.templatable(config[CONF_VALUE], args, cg.std_string)
|
||||||
|
cg.add(var.set_value(template_))
|
||||||
|
return var
|
14
automation.h
14
automation.h
@ -1,22 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "marlin2.h"
|
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
|
#include "esphome/core/component.h"
|
||||||
#include <vector>
|
#include "marlin2.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
|
||||||
template<typename... Ts> class Marlin2WriteGCodeAction : public Action<Ts...> {
|
template<typename... Ts> class Marlin2WriteAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit Marlin2WriteGCodeAction(Marlin2 *marlin2) : marlin2_(marlin2) {}
|
explicit Marlin2WriteAction(Marlin2 *marlin2) : marlin2_(marlin2) {}
|
||||||
TEMPLATABLE_VALUE(std::string, gcode)
|
TEMPLATABLE_VALUE(std::string, value)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
void play(Ts... x) override {
|
||||||
this->marlin2_->write_str("\r\n\r\nM117 Action Called!\r\n");;
|
this->marlin2_->write("M117 Action Called!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Marlin2 *marlin2_;
|
Marlin2 *marlin2_;
|
||||||
};
|
};
|
||||||
|
@ -50,12 +50,12 @@ namespace esphome {
|
|||||||
set_printer_state("IDLE");
|
set_printer_state("IDLE");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marlin2::set_bed_setpoint() {
|
void Marlin2::write(std::string gcode) {
|
||||||
|
ESP_LOGD(TAG, "->GCODE: %s", gcode.c_str());
|
||||||
|
write_str(gcode.c_str());
|
||||||
|
flush();
|
||||||
}
|
}
|
||||||
void Marlin2::set_extruder_setpoint() {
|
|
||||||
|
|
||||||
}
|
|
||||||
void Marlin2::update() {
|
void Marlin2::update() {
|
||||||
while (available()) {
|
while (available()) {
|
||||||
char c = read();
|
char c = read();
|
||||||
|
@ -24,8 +24,7 @@ class Marlin2 : public PollingComponent, public uart::UARTDevice {
|
|||||||
void add_text_sensor(const std::string& sName, text_sensor::TextSensor *tSens);
|
void add_text_sensor(const std::string& sName, text_sensor::TextSensor *tSens);
|
||||||
text_sensor::TextSensor* find_text_sensor(std::string key);
|
text_sensor::TextSensor* find_text_sensor(std::string key);
|
||||||
#endif
|
#endif
|
||||||
void set_bed_setpoint();
|
void write(std::string status);
|
||||||
void set_extruder_setpoint();
|
|
||||||
|
|
||||||
float get_setup_priority() const override { return setup_priority::LATE; }
|
float get_setup_priority() const override { return setup_priority::LATE; }
|
||||||
void setup() override;
|
void setup() override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user