mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Add slicer time based estimates
This commit is contained in:
@@ -5,6 +5,12 @@
|
|||||||
|
|
||||||
#define CONFIG_VERSION 4
|
#define CONFIG_VERSION 4
|
||||||
|
|
||||||
|
enum {
|
||||||
|
REMAINING_TIME_CALC_PERCENTAGE = 0,
|
||||||
|
REMAINING_TIME_CALC_INTERPOLATED = 1,
|
||||||
|
REMAINING_TIME_CALC_SLICER = 2,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct _GLOBAL_CONFIG {
|
typedef struct _GLOBAL_CONFIG {
|
||||||
unsigned char version;
|
unsigned char version;
|
||||||
union {
|
union {
|
||||||
@@ -21,6 +27,7 @@ typedef struct _GLOBAL_CONFIG {
|
|||||||
bool rotateScreen : 1;
|
bool rotateScreen : 1;
|
||||||
bool onDuringPrint : 1;
|
bool onDuringPrint : 1;
|
||||||
bool autoOtaUpdate : 1;
|
bool autoOtaUpdate : 1;
|
||||||
|
unsigned char remaining_time_calc_mode : 2;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
float screenCalXOffset;
|
float screenCalXOffset;
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ void send_gcode(bool wait, const char *gcode)
|
|||||||
sprintf(buff, "http://%s:%d/printer/gcode/script?script=%s", global_config.klipperHost, global_config.klipperPort, urlEncode(gcode).c_str());
|
sprintf(buff, "http://%s:%d/printer/gcode/script?script=%s", global_config.klipperHost, global_config.klipperPort, urlEncode(gcode).c_str());
|
||||||
HTTPClient client;
|
HTTPClient client;
|
||||||
client.begin(buff);
|
client.begin(buff);
|
||||||
|
int httpCode = client.GET();
|
||||||
|
|
||||||
|
|
||||||
if (!wait)
|
if (!wait)
|
||||||
{
|
{
|
||||||
@@ -65,6 +67,30 @@ void send_gcode(bool wait, const char *gcode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_slicer_time_estimate_s()
|
||||||
|
{
|
||||||
|
if (printer.state == PRINTER_STATE_IDLE)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
char buff[256] = {};
|
||||||
|
sprintf(buff, "http://%s:%d/server/files/metadata?filename=%s", global_config.klipperHost, global_config.klipperPort, urlEncode(printer.print_filename).c_str());
|
||||||
|
HTTPClient client;
|
||||||
|
client.useHTTP10(true);
|
||||||
|
client.begin(buff);
|
||||||
|
int httpCode = client.GET();
|
||||||
|
|
||||||
|
if (httpCode != 200)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
JsonDocument doc;
|
||||||
|
deserializeJson(doc, client.getStream());
|
||||||
|
int time_estimate_s = doc["result"]["estimated_time"];
|
||||||
|
Serial.printf("Got slicer time estimate: %ds\n", time_estimate_s);
|
||||||
|
return time_estimate_s;
|
||||||
|
}
|
||||||
|
|
||||||
void move_printer(const char* axis, float amount, bool relative) {
|
void move_printer(const char* axis, float amount, bool relative) {
|
||||||
if (!printer.homed_axis || printer.state == PRINTER_STATE_PRINTING)
|
if (!printer.homed_axis || printer.state == PRINTER_STATE_PRINTING)
|
||||||
return;
|
return;
|
||||||
@@ -222,7 +248,36 @@ void fetch_printer_data()
|
|||||||
|
|
||||||
if (printer.state == PRINTER_STATE_PRINTING && printer.print_progress > 0)
|
if (printer.state == PRINTER_STATE_PRINTING && printer.print_progress > 0)
|
||||||
{
|
{
|
||||||
printer.remaining_time_s = (printer.elapsed_time_s / printer.print_progress) - printer.elapsed_time_s;
|
float remaining_time_s_percentage = (printer.elapsed_time_s / printer.print_progress) - printer.elapsed_time_s;
|
||||||
|
float remaining_time_s_slicer = 0;
|
||||||
|
|
||||||
|
if (printer.slicer_estimated_print_time_s > 0)
|
||||||
|
{
|
||||||
|
remaining_time_s_slicer = printer.slicer_estimated_print_time_s - printer.elapsed_time_s;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remaining_time_s_slicer <= 0 || global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_PERCENTAGE)
|
||||||
|
{
|
||||||
|
printer.remaining_time_s = remaining_time_s_percentage;
|
||||||
|
}
|
||||||
|
else if (global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_INTERPOLATED)
|
||||||
|
{
|
||||||
|
printer.remaining_time_s = remaining_time_s_percentage * printer.print_progress + remaining_time_s_slicer * (1 - printer.print_progress);
|
||||||
|
}
|
||||||
|
else if (global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_SLICER)
|
||||||
|
{
|
||||||
|
printer.remaining_time_s = remaining_time_s_slicer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (printer.remaining_time_s < 0)
|
||||||
|
{
|
||||||
|
printer.remaining_time_s = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (printer.state == PRINTER_STATE_IDLE)
|
||||||
|
{
|
||||||
|
printer.slicer_estimated_print_time_s = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_msg_send(DATA_PRINTER_DATA, &printer);
|
lv_msg_send(DATA_PRINTER_DATA, &printer);
|
||||||
@@ -230,6 +285,10 @@ void fetch_printer_data()
|
|||||||
|
|
||||||
if (printer.state != printer_state || emit_state_update)
|
if (printer.state != printer_state || emit_state_update)
|
||||||
{
|
{
|
||||||
|
if (printer_state == PRINTER_STATE_PRINTING){
|
||||||
|
printer.slicer_estimated_print_time_s = get_slicer_time_estimate_s();
|
||||||
|
}
|
||||||
|
|
||||||
printer.state = printer_state;
|
printer.state = printer_state;
|
||||||
lv_msg_send(DATA_PRINTER_STATE, &printer);
|
lv_msg_send(DATA_PRINTER_STATE, &printer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ typedef struct _Printer {
|
|||||||
float elapsed_time_s;
|
float elapsed_time_s;
|
||||||
float remaining_time_s;
|
float remaining_time_s;
|
||||||
float filament_used_mm;
|
float filament_used_mm;
|
||||||
char* print_filename; // 0 -> 1
|
char* print_filename;
|
||||||
float print_progress;
|
float print_progress; // 0 -> 1
|
||||||
float fan_speed; // 0 -> 1
|
float fan_speed; // 0 -> 1
|
||||||
float gcode_offset[3];
|
float gcode_offset[3];
|
||||||
float speed_mult;
|
float speed_mult;
|
||||||
@@ -34,6 +34,7 @@ typedef struct _Printer {
|
|||||||
float pressure_advance;
|
float pressure_advance;
|
||||||
float smooth_time;
|
float smooth_time;
|
||||||
int feedrate_mm_per_s;
|
int feedrate_mm_per_s;
|
||||||
|
int slicer_estimated_print_time_s;
|
||||||
} Printer;
|
} Printer;
|
||||||
|
|
||||||
extern Printer printer;
|
extern Printer printer;
|
||||||
|
|||||||
@@ -99,6 +99,14 @@ static void auto_ota_update_switch(lv_event_t* e){
|
|||||||
WriteGlobalConfig();
|
WriteGlobalConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* estimated_time_options = "Percentage\nInterpolated\nSlicer";
|
||||||
|
|
||||||
|
static void estimated_time_dropdown(lv_event_t * e){
|
||||||
|
lv_obj_t * dropdown = lv_event_get_target(e);
|
||||||
|
global_config.remaining_time_calc_mode = lv_dropdown_get_selected(dropdown);
|
||||||
|
WriteGlobalConfig();
|
||||||
|
}
|
||||||
|
|
||||||
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
|
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
|
||||||
|
|
||||||
void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true){
|
void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true){
|
||||||
@@ -256,4 +264,11 @@ void settings_panel_init(lv_obj_t* panel){
|
|||||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||||
|
|
||||||
create_settings_widget("Auto Update", toggle, panel);
|
create_settings_widget("Auto Update", toggle, panel);
|
||||||
|
|
||||||
|
dropdown = lv_dropdown_create(panel);
|
||||||
|
lv_dropdown_set_options(dropdown, estimated_time_options);
|
||||||
|
lv_obj_add_event_cb(dropdown, estimated_time_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
|
||||||
|
lv_dropdown_set_selected(dropdown, global_config.remaining_time_calc_mode);
|
||||||
|
create_settings_widget("Estimated Time", dropdown, panel);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user