Skip to content

Commit

Permalink
Beep when target temp is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
andrivet committed Jul 23, 2023
1 parent c88de3a commit ad3b250
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/advi3pp/screens/controls/preheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/advi3pp/screens/print/change_temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
18 changes: 11 additions & 7 deletions Marlin/src/advi3pp/screens/tuning/extruder_tuning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,38 @@ 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;
}

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

Expand All @@ -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();
Expand Down
13 changes: 8 additions & 5 deletions Marlin/src/lcd/extui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -1097,31 +1098,32 @@ 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;
#endif
#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)));
Expand All @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions Marlin/src/lcd/extui/ui_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit ad3b250

Please sign in to comment.