♻️ ELAPSED / PENDING (ms, start, duration)
This commit is contained in:
parent
b5068bbc17
commit
c1e8d46d21
16 changed files with 42 additions and 34 deletions
|
|
@ -678,14 +678,14 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
|
|||
TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check());
|
||||
|
||||
#if ANY(PSU_CONTROL, AUTO_POWER_CONTROL) && PIN_EXISTS(PS_ON_EDM)
|
||||
if ( ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE)
|
||||
if ( ELAPSED(ms, powerManager.last_state_change_ms, PS_EDM_RESPONSE)
|
||||
&& (READ(PS_ON_PIN) != READ(PS_ON_EDM_PIN) || TERN0(PSU_OFF_REDUNDANT, extDigitalRead(PS_ON1_PIN) != extDigitalRead(PS_ON1_EDM_PIN)))
|
||||
) kill(GET_TEXT_F(MSG_POWER_EDM_FAULT));
|
||||
#endif
|
||||
|
||||
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
|
||||
if (thermalManager.degHotend(active_extruder) > (EXTRUDER_RUNOUT_MINTEMP)
|
||||
&& ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))
|
||||
&& ELAPSED(ms, gcode.previous_move_ms, SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))
|
||||
&& !planner.has_blocks_queued()
|
||||
) {
|
||||
const int8_t e_stepper = TERN(HAS_SWITCHING_EXTRUDER, active_extruder >> 1, active_extruder);
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ typedef uint32_t millis_t;
|
|||
#define MS_TO_SEC(N) millis_t((N)/1000UL)
|
||||
#define MS_TO_SEC_PRECISE(N) (float(N)/1000.0f)
|
||||
|
||||
#define FUTURE(START,DURA) (millis_t(millis()-(START))<(DURA))
|
||||
#define PAST(START,DURA) (!FUTURE(START,DURA))
|
||||
|
||||
#define PENDING(NOW,SOON) (int32_t((NOW)-(SOON))<0)
|
||||
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
|
||||
constexpr bool _PENDING(const millis_t now, const millis_t when) { return int32_t(when - now) > 0; }
|
||||
constexpr bool _PENDING(const millis_t now, const millis_t start, const millis_t interval) { return (now - start) < interval; }
|
||||
#define PENDING(V...) _PENDING(V)
|
||||
#define ELAPSED(V...) !_PENDING(V)
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ void ControllerFan::update() {
|
|||
* - If System is on idle and idle fan speed settings is activated.
|
||||
*/
|
||||
set_fan_speed(
|
||||
settings.auto_mode && lastComponentOn && PENDING(ms, lastComponentOn + SEC_TO_MS(settings.duration))
|
||||
settings.auto_mode && lastComponentOn && PENDING(ms, lastComponentOn, SEC_TO_MS(settings.duration))
|
||||
? settings.active_speed : settings.idle_speed
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -78,9 +78,9 @@ void EasythreedUI::blinkLED() {
|
|||
prev_blink_interval_ms = blink_interval_ms;
|
||||
blink_start_ms = ms;
|
||||
}
|
||||
if (PENDING(ms, blink_start_ms + blink_interval_ms))
|
||||
if (PENDING(ms, blink_start_ms, blink_interval_ms))
|
||||
WRITE(EASYTHREED_LED_PIN, LOW);
|
||||
else if (PENDING(ms, blink_start_ms + 2 * blink_interval_ms))
|
||||
else if (PENDING(ms, blink_start_ms, 2 * blink_interval_ms))
|
||||
WRITE(EASYTHREED_LED_PIN, HIGH);
|
||||
else
|
||||
blink_start_ms = ms;
|
||||
|
|
@ -107,7 +107,7 @@ void EasythreedUI::loadButton() {
|
|||
break;
|
||||
|
||||
case FS_PRESS:
|
||||
if (ELAPSED(millis(), filament_time + BTN_DEBOUNCE_MS)) { // After a short debounce delay...
|
||||
if (ELAPSED(millis(), filament_time, BTN_DEBOUNCE_MS)) { // After a short debounce delay...
|
||||
if (!READ(BTN_RETRACT) || !READ(BTN_FEED)) { // ...if switch still toggled...
|
||||
thermalManager.setTargetHotend(EXTRUDE_MINTEMP + 10, 0); // Start heating up
|
||||
blink_interval_ms = LED_BLINK_7; // Set the LED to blink fast
|
||||
|
|
@ -175,14 +175,14 @@ void EasythreedUI::printButton() {
|
|||
break;
|
||||
|
||||
case KS_PRESS:
|
||||
if (ELAPSED(ms, key_time + BTN_DEBOUNCE_MS)) // Wait for debounce interval to expire
|
||||
if (ELAPSED(ms, key_time, BTN_DEBOUNCE_MS)) // Wait for debounce interval to expire
|
||||
key_status = READ(BTN_PRINT) ? KS_IDLE : KS_PROCEED; // Proceed if still pressed
|
||||
break;
|
||||
|
||||
case KS_PROCEED:
|
||||
if (!READ(BTN_PRINT)) break; // Wait for the button to be released
|
||||
key_status = KS_IDLE; // Ready for the next press
|
||||
if (PENDING(ms, key_time + 1200 - BTN_DEBOUNCE_MS)) { // Register a press < 1.2 seconds
|
||||
if (PENDING(ms, key_time, 1200 - BTN_DEBOUNCE_MS)) { // Register a press < 1.2 seconds
|
||||
switch (print_key_flag) {
|
||||
case PF_START: { // The "Print" button starts an SD card print
|
||||
if (printingIsActive()) break; // Already printing? (find another line that checks for 'is planner doing anything else right now?')
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@
|
|||
if (mode == ACCUMULATE_TOTAL) return;
|
||||
|
||||
// update time_fraction every hundred milliseconds
|
||||
if (instance_count == 0 && ELAPSED(now, last_calc_time + 100000)) {
|
||||
if (instance_count == 0 && now - last_calc_time > 100000) {
|
||||
time_fraction = total_time * 128 / (now - last_calc_time);
|
||||
last_calc_time = now;
|
||||
total_time = 0;
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ void MMU2::mmu_loop() {
|
|||
MMU2_SEND("S1"); // Read Version
|
||||
state = -2;
|
||||
}
|
||||
else if (ELAPSED(millis(), prev_request + 30000)) { // 30sec after reset disable MMU
|
||||
else if (ELAPSED(millis(), prev_request, 30000)) { // 30sec after reset disable MMU
|
||||
SERIAL_ECHOLNPGM("MMU not responding - DISABLED");
|
||||
state = 0;
|
||||
}
|
||||
|
|
@ -276,7 +276,7 @@ void MMU2::mmu_loop() {
|
|||
last_cmd = cmd;
|
||||
cmd = MMU_CMD_NONE;
|
||||
}
|
||||
else if (ELAPSED(millis(), prev_P0_request + 300)) {
|
||||
else if (ELAPSED(millis(), prev_P0_request, 300)) {
|
||||
MMU2_SEND("P0"); // Read FINDA
|
||||
state = 2; // wait for response
|
||||
}
|
||||
|
|
@ -296,7 +296,7 @@ void MMU2::mmu_loop() {
|
|||
if (cmd == MMU_CMD_NONE) ready = true;
|
||||
state = 1;
|
||||
}
|
||||
else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
|
||||
else if (ELAPSED(millis(), prev_request, MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
|
||||
state = 1;
|
||||
|
||||
TERN_(HAS_PRUSA_MMU2S, check_filament());
|
||||
|
|
@ -335,7 +335,7 @@ void MMU2::mmu_loop() {
|
|||
last_cmd = MMU_CMD_NONE;
|
||||
}
|
||||
}
|
||||
else if (ELAPSED(millis(), prev_request + MMU_CMD_TIMEOUT)) {
|
||||
else if (ELAPSED(millis(), prev_request, MMU_CMD_TIMEOUT)) {
|
||||
// resend request after timeout
|
||||
if (last_cmd) {
|
||||
DEBUG_ECHOLNPGM("MMU retry");
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ void Power::power_off() {
|
|||
nextPowerCheck = now + 2500UL;
|
||||
if (is_power_needed())
|
||||
power_on();
|
||||
else if (!lastPowerOn || (POWER_TIMEOUT > 0 && ELAPSED(now, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT))))
|
||||
else if (!lastPowerOn || (POWER_TIMEOUT > 0 && ELAPSED(now, lastPowerOn, SEC_TO_MS(POWER_TIMEOUT))))
|
||||
power_off();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -246,8 +246,8 @@ void GcodeSuite::get_destination_from_command() {
|
|||
* Dwell waits immediately. It does not synchronize.
|
||||
*/
|
||||
void GcodeSuite::dwell(const millis_t time) {
|
||||
const millis_t startMillis = millis();
|
||||
while (FUTURE(startMillis, time)) idle();
|
||||
const millis_t start_ms = millis();
|
||||
while (PENDING(millis(), start_ms, time)) idle();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -433,14 +433,14 @@ public:
|
|||
|
||||
static millis_t previous_move_ms, max_inactive_time;
|
||||
FORCE_INLINE static bool stepper_max_timed_out(const millis_t ms=millis()) {
|
||||
return max_inactive_time && ELAPSED(ms, previous_move_ms + max_inactive_time);
|
||||
return max_inactive_time && ELAPSED(ms, previous_move_ms, max_inactive_time);
|
||||
}
|
||||
FORCE_INLINE static void reset_stepper_timeout(const millis_t ms=millis()) { previous_move_ms = ms; }
|
||||
|
||||
#if HAS_DISABLE_IDLE_AXES
|
||||
static millis_t stepper_inactive_time;
|
||||
FORCE_INLINE static bool stepper_inactive_timeout(const millis_t ms=millis()) {
|
||||
return ELAPSED(ms, previous_move_ms + stepper_inactive_time);
|
||||
return ELAPSED(ms, previous_move_ms, stepper_inactive_time);
|
||||
}
|
||||
#else
|
||||
static bool stepper_inactive_timeout(const millis_t) { return false; }
|
||||
|
|
|
|||
|
|
@ -426,7 +426,7 @@ void GCodeQueue::get_serial_commands() {
|
|||
// send "wait" to indicate Marlin is still waiting.
|
||||
#if NO_TIMEOUTS > 0
|
||||
const millis_t ms = millis();
|
||||
if (ring_buffer.empty() && !any_serial_data_available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) {
|
||||
if (ring_buffer.empty() && !any_serial_data_available() && ELAPSED(ms, last_command_time, NO_TIMEOUTS)) {
|
||||
SERIAL_ECHOLNPGM(STR_WAIT);
|
||||
last_command_time = ms;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -755,7 +755,7 @@ void MarlinUI::draw_status_message(const bool blink) {
|
|||
|
||||
// Draw the progress bar if the message has shown long enough
|
||||
// or if there is no message set.
|
||||
if (ELAPSED(millis(), progress_bar_ms + PROGRESS_BAR_MSG_TIME) || !has_status()) {
|
||||
if (ELAPSED(millis(), progress_bar_ms, PROGRESS_BAR_MSG_TIME) || !has_status()) {
|
||||
const uint8_t progress = get_progress_percent();
|
||||
if (progress > 2) return draw_progress_bar(progress);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -632,7 +632,7 @@ void MarlinUI::init() {
|
|||
|
||||
// If the message will blink rather than expire...
|
||||
#if DISABLED(PROGRESS_MSG_ONCE)
|
||||
if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME))
|
||||
if (ELAPSED(ms, progress_bar_ms, PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME))
|
||||
progress_bar_ms = ms;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ void Touch::idle() {
|
|||
|
||||
if (touch_time) {
|
||||
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||
if (touch_control_type == NONE && ELAPSED(now, touch_time + TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS) && ui.on_status_screen())
|
||||
if (touch_control_type == NONE && ELAPSED(now, touch_time, TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS) && ui.on_status_screen())
|
||||
ui.goto_screen(touch_screen_calibration);
|
||||
#endif
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ inline uint16_t MAX31865::readRawImmediate() {
|
|||
}
|
||||
else {
|
||||
TERN_(MAX31865_USE_READ_ERROR_DETECTION, const millis_t ms = millis());
|
||||
if (TERN0(MAX31865_USE_READ_ERROR_DETECTION, ABS((int)(lastRead - rtd)) > 500 && PENDING(ms, lastReadStamp + 1000))) {
|
||||
if (TERN0(MAX31865_USE_READ_ERROR_DETECTION, ABS(int(lastRead - rtd)) > 500 && PENDING(ms, lastReadStamp, 1000UL))) {
|
||||
// If 2 readings within 1s differ too much (~20°C) it's a read error.
|
||||
lastFault = 0x01;
|
||||
lastRead |= 1;
|
||||
|
|
|
|||
|
|
@ -823,7 +823,7 @@ volatile bool Temperature::raw_temps_ready = false;
|
|||
ONHEATING(start_temp, current_temp, target);
|
||||
#endif
|
||||
|
||||
if (heating && current_temp > target && ELAPSED(ms, t2 + 5000UL)) {
|
||||
if (heating && current_temp > target && ELAPSED(ms, t2, 5000UL)) {
|
||||
heating = false;
|
||||
SHV((bias - d) >> 1);
|
||||
t1 = ms;
|
||||
|
|
@ -831,7 +831,7 @@ volatile bool Temperature::raw_temps_ready = false;
|
|||
maxT = target;
|
||||
}
|
||||
|
||||
if (!heating && current_temp < target && ELAPSED(ms, t1 + 5000UL)) {
|
||||
if (!heating && current_temp < target && ELAPSED(ms, t1, 5000UL)) {
|
||||
heating = true;
|
||||
t2 = ms;
|
||||
t_low = t2 - t1;
|
||||
|
|
@ -4666,7 +4666,7 @@ void Temperature::isr() {
|
|||
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 + SEC_TO_MS(TEMP_RESIDENCY_TIME)))
|
||||
#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))
|
||||
|
|
@ -4808,7 +4808,7 @@ void Temperature::isr() {
|
|||
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 + SEC_TO_MS(TEMP_BED_RESIDENCY_TIME)))
|
||||
#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())
|
||||
|
|
@ -5008,7 +5008,7 @@ void Temperature::isr() {
|
|||
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 + SEC_TO_MS(TEMP_CHAMBER_RESIDENCY_TIME)))
|
||||
#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())
|
||||
|
|
@ -5108,7 +5108,7 @@ void Temperature::isr() {
|
|||
millis_t residency_start_ms = 0;
|
||||
bool first_loop = true;
|
||||
// Loop until the temperature has stabilized
|
||||
#define TEMP_COOLER_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + SEC_TO_MS(TEMP_COOLER_RESIDENCY_TIME)))
|
||||
#define TEMP_COOLER_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms, SEC_TO_MS(TEMP_COOLER_RESIDENCY_TIME)))
|
||||
#else
|
||||
// Loop until the temperature is very close target
|
||||
#define TEMP_COOLER_CONDITIONS (wants_to_cool ? isLaserHeating() : isLaserCooling())
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "../test/unit_tests.h"
|
||||
#include "src/core/types.h"
|
||||
#include "src/core/millis_t.h"
|
||||
|
||||
MARLIN_TEST(types, XYval_const_as_bools) {
|
||||
const XYval<int> xy_const_true = {1, 2};
|
||||
|
|
@ -656,3 +657,11 @@ MARLIN_TEST(types, SString) {
|
|||
|
||||
TEST_ASSERT_TRUE(strcmp_P(str, PSTR("Hello World!-123456------ < spaces!33\n^ eol! ... 1234.50*2345.602 = 2895645.67")) == 0);
|
||||
}
|
||||
|
||||
MARLIN_TEST(types, PENDING) {
|
||||
TEST_ASSERT_TRUE(PENDING(0x0000FFFF, 0x00010000)); // <= ~24.4 days
|
||||
TEST_ASSERT_TRUE(ELAPSED(0x0090000A, 0x00900000)); // <= ~24.4 days
|
||||
TEST_ASSERT_FALSE(PENDING(0x00000000, 0x80000000)); // > ~24.4 days
|
||||
TEST_ASSERT_TRUE(PENDING(0x00000000, 0, 0x80000000)); // <= ~48.8 days
|
||||
TEST_ASSERT_TRUE(PENDING(0x80000000, 0x7FFFFFF0, 0x0020)); // <= ~48.8 days
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue