Pārlūkot izejas kodu

Merge pull request #3453 from thinkyhead/rc_jbrazio_m190

ELAPSED / PENDING for rollover-safe time checking
Scott Lahteine 8 gadus atpakaļ
vecāks
revīzija
02550af7c3

+ 30
- 30
Marlin/Marlin_main.cpp Parādīt failu

@@ -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();

+ 1
- 1
Marlin/cardreader.cpp Parādīt failu

@@ -508,7 +508,7 @@ void CardReader::write_command(char *buf) {
508 508
 }
509 509
 
510 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 512
     return;
513 513
 
514 514
   autostart_stilltocheck = false;

+ 1
- 1
Marlin/dogm_lcd_implementation.h Parādīt failu

@@ -459,7 +459,7 @@ static void lcd_implementation_status_screen() {
459 459
   #if DISABLED(FILAMENT_LCD_DISPLAY)
460 460
     lcd_print(lcd_status_message);
461 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 463
       lcd_print(lcd_status_message);
464 464
     }
465 465
     else {

+ 3
- 0
Marlin/macros.h Parādīt failu

@@ -57,4 +57,7 @@
57 57
 
58 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 63
 #endif //__MACROS_H

+ 1
- 1
Marlin/planner.cpp Parādīt failu

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

+ 13
- 13
Marlin/temperature.cpp Parādīt failu

@@ -235,7 +235,7 @@ void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false
235 235
   float max = 0, min = 10000;
236 236
 
237 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 239
   #endif
240 240
 
241 241
   if (extruder >= EXTRUDERS
@@ -270,14 +270,14 @@ void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false
270 270
       min = min(min, input);
271 271
 
272 272
       #if HAS_AUTO_FAN
273
-        if (ms > next_auto_fan_check_ms) {
273
+        if (ELAPSED(ms, next_auto_fan_check_ms)) {
274 274
           checkExtruderAutoFans();
275
-          next_auto_fan_check_ms = ms + 2500;
275
+          next_auto_fan_check_ms = ms + 2500UL;
276 276
         }
277 277
       #endif
278 278
 
279 279
       if (heating && input > temp) {
280
-        if (ms > t2 + 5000) {
280
+        if (ELAPSED(ms, t2 + 5000UL)) {
281 281
           heating = false;
282 282
           if (extruder < 0)
283 283
             soft_pwm_bed = (bias - d) >> 1;
@@ -290,7 +290,7 @@ void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false
290 290
       }
291 291
 
292 292
       if (!heating && input < temp) {
293
-        if (ms > t1 + 5000) {
293
+        if (ELAPSED(ms, t1 + 5000UL)) {
294 294
           heating = true;
295 295
           t2 = ms;
296 296
           t_low = t2 - t1;
@@ -349,7 +349,7 @@ void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false
349 349
       return;
350 350
     }
351 351
     // Every 2 seconds...
352
-    if (ms > temp_ms + 2000) {
352
+    if (ELAPSED(ms, temp_ms + 2000UL)) {
353 353
       #if HAS_TEMP_HOTEND || HAS_TEMP_BED
354 354
         print_heaterstates();
355 355
         SERIAL_EOL;
@@ -673,7 +673,7 @@ void manage_heater() {
673 673
     #if ENABLED(THERMAL_PROTECTION_HOTENDS)
674 674
 
675 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 677
         // Has it failed to increase enough?
678 678
         if (degHotend(e) < watch_target_temp[e]) {
679 679
           // Stop!
@@ -696,9 +696,9 @@ void manage_heater() {
696 696
   } // Extruders Loop
697 697
 
698 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 700
       checkExtruderAutoFans();
701
-      next_auto_fan_check_ms = ms + 2500;
701
+      next_auto_fan_check_ms = ms + 2500UL;
702 702
     }
703 703
   #endif
704 704
 
@@ -718,7 +718,7 @@ void manage_heater() {
718 718
   #endif //FILAMENT_WIDTH_SENSOR
719 719
 
720 720
   #if DISABLED(PIDTEMPBED)
721
-    if (ms < next_bed_check_ms) return;
721
+    if (PENDING(ms, next_bed_check_ms)) return;
722 722
     next_bed_check_ms = ms + BED_CHECK_INTERVAL;
723 723
   #endif
724 724
 
@@ -1105,7 +1105,7 @@ void tp_init() {
1105 1105
   void start_watching_heater(int e) {
1106 1106
     if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1107 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 1110
     else
1111 1111
       watch_heater_next_ms[e] = 0;
@@ -1160,7 +1160,7 @@ void tp_init() {
1160 1160
         if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc)
1161 1161
           *timer = millis();
1162 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 1164
           *state = TRRunaway;
1165 1165
         break;
1166 1166
       case TRRunaway:
@@ -1232,7 +1232,7 @@ void disable_all_heaters() {
1232 1232
 
1233 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 1237
     next_max6675_ms = ms + MAX6675_HEAT_INTERVAL;
1238 1238
 

+ 2
- 2
Marlin/twibus.cpp Parādīt failu

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

+ 6
- 6
Marlin/ultralcd.cpp Parādīt failu

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

+ 3
- 3
Marlin/ultralcd_implementation_hitachi_HD44780.h Parādīt failu

@@ -741,7 +741,7 @@ static void lcd_implementation_status_screen() {
741 741
     if (card.isFileOpen()) {
742 742
       // Draw the progress bar if the message has shown long enough
743 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 745
         int tix = (int)(card.percentDone() * (LCD_WIDTH) * 3) / 100,
746 746
           cel = tix / 3, rem = tix % 3, i = LCD_WIDTH;
747 747
         char msg[LCD_WIDTH + 1], b = ' ';
@@ -762,7 +762,7 @@ static void lcd_implementation_status_screen() {
762 762
 
763 763
     // Show Filament Diameter and Volumetric Multiplier %
764 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 766
       lcd_printPGM(PSTR("Dia "));
767 767
       lcd.print(ftostr12ns(filament_width_meas));
768 768
       lcd_printPGM(PSTR(" V"));
@@ -930,7 +930,7 @@ void lcd_implementation_drawedit(const char* pstr, const char* value) {
930 930
       // so they are called during normal lcd_update
931 931
       uint8_t slow_bits = lcd.readButtons() << B_I2C_BTN_OFFSET;
932 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 934
           slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
935 935
       #endif // LCD_I2C_VIKI
936 936
       return slow_bits;

Notiek ielāde…
Atcelt
Saglabāt