diff --git a/README.md b/README.md index 56f0b75..907fe37 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Notes: * https://github.com/esphome/esphome/blob/dev/esphome/components/dht/sensor.py#L34 * https://github.com/mulcmu/esphome-marlin-uart * https://github.com/oxan/esphome-stream-server/blob/master/components/stream_server/stream_server.cpp +* https://github.com/esphome/esphome/blob/dev/esphome/components/api/__init__.py Full COnfiguration: ```yaml diff --git a/__init__.py b/__init__.py index 84a4e2e..1664827 100644 --- a/__init__.py +++ b/__init__.py @@ -31,6 +31,11 @@ CONFIG_SCHEMA = cv.All( .extend(uart.UART_DEVICE_SCHEMA), ) +@automation.register_action("marlin2.set_bed_temperature", SetTemperatureAction, SWITCH_ACTION_SCHEMA) +async def marlin2_set_bed_temperature_to_code(config, action_id, template_arg, args): + paren = await cg.get_variable(config[CONF_ID]) + return cg.new_Pvariable(action_id, template_arg, paren) + async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) diff --git a/marlin2.cpp b/marlin2.cpp index 73ca218..9b9394b 100644 --- a/marlin2.cpp +++ b/marlin2.cpp @@ -48,8 +48,17 @@ namespace esphome { flush(); set_printer_state("IDLE"); + + register_service(&Marlin2::set_bed_setpoint, "set_bed_setpoint", {"temp_degC"}); + register_service(&Marlin2::set_extruder_setpoint, "set_extruder_setpoint", {"temp_degC"}); } +void Marlin2::set_bed_setpoint() { + +} +void Marlin2::set_extruder_setpoint() { + +} void Marlin2::update() { while (available()) { char c = read(); @@ -271,7 +280,7 @@ namespace esphome { *current = round(((d)*24*60*60) + ((h)*60*60) + ((m)*60) + (s)); if(progress != 0.0 && progress != 100.0) { - *remaining = (((100 * *current) / progress) -*current); + *remaining = (((100 * *current) / round(progress)) - *current); } return 1; diff --git a/marlin2.h b/marlin2.h index 7cdc71a..1ac55b7 100644 --- a/marlin2.h +++ b/marlin2.h @@ -24,6 +24,8 @@ class Marlin2 : public PollingComponent, public uart::UARTDevice { void add_text_sensor(const std::string& sName, text_sensor::TextSensor *tSens); text_sensor::TextSensor* find_text_sensor(std::string key); #endif + void set_bed_setpoint(); + void set_extruder_setpoint(); float get_setup_priority() const override { return setup_priority::LATE; } void setup() override;