Fixes to text sensor
This commit is contained in:
parent
64183c33d2
commit
84c2391cd3
78
marlin2.cpp
78
marlin2.cpp
@ -46,6 +46,8 @@ namespace esphome {
|
|||||||
write_str("\r\n\r\nM155 S10\r\n");
|
write_str("\r\n\r\nM155 S10\r\n");
|
||||||
write_str("\r\n\r\nM117 Hello World!\r\n");
|
write_str("\r\n\r\nM117 Hello World!\r\n");
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
|
set_printer_state("IDLE");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marlin2::update() {
|
void Marlin2::update() {
|
||||||
@ -104,17 +106,14 @@ namespace esphome {
|
|||||||
#ifdef USE_TEXT_SENSOR
|
#ifdef USE_TEXT_SENSOR
|
||||||
if(bed_set_temperature==0.0 && ext_set_temperature==0.0) {
|
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(ext_temperature < 32.0 && bed_temperature < 32.0){ //TODO define constants for these
|
||||||
if (find_text_sensor("printer_status") != nullptr)
|
set_printer_state("IDLE");
|
||||||
find_text_sensor("printer_status")->publish_state("IDLE");
|
|
||||||
}
|
}
|
||||||
else if(ext_temperature < 150.0 && bed_temperature < 55.0){
|
else if(ext_temperature < 150.0 && bed_temperature < 55.0){
|
||||||
if (find_text_sensor("printer_status") != nullptr)
|
set_printer_state("COOLING");
|
||||||
find_text_sensor("printer_status")->publish_state("COOLING");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(bed_set_temperature!=0.0 || ext_set_temperature!=0.0) {
|
if(bed_set_temperature!=0.0 || ext_set_temperature!=0.0) {
|
||||||
if (find_text_sensor("printer_status") != nullptr)
|
set_printer_state("PREHEATING");
|
||||||
find_text_sensor("printer_status")->publish_state("PREHEATING");
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -162,16 +161,18 @@ namespace esphome {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Print From SD Card Started
|
||||||
|
if(MarlinOutput.find("File selected") != std::string::npos) {
|
||||||
|
set_printer_state("PRINTING");
|
||||||
|
|
||||||
|
//reset string for next line
|
||||||
|
MarlinOutput="";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Print Finished
|
//Print Finished
|
||||||
if(MarlinOutput.find("Done printing") != std::string::npos) {
|
if(MarlinOutput.find("Done printing") != std::string::npos) {
|
||||||
#ifdef USE_TEXT_SENSOR
|
|
||||||
if (find_text_sensor("printer_status") != nullptr)
|
|
||||||
find_text_sensor("printer_status")->publish_state("FINISHED");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Print Finished");
|
|
||||||
print_progress = 100;
|
print_progress = 100;
|
||||||
|
|
||||||
#ifdef USE_SENSOR
|
#ifdef USE_SENSOR
|
||||||
if (find_sensor("print_progress") != nullptr)
|
if (find_sensor("print_progress") != nullptr)
|
||||||
find_sensor("print_progress")->publish_state(print_progress);
|
find_sensor("print_progress")->publish_state(print_progress);
|
||||||
@ -179,35 +180,32 @@ namespace esphome {
|
|||||||
if (find_sensor("print_time_remaining") != nullptr)
|
if (find_sensor("print_time_remaining") != nullptr)
|
||||||
find_sensor("print_time_remaining")->publish_state(0);
|
find_sensor("print_time_remaining")->publish_state(0);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_TEXT_SENSOR
|
||||||
|
set_printer_state("FINISHED");
|
||||||
|
#endif
|
||||||
|
|
||||||
//reset string for next line
|
//reset string for next line
|
||||||
MarlinOutput="";
|
MarlinOutput="";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// //Print Paused
|
//Print Paused
|
||||||
// if(MarlinOutput.find("Printer halted") != std::string::npos) {
|
if(MarlinOutput.find("Printer halted") != std::string::npos) {
|
||||||
// //if (find_text_sensor("printer_status") != nullptr)
|
set_printer_state("PAUSED");
|
||||||
// //find_text_sensor("printer_status")->publish_state("PAUSED");
|
|
||||||
|
|
||||||
// ESP_LOGD(TAG, "Print Finished");
|
//reset string for next line
|
||||||
|
MarlinOutput="";
|
||||||
// //reset string for next line
|
return;
|
||||||
// MarlinOutput="";
|
}
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //Print Stoped
|
// //Print Stoped
|
||||||
// if(MarlinOutput.find("Print Aborted") != std::string::npos) {
|
if(MarlinOutput.find("Print Aborted") != std::string::npos) {
|
||||||
// //if (find_text_sensor("printer_status") != nullptr)
|
set_printer_state("STOPPED");
|
||||||
// //find_text_sensor("printer_status")->publish_state("ABOARTED");
|
|
||||||
|
|
||||||
// ESP_LOGD(TAG, "Print Finished");
|
//reset string for next line
|
||||||
|
MarlinOutput="";
|
||||||
// //reset string for next line
|
return;
|
||||||
// MarlinOutput="";
|
}
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, "#%s#",MarlinOutput.c_str());
|
ESP_LOGD(TAG, "#%s#",MarlinOutput.c_str());
|
||||||
MarlinOutput="";
|
MarlinOutput="";
|
||||||
@ -217,7 +215,7 @@ namespace esphome {
|
|||||||
int Marlin2::process_temp_msg(float* ext_temperature, float* ext_set_temperature, float* bed_temperature, float* bed_set_temperature) {
|
int Marlin2::process_temp_msg(float* ext_temperature, float* ext_set_temperature, float* bed_temperature, float* bed_set_temperature) {
|
||||||
float dc;
|
float dc;
|
||||||
|
|
||||||
while(MarlinOutput.find(' ') != std::string::npos)
|
while(MarlinOutput.find(" ") != std::string::npos)
|
||||||
MarlinOutput.erase(MarlinOutput.find(' '), 1);
|
MarlinOutput.erase(MarlinOutput.find(' '), 1);
|
||||||
|
|
||||||
while(MarlinOutput.find("ok") != std::string::npos)
|
while(MarlinOutput.find("ok") != std::string::npos)
|
||||||
@ -277,4 +275,18 @@ namespace esphome {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Marlin2::set_printer_state(std::string status){
|
||||||
|
#ifdef USE_TEXT_SENSOR
|
||||||
|
// if (!PrinterState.compare(status))
|
||||||
|
// return;
|
||||||
|
|
||||||
|
if (find_text_sensor("printer_state") != nullptr){
|
||||||
|
find_text_sensor("printer_state")->publish_state(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGD(TAG, "Printer Status %s", status.c_str());
|
||||||
|
// PrinterState = status;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace esphome
|
} // namespace esphome
|
@ -44,6 +44,7 @@ class Marlin2 : public PollingComponent, public uart::UARTDevice {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void process_line();
|
void process_line();
|
||||||
|
void set_printer_state(std::string status);
|
||||||
int process_temp_msg(float* ext_temperature, float* ext_set_temperature, float* bed_temperature, float* bed_set_temperature);
|
int process_temp_msg(float* ext_temperature, float* ext_set_temperature, float* bed_temperature, float* bed_set_temperature);
|
||||||
float process_progress_msg();
|
float process_progress_msg();
|
||||||
int process_print_time_msg(double* current, double* remaining, float progress);
|
int process_print_time_msg(double* current, double* remaining, float progress);
|
||||||
|
Loading…
Reference in New Issue
Block a user