From 331ceaf04480f9bb8070780fa34340f1cffbcb65 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sun, 19 Nov 2023 11:57:30 +0000 Subject: [PATCH] M77: Save statistics when timer is stopped For remote hosts, when the timer is stopped, then also save the statistics. Slightly refactored save_statistics function by removing the parameters. The function parameters are always the same. Change in memory: Flash: -40 bytes SRAM: 0 bytes --- Firmware/Marlin.h | 4 +--- Firmware/Marlin_main.cpp | 10 ++++++---- Firmware/cmdqueue.cpp | 2 +- Firmware/ultralcd.cpp | 4 +--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 294fa7f33..5db418b7b 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -268,9 +268,7 @@ extern bool homing_flag; extern uint32_t total_filament_used; // mm/100 or 10um /// @brief Save print statistics to EEPROM -/// @param _total_filament_used has unit mm/100 or 10um -/// @param _total_print_time has unit minutes, for example 123 minutes -void save_statistics(uint32_t _total_filament_used, uint32_t _total_print_time); +void save_statistics(); extern int fan_edge_counter[2]; extern int fan_speed[2]; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index aa6e8dd50..1445938a9 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -175,7 +175,7 @@ static LongTimer crashDetTimer; bool mesh_bed_leveling_flag = false; -uint32_t total_filament_used; +uint32_t total_filament_used; // unit mm/100 or 10um HeatingStatus heating_status; int fan_edge_counter[2]; int fan_speed[2]; @@ -5897,6 +5897,7 @@ Sigma_Exit: case 77: { print_job_timer.stop(); + save_statistics(); break; } @@ -9803,12 +9804,13 @@ void setPwmFrequency(uint8_t pin, int val) } #endif //FAST_PWM_FAN -void save_statistics(uint32_t _total_filament_used, uint32_t _total_print_time) { +void save_statistics() { uint32_t _previous_filament = eeprom_init_default_dword((uint32_t *)EEPROM_FILAMENTUSED, 0); //_previous_filament unit: meter uint32_t _previous_time = eeprom_init_default_dword((uint32_t *)EEPROM_TOTALTIME, 0); //_previous_time unit: min - eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, _previous_time + _total_print_time); // EEPROM_TOTALTIME unit: min - eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, _previous_filament + (_total_filament_used / 1000)); + uint32_t time_minutes = print_job_timer.duration() / 60; + eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, _previous_time + time_minutes); // EEPROM_TOTALTIME unit: min + eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, _previous_filament + (total_filament_used / 1000)); print_job_timer.reset(); total_filament_used = 0; diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index bb2bc8c33..84f11329e 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -663,7 +663,7 @@ void get_command() int hours, minutes; minutes = t % 60; hours = t / 60; - save_statistics(total_filament_used, t); + save_statistics(); sprintf_P(time, PSTR("%i hours %i minutes"),hours, minutes); SERIAL_ECHO_START; SERIAL_ECHOLN(time); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index cbd14b4cc..d2ad902f7 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5579,9 +5579,7 @@ static void lcd_sd_updir() // continue stopping the print from the main loop after lcd_print_stop() is called void lcd_print_stop_finish() { - // Convert the time from ms to minutes, divide by 60 * 1000 - uint32_t t = print_job_timer.duration() / 60; - save_statistics(total_filament_used, t); + save_statistics(); // lift Z raise_z(10);