Merge pull request #3403 from leptun/MK3_fix_usb_timer

Fix usb printing timer
This commit is contained in:
Alex Voinea 2022-02-15 15:44:44 +01:00 committed by GitHub
commit f97808e19a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 45 deletions

View file

@ -328,11 +328,10 @@ extern uint8_t host_keepalive_interval;
extern unsigned long starttime;
extern unsigned long stoptime;
extern ShortTimer usb_timer;
extern int bowden_length[4];
extern bool is_usb_printing;
extern bool homing_flag;
extern bool loading_flag;
extern uint8_t usb_printing_counter;
extern unsigned long total_filament_used;
void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time);
extern uint8_t status_number;
@ -383,7 +382,7 @@ extern uint16_t gcode_in_progress;
extern LongTimer safetyTimer;
#define PRINT_PERCENT_DONE_INIT 0xff
#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || mmu_print_saved || homing_flag || mesh_bed_leveling_flag)
#define PRINTER_ACTIVE (IS_SD_PRINTING || usb_timer.running() || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || mmu_print_saved || homing_flag || mesh_bed_leveling_flag)
//! Beware - mcode_in_progress is set as soon as the command gets really processed,
//! which is not the same as posting the M600 command into the command queue
@ -392,7 +391,7 @@ extern LongTimer safetyTimer;
//! Instead, the fsensor uses another state variable :( , which is set to true, when the M600 command is enqued
//! and is reset to false when the fsensor returns into its filament runout finished handler
//! I'd normally change this macro, but who knows what would happen in the MMU :)
#define CHECK_FSENSOR ((IS_SD_PRINTING || is_usb_printing) && (mcode_in_progress != 600) && !saved_printing && e_active())
#define CHECK_FSENSOR ((IS_SD_PRINTING || usb_timer.running()) && (mcode_in_progress != 600) && !saved_printing && e_active())
extern void calculate_extruder_multipliers();

View file

@ -192,11 +192,8 @@ int extruder_multiply[EXTRUDERS] = {100
int bowden_length[4] = {385, 385, 385, 385};
bool is_usb_printing = false;
bool homing_flag = false;
uint8_t usb_printing_counter;
int8_t lcd_change_fil_state = 0;
unsigned long pause_time = 0;
@ -360,7 +357,7 @@ static unsigned long safetytimer_inactive_time = DEFAULT_SAFETYTIMER_TIME_MINS*6
unsigned long starttime=0;
unsigned long stoptime=0;
ShortTimer _usb_timer;
ShortTimer usb_timer;
bool Stopped=false;
@ -1893,19 +1890,11 @@ void loop()
{
KEEPALIVE_STATE(NOT_BUSY);
if ((usb_printing_counter > 0) && _usb_timer.expired(1000))
{
is_usb_printing = true;
usb_printing_counter--;
_usb_timer.start(); // reset timer
if (isPrintPaused && saved_printing_type == PRINTING_TYPE_USB) { //keep believing that usb is being printed. Prevents accessing dangerous menus while pausing.
usb_timer.start();
}
if (usb_printing_counter == 0)
{
is_usb_printing = false;
}
if (isPrintPaused && saved_printing_type == PRINTING_TYPE_USB) //keep believing that usb is being printed. Prevents accessing dangerous menus while pausing.
{
is_usb_printing = true;
else if (usb_timer.expired(10000)) { //just need to check if it expired. Nothing else is needed to be done.
;
}
#ifdef FANCHECK
@ -4239,7 +4228,7 @@ void process_commands()
#ifdef FANCHECK
if(fan_check_error == EFCE_DETECTED) {
fan_check_error = EFCE_REPORTED;
if (is_usb_printing)
if (usb_timer.running())
lcd_pause_usb_print();
else
lcd_pause_print();
@ -8982,7 +8971,7 @@ Sigma_Exit:
if (mmu_enabled)
{
st_synchronize();
mmu_continue_loading(is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal));
mmu_continue_loading(usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal));
mmu_extruder = tmp_extruder; //filament change is finished
mmu_load_to_nozzle();
}
@ -9026,7 +9015,7 @@ Sigma_Exit:
#endif //defined(MMU_HAS_CUTTER) && defined(MMU_ALWAYS_CUT)
mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE);
mmu_continue_loading(is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal));
mmu_continue_loading(usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal));
mmu_extruder = tmp_extruder; //filament change is finished
@ -9879,7 +9868,7 @@ static uint16_t nFSCheckCount=0;
#endif // IR_SENSOR_ANALOG
if ((mcode_in_progress != 600) && (eFilamentAction != FilamentAction::AutoLoad) && (!bInhibitFlag) && (menu_menu != lcd_move_e)) //M600 not in progress, preHeat @ autoLoad menu not active
{
if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && ! eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
if (!moves_planned() && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal) && ! eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
{
#ifdef IR_SENSOR_ANALOG
static uint16_t minVolt = Voltage2Raw(6.F), maxVolt = 0;
@ -11599,7 +11588,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
saved_printing_type = PRINTING_TYPE_SD;
}
else if (is_usb_printing) { //reuse saved_sdpos for storing line number
else if (usb_timer.running()) { //reuse saved_sdpos for storing line number
saved_sdpos = gcode_LastN; //start with line number of command added recently to cmd queue
//reuse planner_calc_sd_length function for getting number of lines of commands in planner:
nlines = planner_calc_sd_length(); //number of lines of commands in planner

View file

@ -479,10 +479,9 @@ void get_command()
return;
}
if ((strchr_pointer = strchr(cmdbuffer+bufindw+CMDHDRSIZE, 'G')) != NULL) {
if (! IS_SD_PRINTING) {
usb_printing_counter = 10;
is_usb_printing = true;
}
if (!IS_SD_PRINTING) {
usb_timer.start();
}
if (Stopped == true) {
if (code_value_uint8() <= 3) {
SERIAL_ERRORLNRPGM(MSG_ERR_STOPPED);

View file

@ -889,7 +889,7 @@ void mmu_M600_load_filament(bool automatic, float nozzle_temp)
mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(false, true, MMU_LOAD_MOVE);
mmu_continue_loading(is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal));
mmu_continue_loading(usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal));
mmu_extruder = tmp_extruder; //filament change is finished
mmu_load_to_nozzle();

View file

@ -614,7 +614,7 @@ static void fanSpeedErrorBeep(const char *serialMsg, const char *lcdMsg){
void fanSpeedError(unsigned char _fan) {
if (get_message_level() != 0 && isPrintPaused) return;
//to ensure that target temp. is not set to zero in case that we are resuming print
if (card.sdprinting || is_usb_printing) {
if (card.sdprinting || usb_timer.running()) {
if (heating_status != HeatingStatus::NO_HEATING) {
lcd_print_stop();
}
@ -623,7 +623,7 @@ void fanSpeedError(unsigned char _fan) {
}
}
else {
// SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //Why pause octoprint? is_usb_printing would be true in that case, so there is no need for this.
// SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //Why pause octoprint? usb_timer.running() would be true in that case, so there is no need for this.
setTargetHotend0(0);
heating_status = HeatingStatus::NO_HEATING;
fan_check_error = EFCE_REPORTED;

View file

@ -450,7 +450,7 @@ void lcdui_print_feedrate(void)
// Print percent done in form "USB---%", " SD---%", " ---%" (7 chars total)
void lcdui_print_percent_done(void)
{
const char* src = is_usb_printing?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" "));
const char* src = usb_timer.running()?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" "));
char per[4];
bool num = IS_SD_PRINTING || (PRINTER_ACTIVE && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
if (!num || heating_status != HeatingStatus::NO_HEATING) // either not printing or heating
@ -3824,7 +3824,7 @@ static void lcd_show_sensors_state()
if (mmu_enabled == false)
{
// pat9125_update is already called while printing: only update manually when idling
if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal))
if (!moves_planned() && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal))
pat9125_update();
lcd_set_cursor(0, 2);
@ -4308,7 +4308,7 @@ static void crash_mode_switch()
{
lcd_crash_detect_enable();
}
if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true);
if (IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true);
else menu_goto(lcd_settings_menu, 9, true, true);
}
#endif //TMC2130
@ -6278,7 +6278,7 @@ void lcd_resume_print()
lcd_return_to_status();
lcd_reset_alert_level(); //for fan speed error
if (fan_error_selftest()) {
if (is_usb_printing) SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED);
if (usb_timer.running()) SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED);
return; //abort if error persists
}
cmdqueue_serial_disabled = false;
@ -6455,7 +6455,7 @@ static void lcd_main_menu()
MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
#endif //TMC2130_DEBUG
if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) {
if ( ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) {
MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
}
@ -6469,7 +6469,7 @@ static void lcd_main_menu()
}
if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused) {
if (is_usb_printing) {
if (usb_timer.running()) {
MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_usb_print);////MSG_PAUSE_PRINT c=18
} else if (IS_SD_PRINTING) {
MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_print);////MSG_PAUSE_PRINT c=18
@ -6481,20 +6481,20 @@ static void lcd_main_menu()
if((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
#endif //FANCHECK
{
if (is_usb_printing) {
if (usb_timer.running()) {
MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print);////MSG_RESUME_PRINT c=18
} else {
MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);////MSG_RESUME_PRINT c=18
}
}
}
if((IS_SD_PRINTING || is_usb_printing || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling)) {
if((IS_SD_PRINTING || usb_timer.running() || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling)) {
MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
}
#ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) {
if (!card.isFileOpen()) {
if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
//if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
/*else*/{
bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
@ -6514,7 +6514,7 @@ static void lcd_main_menu()
}
#endif //SDSUPPORT
if(!isPrintPaused && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
if(!isPrintPaused && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
if (!farm_mode) {
const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
@ -6524,7 +6524,7 @@ static void lcd_main_menu()
}
}
if ( ! ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal) ) ) {
if ( ! ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal) ) ) {
if (mmu_enabled) {
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18
@ -6556,7 +6556,7 @@ static void lcd_main_menu()
if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
}
if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18
}
@ -8655,7 +8655,7 @@ void menu_lcd_longpress_func(void)
// explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
// The lists are not the same for both functions, so first decide which function is to be performed
if ( (moves_planned() || IS_SD_PRINTING || is_usb_printing )){ // long press as live-adj-z
if ( (moves_planned() || IS_SD_PRINTING || usb_timer.running() )){ // long press as live-adj-z
if(( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
&& ( menu_menu == lcd_status_screen // and in listed menus...
|| menu_menu == lcd_main_menu