Additional Fixes
This commit is contained in:
parent
59a1cc6a1a
commit
fe2d7ab342
38
marlin2.cpp
38
marlin2.cpp
@ -121,7 +121,7 @@ namespace esphome {
|
|||||||
|
|
||||||
//Parse Progress of the print
|
//Parse Progress of the print
|
||||||
if(MarlinOutput.find("SD printing byte") == 0 ) {
|
if(MarlinOutput.find("SD printing byte") == 0 ) {
|
||||||
float print_progress = process_progress_msg();
|
print_progress = process_progress_msg();
|
||||||
|
|
||||||
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);
|
||||||
@ -138,12 +138,12 @@ namespace esphome {
|
|||||||
double current=0;
|
double current=0;
|
||||||
double remaining=0;
|
double remaining=0;
|
||||||
|
|
||||||
if (process_print_time_msg(¤t, &remaining) != 0) {
|
if (process_print_time_msg(¤t, &remaining, print_progress) != 0) {
|
||||||
if (find_sensor("print_time") != nullptr)
|
if (find_sensor("print_time") != nullptr)
|
||||||
find_sensor("print_time")->publish_state(current);
|
find_sensor("print_time")->publish_state(current);
|
||||||
|
|
||||||
// if (find_sensor("print_time_remaining") != nullptr)
|
if (find_sensor("print_time_remaining") != nullptr)
|
||||||
// find_sensor("print_time_remaining")->publish_state(remaining);
|
find_sensor("print_time_remaining")->publish_state(remaining);
|
||||||
|
|
||||||
ESP_LOGD(TAG, "time=%f remaining=%f", current, remaining);
|
ESP_LOGD(TAG, "time=%f remaining=%f", current, remaining);
|
||||||
}
|
}
|
||||||
@ -153,17 +153,24 @@ namespace esphome {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// //Print Finished
|
//Print Finished
|
||||||
// if(MarlinOutput.find("Done printing") != std::string::npos) {
|
if(MarlinOutput.find("Done printing") != std::string::npos) {
|
||||||
// //if (find_text_sensor("printer_status") != nullptr)
|
// //if (find_text_sensor("printer_status") != nullptr)
|
||||||
// //find_text_sensor("printer_status")->publish_state("FINISHED");
|
// //find_text_sensor("printer_status")->publish_state("FINISHED");
|
||||||
|
|
||||||
// ESP_LOGD(TAG, "Print Finished");
|
ESP_LOGD(TAG, "Print Finished");
|
||||||
|
print_progress = 100;
|
||||||
|
|
||||||
// //reset string for next line
|
if (find_sensor("print_progress") != nullptr)
|
||||||
// MarlinOutput="";
|
find_sensor("print_progress")->publish_state(print_progress);
|
||||||
// return;
|
|
||||||
// }
|
if (find_sensor("print_time_remaining") != nullptr)
|
||||||
|
find_sensor("print_time_remaining")->publish_state(0);
|
||||||
|
|
||||||
|
//reset string for next line
|
||||||
|
MarlinOutput="";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// //Print Paused
|
// //Print Paused
|
||||||
// if(MarlinOutput.find("Printer halted") != std::string::npos) {
|
// if(MarlinOutput.find("Printer halted") != std::string::npos) {
|
||||||
@ -226,10 +233,10 @@ namespace esphome {
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((float) current / (float) total) * 100.0;
|
return (((float) current * 100.0) / (float) total);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Marlin2::process_print_time_msg(double* current, double* remaining){
|
int Marlin2::process_print_time_msg(double* current, double* remaining, float progress){
|
||||||
MarlinTime = MarlinOutput.substr(16);
|
MarlinTime = MarlinOutput.substr(16);
|
||||||
float d = 0, h = 0, m = 0, s = 0;
|
float d = 0, h = 0, m = 0, s = 0;
|
||||||
|
|
||||||
@ -249,6 +256,11 @@ namespace esphome {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*current = round(((d)*24*60*60) + ((h)*60*60) + ((m)*60) + (s));
|
*current = round(((d)*24*60*60) + ((h)*60*60) + ((m)*60) + (s));
|
||||||
|
|
||||||
|
if(progress != 0.0 && progress != 100.0) {
|
||||||
|
*remaining = ((100 * *current) / progress);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,14 @@ class Marlin2 : public PollingComponent, /*public text_sensor::TextSensor,*/ pub
|
|||||||
void process_line();
|
void process_line();
|
||||||
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);
|
int process_print_time_msg(double* current, double* remaining, float progress);
|
||||||
|
|
||||||
std::string MarlinOutput;
|
std::string MarlinOutput;
|
||||||
std::string MarlinTime;
|
std::string MarlinTime;
|
||||||
std::string PrinterState;
|
std::string PrinterState;
|
||||||
|
|
||||||
|
float print_progress = 0;
|
||||||
|
|
||||||
std::vector<std::pair<std::string, sensor::Sensor *>> sensors;
|
std::vector<std::pair<std::string, sensor::Sensor *>> sensors;
|
||||||
// std::vector<std::pair<std::string, text_sensor::TextSensor *>> text_sensors;
|
// std::vector<std::pair<std::string, text_sensor::TextSensor *>> text_sensors;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user