Skip to content

Commit 09e943a

Browse files
committed
πŸ§‘β€πŸ’» duration_t::remainingEstimate
1 parent a6d8c6d commit 09e943a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

β€ŽMarlin/src/libs/duration_t.hβ€Ž

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,28 @@ struct duration_t {
211211
}
212212
}
213213

214+
/**
215+
* @brief Get the estimated remaining time
216+
* @details Use the given start time and sdpos values to estimate the
217+
* remaining time (as reckoned from this duration_t value).
218+
* Should be superseded by 'M73 R' (SET_REMAINING_TIME).
219+
* This estimate is rendered meaningless by M808, but reset start_time for per-object estimates.
220+
* The UI should consider a "start_sdpos" of 0 to be unset and show "---"
221+
*
222+
* @param start_time The time to consider the "real" start of the print. Saved time of the first E move with X and/or Y.
223+
* @param start_sdpos The sdpos of the first printing move (E move with X and/or Y).
224+
* @param end_sdpos The sdpos of the end of the print (before cooldown).
225+
* @param sdpos The current sdpos of the print job.
226+
*/
227+
uint32_t remainingEstimate(const uint32_t start_time, const uint32_t start_sdpos, const uint32_t end_sdpos, const uint32_t sdpos) const {
228+
const float elapsed_data = float(sdpos - start_sdpos), // Ex: 460b - 280b = 180b
229+
total_data = float(end_sdpos - start_sdpos), // Ex: 1000b - 280b = 720b
230+
sd_percent = elapsed_data / total_data, // Ex: 180b / 720b = 0.25
231+
sd_ratio = (1.0f - sd_percent) / sd_percent; // Ex: (1.0 - 0.25) / 0.25 = 3.0
232+
233+
const uint32_t elapsed_time = value - start_time; // Ex: T2 - T1 = 300s
234+
return uint32_t(elapsed_time * sd_ratio); // Ex: 300s * 3.0f = 900s
235+
}
236+
214237
#pragma GCC diagnostic pop
215238
};

0 commit comments

Comments
Β (0)