|
@@ -306,7 +306,7 @@ const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
|
306
|
306
|
// Inactivity shutdown
|
307
|
307
|
millis_t previous_cmd_ms = 0;
|
308
|
308
|
static millis_t max_inactive_time = 0;
|
309
|
|
-static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000L;
|
|
309
|
+static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL;
|
310
|
310
|
Stopwatch print_job_timer = Stopwatch();
|
311
|
311
|
static uint8_t target_extruder;
|
312
|
312
|
|
|
@@ -435,7 +435,7 @@ static bool send_ok[BUFSIZE];
|
435
|
435
|
#endif
|
436
|
436
|
|
437
|
437
|
#ifdef CHDK
|
438
|
|
- unsigned long chdkHigh = 0;
|
|
438
|
+ millis_t chdkHigh = 0;
|
439
|
439
|
boolean chdkActive = false;
|
440
|
440
|
#endif
|
441
|
441
|
|
|
@@ -456,7 +456,7 @@ static bool send_ok[BUFSIZE];
|
456
|
456
|
};
|
457
|
457
|
|
458
|
458
|
static MarlinBusyState busy_state = NOT_BUSY;
|
459
|
|
- static millis_t prev_busy_signal_ms = -1;
|
|
459
|
+ static millis_t next_busy_signal_ms = 0;
|
460
|
460
|
uint8_t host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
|
461
|
461
|
#define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
|
462
|
462
|
#else
|
|
@@ -874,7 +874,7 @@ inline void get_serial_commands() {
|
874
|
874
|
#if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
|
875
|
875
|
static millis_t last_command_time = 0;
|
876
|
876
|
millis_t ms = millis();
|
877
|
|
- if (commands_in_queue == 0 && !MYSERIAL.available() && ms > last_command_time + NO_TIMEOUTS) {
|
|
877
|
+ if (commands_in_queue == 0 && !MYSERIAL.available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) {
|
878
|
878
|
SERIAL_ECHOLNPGM(MSG_WAIT);
|
879
|
879
|
last_command_time = ms;
|
880
|
880
|
}
|
|
@@ -2280,7 +2280,7 @@ void unknown_command_error() {
|
2280
|
2280
|
void host_keepalive() {
|
2281
|
2281
|
millis_t ms = millis();
|
2282
|
2282
|
if (host_keepalive_interval && busy_state != NOT_BUSY) {
|
2283
|
|
- if (ms - prev_busy_signal_ms < 1000UL * host_keepalive_interval) return;
|
|
2283
|
+ if (PENDING(ms, next_busy_signal_ms)) return;
|
2284
|
2284
|
switch (busy_state) {
|
2285
|
2285
|
case IN_HANDLER:
|
2286
|
2286
|
case IN_PROCESS:
|
|
@@ -2299,7 +2299,7 @@ void unknown_command_error() {
|
2299
|
2299
|
break;
|
2300
|
2300
|
}
|
2301
|
2301
|
}
|
2302
|
|
- prev_busy_signal_ms = ms;
|
|
2302
|
+ next_busy_signal_ms = ms + host_keepalive_interval * 1000UL;
|
2303
|
2303
|
}
|
2304
|
2304
|
|
2305
|
2305
|
#endif //HOST_KEEPALIVE_FEATURE
|
|
@@ -2368,7 +2368,7 @@ inline void gcode_G4() {
|
2368
|
2368
|
millis_t codenum = 0;
|
2369
|
2369
|
|
2370
|
2370
|
if (code_seen('P')) codenum = code_value_long(); // milliseconds to wait
|
2371
|
|
- if (code_seen('S')) codenum = code_value() * 1000; // seconds to wait
|
|
2371
|
+ if (code_seen('S')) codenum = code_value() * 1000UL; // seconds to wait
|
2372
|
2372
|
|
2373
|
2373
|
st_synchronize();
|
2374
|
2374
|
refresh_cmd_timeout();
|
|
@@ -2376,7 +2376,7 @@ inline void gcode_G4() {
|
2376
|
2376
|
|
2377
|
2377
|
if (!lcd_hasstatus()) LCD_MESSAGEPGM(MSG_DWELL);
|
2378
|
2378
|
|
2379
|
|
- while (millis() < codenum) idle();
|
|
2379
|
+ while (PENDING(millis(), codenum)) idle();
|
2380
|
2380
|
}
|
2381
|
2381
|
|
2382
|
2382
|
#if ENABLED(FWRETRACT)
|
|
@@ -3525,7 +3525,7 @@ inline void gcode_G92() {
|
3525
|
3525
|
hasP = codenum > 0;
|
3526
|
3526
|
}
|
3527
|
3527
|
if (code_seen('S')) {
|
3528
|
|
- codenum = code_value() * 1000; // seconds to wait
|
|
3528
|
+ codenum = code_value() * 1000UL; // seconds to wait
|
3529
|
3529
|
hasS = codenum > 0;
|
3530
|
3530
|
}
|
3531
|
3531
|
|
|
@@ -3544,7 +3544,7 @@ inline void gcode_G92() {
|
3544
|
3544
|
if (codenum > 0) {
|
3545
|
3545
|
codenum += previous_cmd_ms; // wait until this time for a click
|
3546
|
3546
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
3547
|
|
- while (millis() < codenum && !lcd_clicked()) idle();
|
|
3547
|
+ while (PENDING(millis(), codenum) && !lcd_clicked()) idle();
|
3548
|
3548
|
KEEPALIVE_STATE(IN_HANDLER);
|
3549
|
3549
|
lcd_ignore_click(false);
|
3550
|
3550
|
}
|
|
@@ -4290,9 +4290,9 @@ inline void gcode_M109() {
|
4290
|
4290
|
if (degTargetHotend(target_extruder) < (EXTRUDE_MINTEMP)/2) return;
|
4291
|
4291
|
|
4292
|
4292
|
#ifdef TEMP_RESIDENCY_TIME
|
4293
|
|
- long residency_start_ms = -1;
|
|
4293
|
+ millis_t residency_start_ms = 0;
|
4294
|
4294
|
// Loop until the temperature has stabilized
|
4295
|
|
- #define TEMP_CONDITIONS (residency_start_ms == -1 || now < residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL)
|
|
4295
|
+ #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
|
4296
|
4296
|
#else
|
4297
|
4297
|
// Loop until the temperature is very close target
|
4298
|
4298
|
#define TEMP_CONDITIONS (isHeatingHotend(target_extruder))
|
|
@@ -4302,14 +4302,14 @@ inline void gcode_M109() {
|
4302
|
4302
|
millis_t now = millis(), next_temp_ms = now + 1000UL;
|
4303
|
4303
|
while (!cancel_heatup && TEMP_CONDITIONS) {
|
4304
|
4304
|
now = millis();
|
4305
|
|
- if (now > next_temp_ms) { //Print temp & remaining time every 1s while waiting
|
|
4305
|
+ if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
|
4306
|
4306
|
next_temp_ms = now + 1000UL;
|
4307
|
4307
|
#if HAS_TEMP_HOTEND || HAS_TEMP_BED
|
4308
|
4308
|
print_heaterstates();
|
4309
|
4309
|
#endif
|
4310
|
4310
|
#ifdef TEMP_RESIDENCY_TIME
|
4311
|
4311
|
SERIAL_PROTOCOLPGM(" W:");
|
4312
|
|
- if (residency_start_ms != -1) {
|
|
4312
|
+ if (residency_start_ms) {
|
4313
|
4313
|
long rem = (((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL;
|
4314
|
4314
|
SERIAL_PROTOCOLLN(rem);
|
4315
|
4315
|
}
|
|
@@ -4328,7 +4328,7 @@ inline void gcode_M109() {
|
4328
|
4328
|
|
4329
|
4329
|
float temp_diff = labs(degHotend(target_extruder) - degTargetHotend(target_extruder));
|
4330
|
4330
|
|
4331
|
|
- if (residency_start_ms == -1) {
|
|
4331
|
+ if (!residency_start_ms) {
|
4332
|
4332
|
// Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
|
4333
|
4333
|
if (temp_diff < TEMP_WINDOW) residency_start_ms = millis();
|
4334
|
4334
|
}
|
|
@@ -4365,7 +4365,7 @@ inline void gcode_M109() {
|
4365
|
4365
|
millis_t now = millis(), next_temp_ms = now + 1000UL;
|
4366
|
4366
|
while (!cancel_heatup && isHeatingBed()) {
|
4367
|
4367
|
millis_t now = millis();
|
4368
|
|
- if (now > next_temp_ms) { //Print Temp Reading every 1 second while heating up.
|
|
4368
|
+ if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
|
4369
|
4369
|
next_temp_ms = now + 1000UL;
|
4370
|
4370
|
print_heaterstates();
|
4371
|
4371
|
SERIAL_EOL;
|
|
@@ -4613,7 +4613,7 @@ inline void gcode_M83() { axis_relative_modes[E_AXIS] = true; }
|
4613
|
4613
|
*/
|
4614
|
4614
|
inline void gcode_M18_M84() {
|
4615
|
4615
|
if (code_seen('S')) {
|
4616
|
|
- stepper_inactive_time = code_value() * 1000;
|
|
4616
|
+ stepper_inactive_time = code_value() * 1000UL;
|
4617
|
4617
|
}
|
4618
|
4618
|
else {
|
4619
|
4619
|
bool all_axis = !((code_seen(axis_codes[X_AXIS])) || (code_seen(axis_codes[Y_AXIS])) || (code_seen(axis_codes[Z_AXIS])) || (code_seen(axis_codes[E_AXIS])));
|
|
@@ -4641,7 +4641,7 @@ inline void gcode_M18_M84() {
|
4641
|
4641
|
* M85: Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
|
4642
|
4642
|
*/
|
4643
|
4643
|
inline void gcode_M85() {
|
4644
|
|
- if (code_seen('S')) max_inactive_time = code_value() * 1000;
|
|
4644
|
+ if (code_seen('S')) max_inactive_time = code_value() * 1000UL;
|
4645
|
4645
|
}
|
4646
|
4646
|
|
4647
|
4647
|
/**
|
|
@@ -5868,9 +5868,9 @@ inline void gcode_M503() {
|
5868
|
5868
|
while (!lcd_clicked()) {
|
5869
|
5869
|
#if DISABLED(AUTO_FILAMENT_CHANGE)
|
5870
|
5870
|
millis_t ms = millis();
|
5871
|
|
- if (ms >= next_tick) {
|
|
5871
|
+ if (ELAPSED(ms, next_tick)) {
|
5872
|
5872
|
lcd_quick_feedback();
|
5873
|
|
- next_tick = ms + 2500; // feedback every 2.5s while waiting
|
|
5873
|
+ next_tick = ms + 2500UL; // feedback every 2.5s while waiting
|
5874
|
5874
|
}
|
5875
|
5875
|
idle(true);
|
5876
|
5876
|
#else
|
|
@@ -6109,7 +6109,7 @@ inline void gcode_T(uint8_t tmp_extruder) {
|
6109
|
6109
|
set_destination_to_current();
|
6110
|
6110
|
#if ENABLED(DUAL_X_CARRIAGE)
|
6111
|
6111
|
if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE && IsRunning() &&
|
6112
|
|
- (delayed_move_time != 0 || current_position[X_AXIS] != x_home_pos(active_extruder))) {
|
|
6112
|
+ (delayed_move_time || current_position[X_AXIS] != x_home_pos(active_extruder))) {
|
6113
|
6113
|
// Park old head: 1) raise 2) move to park position 3) lower
|
6114
|
6114
|
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
|
6115
|
6115
|
current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
|
|
@@ -7345,8 +7345,8 @@ void plan_arc(
|
7345
|
7345
|
static millis_t lastMotorOn = 0; // Last time a motor was turned on
|
7346
|
7346
|
static millis_t nextMotorCheck = 0; // Last time the state was checked
|
7347
|
7347
|
millis_t ms = millis();
|
7348
|
|
- if (ms >= nextMotorCheck) {
|
7349
|
|
- nextMotorCheck = ms + 2500; // Not a time critical function, so only check every 2.5s
|
|
7348
|
+ if (ELAPSED(ms, nextMotorCheck)) {
|
|
7349
|
+ nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
|
7350
|
7350
|
if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
|
7351
|
7351
|
|| E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
|
7352
|
7352
|
#if EXTRUDERS > 1
|
|
@@ -7366,7 +7366,7 @@ void plan_arc(
|
7366
|
7366
|
}
|
7367
|
7367
|
|
7368
|
7368
|
// Fan off if no steppers have been enabled for CONTROLLERFAN_SECS seconds
|
7369
|
|
- uint8_t speed = (lastMotorOn == 0 || ms >= lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL) ? 0 : CONTROLLERFAN_SPEED;
|
|
7369
|
+ uint8_t speed = (!lastMotorOn || ELAPSED(ms, lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL)) ? 0 : CONTROLLERFAN_SPEED;
|
7370
|
7370
|
|
7371
|
7371
|
// allows digital or PWM fan output to be used (see M42 handling)
|
7372
|
7372
|
digitalWrite(CONTROLLERFAN_PIN, speed);
|
|
@@ -7462,7 +7462,7 @@ void plan_arc(
|
7462
|
7462
|
|
7463
|
7463
|
void handle_status_leds(void) {
|
7464
|
7464
|
float max_temp = 0.0;
|
7465
|
|
- if (millis() > next_status_led_update_ms) {
|
|
7465
|
+ if (ELAPSED(millis(), next_status_led_update_ms)) {
|
7466
|
7466
|
next_status_led_update_ms += 500; // Update every 0.5s
|
7467
|
7467
|
for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder)
|
7468
|
7468
|
max_temp = max(max(max_temp, degHotend(cur_extruder)), degTargetHotend(cur_extruder));
|
|
@@ -7541,9 +7541,9 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
|
7541
|
7541
|
|
7542
|
7542
|
millis_t ms = millis();
|
7543
|
7543
|
|
7544
|
|
- if (max_inactive_time && ms > previous_cmd_ms + max_inactive_time) kill(PSTR(MSG_KILLED));
|
|
7544
|
+ if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) kill(PSTR(MSG_KILLED));
|
7545
|
7545
|
|
7546
|
|
- if (stepper_inactive_time && ms > previous_cmd_ms + stepper_inactive_time
|
|
7546
|
+ if (stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time)
|
7547
|
7547
|
&& !ignore_stepper_queue && !blocks_queued()) {
|
7548
|
7548
|
#if ENABLED(DISABLE_INACTIVE_X)
|
7549
|
7549
|
disable_x();
|
|
@@ -7563,7 +7563,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
|
7563
|
7563
|
}
|
7564
|
7564
|
|
7565
|
7565
|
#ifdef CHDK // Check if pin should be set to LOW after M240 set it to HIGH
|
7566
|
|
- if (chdkActive && ms > chdkHigh + CHDK_DELAY) {
|
|
7566
|
+ if (chdkActive && PENDING(ms, chdkHigh + CHDK_DELAY)) {
|
7567
|
7567
|
chdkActive = false;
|
7568
|
7568
|
WRITE(CHDK, LOW);
|
7569
|
7569
|
}
|
|
@@ -7609,7 +7609,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
|
7609
|
7609
|
#endif
|
7610
|
7610
|
|
7611
|
7611
|
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
|
7612
|
|
- if (ms > previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000)
|
|
7612
|
+ if (ELAPSED(ms, previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL))
|
7613
|
7613
|
if (degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) {
|
7614
|
7614
|
bool oldstatus;
|
7615
|
7615
|
switch (active_extruder) {
|
|
@@ -7670,7 +7670,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
|
7670
|
7670
|
|
7671
|
7671
|
#if ENABLED(DUAL_X_CARRIAGE)
|
7672
|
7672
|
// handle delayed move timeout
|
7673
|
|
- if (delayed_move_time && ms > delayed_move_time + 1000 && IsRunning()) {
|
|
7673
|
+ if (delayed_move_time && ELAPSED(ms, delayed_move_time + 1000UL) && IsRunning()) {
|
7674
|
7674
|
// travel moves have been received so enact them
|
7675
|
7675
|
delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
|
7676
|
7676
|
set_destination_to_current();
|