Skip to content

Commit

Permalink
Proposed 'early_safe_delay'
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 20, 2021
1 parent 79b6fef commit ab9b91d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Marlin/src/core/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ void safe_delay(millis_t ms) {
thermalManager.manage_heater(); // This keeps us safe if too many small safe_delay() calls are made
}

#if ENABLED(MARLIN_DEV_MODE)
void early_safe_delay(millis_t ms) {
while (ms > 50) {
ms -= 50;
delay(50);
watchdog_refresh();
}
delay(ms);
watchdog_refresh();
}
#endif

// A delay to provide brittle hosts time to receive bytes
#if ENABLED(SERIAL_OVERRUN_PROTECTION)

Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/core/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#include "../core/millis_t.h"

void safe_delay(millis_t ms); // Delay ensuring that temperatures are updated and the watchdog is kept alive.
#if ENABLED(MARLIN_DEV_MODE)
void early_safe_delay(millis_t ms); // Delay ensuring that the watchdog is kept alive. Can be used before the Temperature ISR starts.
#else
inline void early_safe_delay(millis_t ms) { safe_delay(ms); }
#endif

#if ENABLED(SERIAL_OVERRUN_PROTECTION)
void serial_delay(const millis_t ms);
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ bool MarlinUI::detected() { return true; }
#endif
u8g.firstPage();
do { draw_custom_bootscreen(f); } while (u8g.nextPage());
if (frame_time) safe_delay(frame_time);
if (frame_time) early_safe_delay(frame_time);
}

#ifndef CUSTOM_BOOTSCREEN_TIMEOUT
#define CUSTOM_BOOTSCREEN_TIMEOUT 2500
#endif
#if CUSTOM_BOOTSCREEN_TIMEOUT
safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
early_safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
#endif
}
#endif // SHOW_CUSTOM_BOOTSCREEN
Expand Down Expand Up @@ -226,7 +226,7 @@ bool MarlinUI::detected() { return true; }
constexpr millis_t frame_time = MARLIN_BOOTSCREEN_FRAME_TIME;
LOOP_L_N(f, COUNT(marlin_bootscreen_animation)) {
draw_bootscreen_bmp((uint8_t*)pgm_read_ptr(&marlin_bootscreen_animation[f]));
if (frame_time) safe_delay(frame_time);
if (frame_time) early_safe_delay(frame_time);
}
#endif
}
Expand All @@ -235,7 +235,7 @@ bool MarlinUI::detected() { return true; }
void MarlinUI::show_marlin_bootscreen() {
for (uint8_t q = bootscreen_pages; q--;) {
draw_marlin_bootscreen(q == 0);
if (q) safe_delay((BOOTSCREEN_TIMEOUT) / bootscreen_pages);
if (q) early_safe_delay((BOOTSCREEN_TIMEOUT) / bootscreen_pages);
}
}

Expand Down

0 comments on commit ab9b91d

Please sign in to comment.