Skip to content

Commit 0f01641

Browse files
committed
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/20299
2 parents e31f5e6 + d466ac1 commit 0f01641

File tree

22 files changed

+307
-32
lines changed

22 files changed

+307
-32
lines changed

Marlin/Configuration.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,8 @@
10991099

11001100
// @section homing
11011101

1102-
//#define NO_MOTION_BEFORE_HOMING // Inhibit movement until all axes have been homed
1103-
1102+
//#define NO_MOTION_BEFORE_HOMING // Inhibit movement until all axes have been homed. Also enable HOME_AFTER_DEACTIVATE for extra safety.
1103+
//#define HOME_AFTER_DEACTIVATE // Require rehoming after steppers are deactivated. Also enable NO_MOTION_BEFORE_HOMING for extra safety.
11041104
//#define UNKNOWN_Z_NO_RAISE // Don't raise Z (lower the bed) if Z is "unknown." For beds that fall when Z is powered off.
11051105

11061106
//#define Z_HOMING_HEIGHT 4 // (mm) Minimal Z height before homing (G28) for Z clearance above the bed, clamps, ...

Marlin/Configuration_adv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,6 @@
854854
// If the Nozzle or Bed falls when the Z stepper is disabled, set its resting position here.
855855
//#define Z_AFTER_DEACTIVATE Z_HOME_POS
856856

857-
//#define HOME_AFTER_DEACTIVATE // Require rehoming after steppers are deactivated
858-
859857
// Default Minimum Feedrates for printing and travel moves
860858
#define DEFAULT_MINIMUMFEEDRATE 0.0 // (mm/s) Minimum feedrate. Set with M205 S.
861859
#define DEFAULT_MINTRAVELFEEDRATE 0.0 // (mm/s) Minimum travel feedrate. Set with M205 T.
@@ -1186,6 +1184,8 @@
11861184
//#define SD_IGNORE_AT_STARTUP // Don't mount the SD card when starting up
11871185
//#define SDCARD_READONLY // Read-only SD card (to save over 2K of flash)
11881186

1187+
//#define GCODE_REPEAT_MARKERS // Enable G-code M808 to set repeat markers and do looping
1188+
11891189
#define SD_PROCEDURE_DEPTH 1 // Increase if you need more nested M32 calls
11901190

11911191
#define SD_FINISHED_STEPPERRELEASE true // Disable steppers when SD Print is finished

Marlin/src/MarlinCore.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@
173173
#include "feature/pause.h"
174174
#endif
175175

176+
#if ENABLED(GCODE_REPEAT_MARKERS)
177+
#include "feature/repeat.h"
178+
#endif
179+
176180
#if ENABLED(POWER_LOSS_RECOVERY)
177181
#include "feature/powerloss.h"
178182
#endif
@@ -435,6 +439,7 @@ bool printingIsPaused() {
435439

436440
void startOrResumeJob() {
437441
if (!printingIsPaused()) {
442+
TERN_(GCODE_REPEAT_MARKERS, repeat.reset());
438443
TERN_(CANCEL_OBJECTS, cancelable.reset());
439444
TERN_(LCD_SHOW_E_TOTAL, e_move_accumulator = 0);
440445
#if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)

Marlin/src/feature/powerloss.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/
182182
info.current_position = current_position;
183183
info.feedrate = uint16_t(feedrate_mm_s * 60.0f);
184184
info.zraise = zraise;
185+
186+
TERN_(GCODE_REPEAT_MARKERS, info.stored_repeat = repeat);
185187
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
186188
TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
187189

@@ -507,6 +509,7 @@ void PrintJobRecovery::resume() {
507509
sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(info.current_position.e, 1, 3, str_1));
508510
gcode.process_subcommands_now(cmd);
509511

512+
TERN_(GCODE_REPEAT_MARKERS, repeat = info.stored_repeat);
510513
TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
511514
TERN_(HAS_POSITION_SHIFT, position_shift = info.position_shift);
512515
#if HAS_HOME_OFFSET || HAS_POSITION_SHIFT

Marlin/src/feature/powerloss.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030

3131
#include "../inc/MarlinConfig.h"
3232

33+
#if ENABLED(GCODE_REPEAT_MARKERS)
34+
#include "../feature/repeat.h"
35+
#endif
36+
3337
#if ENABLED(MIXING_EXTRUDER)
3438
#include "../feature/mixing.h"
3539
#endif
@@ -50,6 +54,8 @@ typedef struct {
5054
uint16_t feedrate;
5155
float zraise;
5256

57+
// Repeat information
58+
TERN_(GCODE_REPEAT_MARKERS, Repeat stored_repeat);
5359

5460
TERN_(HAS_HOME_OFFSET, xyz_pos_t home_offset);
5561
TERN_(HAS_POSITION_SHIFT, xyz_pos_t position_shift);

Marlin/src/feature/repeat.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#include "../inc/MarlinConfig.h"
23+
24+
#if ENABLED(GCODE_REPEAT_MARKERS)
25+
26+
//#define DEBUG_GCODE_REPEAT_MARKERS
27+
28+
#include "repeat.h"
29+
30+
#include "../gcode/gcode.h"
31+
#include "../sd/cardreader.h"
32+
33+
#define DEBUG_OUT ENABLED(DEBUG_GCODE_REPEAT_MARKERS)
34+
#include "../core/debug_out.h"
35+
36+
repeat_marker_t Repeat::marker[MAX_REPEAT_NESTING];
37+
uint8_t Repeat::index;
38+
39+
void Repeat::add_marker(const uint32_t sdpos, const uint16_t count) {
40+
if (index >= MAX_REPEAT_NESTING)
41+
SERIAL_ECHO_MSG("!Too many markers.");
42+
else {
43+
marker[index].sdpos = sdpos;
44+
marker[index].counter = count ?: -1;
45+
index++;
46+
DEBUG_ECHOLNPAIR("Add Marker ", int(index), " at ", sdpos, " (", count, ")");
47+
}
48+
}
49+
50+
void Repeat::loop() {
51+
if (!index) // No marker?
52+
SERIAL_ECHO_MSG("!No marker set."); // Inform the user.
53+
else {
54+
const uint8_t ind = index - 1; // Active marker's index
55+
if (!marker[ind].counter) { // Did its counter run out?
56+
DEBUG_ECHOLNPAIR("Pass Marker ", int(index));
57+
index--; // Carry on. Previous marker on the next 'M808'.
58+
}
59+
else {
60+
card.setIndex(marker[ind].sdpos); // Loop back to the marker.
61+
if (marker[ind].counter > 0) // Ignore a negative (or zero) counter.
62+
--marker[ind].counter; // Decrement the counter. If zero this 'M808' will be skipped next time.
63+
DEBUG_ECHOLNPAIR("Goto Marker ", int(index), " at ", marker[ind].sdpos, " (", marker[ind].counter, ")");
64+
}
65+
}
66+
}
67+
68+
void Repeat::cancel() { LOOP_L_N(i, index) marker[i].counter = 0; }
69+
70+
void Repeat::early_parse_M808(char * const cmd) {
71+
if (is_command_M808(cmd)) {
72+
DEBUG_ECHOLNPAIR("Parsing \"", cmd, "\"");
73+
parser.parse(cmd);
74+
if (parser.seen('L'))
75+
add_marker(card.getIndex(), parser.value_ushort());
76+
else
77+
Repeat::loop();
78+
}
79+
}
80+
81+
#endif // GCODE_REPEAT_MARKERS

Marlin/src/feature/repeat.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
#include "../inc/MarlinConfigPre.h"
25+
#include "../gcode/parser.h"
26+
27+
#include <stdint.h>
28+
29+
#define MAX_REPEAT_NESTING 10
30+
31+
typedef struct {
32+
uint32_t sdpos; // The repeat file position
33+
int16_t counter; // The counter for looping
34+
} repeat_marker_t;
35+
36+
class Repeat {
37+
private:
38+
static repeat_marker_t marker[MAX_REPEAT_NESTING];
39+
static uint8_t index;
40+
public:
41+
static inline void reset() { index = 0; }
42+
static bool is_command_M808(char * const cmd) { return cmd[0] == 'M' && cmd[1] == '8' && cmd[2] == '0' && cmd[3] == '8' && !NUMERIC(cmd[4]); }
43+
static void early_parse_M808(char * const cmd);
44+
static void add_marker(const uint32_t sdpos, const uint16_t count);
45+
static void loop();
46+
static void cancel();
47+
};
48+
49+
extern Repeat repeat;

Marlin/src/gcode/gcode.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
882882
case 800: parser.debug(); break; // M800: GCode Parser Test for M
883883
#endif
884884

885+
#if ENABLED(GCODE_REPEAT_MARKERS)
886+
case 808: M808(); break; // M808: Set / Goto repeat markers
887+
#endif
888+
885889
#if ENABLED(I2C_POSITION_ENCODERS)
886890
case 860: M860(); break; // M860: Report encoder module position
887891
case 861: M861(); break; // M861: Report encoder module status

Marlin/src/gcode/gcode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
* M672 - Set/Reset Duet Smart Effector's sensitivity. (Requires DUET_SMART_EFFECTOR and SMART_EFFECTOR_MOD_PIN)
243243
* M701 - Load filament (Requires FILAMENT_LOAD_UNLOAD_GCODES)
244244
* M702 - Unload filament (Requires FILAMENT_LOAD_UNLOAD_GCODES)
245+
* M808 - Set or Goto a Repeat Marker (Requires GCODE_REPEAT_MARKERS)
245246
* M810-M819 - Define/execute a G-code macro (Requires GCODE_MACROS)
246247
* M851 - Set Z probe's XYZ offsets in current units. (Negative values: X=left, Y=front, Z=below)
247248
* M852 - Set skew factors: "M852 [I<xy>] [J<xz>] [K<yz>]". (Requires SKEW_CORRECTION_GCODE, and SKEW_CORRECTION_FOR_Z for IJ)
@@ -807,6 +808,8 @@ class GcodeSuite {
807808
static void M702();
808809
#endif
809810

811+
TERN_(GCODE_REPEAT_MARKERS, static void M808());
812+
810813
TERN_(GCODE_MACROS, static void M810_819());
811814

812815
TERN_(HAS_BED_PROBE, static void M851());

Marlin/src/gcode/host/M115.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ void GcodeSuite::M115() {
117117
// SDCARD (M20, M23, M24, etc.)
118118
cap_line(PSTR("SDCARD"), ENABLED(SDSUPPORT));
119119

120+
// REPEAT (M808)
121+
cap_line(PSTR("REPEAT"), ENABLED(GCODE_REPEAT_MARKERS));
122+
120123
// AUTOREPORT_SD_STATUS (M27 extension)
121124
cap_line(PSTR("AUTOREPORT_SD_STATUS"), ENABLED(AUTO_REPORT_SD_STATUS));
122125

0 commit comments

Comments
 (0)