Browse Source

Add millis helper macros

Scott Lahteine 4 years ago
parent
commit
0e06aaa2bc

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

227
 
227
 
228
 // Inactivity shutdown
228
 // Inactivity shutdown
229
 millis_t max_inactive_time, // = 0
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
 #if PIN_EXISTS(CHDK)
232
 #if PIN_EXISTS(CHDK)
233
   extern millis_t chdk_timeout;
233
   extern millis_t chdk_timeout;
543
 
543
 
544
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
544
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
545
     if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP
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
       && !planner.has_blocks_queued()
547
       && !planner.has_blocks_queued()
548
     ) {
548
     ) {
549
       #if ENABLED(SWITCHING_EXTRUDER)
549
       #if ENABLED(SWITCHING_EXTRUDER)

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

25
 
25
 
26
 typedef uint32_t millis_t;
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
 #define PENDING(NOW,SOON) ((int32_t)(NOW-(SOON))<0)
32
 #define PENDING(NOW,SOON) ((int32_t)(NOW-(SOON))<0)
29
 #define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
33
 #define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))

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

91
     //  - If AutoMode is on and steppers have been enabled for CONTROLLERFAN_IDLE_TIME seconds.
91
     //  - If AutoMode is on and steppers have been enabled for CONTROLLERFAN_IDLE_TIME seconds.
92
     //  - If System is on idle and idle fan speed settings is activated.
92
     //  - If System is on idle and idle fan speed settings is activated.
93
     set_fan_speed(
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
       ? settings.active_speed : settings.idle_speed
95
       ? settings.active_speed : settings.idle_speed
96
     );
96
     );
97
 
97
 

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

485
   #endif
485
   #endif
486
 
486
 
487
   // Start the heater idle timers
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
   HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
490
   HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
491
 
491
 
549
       show_continue_prompt(is_reload);
549
       show_continue_prompt(is_reload);
550
 
550
 
551
       // Start the heater idle timers
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
       HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
554
       HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
555
       #if ENABLED(HOST_PROMPT_SUPPORT)
555
       #if ENABLED(HOST_PROMPT_SUPPORT)

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

98
     nextPowerCheck = ms + 2500UL;
98
     nextPowerCheck = ms + 2500UL;
99
     if (is_power_needed())
99
     if (is_power_needed())
100
       power_on();
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
       power_off();
102
       power_off();
103
   }
103
   }
104
 }
104
 }

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

182
       do_blocking_move_to(parkpos);
182
       do_blocking_move_to(parkpos);
183
 
183
 
184
       // Wait for heatbed to reach target temp and probe to cool below target temp
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
         SERIAL_ECHOLNPGM("!Bed heating timeout.");
186
         SERIAL_ECHOLNPGM("!Bed heating timeout.");
187
         break;
187
         break;
188
       }
188
       }

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

988
           break;
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
 #endif // HOST_KEEPALIVE_FEATURE
994
 #endif // HOST_KEEPALIVE_FEATURE

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

106
 }
106
 }
107
 
107
 
108
 millis_t Stopwatch::duration() {
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
 #if ENABLED(DEBUG_STOPWATCH)
112
 #if ENABLED(DEBUG_STOPWATCH)

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

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

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

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

Loading…
Cancel
Save