Additional State of the Printer + Refactoring
This commit is contained in:
parent
3c229f2cb8
commit
0c0bd23b82
50
marlin2.cpp
50
marlin2.cpp
@ -22,6 +22,7 @@ namespace esphome {
|
||||
MarlinOutput = "";
|
||||
|
||||
MarlinTime.reserve(32);
|
||||
PrinterState.reserve(32);
|
||||
|
||||
ESP_LOGD(TAG, "M155 S10");
|
||||
|
||||
@ -86,6 +87,19 @@ namespace esphome {
|
||||
ESP_LOGD(TAG, "Bed Temperature=%.1f°C Ext Temperature=%.1f°C ", bed_temperature, ext_temperature);
|
||||
}
|
||||
|
||||
if(bed_set_temperature==0.0 && ext_set_temperature==0.0) {
|
||||
if(ext_temperature < 32.0 && bed_temperature < 32.0) //TODO define constants for these
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('IDLE');
|
||||
else if(ext_temperature < 150.0 && bed_temperature < 55.0)
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('COOLING');
|
||||
}
|
||||
if(bed_set_temperature!=0.0 || ext_set_temperature!=0.0) {
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('PREHEATING');
|
||||
}
|
||||
|
||||
//reset string for next line
|
||||
MarlinOutput="";
|
||||
return;
|
||||
@ -125,6 +139,42 @@ namespace esphome {
|
||||
return;
|
||||
}
|
||||
|
||||
//Print Finished
|
||||
if(MarlinOutput.find("Done printing") != std::string::npos) {
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('FINISHED');
|
||||
|
||||
ESP_LOGD(TAG, "Print Finished");
|
||||
|
||||
//reset string for next line
|
||||
MarlinOutput="";
|
||||
return;
|
||||
}
|
||||
|
||||
//Print Paused
|
||||
if(MarlinOutput.find("Printer halted") != std::string::npos) {
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('PAUSED');
|
||||
|
||||
ESP_LOGD(TAG, "Print Finished");
|
||||
|
||||
//reset string for next line
|
||||
MarlinOutput="";
|
||||
return;
|
||||
}
|
||||
|
||||
//Print Stoped
|
||||
if(MarlinOutput.find("Print Aborted") != std::string::npos) {
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('ABOARTED');
|
||||
|
||||
ESP_LOGD(TAG, "Print Finished");
|
||||
|
||||
//reset string for next line
|
||||
MarlinOutput="";
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "#%s#",MarlinOutput.c_str());
|
||||
MarlinOutput="";
|
||||
return;
|
||||
|
@ -21,6 +21,8 @@ class Marlin2 : public PollingComponent , public uart::UARTDevice {
|
||||
int process_print_time_msg(int* d, int* h, int* m, unsigned long* current, unsigned long* remaining);
|
||||
|
||||
std::string MarlinOutput;
|
||||
std::string PrinterState;
|
||||
|
||||
std::vector<std::pair<std::string, sensor::Sensor *>> sensors;
|
||||
|
||||
private:
|
||||
|
12
sensor.py
12
sensor.py
@ -11,9 +11,10 @@ from esphome.const import (
|
||||
CONF_MODEL,
|
||||
CONF_PIN,
|
||||
CONF_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_CELSIUS,
|
||||
UNIT_PERCENT,
|
||||
UNIT_SECONDS,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
DEVICE_CLASS_TEMPERATURE
|
||||
)
|
||||
|
||||
@ -31,6 +32,8 @@ CONF_PRINT_PROGRESS = "print_progress"
|
||||
CONF_PRINT_TIME = "print_time"
|
||||
CONF_PRINT_TIME_REMAINING = "print_time_remaining"
|
||||
|
||||
CONF_PRINTER_STATUS = "printer_status"
|
||||
|
||||
Marlin2 = cg.esphome_ns.class_('Marlin2', cg.Component, sensor.Sensor, uart.UARTDevice)
|
||||
|
||||
CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend(
|
||||
@ -66,17 +69,20 @@ CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend(
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PRINT_TIME): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_PERCENT,
|
||||
unit_of_measurement=UNIT_SECONDS,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_DURATION,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PRINT_TIME_REMAINING): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_PERCENT,
|
||||
unit_of_measurement=UNIT_SECONDS,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_DURATION,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PRINTER_STATUS): sensor.sensor_schema(
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
).extend(cv.polling_component_schema("15s"))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user