From 0ba6a805f24d08145283d274e1ef79f8455702c7 Mon Sep 17 00:00:00 2001 From: "info@revskills.de" Date: Sat, 6 Jan 2024 15:21:07 +0100 Subject: [PATCH] Simply code and fix issues on float vs double for nozzle diameter check --- lib/WUI/link_content/basic_gets.cpp | 4 ++-- src/common/gcode/gcode_info.cpp | 4 ++-- src/common/marlin_print_preview.cpp | 4 ++-- src/gui/screen_tools_mapping.cpp | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/WUI/link_content/basic_gets.cpp b/lib/WUI/link_content/basic_gets.cpp index 4049a1f1c3..b0870e7627 100644 --- a/lib/WUI/link_content/basic_gets.cpp +++ b/lib/WUI/link_content/basic_gets.cpp @@ -185,7 +185,7 @@ JsonResult get_printer(size_t resume_point, JsonOutput &output) { JsonResult get_version(size_t resume_point, JsonOutput &output) { char hostname[ETH_HOSTNAME_LEN + 1]; netdev_get_hostname(netdev_get_active_id(), hostname, sizeof hostname); - auto nozzle_diameter = config_store().get_nozzle_diameter(0); + float nozzle_diameter = config_store().get_nozzle_diameter(0); // Keep the indentation of the JSON in here! // clang-format off @@ -210,7 +210,7 @@ JsonResult get_version(size_t resume_point, JsonOutput &output) { JsonResult get_info(size_t resume_point, JsonOutput &output) { char hostname[ETH_HOSTNAME_LEN + 1]; netdev_get_hostname(netdev_get_active_id(), hostname, sizeof hostname); - auto nozzle_diameter = config_store().get_nozzle_diameter(0); + float nozzle_diameter = config_store().get_nozzle_diameter(0); auto mmu2_enabled = #if HAS_MMU2() config_store().mmu2_enabled.get(); diff --git a/src/common/gcode/gcode_info.cpp b/src/common/gcode/gcode_info.cpp index 4673c55afc..e8bc108431 100644 --- a/src/common/gcode/gcode_info.cpp +++ b/src/common/gcode/gcode_info.cpp @@ -220,8 +220,8 @@ void GCodeInfo::EvaluateToolsValid() { if (per_extruder_info[e].nozzle_diameter.has_value()) { auto do_nozzle_check = [&](uint8_t hotend) { assert(hotend < HOTENDS); - float nozzle_diameter_distance = per_extruder_info[e].nozzle_diameter.value() - config_store().get_nozzle_diameter(hotend); - if (nozzle_diameter_distance > 0.001f || nozzle_diameter_distance < -0.001f) { + float nozzle_diameter_distance = std::abs(per_extruder_info[e].nozzle_diameter.value() - config_store().get_nozzle_diameter(hotend)); + if (nozzle_diameter_distance > 0.001f) { valid_printer_settings.wrong_nozzle_diameter.fail(); } }; diff --git a/src/common/marlin_print_preview.cpp b/src/common/marlin_print_preview.cpp index 3404da2eaf..1d90ab8a60 100644 --- a/src/common/marlin_print_preview.cpp +++ b/src/common/marlin_print_preview.cpp @@ -166,8 +166,8 @@ auto PrintPreview::check_tools_mapping_validity(const ToolMapper &mapper, const return true; } - float nozzle_diameter_distance = gcode.get_extruder_info(gcode_tool).nozzle_diameter.value() - get_nozzle_diameter(physical_extruder); - if (nozzle_diameter_distance > 0.001f || nozzle_diameter_distance < -0.001f) { + float nozzle_diameter_distance = std::abs(static_cast(gcode.get_extruder_info(gcode_tool).nozzle_diameter.value()) - static_cast(get_nozzle_diameter(physical_extruder))); + if (nozzle_diameter_distance > 0.001f) { return false; } diff --git a/src/gui/screen_tools_mapping.cpp b/src/gui/screen_tools_mapping.cpp index 71483c7014..655bf4bcc3 100644 --- a/src/gui/screen_tools_mapping.cpp +++ b/src/gui/screen_tools_mapping.cpp @@ -144,11 +144,11 @@ void disable_radio(RadioButton &radio) { radio.Invalidate(); } -double get_nozzle_diameter([[maybe_unused]] size_t idx) { +float get_nozzle_diameter([[maybe_unused]] size_t idx) { #if HAS_TOOLCHANGER() - return static_cast(config_store().get_nozzle_diameter(idx)); + return static_cast(config_store().get_nozzle_diameter(idx)); #elif HAS_MMU2() - return static_cast(config_store().get_nozzle_diameter(0)); + return static_cast(config_store().get_nozzle_diameter(0)); #endif } @@ -162,7 +162,7 @@ void print_right_tool_into_buffer(size_t idx, std::array(get_nozzle_diameter(idx))); } } @@ -268,8 +268,8 @@ bool all_nozzles_same(GCodeInfo &gcode_info) { bool initialized { false }; auto nozzles_are_matching = [](float lhs, float rhs) { - float nozzle_diameter_distance = lhs - rhs; - return !(nozzle_diameter_distance > 0.001f || nozzle_diameter_distance < -0.001f); + float nozzle_diameter_distance = std::abs(lhs - rhs); + return nozzle_diameter_distance <= 0.001f; }; // check gcodes EXTRUDER_LOOP() {