|
| 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 |
0 commit comments