-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd893e8
commit aeacf10
Showing
13 changed files
with
209 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2020 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/>. | ||
* | ||
*/ | ||
#include "../inc/MarlinConfig.h" | ||
|
||
#if ENABLED(GCODE_REPEAT_MARKERS) | ||
|
||
#include "repeat.h" | ||
|
||
#include "../gcode/gcode.h" | ||
#include "../sd/cardreader.h" | ||
|
||
repeat_marker_t Repeat::marker[MAX_REPEAT_NESTING]; | ||
int8_t Repeat::index; | ||
|
||
bool Repeat::early_parse_M41(char * const cmd, const uint32_t &sdpos) { | ||
parser.parse(cmd); | ||
if (parser.is_command('M', 41)) { | ||
if (sdpos) { | ||
gcode.process_parsed_command(); | ||
marker[index].sdpos = sdpos; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void Repeat::add_marker(const uint16_t count) { | ||
if (index < MAX_REPEAT_NESTING) { | ||
marker[index].counter = count ? count : -1; | ||
index++; | ||
} | ||
} | ||
|
||
void Repeat::loop() { | ||
if (!index) // No marker has been set? | ||
card.setIndex(0); // Go back to the top | ||
else { | ||
const uint16_t ind = index - 1; // The relevant marker index | ||
if (!marker[ind].counter) // Did the counter run out? | ||
--index; // Carry on and loop elsewhere on the next 'M41' | ||
else { | ||
card.setIndex(marker[ind].sdpos); // Loop back to the marker. | ||
if (marker[ind].counter > 0) // Don't decrement a negative (or zero) counter. | ||
--marker[ind].counter; // Decrement the counter. If zero this 'M41' will be skipped next time. | ||
} | ||
} | ||
} | ||
|
||
#endif // GCODE_REPEAT_MARKERS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2020 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/>. | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include "../inc/MarlinConfigPre.h" | ||
|
||
#include <stdint.h> | ||
|
||
#define MAX_REPEAT_NESTING 10 | ||
|
||
typedef struct { | ||
uint32_t sdpos; // The repeat file position | ||
int16_t counter; // The counter for looping | ||
} repeat_marker_t; | ||
|
||
class Repeat { | ||
public: | ||
static repeat_marker_t marker[MAX_REPEAT_NESTING]; | ||
static int8_t index; | ||
static bool early_parse_M41(char * const cmd, const uint32_t &sdpos); | ||
static void add_marker(const uint16_t count); | ||
static void loop(); | ||
}; | ||
|
||
extern Repeat repeat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2020 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/>. | ||
* | ||
*/ | ||
|
||
#include "../../inc/MarlinConfig.h" | ||
|
||
#if ENABLED(GCODE_REPEAT_MARKERS) | ||
|
||
#include "../gcode.h" | ||
#include "../../feature/repeat.h" | ||
#include "../../sd/cardreader.h" | ||
|
||
/** | ||
* M41: Set / Goto a repeat marker | ||
* | ||
* S<count> - Set a repeat marker with 'count' repetitions. If omitted, infinity. | ||
* | ||
* Examples: | ||
* | ||
* M41 S ; Set a loop marker with a count of infinity | ||
* M41 S2 ; Set a loop marker with a count of 2 | ||
* M41 ; Decrement and loop if not zero. | ||
*/ | ||
void GcodeSuite::M41() { | ||
|
||
if (!IS_SD_PRINTING()) return; | ||
|
||
if (parser.seen('S')) // If 'S' was seen... | ||
repeat.add_marker(parser.value_ushort()); // Add a marker with a count. 'S' or 'S0' = forever. | ||
else | ||
repeat.loop(); | ||
|
||
} | ||
|
||
#endif // GCODE_REPEAT_MARKERS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters