Browse Source

Test time difference in safe way

Scott Lahteine 8 years ago
parent
commit
386140f361

+ 30
- 30
Marlin/Marlin_main.cpp View File

306
 // Inactivity shutdown
306
 // Inactivity shutdown
307
 millis_t previous_cmd_ms = 0;
307
 millis_t previous_cmd_ms = 0;
308
 static millis_t max_inactive_time = 0;
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
 Stopwatch print_job_timer = Stopwatch();
310
 Stopwatch print_job_timer = Stopwatch();
311
 static uint8_t target_extruder;
311
 static uint8_t target_extruder;
312
 
312
 
435
 #endif
435
 #endif
436
 
436
 
437
 #ifdef CHDK
437
 #ifdef CHDK
438
-  unsigned long chdkHigh = 0;
438
+  millis_t chdkHigh = 0;
439
   boolean chdkActive = false;
439
   boolean chdkActive = false;
440
 #endif
440
 #endif
441
 
441
 
456
   };
456
   };
457
 
457
 
458
   static MarlinBusyState busy_state = NOT_BUSY;
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
   uint8_t host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
460
   uint8_t host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
461
   #define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
461
   #define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
462
 #else
462
 #else
874
   #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
874
   #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
875
     static millis_t last_command_time = 0;
875
     static millis_t last_command_time = 0;
876
     millis_t ms = millis();
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
       SERIAL_ECHOLNPGM(MSG_WAIT);
878
       SERIAL_ECHOLNPGM(MSG_WAIT);
879
       last_command_time = ms;
879
       last_command_time = ms;
880
     }
880
     }
2280
   void host_keepalive() {
2280
   void host_keepalive() {
2281
     millis_t ms = millis();
2281
     millis_t ms = millis();
2282
     if (host_keepalive_interval && busy_state != NOT_BUSY) {
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
       switch (busy_state) {
2284
       switch (busy_state) {
2285
         case IN_HANDLER:
2285
         case IN_HANDLER:
2286
         case IN_PROCESS:
2286
         case IN_PROCESS:
2299
           break;
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
 #endif //HOST_KEEPALIVE_FEATURE
2305
 #endif //HOST_KEEPALIVE_FEATURE
2368
   millis_t codenum = 0;
2368
   millis_t codenum = 0;
2369
 
2369
 
2370
   if (code_seen('P')) codenum = code_value_long(); // milliseconds to wait
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
   st_synchronize();
2373
   st_synchronize();
2374
   refresh_cmd_timeout();
2374
   refresh_cmd_timeout();
2376
 
2376
 
2377
   if (!lcd_hasstatus()) LCD_MESSAGEPGM(MSG_DWELL);
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
 #if ENABLED(FWRETRACT)
2382
 #if ENABLED(FWRETRACT)
3525
       hasP = codenum > 0;
3525
       hasP = codenum > 0;
3526
     }
3526
     }
3527
     if (code_seen('S')) {
3527
     if (code_seen('S')) {
3528
-      codenum = code_value() * 1000; // seconds to wait
3528
+      codenum = code_value() * 1000UL; // seconds to wait
3529
       hasS = codenum > 0;
3529
       hasS = codenum > 0;
3530
     }
3530
     }
3531
 
3531
 
3544
     if (codenum > 0) {
3544
     if (codenum > 0) {
3545
       codenum += previous_cmd_ms;  // wait until this time for a click
3545
       codenum += previous_cmd_ms;  // wait until this time for a click
3546
       KEEPALIVE_STATE(PAUSED_FOR_USER);
3546
       KEEPALIVE_STATE(PAUSED_FOR_USER);
3547
-      while (millis() < codenum && !lcd_clicked()) idle();
3547
+      while (PENDING(millis(), codenum) && !lcd_clicked()) idle();
3548
       KEEPALIVE_STATE(IN_HANDLER);
3548
       KEEPALIVE_STATE(IN_HANDLER);
3549
       lcd_ignore_click(false);
3549
       lcd_ignore_click(false);
3550
     }
3550
     }
4290
   if (degTargetHotend(target_extruder) < (EXTRUDE_MINTEMP)/2) return;
4290
   if (degTargetHotend(target_extruder) < (EXTRUDE_MINTEMP)/2) return;
4291
 
4291
 
4292
   #ifdef TEMP_RESIDENCY_TIME
4292
   #ifdef TEMP_RESIDENCY_TIME
4293
-    long residency_start_ms = -1;
4293
+    millis_t residency_start_ms = 0;
4294
     // Loop until the temperature has stabilized
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
   #else
4296
   #else
4297
     // Loop until the temperature is very close target
4297
     // Loop until the temperature is very close target
4298
     #define TEMP_CONDITIONS (isHeatingHotend(target_extruder))
4298
     #define TEMP_CONDITIONS (isHeatingHotend(target_extruder))
4302
   millis_t now = millis(), next_temp_ms = now + 1000UL;
4302
   millis_t now = millis(), next_temp_ms = now + 1000UL;
4303
   while (!cancel_heatup && TEMP_CONDITIONS) {
4303
   while (!cancel_heatup && TEMP_CONDITIONS) {
4304
     now = millis();
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
       next_temp_ms = now + 1000UL;
4306
       next_temp_ms = now + 1000UL;
4307
       #if HAS_TEMP_HOTEND || HAS_TEMP_BED
4307
       #if HAS_TEMP_HOTEND || HAS_TEMP_BED
4308
         print_heaterstates();
4308
         print_heaterstates();
4309
       #endif
4309
       #endif
4310
       #ifdef TEMP_RESIDENCY_TIME
4310
       #ifdef TEMP_RESIDENCY_TIME
4311
         SERIAL_PROTOCOLPGM(" W:");
4311
         SERIAL_PROTOCOLPGM(" W:");
4312
-        if (residency_start_ms != -1) {
4312
+        if (residency_start_ms) {
4313
           long rem = (((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL;
4313
           long rem = (((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL;
4314
           SERIAL_PROTOCOLLN(rem);
4314
           SERIAL_PROTOCOLLN(rem);
4315
         }
4315
         }
4328
 
4328
 
4329
       float temp_diff = labs(degHotend(target_extruder) - degTargetHotend(target_extruder));
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
         // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
4332
         // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
4333
         if (temp_diff < TEMP_WINDOW) residency_start_ms = millis();
4333
         if (temp_diff < TEMP_WINDOW) residency_start_ms = millis();
4334
       }
4334
       }
4365
     millis_t now = millis(), next_temp_ms = now + 1000UL;
4365
     millis_t now = millis(), next_temp_ms = now + 1000UL;
4366
     while (!cancel_heatup && isHeatingBed()) {
4366
     while (!cancel_heatup && isHeatingBed()) {
4367
       millis_t now = millis();
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
         next_temp_ms = now + 1000UL;
4369
         next_temp_ms = now + 1000UL;
4370
         print_heaterstates();
4370
         print_heaterstates();
4371
         SERIAL_EOL;
4371
         SERIAL_EOL;
4613
  */
4613
  */
4614
 inline void gcode_M18_M84() {
4614
 inline void gcode_M18_M84() {
4615
   if (code_seen('S')) {
4615
   if (code_seen('S')) {
4616
-    stepper_inactive_time = code_value() * 1000;
4616
+    stepper_inactive_time = code_value() * 1000UL;
4617
   }
4617
   }
4618
   else {
4618
   else {
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])));
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
  * M85: Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
4641
  * M85: Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
4642
  */
4642
  */
4643
 inline void gcode_M85() {
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
     while (!lcd_clicked()) {
5868
     while (!lcd_clicked()) {
5869
       #if DISABLED(AUTO_FILAMENT_CHANGE)
5869
       #if DISABLED(AUTO_FILAMENT_CHANGE)
5870
         millis_t ms = millis();
5870
         millis_t ms = millis();
5871
-        if (ms >= next_tick) {
5871
+        if (ELAPSED(ms, next_tick)) {
5872
           lcd_quick_feedback();
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
         idle(true);
5875
         idle(true);
5876
       #else
5876
       #else
6109
         set_destination_to_current();
6109
         set_destination_to_current();
6110
         #if ENABLED(DUAL_X_CARRIAGE)
6110
         #if ENABLED(DUAL_X_CARRIAGE)
6111
           if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE && IsRunning() &&
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
             // Park old head: 1) raise 2) move to park position 3) lower
6113
             // Park old head: 1) raise 2) move to park position 3) lower
6114
             plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6114
             plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6115
                              current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
6115
                              current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
7337
     static millis_t lastMotorOn = 0; // Last time a motor was turned on
7337
     static millis_t lastMotorOn = 0; // Last time a motor was turned on
7338
     static millis_t nextMotorCheck = 0; // Last time the state was checked
7338
     static millis_t nextMotorCheck = 0; // Last time the state was checked
7339
     millis_t ms = millis();
7339
     millis_t ms = millis();
7340
-    if (ms >= nextMotorCheck) {
7341
-      nextMotorCheck = ms + 2500; // Not a time critical function, so only check every 2.5s
7340
+    if (ELAPSED(ms, nextMotorCheck)) {
7341
+      nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
7342
       if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
7342
       if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
7343
           || E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
7343
           || E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
7344
           #if EXTRUDERS > 1
7344
           #if EXTRUDERS > 1
7358
       }
7358
       }
7359
 
7359
 
7360
       // Fan off if no steppers have been enabled for CONTROLLERFAN_SECS seconds
7360
       // Fan off if no steppers have been enabled for CONTROLLERFAN_SECS seconds
7361
-      uint8_t speed = (lastMotorOn == 0 || ms >= lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL) ? 0 : CONTROLLERFAN_SPEED;
7361
+      uint8_t speed = (!lastMotorOn || ELAPSED(ms, lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL)) ? 0 : CONTROLLERFAN_SPEED;
7362
 
7362
 
7363
       // allows digital or PWM fan output to be used (see M42 handling)
7363
       // allows digital or PWM fan output to be used (see M42 handling)
7364
       digitalWrite(CONTROLLERFAN_PIN, speed);
7364
       digitalWrite(CONTROLLERFAN_PIN, speed);
7454
 
7454
 
7455
   void handle_status_leds(void) {
7455
   void handle_status_leds(void) {
7456
     float max_temp = 0.0;
7456
     float max_temp = 0.0;
7457
-    if (millis() > next_status_led_update_ms) {
7457
+    if (ELAPSED(millis(), next_status_led_update_ms)) {
7458
       next_status_led_update_ms += 500; // Update every 0.5s
7458
       next_status_led_update_ms += 500; // Update every 0.5s
7459
       for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder)
7459
       for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder)
7460
         max_temp = max(max(max_temp, degHotend(cur_extruder)), degTargetHotend(cur_extruder));
7460
         max_temp = max(max(max_temp, degHotend(cur_extruder)), degTargetHotend(cur_extruder));
7533
 
7533
 
7534
   millis_t ms = millis();
7534
   millis_t ms = millis();
7535
 
7535
 
7536
-  if (max_inactive_time && ms > previous_cmd_ms + max_inactive_time) kill(PSTR(MSG_KILLED));
7536
+  if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) kill(PSTR(MSG_KILLED));
7537
 
7537
 
7538
-  if (stepper_inactive_time && ms > previous_cmd_ms + stepper_inactive_time
7538
+  if (stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time)
7539
       && !ignore_stepper_queue && !blocks_queued()) {
7539
       && !ignore_stepper_queue && !blocks_queued()) {
7540
     #if ENABLED(DISABLE_INACTIVE_X)
7540
     #if ENABLED(DISABLE_INACTIVE_X)
7541
       disable_x();
7541
       disable_x();
7555
   }
7555
   }
7556
 
7556
 
7557
   #ifdef CHDK // Check if pin should be set to LOW after M240 set it to HIGH
7557
   #ifdef CHDK // Check if pin should be set to LOW after M240 set it to HIGH
7558
-    if (chdkActive && ms > chdkHigh + CHDK_DELAY) {
7558
+    if (chdkActive && PENDING(ms, chdkHigh + CHDK_DELAY)) {
7559
       chdkActive = false;
7559
       chdkActive = false;
7560
       WRITE(CHDK, LOW);
7560
       WRITE(CHDK, LOW);
7561
     }
7561
     }
7601
   #endif
7601
   #endif
7602
 
7602
 
7603
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
7603
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
7604
-    if (ms > previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000)
7604
+    if (ELAPSED(ms, previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL))
7605
       if (degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) {
7605
       if (degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) {
7606
         bool oldstatus;
7606
         bool oldstatus;
7607
         switch (active_extruder) {
7607
         switch (active_extruder) {
7662
 
7662
 
7663
   #if ENABLED(DUAL_X_CARRIAGE)
7663
   #if ENABLED(DUAL_X_CARRIAGE)
7664
     // handle delayed move timeout
7664
     // handle delayed move timeout
7665
-    if (delayed_move_time && ms > delayed_move_time + 1000 && IsRunning()) {
7665
+    if (delayed_move_time && ELAPSED(ms, delayed_move_time + 1000UL) && IsRunning()) {
7666
       // travel moves have been received so enact them
7666
       // travel moves have been received so enact them
7667
       delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
7667
       delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
7668
       set_destination_to_current();
7668
       set_destination_to_current();

+ 1
- 1
Marlin/cardreader.cpp View File

508
 }
508
 }
509
 
509
 
510
 void CardReader::checkautostart(bool force) {
510
 void CardReader::checkautostart(bool force) {
511
-  if (!force && (!autostart_stilltocheck || next_autostart_ms < millis()))
511
+  if (!force && (!autostart_stilltocheck || ELAPSED(millis(), next_autostart_ms)))
512
     return;
512
     return;
513
 
513
 
514
   autostart_stilltocheck = false;
514
   autostart_stilltocheck = false;

+ 1
- 1
Marlin/dogm_lcd_implementation.h View File

459
   #if DISABLED(FILAMENT_LCD_DISPLAY)
459
   #if DISABLED(FILAMENT_LCD_DISPLAY)
460
     lcd_print(lcd_status_message);
460
     lcd_print(lcd_status_message);
461
   #else
461
   #else
462
-    if (millis() < previous_lcd_status_ms + 5000) {  //Display both Status message line and Filament display on the last line
462
+    if (PENDING(millis(), previous_lcd_status_ms + 5000)) {  //Display both Status message line and Filament display on the last line
463
       lcd_print(lcd_status_message);
463
       lcd_print(lcd_status_message);
464
     }
464
     }
465
     else {
465
     else {

+ 3
- 0
Marlin/macros.h View File

57
 
57
 
58
 #define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0)
58
 #define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0)
59
 
59
 
60
+#define PENDING(NOW,SOON) ((long)(NOW-(SOON))<0)
61
+#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
62
+
60
 #endif //__MACROS_H
63
 #endif //__MACROS_H

+ 1
- 1
Marlin/planner.cpp View File

491
             fan_kick_end[f] = ms + FAN_KICKSTART_TIME; \
491
             fan_kick_end[f] = ms + FAN_KICKSTART_TIME; \
492
             tail_fan_speed[f] = 255; \
492
             tail_fan_speed[f] = 255; \
493
           } else { \
493
           } else { \
494
-            if (fan_kick_end[f] > ms) { \
494
+            if (PENDING(ms, fan_kick_end[f])) { \
495
               tail_fan_speed[f] = 255; \
495
               tail_fan_speed[f] = 255; \
496
             } \
496
             } \
497
           } \
497
           } \

+ 13
- 13
Marlin/temperature.cpp View File

235
   float max = 0, min = 10000;
235
   float max = 0, min = 10000;
236
 
236
 
237
   #if HAS_AUTO_FAN
237
   #if HAS_AUTO_FAN
238
-    millis_t next_auto_fan_check_ms = temp_ms + 2500;
238
+    millis_t next_auto_fan_check_ms = temp_ms + 2500UL;
239
   #endif
239
   #endif
240
 
240
 
241
   if (extruder >= EXTRUDERS
241
   if (extruder >= EXTRUDERS
270
       min = min(min, input);
270
       min = min(min, input);
271
 
271
 
272
       #if HAS_AUTO_FAN
272
       #if HAS_AUTO_FAN
273
-        if (ms > next_auto_fan_check_ms) {
273
+        if (ELAPSED(ms, next_auto_fan_check_ms)) {
274
           checkExtruderAutoFans();
274
           checkExtruderAutoFans();
275
-          next_auto_fan_check_ms = ms + 2500;
275
+          next_auto_fan_check_ms = ms + 2500UL;
276
         }
276
         }
277
       #endif
277
       #endif
278
 
278
 
279
       if (heating && input > temp) {
279
       if (heating && input > temp) {
280
-        if (ms > t2 + 5000) {
280
+        if (ELAPSED(ms, t2 + 5000UL)) {
281
           heating = false;
281
           heating = false;
282
           if (extruder < 0)
282
           if (extruder < 0)
283
             soft_pwm_bed = (bias - d) >> 1;
283
             soft_pwm_bed = (bias - d) >> 1;
290
       }
290
       }
291
 
291
 
292
       if (!heating && input < temp) {
292
       if (!heating && input < temp) {
293
-        if (ms > t1 + 5000) {
293
+        if (ELAPSED(ms, t1 + 5000UL)) {
294
           heating = true;
294
           heating = true;
295
           t2 = ms;
295
           t2 = ms;
296
           t_low = t2 - t1;
296
           t_low = t2 - t1;
349
       return;
349
       return;
350
     }
350
     }
351
     // Every 2 seconds...
351
     // Every 2 seconds...
352
-    if (ms > temp_ms + 2000) {
352
+    if (ELAPSED(ms, temp_ms + 2000UL)) {
353
       #if HAS_TEMP_HOTEND || HAS_TEMP_BED
353
       #if HAS_TEMP_HOTEND || HAS_TEMP_BED
354
         print_heaterstates();
354
         print_heaterstates();
355
         SERIAL_EOL;
355
         SERIAL_EOL;
673
     #if ENABLED(THERMAL_PROTECTION_HOTENDS)
673
     #if ENABLED(THERMAL_PROTECTION_HOTENDS)
674
 
674
 
675
       // Is it time to check this extruder's heater?
675
       // Is it time to check this extruder's heater?
676
-      if (watch_heater_next_ms[e] && ms > watch_heater_next_ms[e]) {
676
+      if (watch_heater_next_ms[e] && ELAPSED(ms, watch_heater_next_ms[e])) {
677
         // Has it failed to increase enough?
677
         // Has it failed to increase enough?
678
         if (degHotend(e) < watch_target_temp[e]) {
678
         if (degHotend(e) < watch_target_temp[e]) {
679
           // Stop!
679
           // Stop!
696
   } // Extruders Loop
696
   } // Extruders Loop
697
 
697
 
698
   #if HAS_AUTO_FAN
698
   #if HAS_AUTO_FAN
699
-    if (ms > next_auto_fan_check_ms) { // only need to check fan state very infrequently
699
+    if (ELAPSED(ms > next_auto_fan_check_ms)) { // only need to check fan state very infrequently
700
       checkExtruderAutoFans();
700
       checkExtruderAutoFans();
701
-      next_auto_fan_check_ms = ms + 2500;
701
+      next_auto_fan_check_ms = ms + 2500UL;
702
     }
702
     }
703
   #endif
703
   #endif
704
 
704
 
718
   #endif //FILAMENT_WIDTH_SENSOR
718
   #endif //FILAMENT_WIDTH_SENSOR
719
 
719
 
720
   #if DISABLED(PIDTEMPBED)
720
   #if DISABLED(PIDTEMPBED)
721
-    if (ms < next_bed_check_ms) return;
721
+    if (PENDING(ms, next_bed_check_ms)) return;
722
     next_bed_check_ms = ms + BED_CHECK_INTERVAL;
722
     next_bed_check_ms = ms + BED_CHECK_INTERVAL;
723
   #endif
723
   #endif
724
 
724
 
1105
   void start_watching_heater(int e) {
1105
   void start_watching_heater(int e) {
1106
     if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1106
     if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1107
       watch_target_temp[e] = degHotend(e) + WATCH_TEMP_INCREASE;
1107
       watch_target_temp[e] = degHotend(e) + WATCH_TEMP_INCREASE;
1108
-      watch_heater_next_ms[e] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
1108
+      watch_heater_next_ms[e] = millis() + (WATCH_TEMP_PERIOD) * 1000;
1109
     }
1109
     }
1110
     else
1110
     else
1111
       watch_heater_next_ms[e] = 0;
1111
       watch_heater_next_ms[e] = 0;
1160
         if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc)
1160
         if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc)
1161
           *timer = millis();
1161
           *timer = millis();
1162
         // If the timer goes too long without a reset, trigger shutdown
1162
         // If the timer goes too long without a reset, trigger shutdown
1163
-        else if (millis() > *timer + period_seconds * 1000UL)
1163
+        else if (ELAPSED(millis(), *timer + period_seconds * 1000UL))
1164
           *state = TRRunaway;
1164
           *state = TRRunaway;
1165
         break;
1165
         break;
1166
       case TRRunaway:
1166
       case TRRunaway:
1232
 
1232
 
1233
     millis_t ms = millis();
1233
     millis_t ms = millis();
1234
 
1234
 
1235
-    if (ms < next_max6675_ms) return (int)max6675_temp;
1235
+    if (PENDING(ms, next_max6675_ms)) return (int)max6675_temp;
1236
 
1236
 
1237
     next_max6675_ms = ms + MAX6675_HEAT_INTERVAL;
1237
     next_max6675_ms = ms + MAX6675_HEAT_INTERVAL;
1238
 
1238
 

+ 2
- 2
Marlin/twibus.cpp View File

77
     SERIAL_EOL;
77
     SERIAL_EOL;
78
   }
78
   }
79
 
79
 
80
-  millis_t t = millis();
80
+  millis_t t = millis() + this->timeout;
81
   Wire.requestFrom(this->addr, bytes);
81
   Wire.requestFrom(this->addr, bytes);
82
 
82
 
83
     // requestFrom() is a blocking function
83
     // requestFrom() is a blocking function
84
   while (Wire.available() < bytes) {
84
   while (Wire.available() < bytes) {
85
-    if (millis() - t >= this->timeout) break;
85
+    if (ELAPSED(millis(), t)) break;
86
     else continue;
86
     else continue;
87
   }
87
   }
88
 
88
 

+ 6
- 6
Marlin/ultralcd.cpp View File

369
   #if ENABLED(LCD_PROGRESS_BAR)
369
   #if ENABLED(LCD_PROGRESS_BAR)
370
     millis_t ms = millis();
370
     millis_t ms = millis();
371
     #if DISABLED(PROGRESS_MSG_ONCE)
371
     #if DISABLED(PROGRESS_MSG_ONCE)
372
-      if (ms > progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
372
+      if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
373
         progress_bar_ms = ms;
373
         progress_bar_ms = ms;
374
       }
374
       }
375
     #endif
375
     #endif
380
           if (card.isFileOpen()) {
380
           if (card.isFileOpen()) {
381
             // Expire the message when printing is active
381
             // Expire the message when printing is active
382
             if (IS_SD_PRINTING) {
382
             if (IS_SD_PRINTING) {
383
-              if (ms >= expire_status_ms) {
383
+              if (ELAPSED(ms, expire_status_ms)) {
384
                 lcd_status_message[0] = '\0';
384
                 lcd_status_message[0] = '\0';
385
                 expire_status_ms = 0;
385
                 expire_status_ms = 0;
386
               }
386
               }
2025
   static uint8_t blink = 0;
2025
   static uint8_t blink = 0;
2026
   static millis_t next_blink_ms = 0;
2026
   static millis_t next_blink_ms = 0;
2027
   millis_t ms = millis();
2027
   millis_t ms = millis();
2028
-  if (ms >= next_blink_ms) {
2028
+  if (ELAPSED(ms, next_blink_ms)) {
2029
     blink ^= 0xFF;
2029
     blink ^= 0xFF;
2030
     next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
2030
     next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
2031
   }
2031
   }
2094
   #endif //SDSUPPORT && SD_DETECT_PIN
2094
   #endif //SDSUPPORT && SD_DETECT_PIN
2095
 
2095
 
2096
   millis_t ms = millis();
2096
   millis_t ms = millis();
2097
-  if (ms > next_lcd_update_ms) {
2097
+  if (ELAPSED(ms, next_lcd_update_ms)) {
2098
 
2098
 
2099
     #if ENABLED(LCD_HAS_SLOW_BUTTONS)
2099
     #if ENABLED(LCD_HAS_SLOW_BUTTONS)
2100
       slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
2100
       slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
2343
         millis_t now = millis();
2343
         millis_t now = millis();
2344
       #endif
2344
       #endif
2345
       #if ENABLED(RIGIDBOT_PANEL)
2345
       #if ENABLED(RIGIDBOT_PANEL)
2346
-        if (now > next_button_update_ms) {
2346
+        if (ELAPSED(now, next_button_update_ms)) {
2347
           if (BUTTON_PRESSED(UP)) {
2347
           if (BUTTON_PRESSED(UP)) {
2348
             encoderDiff = -1 * (ENCODER_STEPS_PER_MENU_ITEM);
2348
             encoderDiff = -1 * (ENCODER_STEPS_PER_MENU_ITEM);
2349
             next_button_update_ms = now + 300;
2349
             next_button_update_ms = now + 300;
2363
         }
2363
         }
2364
       #endif
2364
       #endif
2365
       #if BUTTON_EXISTS(ENC)
2365
       #if BUTTON_EXISTS(ENC)
2366
-        if (now > next_button_update_ms && BUTTON_PRESSED(ENC)) newbutton |= EN_C;
2366
+        if (ELAPSED(now, next_button_update_ms) && BUTTON_PRESSED(ENC)) newbutton |= EN_C;
2367
       #endif
2367
       #endif
2368
       buttons = newbutton;
2368
       buttons = newbutton;
2369
       #if ENABLED(LCD_HAS_SLOW_BUTTONS)
2369
       #if ENABLED(LCD_HAS_SLOW_BUTTONS)

+ 3
- 3
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

741
     if (card.isFileOpen()) {
741
     if (card.isFileOpen()) {
742
       // Draw the progress bar if the message has shown long enough
742
       // Draw the progress bar if the message has shown long enough
743
       // or if there is no message set.
743
       // or if there is no message set.
744
-      if (millis() >= progress_bar_ms + PROGRESS_BAR_MSG_TIME || !lcd_status_message[0]) {
744
+      if (ELAPSED(millis(), progress_bar_ms + PROGRESS_BAR_MSG_TIME) || !lcd_status_message[0]) {
745
         int tix = (int)(card.percentDone() * (LCD_WIDTH) * 3) / 100,
745
         int tix = (int)(card.percentDone() * (LCD_WIDTH) * 3) / 100,
746
           cel = tix / 3, rem = tix % 3, i = LCD_WIDTH;
746
           cel = tix / 3, rem = tix % 3, i = LCD_WIDTH;
747
         char msg[LCD_WIDTH + 1], b = ' ';
747
         char msg[LCD_WIDTH + 1], b = ' ';
762
 
762
 
763
     // Show Filament Diameter and Volumetric Multiplier %
763
     // Show Filament Diameter and Volumetric Multiplier %
764
     // After allowing lcd_status_message to show for 5 seconds
764
     // After allowing lcd_status_message to show for 5 seconds
765
-    if (millis() >= previous_lcd_status_ms + 5000) {
765
+    if (ELAPSED(millis(), previous_lcd_status_ms + 5000)) {
766
       lcd_printPGM(PSTR("Dia "));
766
       lcd_printPGM(PSTR("Dia "));
767
       lcd.print(ftostr12ns(filament_width_meas));
767
       lcd.print(ftostr12ns(filament_width_meas));
768
       lcd_printPGM(PSTR(" V"));
768
       lcd_printPGM(PSTR(" V"));
930
       // so they are called during normal lcd_update
930
       // so they are called during normal lcd_update
931
       uint8_t slow_bits = lcd.readButtons() << B_I2C_BTN_OFFSET;
931
       uint8_t slow_bits = lcd.readButtons() << B_I2C_BTN_OFFSET;
932
       #if ENABLED(LCD_I2C_VIKI)
932
       #if ENABLED(LCD_I2C_VIKI)
933
-        if ((slow_bits & (B_MI | B_RI)) && millis() < next_button_update_ms) // LCD clicked
933
+        if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms)) // LCD clicked
934
           slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
934
           slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
935
       #endif // LCD_I2C_VIKI
935
       #endif // LCD_I2C_VIKI
936
       return slow_bits;
936
       return slow_bits;

Loading…
Cancel
Save