Add millis helper macros
This commit is contained in:
parent
723d4d6f61
commit
0e06aaa2bc
|
@ -227,7 +227,7 @@ bool wait_for_heatup = true;
|
|||
|
||||
// Inactivity shutdown
|
||||
millis_t max_inactive_time, // = 0
|
||||
stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL;
|
||||
stepper_inactive_time = SEC_TO_MS(DEFAULT_STEPPER_DEACTIVE_TIME);
|
||||
|
||||
#if PIN_EXISTS(CHDK)
|
||||
extern millis_t chdk_timeout;
|
||||
|
@ -543,7 +543,7 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
|
|||
|
||||
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
|
||||
if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP
|
||||
&& ELAPSED(ms, gcode.previous_move_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL)
|
||||
&& ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))
|
||||
&& !planner.has_blocks_queued()
|
||||
) {
|
||||
#if ENABLED(SWITCHING_EXTRUDER)
|
||||
|
|
|
@ -25,5 +25,9 @@
|
|||
|
||||
typedef uint32_t millis_t;
|
||||
|
||||
#define SEC_TO_MS(N) millis_t((N)*1000UL)
|
||||
#define MIN_TO_MS(N) SEC_TO_MS((N)*60UL)
|
||||
#define MS_TO_SEC(N) millis_t((N)/1000UL)
|
||||
|
||||
#define PENDING(NOW,SOON) ((int32_t)(NOW-(SOON))<0)
|
||||
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
|
||||
|
|
|
@ -91,7 +91,7 @@ void ControllerFan::update() {
|
|||
// - If AutoMode is on and steppers have been enabled for CONTROLLERFAN_IDLE_TIME seconds.
|
||||
// - If System is on idle and idle fan speed settings is activated.
|
||||
set_fan_speed(
|
||||
settings.auto_mode && lastMotorOn && PENDING(ms, lastMotorOn + settings.duration * 1000UL)
|
||||
settings.auto_mode && lastMotorOn && PENDING(ms, lastMotorOn + SEC_TO_MS(settings.duration))
|
||||
? settings.active_speed : settings.idle_speed
|
||||
);
|
||||
|
||||
|
|
|
@ -485,7 +485,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
|
|||
#endif
|
||||
|
||||
// Start the heater idle timers
|
||||
const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
|
||||
const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
|
||||
|
||||
HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
|
||||
|
||||
|
@ -549,7 +549,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
|
|||
show_continue_prompt(is_reload);
|
||||
|
||||
// Start the heater idle timers
|
||||
const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
|
||||
const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
|
||||
|
||||
HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
|
||||
#if ENABLED(HOST_PROMPT_SUPPORT)
|
||||
|
|
|
@ -98,7 +98,7 @@ void Power::check() {
|
|||
nextPowerCheck = ms + 2500UL;
|
||||
if (is_power_needed())
|
||||
power_on();
|
||||
else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + (POWER_TIMEOUT) * 1000UL))
|
||||
else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT)))
|
||||
power_off();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ void GcodeSuite::G76() {
|
|||
do_blocking_move_to(parkpos);
|
||||
|
||||
// Wait for heatbed to reach target temp and probe to cool below target temp
|
||||
if (wait_for_temps(target_bed, target_probe, next_temp_report, millis() + 900UL * 1000UL)) {
|
||||
if (wait_for_temps(target_bed, target_probe, next_temp_report, millis() + MIN_TO_MS(15))) {
|
||||
SERIAL_ECHOLNPGM("!Bed heating timeout.");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -988,7 +988,7 @@ void GcodeSuite::process_subcommands_now(char * gcode) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
next_busy_signal_ms = ms + host_keepalive_interval * 1000UL;
|
||||
next_busy_signal_ms = ms + SEC_TO_MS(host_keepalive_interval);
|
||||
}
|
||||
|
||||
#endif // HOST_KEEPALIVE_FEATURE
|
||||
|
|
|
@ -106,8 +106,7 @@ void Stopwatch::reset() {
|
|||
}
|
||||
|
||||
millis_t Stopwatch::duration() {
|
||||
return ((isRunning() ? millis() : stopTimestamp)
|
||||
- startTimestamp) / 1000UL + accumulator;
|
||||
return accumulator + MS_TO_SEC((isRunning() ? millis() : stopTimestamp) - startTimestamp);
|
||||
}
|
||||
|
||||
#if ENABLED(DEBUG_STOPWATCH)
|
||||
|
|
|
@ -399,7 +399,7 @@ volatile bool Temperature::raw_temps_ready = false;
|
|||
const uint16_t watch_temp_period = GTV(WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD);
|
||||
const uint8_t watch_temp_increase = GTV(WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE);
|
||||
const float watch_temp_target = target - float(watch_temp_increase + GTV(TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1);
|
||||
millis_t temp_change_ms = next_temp_ms + watch_temp_period * 1000UL;
|
||||
millis_t temp_change_ms = next_temp_ms + SEC_TO_MS(watch_temp_period);
|
||||
float next_watch_temp = 0.0;
|
||||
bool heated = false;
|
||||
#endif
|
||||
|
@ -546,7 +546,7 @@ volatile bool Temperature::raw_temps_ready = false;
|
|||
if (!heated) { // If not yet reached target...
|
||||
if (current_temp > next_watch_temp) { // Over the watch temp?
|
||||
next_watch_temp = current_temp + watch_temp_increase; // - set the next temp to watch for
|
||||
temp_change_ms = ms + watch_temp_period * 1000UL; // - move the expiration timer up
|
||||
temp_change_ms = ms + SEC_TO_MS(watch_temp_period); // - move the expiration timer up
|
||||
if (current_temp > watch_temp_target) heated = true; // - Flag if target temperature reached
|
||||
}
|
||||
else if (ELAPSED(ms, temp_change_ms)) // Watch timer expired
|
||||
|
@ -2051,7 +2051,7 @@ void Temperature::init() {
|
|||
#endif
|
||||
|
||||
if (current >= tr_target_temperature[heater_index] - hysteresis_degc) {
|
||||
sm.timer = millis() + period_seconds * 1000UL;
|
||||
sm.timer = millis() + SEC_TO_MS(period_seconds);
|
||||
break;
|
||||
}
|
||||
else if (PENDING(millis(), sm.timer)) break;
|
||||
|
@ -3124,7 +3124,7 @@ void Temperature::tick() {
|
|||
millis_t residency_start_ms = 0;
|
||||
bool first_loop = true;
|
||||
// Loop until the temperature has stabilized
|
||||
#define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
|
||||
#define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + SEC_TO_MS(TEMP_RESIDENCY_TIME)))
|
||||
#else
|
||||
// Loop until the temperature is very close target
|
||||
#define TEMP_CONDITIONS (wants_to_cool ? isCoolingHotend(target_extruder) : isHeatingHotend(target_extruder))
|
||||
|
@ -3160,7 +3160,7 @@ void Temperature::tick() {
|
|||
#if TEMP_RESIDENCY_TIME > 0
|
||||
SERIAL_ECHOPGM(" W:");
|
||||
if (residency_start_ms)
|
||||
SERIAL_ECHO(long((((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
|
||||
SERIAL_ECHO(long((SEC_TO_MS(TEMP_RESIDENCY_TIME) - (now - residency_start_ms)) / 1000UL));
|
||||
else
|
||||
SERIAL_CHAR('?');
|
||||
#endif
|
||||
|
@ -3185,7 +3185,7 @@ void Temperature::tick() {
|
|||
// Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
|
||||
if (temp_diff < TEMP_WINDOW) {
|
||||
residency_start_ms = now;
|
||||
if (first_loop) residency_start_ms += (TEMP_RESIDENCY_TIME) * 1000UL;
|
||||
if (first_loop) residency_start_ms += SEC_TO_MS(TEMP_RESIDENCY_TIME);
|
||||
}
|
||||
}
|
||||
else if (temp_diff > TEMP_HYSTERESIS) {
|
||||
|
@ -3247,7 +3247,7 @@ void Temperature::tick() {
|
|||
millis_t residency_start_ms = 0;
|
||||
bool first_loop = true;
|
||||
// Loop until the temperature has stabilized
|
||||
#define TEMP_BED_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_BED_RESIDENCY_TIME) * 1000UL))
|
||||
#define TEMP_BED_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + SEC_TO_MS(TEMP_BED_RESIDENCY_TIME)))
|
||||
#else
|
||||
// Loop until the temperature is very close target
|
||||
#define TEMP_BED_CONDITIONS (wants_to_cool ? isCoolingBed() : isHeatingBed())
|
||||
|
@ -3284,7 +3284,7 @@ void Temperature::tick() {
|
|||
#if TEMP_BED_RESIDENCY_TIME > 0
|
||||
SERIAL_ECHOPGM(" W:");
|
||||
if (residency_start_ms)
|
||||
SERIAL_ECHO(long((((TEMP_BED_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
|
||||
SERIAL_ECHO(long((SEC_TO_MS(TEMP_BED_RESIDENCY_TIME) - (now - residency_start_ms)) / 1000UL));
|
||||
else
|
||||
SERIAL_CHAR('?');
|
||||
#endif
|
||||
|
@ -3309,7 +3309,7 @@ void Temperature::tick() {
|
|||
// Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
|
||||
if (temp_diff < TEMP_BED_WINDOW) {
|
||||
residency_start_ms = now;
|
||||
if (first_loop) residency_start_ms += (TEMP_BED_RESIDENCY_TIME) * 1000UL;
|
||||
if (first_loop) residency_start_ms += SEC_TO_MS(TEMP_BED_RESIDENCY_TIME);
|
||||
}
|
||||
}
|
||||
else if (temp_diff > TEMP_BED_HYSTERESIS) {
|
||||
|
@ -3373,7 +3373,7 @@ void Temperature::tick() {
|
|||
millis_t residency_start_ms = 0;
|
||||
bool first_loop = true;
|
||||
// Loop until the temperature has stabilized
|
||||
#define TEMP_CHAMBER_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_CHAMBER_RESIDENCY_TIME) * 1000UL))
|
||||
#define TEMP_CHAMBER_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + SEC_TO_MS(TEMP_CHAMBER_RESIDENCY_TIME)))
|
||||
#else
|
||||
// Loop until the temperature is very close target
|
||||
#define TEMP_CHAMBER_CONDITIONS (wants_to_cool ? isCoolingChamber() : isHeatingChamber())
|
||||
|
@ -3405,7 +3405,7 @@ void Temperature::tick() {
|
|||
#if TEMP_CHAMBER_RESIDENCY_TIME > 0
|
||||
SERIAL_ECHOPGM(" W:");
|
||||
if (residency_start_ms)
|
||||
SERIAL_ECHO(long((((TEMP_CHAMBER_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
|
||||
SERIAL_ECHO(long((SEC_TO_MS(TEMP_CHAMBER_RESIDENCY_TIME) - (now - residency_start_ms)) / 1000UL));
|
||||
else
|
||||
SERIAL_CHAR('?');
|
||||
#endif
|
||||
|
@ -3425,7 +3425,7 @@ void Temperature::tick() {
|
|||
// Start the TEMP_CHAMBER_RESIDENCY_TIME timer when we reach target temp for the first time.
|
||||
if (temp_diff < TEMP_CHAMBER_WINDOW) {
|
||||
residency_start_ms = now;
|
||||
if (first_loop) residency_start_ms += (TEMP_CHAMBER_RESIDENCY_TIME) * 1000UL;
|
||||
if (first_loop) residency_start_ms += SEC_TO_MS(TEMP_CHAMBER_RESIDENCY_TIME);
|
||||
}
|
||||
}
|
||||
else if (temp_diff > TEMP_CHAMBER_HYSTERESIS) {
|
||||
|
|
|
@ -241,7 +241,7 @@ struct HeaterWatch {
|
|||
const int16_t newtarget = curr + INCREASE;
|
||||
if (newtarget < tgt - HYSTERESIS - 1) {
|
||||
target = newtarget;
|
||||
next_ms = millis() + PERIOD * 1000UL;
|
||||
next_ms = millis() + SEC_TO_MS(PERIOD);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue