🚸 Fix G4 Dwell overflow

This commit is contained in:
Teemo Vaas 2023-12-22 06:47:36 +02:00 committed by Scott Lahteine
parent a68b70de15
commit 363f324179
3 changed files with 9 additions and 6 deletions

View file

@ -30,5 +30,8 @@ typedef uint32_t millis_t;
#define MS_TO_SEC(N) millis_t((N)/1000UL)
#define MS_TO_SEC_PRECISE(N) (float(N)/1000.0f)
#define PENDING(NOW,SOON) ((int32_t)(NOW-(SOON))<0)
#define FUTURE(START,DURA) (millis_t(millis()-(START))<(DURA))
#define PAST(START,DURA) (!FUTURE(START,DURA))
#define PENDING(NOW,SOON) (int32_t((NOW)-(SOON))<0)
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))

View file

@ -242,11 +242,11 @@ void GcodeSuite::get_destination_from_command() {
}
/**
* Dwell waits immediately. It does not synchronize. Use M400 instead of G4
* Dwell waits immediately. It does not synchronize.
*/
void GcodeSuite::dwell(millis_t time) {
time += millis();
while (PENDING(millis(), time)) idle();
void GcodeSuite::dwell(const millis_t time) {
const millis_t startMillis = millis();
while (FUTURE(startMillis, time)) idle();
}
/**

View file

@ -503,7 +503,7 @@ public:
#define KEEPALIVE_STATE(N) NOOP
#endif
static void dwell(millis_t time);
static void dwell(const millis_t time);
private: