-
-
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 62751df
Showing
10 changed files
with
195 additions
and
23 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,62 @@ | ||
/** | ||
* 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::count, Repeat::index; | ||
|
||
bool Repeat::early_parse_M41(char * const cmd, const uint32_t &sdpos) { | ||
parser.parse(cmd); | ||
if (parser.command_letter == 'M' && parser.codenum == 41) { | ||
gcode.process_parsed_command(); | ||
marker[count].sdpos = sdpos; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void Repeat::add_marker(const uint16_t count) { | ||
if (count < MAX_REPEAT_NESTING) { | ||
marker[count].counter = count; | ||
count++; | ||
} | ||
} | ||
|
||
void Repeat::loop() { | ||
if (!count) // No marker has been set? | ||
card.setIndex(0); // Go back to the top | ||
else { | ||
const uint16_t prev = count - 1; // The marker | ||
card.setIndex(marker[prev].sdpos); // Change the SD card position now! | ||
if (marker[prev].counter && !--marker[prev].counter) // If counter is running and reached zero... | ||
--count; // ...The next `M41` will go to the previous marker, or 0 | ||
} | ||
} | ||
|
||
#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,45 @@ | ||
/** | ||
* 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 | ||
uint16_t counter; // The counter for looping | ||
} repeat_marker_t; | ||
|
||
class Repeat { | ||
public: | ||
static repeat_marker_t marker[MAX_REPEAT_NESTING]; | ||
static int8_t count, // Total markers seen | ||
index; // Currently active marker, plus one | ||
static void add_marker(const uint16_t count); | ||
static bool early_parse_M41(char * const cmd); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* 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" | ||
|
||
/** | ||
* 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