Browse Source

Add millis helper macros

Scott Lahteine 4 years ago
parent
commit
0e06aaa2bc

+ 2
- 2
Marlin/src/MarlinCore.cpp View File

@@ -227,7 +227,7 @@ bool wait_for_heatup = true;
227 227
 
228 228
 // Inactivity shutdown
229 229
 millis_t max_inactive_time, // = 0
230
-         stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL;
230
+         stepper_inactive_time = SEC_TO_MS(DEFAULT_STEPPER_DEACTIVE_TIME);
231 231
 
232 232
 #if PIN_EXISTS(CHDK)
233 233
   extern millis_t chdk_timeout;
@@ -543,7 +543,7 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
543 543
 
544 544
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
545 545
     if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP
546
-      && ELAPSED(ms, gcode.previous_move_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL)
546
+      && ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))
547 547
       && !planner.has_blocks_queued()
548 548
     ) {
549 549
       #if ENABLED(SWITCHING_EXTRUDER)

+ 4
- 0
Marlin/src/core/millis_t.h View File

@@ -25,5 +25,9 @@
25 25
 
26 26
 typedef uint32_t millis_t;
27 27
 
28
+#define SEC_TO_MS(N) millis_t((N)*1000UL)
29
+#define MIN_TO_MS(N) SEC_TO_MS((N)*60UL)
30
+#define MS_TO_SEC(N) millis_t((N)/1000UL)
31
+
28 32
 #define PENDING(NOW,SOON) ((int32_t)(NOW-(SOON))<0)
29 33
 #define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))

+ 1
- 1
Marlin/src/feature/controllerfan.cpp View File

@@ -91,7 +91,7 @@ void ControllerFan::update() {
91 91
     //  - If AutoMode is on and steppers have been enabled for CONTROLLERFAN_IDLE_TIME seconds.
92 92
     //  - If System is on idle and idle fan speed settings is activated.
93 93
     set_fan_speed(
94
-      settings.auto_mode && lastMotorOn && PENDING(ms, lastMotorOn + settings.duration * 1000UL)
94
+      settings.auto_mode && lastMotorOn && PENDING(ms, lastMotorOn + SEC_TO_MS(settings.duration))
95 95
       ? settings.active_speed : settings.idle_speed
96 96
     );
97 97
 

+ 2
- 2
Marlin/src/feature/pause.cpp View File

@@ -485,7 +485,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
485 485
   #endif
486 486
 
487 487
   // Start the heater idle timers
488
-  const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
488
+  const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
489 489
 
490 490
   HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
491 491
 
@@ -549,7 +549,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
549 549
       show_continue_prompt(is_reload);
550 550
 
551 551
       // Start the heater idle timers
552
-      const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
552
+      const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
553 553
 
554 554
       HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
555 555
       #if ENABLED(HOST_PROMPT_SUPPORT)

+ 1
- 1
Marlin/src/feature/power.cpp View File

@@ -98,7 +98,7 @@ void Power::check() {
98 98
     nextPowerCheck = ms + 2500UL;
99 99
     if (is_power_needed())
100 100
       power_on();
101
-    else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + (POWER_TIMEOUT) * 1000UL))
101
+    else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT)))
102 102
       power_off();
103 103
   }
104 104
 }

+ 1
- 1
Marlin/src/gcode/calibrate/G76_M871.cpp View File

@@ -182,7 +182,7 @@ void GcodeSuite::G76() {
182 182
       do_blocking_move_to(parkpos);
183 183
 
184 184
       // Wait for heatbed to reach target temp and probe to cool below target temp
185
-      if (wait_for_temps(target_bed, target_probe, next_temp_report, millis() + 900UL * 1000UL)) {
185
+      if (wait_for_temps(target_bed, target_probe, next_temp_report, millis() + MIN_TO_MS(15))) {
186 186
         SERIAL_ECHOLNPGM("!Bed heating timeout.");
187 187
         break;
188 188
       }

+ 1
- 1
Marlin/src/gcode/gcode.cpp View File

@@ -988,7 +988,7 @@ void GcodeSuite::process_subcommands_now(char * gcode) {
988 988
           break;
989 989
       }
990 990
     }
991
-    next_busy_signal_ms = ms + host_keepalive_interval * 1000UL;
991
+    next_busy_signal_ms = ms + SEC_TO_MS(host_keepalive_interval);
992 992
   }
993 993
 
994 994
 #endif // HOST_KEEPALIVE_FEATURE

+ 1
- 2
Marlin/src/libs/stopwatch.cpp View File

@@ -106,8 +106,7 @@ void Stopwatch::reset() {
106 106
 }
107 107
 
108 108
 millis_t Stopwatch::duration() {
109
-  return ((isRunning() ? millis() : stopTimestamp)
110
-          - startTimestamp) / 1000UL + accumulator;
109
+  return accumulator + MS_TO_SEC((isRunning() ? millis() : stopTimestamp) - startTimestamp);
111 110
 }
112 111
 
113 112
 #if ENABLED(DEBUG_STOPWATCH)

+ 12
- 12
Marlin/src/module/temperature.cpp View File

@@ -399,7 +399,7 @@ volatile bool Temperature::raw_temps_ready = false;
399 399
       const uint16_t watch_temp_period = GTV(WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD);
400 400
       const uint8_t watch_temp_increase = GTV(WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE);
401 401
       const float watch_temp_target = target - float(watch_temp_increase + GTV(TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1);
402
-      millis_t temp_change_ms = next_temp_ms + watch_temp_period * 1000UL;
402
+      millis_t temp_change_ms = next_temp_ms + SEC_TO_MS(watch_temp_period);
403 403
       float next_watch_temp = 0.0;
404 404
       bool heated = false;
405 405
     #endif
@@ -546,7 +546,7 @@ volatile bool Temperature::raw_temps_ready = false;
546 546
             if (!heated) {                                            // If not yet reached target...
547 547
               if (current_temp > next_watch_temp) {                   // Over the watch temp?
548 548
                 next_watch_temp = current_temp + watch_temp_increase; // - set the next temp to watch for
549
-                temp_change_ms = ms + watch_temp_period * 1000UL;     // - move the expiration timer up
549
+                temp_change_ms = ms + SEC_TO_MS(watch_temp_period);     // - move the expiration timer up
550 550
                 if (current_temp > watch_temp_target) heated = true;  // - Flag if target temperature reached
551 551
               }
552 552
               else if (ELAPSED(ms, temp_change_ms))                   // Watch timer expired
@@ -2051,7 +2051,7 @@ void Temperature::init() {
2051 2051
         #endif
2052 2052
 
2053 2053
         if (current >= tr_target_temperature[heater_index] - hysteresis_degc) {
2054
-          sm.timer = millis() + period_seconds * 1000UL;
2054
+          sm.timer = millis() + SEC_TO_MS(period_seconds);
2055 2055
           break;
2056 2056
         }
2057 2057
         else if (PENDING(millis(), sm.timer)) break;
@@ -3124,7 +3124,7 @@ void Temperature::tick() {
3124 3124
         millis_t residency_start_ms = 0;
3125 3125
         bool first_loop = true;
3126 3126
         // Loop until the temperature has stabilized
3127
-        #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
3127
+        #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + SEC_TO_MS(TEMP_RESIDENCY_TIME)))
3128 3128
       #else
3129 3129
         // Loop until the temperature is very close target
3130 3130
         #define TEMP_CONDITIONS (wants_to_cool ? isCoolingHotend(target_extruder) : isHeatingHotend(target_extruder))
@@ -3160,7 +3160,7 @@ void Temperature::tick() {
3160 3160
           #if TEMP_RESIDENCY_TIME > 0
3161 3161
             SERIAL_ECHOPGM(" W:");
3162 3162
             if (residency_start_ms)
3163
-              SERIAL_ECHO(long((((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
3163
+              SERIAL_ECHO(long((SEC_TO_MS(TEMP_RESIDENCY_TIME) - (now - residency_start_ms)) / 1000UL));
3164 3164
             else
3165 3165
               SERIAL_CHAR('?');
3166 3166
           #endif
@@ -3185,7 +3185,7 @@ void Temperature::tick() {
3185 3185
             // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
3186 3186
             if (temp_diff < TEMP_WINDOW) {
3187 3187
               residency_start_ms = now;
3188
-              if (first_loop) residency_start_ms += (TEMP_RESIDENCY_TIME) * 1000UL;
3188
+              if (first_loop) residency_start_ms += SEC_TO_MS(TEMP_RESIDENCY_TIME);
3189 3189
             }
3190 3190
           }
3191 3191
           else if (temp_diff > TEMP_HYSTERESIS) {
@@ -3247,7 +3247,7 @@ void Temperature::tick() {
3247 3247
         millis_t residency_start_ms = 0;
3248 3248
         bool first_loop = true;
3249 3249
         // Loop until the temperature has stabilized
3250
-        #define TEMP_BED_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_BED_RESIDENCY_TIME) * 1000UL))
3250
+        #define TEMP_BED_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + SEC_TO_MS(TEMP_BED_RESIDENCY_TIME)))
3251 3251
       #else
3252 3252
         // Loop until the temperature is very close target
3253 3253
         #define TEMP_BED_CONDITIONS (wants_to_cool ? isCoolingBed() : isHeatingBed())
@@ -3284,7 +3284,7 @@ void Temperature::tick() {
3284 3284
           #if TEMP_BED_RESIDENCY_TIME > 0
3285 3285
             SERIAL_ECHOPGM(" W:");
3286 3286
             if (residency_start_ms)
3287
-              SERIAL_ECHO(long((((TEMP_BED_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
3287
+              SERIAL_ECHO(long((SEC_TO_MS(TEMP_BED_RESIDENCY_TIME) - (now - residency_start_ms)) / 1000UL));
3288 3288
             else
3289 3289
               SERIAL_CHAR('?');
3290 3290
           #endif
@@ -3309,7 +3309,7 @@ void Temperature::tick() {
3309 3309
             // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
3310 3310
             if (temp_diff < TEMP_BED_WINDOW) {
3311 3311
               residency_start_ms = now;
3312
-              if (first_loop) residency_start_ms += (TEMP_BED_RESIDENCY_TIME) * 1000UL;
3312
+              if (first_loop) residency_start_ms += SEC_TO_MS(TEMP_BED_RESIDENCY_TIME);
3313 3313
             }
3314 3314
           }
3315 3315
           else if (temp_diff > TEMP_BED_HYSTERESIS) {
@@ -3373,7 +3373,7 @@ void Temperature::tick() {
3373 3373
         millis_t residency_start_ms = 0;
3374 3374
         bool first_loop = true;
3375 3375
         // Loop until the temperature has stabilized
3376
-        #define TEMP_CHAMBER_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_CHAMBER_RESIDENCY_TIME) * 1000UL))
3376
+        #define TEMP_CHAMBER_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + SEC_TO_MS(TEMP_CHAMBER_RESIDENCY_TIME)))
3377 3377
       #else
3378 3378
         // Loop until the temperature is very close target
3379 3379
         #define TEMP_CHAMBER_CONDITIONS (wants_to_cool ? isCoolingChamber() : isHeatingChamber())
@@ -3405,7 +3405,7 @@ void Temperature::tick() {
3405 3405
           #if TEMP_CHAMBER_RESIDENCY_TIME > 0
3406 3406
             SERIAL_ECHOPGM(" W:");
3407 3407
             if (residency_start_ms)
3408
-              SERIAL_ECHO(long((((TEMP_CHAMBER_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
3408
+              SERIAL_ECHO(long((SEC_TO_MS(TEMP_CHAMBER_RESIDENCY_TIME) - (now - residency_start_ms)) / 1000UL));
3409 3409
             else
3410 3410
               SERIAL_CHAR('?');
3411 3411
           #endif
@@ -3425,7 +3425,7 @@ void Temperature::tick() {
3425 3425
             // Start the TEMP_CHAMBER_RESIDENCY_TIME timer when we reach target temp for the first time.
3426 3426
             if (temp_diff < TEMP_CHAMBER_WINDOW) {
3427 3427
               residency_start_ms = now;
3428
-              if (first_loop) residency_start_ms += (TEMP_CHAMBER_RESIDENCY_TIME) * 1000UL;
3428
+              if (first_loop) residency_start_ms += SEC_TO_MS(TEMP_CHAMBER_RESIDENCY_TIME);
3429 3429
             }
3430 3430
           }
3431 3431
           else if (temp_diff > TEMP_CHAMBER_HYSTERESIS) {

+ 1
- 1
Marlin/src/module/temperature.h View File

@@ -241,7 +241,7 @@ struct HeaterWatch {
241 241
       const int16_t newtarget = curr + INCREASE;
242 242
       if (newtarget < tgt - HYSTERESIS - 1) {
243 243
         target = newtarget;
244
-        next_ms = millis() + PERIOD * 1000UL;
244
+        next_ms = millis() + SEC_TO_MS(PERIOD);
245 245
         return;
246 246
       }
247 247
     }

Loading…
Cancel
Save