Skip to content

Commit

Permalink
Add G-codes M86, M87
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jun 8, 2023
1 parent af72def commit bc56407
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 11 deletions.
21 changes: 12 additions & 9 deletions Marlin/src/feature/hotend_idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@
#include "../module/planner.h"
#include "../lcd/marlinui.h"

extern HotendIdleProtection hotend_idle;
HotendIdleProtection hotend_idle;

millis_t HotendIdleProtection::next_protect_ms = 0;
hotend_idle_settings_t HotendIdleProtection::cfg; // Initialized by settings.load()

void HotendIdleProtection::check_hotends(const millis_t &ms) {
bool do_prot = false;
HOTEND_LOOP() {
const bool busy = (TERN0(HAS_RESUME_CONTINUE, wait_for_user) || planner.has_blocks_queued());
if (thermalManager.degHotend(e) >= cfg.trigger && !busy) {
do_prot = true; break;
}
}
if (bool(next_protect_ms) != do_prot)
next_protect_ms = do_prot ? ms + cfg.timeout * 1000 : 0;
const bool busy = (TERN0(HAS_RESUME_CONTINUE, wait_for_user) || planner.has_blocks_queued());
if (!busy && cfg.timeout != 0)
HOTEND_LOOP()
if (thermalManager.degHotend(e) >= cfg.trigger) {
do_prot = true; break;
}

if (!do_prot)
next_protect_ms = 0; // No hotends are hot so cancel timeout
else if (!next_protect_ms) // Timeout is possible?
next_protect_ms = ms + cfg.timeout * 1000; // Start timeout if not already set
}

void HotendIdleProtection::check_e_motion(const millis_t &ms) {
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,15 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 82: M82(); break; // M82: Set E axis normal mode (same as other axes)
case 83: M83(); break; // M83: Set E axis relative mode
#endif

case 18: case 84: M18_M84(); break; // M18/M84: Disable Steppers / Set Timeout
case 85: M85(); break; // M85: Set inactivity stepper shutdown timeout

#if ENABLED(HOTEND_IDLE_TIMEOUT)
case 86: M86(); break; // M86: Set Hotend Idle Timeout
case 87: M87(); break; // M87: Cancel Hotend Idle Timeout
#endif

case 92: M92(); break; // M92: Set the steps-per-unit for one or more axes
case 114: M114(); break; // M114: Report current position
case 115: M115(); break; // M115: Report capabilities
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,13 @@ class GcodeSuite {
#endif

static void M85();

#if ENABLED(HOTEND_IDLE_TIMEOUT)
static void M86();
static void M86_report(const bool forReplay=true);
static void M87();
#endif

static void M92();
static void M92_report(const bool forReplay=true, const int8_t e=-1);

Expand Down
73 changes: 73 additions & 0 deletions Marlin/src/gcode/temp/M86-M87.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

/**
* gcode/temp/M86-M87.cpp
*
* Hotend Idle Timeout
*/

#include "../../inc/MarlinConfigPre.h"

#if ENABLED(HOTEND_IDLE_TIMEOUT)

#include "../gcode.h"
#include "../../feature/hotend_idle.h"

void GcodeSuite::M86_report(const bool forReplay/*=true*/) {
report_heading(forReplay, F("Hotend Idle Timeout"));
SERIAL_ECHOLNPGM(" M86"
" B", hotend_idle.bed_target
, " E", hotend_idle.nozzle_target
, " S", hotend_idle.timeout
, " T", hotend_idle.trigger
);
}

/**
* M86: Set / Report Hotend Idle Timeout
*
* Parameters
* S<seconds> : Idle timeout. Set to 0 to disable.
* E<temp> : Extruder idle temperature to set on timeout
* B<temp> : Bed idle temperature to set on timeout
* T<temp> : Minimum extruder temperature to consider for timeout (> idle temperature)
*/
void GcodeSuite::M86() {
if (!parser.seen_any()) return M86_report();
if (parser.seenval('S')) hotend_idle.timeout = parser.value_ushort();
if (parser.seenval('T')) hotend_idle.trigger = parser.value_celsius();
if (parser.seenval('E')) hotend_idle.nozzle_target = parser.value_celsius();
if (parser.seenval('B')) hotend_idle.bed_target = parser.value_celsius();
const celsius_t min_trigger = hotend_idle.nozzle_target + TEMP_HYSTERESIS;
if (hotend_idle.trigger <= min_trigger)
SERIAL_ECHOLNPGM("?Idle Timeout (T) trigger temperature should be over ", min_trigger, "C.");
}

/**
* M86: Cancel Hotend Idle Timeout (by setting the timeout period to 0)
*/
void GcodeSuite::M87() {
hotend_idle.timeout = 0;
}

#endif // HOTEND_IDLE_TIMEOUT
7 changes: 6 additions & 1 deletion Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ typedef struct SettingsDataStruct {
// HOTEND_IDLE_TIMEOUT
//
#if ENABLED(HOTEND_IDLE_TIMEOUT)
hotend_idle_settings_t hotend_idle_config;
hotend_idle_settings_t hotend_idle_config; // M86 S T E B
#endif

} SettingsData;
Expand Down Expand Up @@ -3877,6 +3877,11 @@ void MarlinSettings::reset() {
//
TERN_(HAS_ZV_SHAPING, gcode.M593_report(forReplay));

//
// Hotend Idle Timeout
//
TERN_(HOTEND_IDLE_TIMEOUT, gcode.M86_report(forReplay));

//
// Linear Advance
//
Expand Down
2 changes: 1 addition & 1 deletion ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ HAS_FANMUX = build_src_filter=+<src/feature/fanmux.c
FILAMENT_WIDTH_SENSOR = build_src_filter=+<src/feature/filwidth.cpp> +<src/gcode/feature/filwidth>
FWRETRACT = build_src_filter=+<src/feature/fwretract.cpp> +<src/gcode/feature/fwretract>
HOST_ACTION_COMMANDS = build_src_filter=+<src/feature/host_actions.cpp>
HOTEND_IDLE_TIMEOUT = build_src_filter=+<src/feature/hotend_idle.cpp>
HOTEND_IDLE_TIMEOUT = build_src_filter=+<src/feature/hotend_idle.cpp> +<src/gcode/temp/M86-M87.cpp>
JOYSTICK = build_src_filter=+<src/feature/joystick.cpp>
BLINKM = build_src_filter=+<src/feature/leds/blinkm.cpp>
HAS_COLOR_LEDS = build_src_filter=+<src/feature/leds/leds.cpp> +<src/gcode/feature/leds/M150.cpp>
Expand Down

0 comments on commit bc56407

Please sign in to comment.