Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit LCD refresh while printing to avoid planner stalls #1940

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Firmware/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,3 +1369,23 @@ uint16_t planner_calc_sd_length()
}
return sdlen;
}

float planned_time()
{
unsigned char _block_buffer_head = block_buffer_head;
unsigned char _block_buffer_tail = block_buffer_tail;

unsigned char n = 0;
float mm = 0;
float speed = 0;

while (_block_buffer_head != _block_buffer_tail)
{
mm += block_buffer[_block_buffer_tail].millimeters;
speed += block_buffer[_block_buffer_tail].nominal_speed;
++n;

_block_buffer_tail = (_block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1);
}
return mm * ((float)n / speed);
}
7 changes: 6 additions & 1 deletion Firmware/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ void set_extrude_min_temp(float temp);
#endif

void reset_acceleration_rates();
#endif

void update_mode_profile();

Expand All @@ -254,3 +253,9 @@ extern void planner_queue_min_reset();
extern void planner_add_sd_length(uint16_t sdlen);

extern uint16_t planner_calc_sd_length();

// Return a rough, optimistic estimate of the total time (s) for the planned moves
// This function takes in the order of 50us
float planned_time();

#endif
52 changes: 40 additions & 12 deletions Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,45 @@ void lcdui_print_status_screen(void)

}


// Attempt to occasionally reinit to revive the LCD if static electricity killed it
#define LCD_REINIT_FULL 30 // time between full reinitializations
#define LCD_REINIT_FAST 10 // time between fast reinitializations
#define LCD_REINIT_OVR 1 // check frequency for overdue full refreshes

static_assert((LCD_REINIT_FULL % LCD_REINIT_FAST) == 0, "FULL should be a multiple of FAST");

static void lcd_attempt_refresh()
{
++ReInitLCD;

if ((ReInitLCD % LCD_REINIT_FAST) == 0)
{
// limit LCD reinitialization while printing as it can starve the planner in tight situations
if (!(IS_SD_PRINTING || is_usb_printing) || !blocks_queued() || planned_time() > 0.25)
{
if (ReInitLCD == LCD_REINIT_FULL)
{
// full reset
lcd_refresh();
ReInitLCD = 0;
}
else
{
// just reinitialize
lcd_refresh_noclear();
}
}
else
{
// Full refresh is overdue: increase the frequency of probing attempts
if (ReInitLCD == LCD_REINIT_FULL)
ReInitLCD = LCD_REINIT_FULL - LCD_REINIT_OVR;
}
}
}


// Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent
static void lcd_status_screen()
{
Expand All @@ -962,18 +1001,7 @@ static void lcd_status_screen()

if (lcd_draw_update)
{
ReInitLCD++;
if (ReInitLCD == 30)
{
lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
ReInitLCD = 0 ;
}
else
{
if ((ReInitLCD % 10) == 0)
lcd_refresh_noclear(); //to maybe revive the LCD if static electricity killed it.
}

lcd_attempt_refresh();
lcdui_print_status_screen();

if (farm_mode)
Expand Down