From ad3b250d3c01bb0e8b5302c710355f6a833a439f Mon Sep 17 00:00:00 2001 From: Sebastien Andrivet Date: Sun, 23 Jul 2023 16:15:07 +0200 Subject: [PATCH] Beep when target temp is reached --- .../src/advi3pp/screens/controls/preheat.cpp | 4 ++-- .../screens/print/change_temperature.cpp | 2 +- .../advi3pp/screens/tuning/extruder_tuning.cpp | 18 +++++++++++------- Marlin/src/lcd/extui/ui_api.cpp | 13 ++++++++----- Marlin/src/lcd/extui/ui_api.h | 5 +++-- Marlin/src/module/temperature.cpp | 4 ++-- Marlin/src/module/temperature.h | 8 ++++---- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Marlin/src/advi3pp/screens/controls/preheat.cpp b/Marlin/src/advi3pp/screens/controls/preheat.cpp index 888fcba0da..a898fe8898 100755 --- a/Marlin/src/advi3pp/screens/controls/preheat.cpp +++ b/Marlin/src/advi3pp/screens/controls/preheat.cpp @@ -103,8 +103,8 @@ void Preheat::next_command() { void Preheat::on_save_command() { retrieve_presets(); - ExtUI::setTargetTemp_celsius(ExtUI::getMaterialPresetHotendTemp_celsius(index_), ExtUI::E0); - ExtUI::setTargetTemp_celsius(ExtUI::getMaterialPresetBedTemp_celsius(index_), ExtUI::BED); + ExtUI::setTargetTemp_celsius(ExtUI::getMaterialPresetHotendTemp_celsius(index_), ExtUI::E0, true); + ExtUI::setTargetTemp_celsius(ExtUI::getMaterialPresetBedTemp_celsius(index_), ExtUI::BED, true); ExtUI::setTargetFan_percent(ExtUI::getMaterialPresetFanSpeed_percent(index_), ExtUI::FAN0); settings.save(); diff --git a/Marlin/src/advi3pp/screens/print/change_temperature.cpp b/Marlin/src/advi3pp/screens/print/change_temperature.cpp index 196f8e8bbc..c0260b61cb 100644 --- a/Marlin/src/advi3pp/screens/print/change_temperature.cpp +++ b/Marlin/src/advi3pp/screens/print/change_temperature.cpp @@ -54,7 +54,7 @@ namespace ADVi3pp { return; } const auto temp = frame.read_word(); - ExtUI::setTargetTemp_celsius(temp, ExtUI::E0); + ExtUI::setTargetTemp_celsius(temp, ExtUI::E0, true); ExtUI::setDefaultTemp_celsius(temp, ExtUI::E0); settings.save(); diff --git a/Marlin/src/advi3pp/screens/tuning/extruder_tuning.cpp b/Marlin/src/advi3pp/screens/tuning/extruder_tuning.cpp index de63753cdd..a0596bb89f 100755 --- a/Marlin/src/advi3pp/screens/tuning/extruder_tuning.cpp +++ b/Marlin/src/advi3pp/screens/tuning/extruder_tuning.cpp @@ -83,20 +83,23 @@ void ExtruderTuning::start_command() { } uint16_t temperature = frame.read_word(); - ExtUI::setTargetTemp_celsius(temperature, ExtUI::E0); + ExtUI::setTargetTemp_celsius(temperature, ExtUI::E0, true); ExtUI::setDefaultTemp_celsius(temperature, ExtUI::E0); + settings.save(); + wait.wait_back(F("Heating the extruder..."), WaitCallback{this, &ExtruderTuning::cancel_heating}); - background_task.set(Callback{this, &ExtruderTuning::heating}, 500); + background_task.set(Callback{this, &ExtruderTuning::heating}, 250); + ExtUI::setHostKeepaliveState(GcodeSuite::IN_PROCESS); } void ExtruderTuning::heating() { - if(ExtUI::getActualTemp_celsius(ExtUI::E0) < ExtUI::getTargetTemp_celsius(ExtUI::E0) - 2) - return; + if(ExtUI::getActualTemp_celsius(ExtUI::E0) < ExtUI::getTargetTemp_celsius(ExtUI::E0)) return; background_task.clear(); extrude(); } bool ExtruderTuning::cancel_heating() { + ExtUI::setHostKeepaliveState(GcodeSuite::NOT_BUSY); background_task.clear(); ExtUI::setTargetTemp_celsius(0, ExtUI::E0); return true; @@ -104,14 +107,14 @@ bool ExtruderTuning::cancel_heating() { void ExtruderTuning::extrude() { extruded_ = ExtUI::getAxisPosition_mm(ExtUI::E0); + ExtUI::setAxisPosition_mm(extruded_ + FILAMENT_TO_EXTRUDE, ExtUI::E0); wait.wait_back(F("Extrude filament..."), WaitCallback{this, &ExtruderTuning::cancel_extrude}); background_task.set(Callback{this, &ExtruderTuning::extruding}, 100); - ExtUI::setAxisPosition_mm(extruded_ + FILAMENT_TO_EXTRUDE, ExtUI::E0); } void ExtruderTuning::extruding() { - if(ExtUI::isMoving()) - return; + if(ExtUI::isMoving()) return; + ExtUI::setHostKeepaliveState(GcodeSuite::NOT_BUSY); background_task.clear(); ExtUI::setTargetTemp_celsius(0, ExtUI::E0); @@ -123,6 +126,7 @@ void ExtruderTuning::extruding() { } bool ExtruderTuning::cancel_extrude() { + ExtUI::setHostKeepaliveState(GcodeSuite::NOT_BUSY); background_task.clear(); ExtUI::setTargetTemp_celsius(0, ExtUI::E0); ExtUI::stopMove(); diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index e3a1168e50..7eaefad4e9 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -444,6 +444,7 @@ namespace ExtUI { #if ENABLED(HOST_KEEPALIVE_FEATURE) GcodeSuite::MarlinBusyState getHostKeepaliveState() { return gcode.busy_state; } bool getHostKeepaliveIsPaused() { return gcode.host_keepalive_is_paused(); } + void setHostKeepaliveState(GcodeSuite::MarlinBusyState state) { gcode.busy_state = state; } #endif #if HAS_SOFTWARE_ENDSTOPS @@ -1083,7 +1084,7 @@ namespace ExtUI { return firmware_name; } - void setTargetTemp_celsius(const_float_t inval, const heater_t heater) { + void setTargetTemp_celsius(const_float_t inval, const heater_t heater, bool beep) { float value = inval; #ifdef TOUCH_UI_LCD_TEMP_SCALING value *= TOUCH_UI_LCD_TEMP_SCALING; @@ -1097,18 +1098,18 @@ namespace ExtUI { case COOLER: thermalManager.setTargetCooler(LROUND(constrain(value, 0, COOLER_MAXTEMP))); break; #endif #if HAS_HEATED_BED - case BED: thermalManager.setTargetBed(LROUND(constrain(value, 0, BED_MAX_TARGET))); break; + case BED: thermalManager.setTargetBed(LROUND(constrain(value, 0, BED_MAX_TARGET)), beep); break; #endif default: { #if HAS_HOTEND const int16_t e = heater - H0; - thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.hotend_max_target(e))), e); + thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.hotend_max_target(e))), e, beep); #endif } break; } } - void setTargetTemp_celsius(const_float_t inval, const extruder_t extruder) { + void setTargetTemp_celsius(const_float_t inval, const extruder_t extruder, bool beep) { float value = inval; #ifdef TOUCH_UI_LCD_TEMP_SCALING value *= TOUCH_UI_LCD_TEMP_SCALING; @@ -1116,12 +1117,13 @@ namespace ExtUI { #if HAS_HOTEND const int16_t e = extruder - E0; enableHeater(extruder); - thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.hotend_max_target(e))), e); + thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.hotend_max_target(e))), e, beep); #endif } // @advi3++ void setDefaultTemp_celsius(const_float_t inval, const heater_t heater) { + if(inval <= 0) return; switch (heater) { #if HAS_HEATED_BED case BED: thermalManager.setDefaultBed(LROUND(constrain(inval, 0, BED_MAX_TARGET))); @@ -1138,6 +1140,7 @@ namespace ExtUI { // @advi3++ void setDefaultTemp_celsius(const_float_t inval, const extruder_t extruder) { + if(inval <= 0) return; const int16_t e = extruder - E0; thermalManager.setDefaultHotend(LROUND(constrain(inval, 0, thermalManager.hotend_max_target(e))), e); } diff --git a/Marlin/src/lcd/extui/ui_api.h b/Marlin/src/lcd/extui/ui_api.h index 8908370f3d..4f44eee0a5 100644 --- a/Marlin/src/lcd/extui/ui_api.h +++ b/Marlin/src/lcd/extui/ui_api.h @@ -87,6 +87,7 @@ namespace ExtUI { #if ENABLED(HOST_KEEPALIVE_FEATURE) GcodeSuite::MarlinBusyState getHostKeepaliveState(); bool getHostKeepaliveIsPaused(); + void setHostKeepaliveState(GcodeSuite::MarlinBusyState state); #endif bool isHeaterIdle(const heater_t); @@ -234,8 +235,8 @@ namespace ExtUI { char* getFilamentUsed_str(char buffer[21]); #endif - void setTargetTemp_celsius(const_float_t, const heater_t); - void setTargetTemp_celsius(const_float_t, const extruder_t); + void setTargetTemp_celsius(const_float_t, const heater_t, bool beep = false); // @advi3++ + void setTargetTemp_celsius(const_float_t, const extruder_t, bool beep = false); // @advi3++ void setDefaultTemp_celsius(const_float_t, const heater_t); // @advi3++ void setDefaultTemp_celsius(const_float_t, const extruder_t); // @advi3++ void setTargetFan_percent(const_float_t, const fan_t); diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 75b37e5c1e..37ffc8e436 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1617,7 +1617,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { #endif // @advi3++ Beep if temperature is reached (only one time) - if(degHotend(e) >= degTargetHotend(e) && temp_hotend_reached_beep[e]) { + if(degTargetHotend(e) > 0 && degHotend(e) >= degTargetHotend(e) && temp_hotend_reached_beep[e]) { temp_hotend_reached_beep[e] = false; BUZZ(10, 440); } @@ -1704,7 +1704,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { } // @advi3++ Beep if temperature is reached (only one time) - if(degBed() >= degTargetBed() && temp_bed_reached_beep) { + if(degTargetBed() > 0 && degBed() >= degTargetBed() && temp_bed_reached_beep) { temp_bed_reached_beep = false; BUZZ(10, 440); } diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index c2e1325e19..a7dfff5269 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -956,7 +956,7 @@ class Temperature { #if HAS_HOTEND - static void setTargetHotend(const celsius_t celsius, const uint8_t E_NAME) { + static void setTargetHotend(const celsius_t celsius, const uint8_t E_NAME, bool beep = false) { // @advi3++ const uint8_t ee = HOTEND_INDEX; #if MILLISECONDS_PREHEAT_TIME > 0 if (celsius == 0) @@ -966,7 +966,7 @@ class Temperature { #endif TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on()); temp_hotend[ee].target = _MIN(celsius, hotend_max_target(ee)); - if(celsius > 0) temp_hotend_reached_beep[ee] = true; // @advi3++ + if(celsius > 0) temp_hotend_reached_beep[ee] = beep; // @advi3++ start_watching_hotend(ee); } @@ -1031,10 +1031,10 @@ class Temperature { // Start watching the Bed to make sure it's really heating up static void start_watching_bed() { TERN_(WATCH_BED, watch_bed.restart(degBed(), degTargetBed())); } - static void setTargetBed(const celsius_t celsius) { + static void setTargetBed(const celsius_t celsius, bool beep = false) { // @advi3++ TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on()); temp_bed.target = _MIN(celsius, BED_MAX_TARGET); - if(celsius > 0) temp_bed_reached_beep = true; // @advi3++ + if(celsius > 0) temp_bed_reached_beep = beep; // @advi3++ start_watching_bed(); }