Skip to content

Commit

Permalink
Fix time in bambu integration
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Nov 2, 2024
1 parent f21b480 commit 66e3a67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions CYD-Klipper/src/core/bambu/bambu_printer_integration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class BambuPrinter : public BasePrinter
popup_message_timeout_s = -1;
bambu_misc = 0;
printer_data.error_screen_features = PrinterFeatureRetryError | PrinterFeatureIgnoreError | PrinterFeatureContinueError;
print_start = millis();
}

bool move_printer(const char* axis, float amount, bool relative);
Expand Down
22 changes: 9 additions & 13 deletions CYD-Klipper/src/core/bambu/bambu_printer_parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,22 @@ void BambuPrinter::parse_state(JsonDocument& in)
}
else if (strcasecmp(state, "running") == 0 || strcasecmp(state, "prepare") == 0)
{
if (print_start <= 0)
{
print_start = millis();
}

printer_data.state = PrinterState::PrinterStatePrinting;
}
else
{
print_start = 0;
printer_data.state = PrinterState::PrinterStateIdle;
}
}



if (printer_data.state == PrinterState::PrinterStatePrinting)
{
printer_data.elapsed_time_s = (millis() - print_start) / 1000;
}

if (print.containsKey("mc_remaining_time"))
{
printer_data.remaining_time_s = print["mc_remaining_time"];
printer_data.remaining_time_s *= 60;
if (printer_data.remaining_time_s > 300)
{
print_start = millis() - (printer_data.remaining_time_s / (1 - printer_data.print_progress) * printer_data.print_progress * 1000);
}
}

if (print.containsKey("mc_percent"))
Expand All @@ -153,6 +144,11 @@ void BambuPrinter::parse_state(JsonDocument& in)
printer_data.print_progress /= 100;
}

if (printer_data.state == PrinterState::PrinterStatePrinting)
{
printer_data.elapsed_time_s = (millis() - print_start) / 1000;
}

if (print.containsKey("layer_num"))
{
printer_data.current_layer = print["layer_num"];
Expand Down

0 comments on commit 66e3a67

Please sign in to comment.