From 56ca47ab9d3e4c3c5711995f80a50c7d5f84d7e4 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 7 May 2017 21:32:01 -0500 Subject: [PATCH] Patch configuration temp units --- Marlin/Marlin_main.cpp | 19 +++++++++++++++---- Marlin/configuration_store.cpp | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e470fc88f7..8a174aeb7b 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1298,19 +1298,30 @@ inline bool code_value_bool() { return !code_has_value() || code_value_byte() > #if ENABLED(TEMPERATURE_UNITS_SUPPORT) inline void set_input_temp_units(TempUnit units) { input_temp_units = units; } - float temp_abs(const float &c) { + float to_temp_units(const float &c) { switch (input_temp_units) { case TEMPUNIT_F: - return (c - 32.0) * 0.5555555556; + return c * 0.5555555556 + 32.0; case TEMPUNIT_K: - return c - 273.15; + return c + 273.15; case TEMPUNIT_C: default: return c; } } - int16_t code_value_temp_abs() { return temp_abs(code_value_float()); } + int16_t code_value_temp_abs() { + const float c = code_value_float(); + switch (input_temp_units) { + case TEMPUNIT_F: + return (int16_t)((c - 32.0) * 0.5555555556); + case TEMPUNIT_K: + return (int16_t)(c - 273.15); + case TEMPUNIT_C: + default: + return (int16_t)(c); + } + } int16_t code_value_temp_diff() { switch (input_temp_units) { diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index ef7e040147..99495997b8 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -1257,8 +1257,8 @@ void MarlinSettings::reset() { CONFIG_ECHO_START; #if ENABLED(TEMPERATURE_UNITS_SUPPORT) extern TempUnit input_temp_units; - extern float temp_abs(const float &f); - #define TEMP_UNIT(N) temp_abs(N) + extern float to_temp_units(const float &f); + #define TEMP_UNIT(N) to_temp_units(N) SERIAL_ECHOPGM(" M149 "); SERIAL_CHAR(input_temp_units == TEMPUNIT_K ? 'K' : input_temp_units == TEMPUNIT_F ? 'F' : 'C'); SERIAL_ECHOPGM(" ; Units in ");