Skip to content

Commit 363f324

Browse files
TBAMaxthinkyhead
authored andcommitted
🚸 Fix G4 Dwell overflow
1 parent a68b70d commit 363f324

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Marlin/src/core/millis_t.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ typedef uint32_t millis_t;
3030
#define MS_TO_SEC(N) millis_t((N)/1000UL)
3131
#define MS_TO_SEC_PRECISE(N) (float(N)/1000.0f)
3232

33-
#define PENDING(NOW,SOON) ((int32_t)(NOW-(SOON))<0)
33+
#define FUTURE(START,DURA) (millis_t(millis()-(START))<(DURA))
34+
#define PAST(START,DURA) (!FUTURE(START,DURA))
35+
36+
#define PENDING(NOW,SOON) (int32_t((NOW)-(SOON))<0)
3437
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))

Marlin/src/gcode/gcode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ void GcodeSuite::get_destination_from_command() {
242242
}
243243

244244
/**
245-
* Dwell waits immediately. It does not synchronize. Use M400 instead of G4
245+
* Dwell waits immediately. It does not synchronize.
246246
*/
247-
void GcodeSuite::dwell(millis_t time) {
248-
time += millis();
249-
while (PENDING(millis(), time)) idle();
247+
void GcodeSuite::dwell(const millis_t time) {
248+
const millis_t startMillis = millis();
249+
while (FUTURE(startMillis, time)) idle();
250250
}
251251

252252
/**

Marlin/src/gcode/gcode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ class GcodeSuite {
503503
#define KEEPALIVE_STATE(N) NOOP
504504
#endif
505505

506-
static void dwell(millis_t time);
506+
static void dwell(const millis_t time);
507507

508508
private:
509509

0 commit comments

Comments
 (0)