From ebf94c572f117fe2e5a294c31e7460fd8d1f0022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 12 Mar 2023 16:05:35 +0000 Subject: [PATCH] PFW-1504 Minor optimisation Change in memory: Flash: -4 bytes SRAM: 0 bytes --- Firmware/mmu2.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index ab3a88b08..46ed0d664 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -248,7 +248,8 @@ bool MMU2::VerifyFilamentEnteredPTFE() { // The total length is twice delta_mm. Divide that length by number of pixels // available to get length per pixel. - const float mm_per_pixel = (2 * (delta_mm)) / LCD_WIDTH; + // Note: Below is the reciprocal of (2 * delta_mm) / LCD_WIDTH [mm/pixel] + const float pixel_per_mm = 0.5f * float(LCD_WIDTH) / (delta_mm); TryLoadUnloadProgressbarInit(); @@ -287,7 +288,7 @@ bool MMU2::VerifyFilamentEnteredPTFE() { fsensorState |= fsensorStateLCD; // No need to do the above comparison twice, just bitwise OR // Always round up, you can only have 'whole' pixels. (floor is also an option) - dpixel1 = ceil((stepper_get_machine_position_E_mm() - planner_get_current_position_E()) / mm_per_pixel); + dpixel1 = ceil((stepper_get_machine_position_E_mm() - planner_get_current_position_E()) * pixel_per_mm); if (dpixel1 - dpixel0) { dpixel0 = dpixel1; if (lcd_cursor_col > (LCD_WIDTH - 1)) lcd_cursor_col = LCD_WIDTH - 1;