Add typedef celsius_t (#21374)

This commit is contained in:
Scott Lahteine
2021-03-24 04:11:43 -05:00
committed by GitHub
parent 07c24e72ac
commit e5ff55a1be
35 changed files with 252 additions and 298 deletions

View File

@ -533,7 +533,7 @@ void GcodeSuite::G26() {
#if HAS_HEATED_BED
// Get a temperature from 'I' or 'B'
int16_t bedtemp = 0;
celsius_t bedtemp = 0;
// Use the 'I' index if temperature presets are defined
#if PREHEAT_COUNT
@ -616,7 +616,7 @@ void GcodeSuite::G26() {
g26_extrusion_multiplier *= g26_filament_diameter * sq(g26_nozzle) / sq(0.3); // Scale up by nozzle size
// Get a temperature from 'I' or 'H'
int16_t noztemp = 0;
celsius_t noztemp = 0;
// Accept 'I' if temperature presets are defined
#if PREHEAT_COUNT

View File

@ -27,6 +27,10 @@
#include "../gcode.h"
#include "../../lcd/marlinui.h"
#if HAS_HOTEND
#include "../../module/temperature.h"
#endif
/**
* M145: Set the heatup state for a material in the LCD menu
*
@ -43,7 +47,7 @@ void GcodeSuite::M145() {
preheat_t &mat = ui.material_preset[material];
#if HAS_HOTEND
if (parser.seenval('H'))
mat.hotend_temp = constrain(parser.value_int(), EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP) - (HOTEND_OVERSHOOT));
mat.hotend_temp = constrain(parser.value_int(), EXTRUDE_MINTEMP, thermalManager.hotend_max_target(0));
#endif
#if HAS_HEATED_BED
if (parser.seenval('B'))

View File

@ -352,50 +352,45 @@ public:
static inline PGM_P temp_units_name() {
return input_temp_units == TEMPUNIT_K ? PSTR("Kelvin") : input_temp_units == TEMPUNIT_F ? PSTR("Fahrenheit") : PSTR("Celsius");
}
static inline float to_temp_units(const float &f) {
static inline float to_temp_units(celsius_t c) {
switch (input_temp_units) {
case TEMPUNIT_F:
return f * 0.5555555556f + 32;
case TEMPUNIT_K:
return f + 273.15f;
case TEMPUNIT_C:
default:
return f;
case TEMPUNIT_C: return c;
case TEMPUNIT_K: return c + 273.15f;
case TEMPUNIT_F: return c * 0.5555555556f + 32;
}
}
#endif // HAS_LCD_MENU && !DISABLE_M503
static inline float value_celsius() {
const float f = value_float();
static inline celsius_t value_celsius() {
float f = value_float();
switch (input_temp_units) {
case TEMPUNIT_F:
return (f - 32) * 0.5555555556f;
case TEMPUNIT_K:
return f - 273.15f;
case TEMPUNIT_C:
default:
return f;
case TEMPUNIT_C: break;
case TEMPUNIT_K: f -= 273.15f;
case TEMPUNIT_F: f = (f - 32) * 0.5555555556f;
}
return LROUND(f + 0.5f);
}
static inline float value_celsius_diff() {
static inline celsius_t value_celsius_diff() {
float f = value_float();
switch (input_temp_units) {
case TEMPUNIT_F:
return value_float() * 0.5555555556f;
case TEMPUNIT_C:
case TEMPUNIT_K:
default:
return value_float();
case TEMPUNIT_C:
case TEMPUNIT_K: break;
case TEMPUNIT_F: f *= 0.5555555556f;
}
return LROUND(f + 0.5f);
}
#else // !TEMPERATURE_UNITS_SUPPORT
static inline float to_temp_units(int16_t c) { return (float)c; }
static inline float value_celsius() { return value_float(); }
static inline float value_celsius_diff() { return value_float(); }
static inline celsius_t value_celsius() { return value_int(); }
static inline celsius_t value_celsius_diff() { return value_int(); }
#endif // !TEMPERATURE_UNITS_SUPPORT
@ -404,16 +399,16 @@ public:
void unknown_command_warning();
// Provide simple value accessors with default option
static inline char* stringval(const char c, char * const dval=nullptr) { return seenval(c) ? value_string() : dval; }
static inline float floatval(const char c, const float dval=0.0) { return seenval(c) ? value_float() : dval; }
static inline bool boolval(const char c, const bool dval=false) { return seenval(c) ? value_bool() : (seen(c) ? true : dval); }
static inline uint8_t byteval(const char c, const uint8_t dval=0) { return seenval(c) ? value_byte() : dval; }
static inline int16_t intval(const char c, const int16_t dval=0) { return seenval(c) ? value_int() : dval; }
static inline uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; }
static inline int32_t longval(const char c, const int32_t dval=0) { return seenval(c) ? value_long() : dval; }
static inline uint32_t ulongval(const char c, const uint32_t dval=0) { return seenval(c) ? value_ulong() : dval; }
static inline float linearval(const char c, const float dval=0) { return seenval(c) ? value_linear_units() : dval; }
static inline float celsiusval(const char c, const float dval=0) { return seenval(c) ? value_celsius() : dval; }
static inline char* stringval(const char c, char * const dval=nullptr) { return seenval(c) ? value_string() : dval; }
static inline float floatval(const char c, const float dval=0.0) { return seenval(c) ? value_float() : dval; }
static inline bool boolval(const char c, const bool dval=false) { return seenval(c) ? value_bool() : (seen(c) ? true : dval); }
static inline uint8_t byteval(const char c, const uint8_t dval=0) { return seenval(c) ? value_byte() : dval; }
static inline int16_t intval(const char c, const int16_t dval=0) { return seenval(c) ? value_int() : dval; }
static inline uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; }
static inline int32_t longval(const char c, const int32_t dval=0) { return seenval(c) ? value_long() : dval; }
static inline uint32_t ulongval(const char c, const uint32_t dval=0) { return seenval(c) ? value_ulong() : dval; }
static inline float linearval(const char c, const float dval=0) { return seenval(c) ? value_linear_units() : dval; }
static inline celsius_t celsiusval(const char c, const float dval=0) { return seenval(c) ? value_celsius() : dval; }
#if ENABLED(MARLIN_DEV_MODE)

View File

@ -69,7 +69,7 @@ void GcodeSuite::M104() {
#endif
bool got_temp = false;
int16_t temp = 0;
celsius_t temp = 0;
// Accept 'I' if temperature presets are defined
#if PREHEAT_COUNT
@ -145,7 +145,7 @@ void GcodeSuite::M109() {
#endif
bool got_temp = false;
int16_t temp = 0;
celsius_t temp = 0;
// Accept 'I' if temperature presets are defined
#if PREHEAT_COUNT
@ -161,7 +161,7 @@ void GcodeSuite::M109() {
if (!got_temp) {
no_wait_for_cooling = parser.seenval('S');
got_temp = no_wait_for_cooling || parser.seenval('R');
if (got_temp) temp = int16_t(parser.value_celsius());
if (got_temp) temp = parser.value_celsius();
}
if (got_temp) {

View File

@ -44,7 +44,7 @@ void GcodeSuite::M140() {
if (DEBUGGING(DRYRUN)) return;
bool got_temp = false;
int16_t temp = 0;
celsius_t temp = 0;
// Accept 'I' if temperature presets are defined
#if PREHEAT_COUNT
@ -94,7 +94,7 @@ void GcodeSuite::M190() {
if (DEBUGGING(DRYRUN)) return;
bool got_temp = false;
int16_t temp = 0;
celsius_t temp = 0;
// Accept 'I' if temperature presets are defined
#if PREHEAT_COUNT
@ -110,7 +110,7 @@ void GcodeSuite::M190() {
if (!got_temp) {
no_wait_for_cooling = parser.seenval('S');
got_temp = no_wait_for_cooling || parser.seenval('R');
if (got_temp) temp = int16_t(parser.value_celsius());
if (got_temp) temp = parser.value_celsius();
}
if (!got_temp) return;