Skip to content

Commit

Permalink
Temperature cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 19, 2021
1 parent 38b44e3 commit 90bcb22
Show file tree
Hide file tree
Showing 50 changed files with 499 additions and 644 deletions.
6 changes: 6 additions & 0 deletions Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ struct IF<true, L, R> { typedef L type; };
//
typedef float feedRate_t;

//
// celsius_t is the native unit of temperature. Signed to handle a disconnected thermistor value (-14).
// For more resolition (e.g., for a chocolate printer) this may later be changed to Celsius x 100
//
typedef int16_t celsius_t;

// Conversion macros
#define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f)
#define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/mmu/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
bool response = false;
mmu_print_saved = false;
xyz_pos_t resume_position;
int16_t resume_hotend_temp = thermalManager.degTargetHotend(active_extruder);
celsius_t resume_hotend_temp = thermalManager.degTargetHotend(active_extruder);

KEEPALIVE_STATE(PAUSED_FOR_USER);

Expand Down
5 changes: 2 additions & 3 deletions Marlin/src/feature/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
* - Send host action for resume, if configured
* - Resume the current SD print job, if any
*/
void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/, int16_t targetTemp/*=0*/ DXC_ARGS) {
void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/, const celsius_t targetTemp/*=0*/ DXC_ARGS) {
DEBUG_SECTION(rp, "resume_print", true);
DEBUG_ECHOLNPAIR("... slowlen:", slow_load_length, " fastlen:", fast_load_length, " purgelen:", purge_length, " maxbeep:", max_beep_count, " targetTemp:", targetTemp DXC_SAY);

Expand All @@ -577,9 +577,8 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le
thermalManager.reset_hotend_idle_timer(e);
}

if (targetTemp > thermalManager.degTargetHotend(active_extruder)) {
if (targetTemp > thermalManager.degTargetHotend(active_extruder))
thermalManager.setTargetHotend(targetTemp, active_extruder);
}

// Load the new filament
load_filament(slow_load_length, fast_load_length, purge_length, max_beep_count, true, nozzle_timed_out, PAUSE_MODE_SAME DXC_PASS);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/pause.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool pause_print(const float &retract, const xyz_pos_t &park_point, const float
void wait_for_confirmation(const bool is_reload=false, const int8_t max_beep_count=0 DXC_PARAMS);

void resume_print(const float &slow_load_length=0, const float &fast_load_length=0, const float &extrude_length=ADVANCED_PAUSE_PURGE_LENGTH,
const int8_t max_beep_count=0, int16_t targetTemp=0 DXC_PARAMS);
const int8_t max_beep_count=0, const celsius_t targetTemp=0 DXC_PARAMS);

bool load_filament(const float &slow_load_length=0, const float &fast_load_length=0, const float &extrude_length=0, const int8_t max_beep_count=0,
const bool show_lcd=false, const bool pause_for_user=false, const PauseMode mode=PAUSE_MODE_PAUSE_PRINT DXC_PARAMS);
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/
#endif

#if EXTRUDERS
HOTEND_LOOP() info.target_temperature[e] = thermalManager.temp_hotend[e].target;
HOTEND_LOOP() info.target_temperature[e] = thermalManager.degTargetHotend(e);
#endif

TERN_(HAS_HEATED_BED, info.target_temperature_bed = thermalManager.temp_bed.target);
TERN_(HAS_HEATED_BED, info.target_temperature_bed = thermalManager.degTargetBed());

#if HAS_FAN
COPY(info.fan_speed, thermalManager.fan_speed);
Expand Down Expand Up @@ -343,7 +343,7 @@ void PrintJobRecovery::resume() {
#endif

#if HAS_HEATED_BED
const int16_t bt = info.target_temperature_bed;
const celsius_t bt = info.target_temperature_bed;
if (bt) {
// Restore the bed temperature
sprintf_P(cmd, PSTR("M190 S%i"), bt);
Expand All @@ -354,7 +354,7 @@ void PrintJobRecovery::resume() {
// Restore all hotend temperatures
#if HAS_HOTEND
HOTEND_LOOP() {
const int16_t et = info.target_temperature[e];
const celsius_t et = info.target_temperature[e];
if (et) {
#if HAS_MULTI_HOTEND
sprintf_P(cmd, PSTR("T%i S"), e);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/powerloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ typedef struct {
float filament_size[EXTRUDERS];
#endif

TERN_(HAS_HOTEND, int16_t target_temperature[HOTENDS]);
TERN_(HAS_HEATED_BED, int16_t target_temperature_bed);
TERN_(HAS_HOTEND, celsius_t target_temperature[HOTENDS]);
TERN_(HAS_HEATED_BED, celsius_t target_temperature_bed);
TERN_(HAS_FAN, uint8_t fan_speed[FAN_COUNT]);

TERN_(HAS_LEVELING, float fade);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/bedlevel/G26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/host/M360.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void GcodeSuite::M360() {
config_line_e(e, PSTR("MaxSpeed"), planner.settings.max_feedrate_mm_s[E_AXIS_N(e)]);
config_line_e(e, PSTR("Acceleration"), planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(e)]);
config_line_e(e, PSTR("Diameter"), TERN(NO_VOLUMETRICS, DEFAULT_NOMINAL_FILAMENT_DIA, planner.filament_size[e]));
config_line_e(e, PSTR("MaxTemp"), thermalManager.heater_maxtemp[e]);
config_line_e(e, PSTR("MaxTemp"), thermalManager.hotend_maxtemp[e]);
}
#endif
}
Expand Down
6 changes: 5 additions & 1 deletion Marlin/src/gcode/lcd/M145.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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'))
Expand Down
61 changes: 28 additions & 33 deletions Marlin/src/gcode/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,50 +352,45 @@ class GCodeParser {
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 celsius_t(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 celsius_t(f + 0.5f);
}

#define TEMP_UNIT(N) parser.to_temp_units(N)

#else // !TEMPERATURE_UNITS_SUPPORT

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(); }

#define TEMP_UNIT(N) (N)

Expand All @@ -406,16 +401,16 @@ class GCodeParser {
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)

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/temp/M104_M109.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/temp/M140_M190.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,15 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char prefix, const bool blink) {
#if HAS_HEATED_BED
const bool isBed = TERN(HAS_HEATED_CHAMBER, heater_id == H_BED, heater_id < 0);
const float t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id)),
t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id));
const celsius_t t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id)),
t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id));
#else
const float t1 = thermalManager.degHotend(heater_id), t2 = thermalManager.degTargetHotend(heater_id);
const celsius_t t1 = thermalManager.degHotend(heater_id), t2 = thermalManager.degTargetHotend(heater_id);
#endif

if (prefix >= 0) lcd_put_wchar(prefix);

lcd_put_u8str(i16tostr3rj(t1 + 0.5));
lcd_put_u8str(i16tostr3rj(t1));
lcd_put_wchar('/');

#if !HEATER_IDLE_HANDLER
Expand All @@ -541,7 +541,7 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char pr
}
else
#endif
lcd_put_u8str(i16tostr3left(t2 + 0.5));
lcd_put_u8str(i16tostr3left(t2));

if (prefix >= 0) {
lcd_put_wchar(LCD_STR_DEGREE[0]);
Expand Down Expand Up @@ -571,9 +571,9 @@ FORCE_INLINE void _draw_bed_status(const bool blink) {
#if ENABLED(LCD_PROGRESS_BAR)

void MarlinUI::draw_progress_bar(const uint8_t percent) {
const int16_t tix = (int16_t)(percent * (LCD_WIDTH) * 3) / 100,
cel = tix / 3,
rem = tix % 3;
const int16_t tix = int16_t(percent * (LCD_WIDTH) * 3) / 100,
cel = tix / 3,
rem = tix % 3;
uint8_t i = LCD_WIDTH;
char msg[LCD_WIDTH + 1], b = ' ';
msg[LCD_WIDTH] = '\0';
Expand Down
19 changes: 9 additions & 10 deletions Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,33 +434,32 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *p
uint8_t pic_hot_bits;
#if HAS_HEATED_BED
const bool isBed = heater_id < 0;
const float t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id));
const float t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id));
const celsius_t t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id)),
t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id));
#else
const float t1 = thermalManager.degHotend(heater_id);
const float t2 = thermalManager.degTargetHotend(heater_id);
const celsius_t t1 = thermalManager.degHotend(heater_id), t2 = thermalManager.degTargetHotend(heater_id);
#endif

#if HOTENDS < 2
if (heater_id == H_E0) {
lcd.setCursor(2, 5); lcd.print(prefix); //HE
lcd.setCursor(1, 6); lcd.print(i16tostr3rj(t1 + 0.5));
lcd.setCursor(1, 6); lcd.print(i16tostr3rj(t1));
lcd.setCursor(1, 7);
}
else {
lcd.setCursor(6, 5); lcd.print(prefix); //BED
lcd.setCursor(6, 6); lcd.print(i16tostr3rj(t1 + 0.5));
lcd.setCursor(6, 6); lcd.print(i16tostr3rj(t1));
lcd.setCursor(6, 7);
}
#else
if (heater_id > H_BED) {
lcd.setCursor(heater_id * 4, 5); lcd.print(prefix); //HE1 or HE2 or HE3
lcd.setCursor(heater_id * 4, 6); lcd.print(i16tostr3rj(t1 + 0.5));
lcd.setCursor(heater_id * 4, 5); lcd.print(prefix); // HE1 or HE2 or HE3
lcd.setCursor(heater_id * 4, 6); lcd.print(i16tostr3rj(t1));
lcd.setCursor(heater_id * 4, 7);
}
else {
lcd.setCursor(13, 5); lcd.print(prefix); //BED
lcd.setCursor(13, 6); lcd.print(i16tostr3rj(t1 + 0.5));
lcd.setCursor(13, 6); lcd.print(i16tostr3rj(t1));
lcd.setCursor(13, 7);
}
#endif // HOTENDS <= 1
Expand All @@ -475,7 +474,7 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *p
}
else
#endif // !HEATER_IDLE_HANDLER
lcd.print(i16tostr3rj(t2 + 0.5));
lcd.print(i16tostr3rj(t2));

switch (heater_id) {
case H_BED: pic_hot_bits = ICON_BED; break;
Expand Down
Loading

0 comments on commit 90bcb22

Please sign in to comment.