Skip to content

Commit

Permalink
Limit LCD refresh while printing to avoid planner stalls (PR prusa3d#…
Browse files Browse the repository at this point in the history
…1940)

Wavexx fix for LCD refesh causing stalls (related to gyroid infill issue)
  • Loading branch information
JPTa committed Jul 3, 2019
1 parent 7bf2e67 commit 0b18cfc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
20 changes: 20 additions & 0 deletions Firmware/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,3 +1420,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 @@ -241,7 +241,6 @@ void set_extrude_min_temp(float temp);
#endif

void reset_acceleration_rates();
#endif

void update_mode_profile();

Expand All @@ -258,3 +257,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
56 changes: 42 additions & 14 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,20 +1001,9 @@ static void lcd_status_screen()

if (lcd_draw_update)
{
#ifndef HAS_OLED_SCREEN // JTa: Disabled for OLED!
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.
}
#endif

// #ifndef HAS_OLED_SCREEN // JTa: Disabled for OLED! TODO: Check if flickering was fixed with Wavexx fix
lcd_attempt_refresh();
// #endif
lcdui_print_status_screen();

if (farm_mode)
Expand Down

0 comments on commit 0b18cfc

Please sign in to comment.