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
This commit is contained in:
gudnimg 2023-11-19 11:57:30 +00:00 committed by Guðni Már Gilbert
parent a2e6cda37e
commit 331ceaf044
4 changed files with 9 additions and 11 deletions

View File

@ -268,9 +268,7 @@ extern bool homing_flag;
extern uint32_t total_filament_used; // mm/100 or 10um extern uint32_t total_filament_used; // mm/100 or 10um
/// @brief Save print statistics to EEPROM /// @brief Save print statistics to EEPROM
/// @param _total_filament_used has unit mm/100 or 10um void save_statistics();
/// @param _total_print_time has unit minutes, for example 123 minutes
void save_statistics(uint32_t _total_filament_used, uint32_t _total_print_time);
extern int fan_edge_counter[2]; extern int fan_edge_counter[2];
extern int fan_speed[2]; extern int fan_speed[2];

View File

@ -175,7 +175,7 @@ static LongTimer crashDetTimer;
bool mesh_bed_leveling_flag = false; bool mesh_bed_leveling_flag = false;
uint32_t total_filament_used; uint32_t total_filament_used; // unit mm/100 or 10um
HeatingStatus heating_status; HeatingStatus heating_status;
int fan_edge_counter[2]; int fan_edge_counter[2];
int fan_speed[2]; int fan_speed[2];
@ -5897,6 +5897,7 @@ Sigma_Exit:
case 77: case 77:
{ {
print_job_timer.stop(); print_job_timer.stop();
save_statistics();
break; break;
} }
@ -9803,12 +9804,13 @@ void setPwmFrequency(uint8_t pin, int val)
} }
#endif //FAST_PWM_FAN #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_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 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 uint32_t time_minutes = print_job_timer.duration() / 60;
eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, _previous_filament + (_total_filament_used / 1000)); 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(); print_job_timer.reset();
total_filament_used = 0; total_filament_used = 0;

View File

@ -663,7 +663,7 @@ void get_command()
int hours, minutes; int hours, minutes;
minutes = t % 60; minutes = t % 60;
hours = t / 60; hours = t / 60;
save_statistics(total_filament_used, t); save_statistics();
sprintf_P(time, PSTR("%i hours %i minutes"),hours, minutes); sprintf_P(time, PSTR("%i hours %i minutes"),hours, minutes);
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLN(time); SERIAL_ECHOLN(time);

View File

@ -5579,9 +5579,7 @@ static void lcd_sd_updir()
// continue stopping the print from the main loop after lcd_print_stop() is called // continue stopping the print from the main loop after lcd_print_stop() is called
void lcd_print_stop_finish() void lcd_print_stop_finish()
{ {
// Convert the time from ms to minutes, divide by 60 * 1000 save_statistics();
uint32_t t = print_job_timer.duration() / 60;
save_statistics(total_filament_used, t);
// lift Z // lift Z
raise_z(10); raise_z(10);