Scott Lahteine
4 years ago
16 changed files with 248 additions and 15 deletions
@ -0,0 +1,81 @@ |
|||||
|
/**
|
||||
|
* 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) |
||||
|
|
||||
|
//#define DEBUG_GCODE_REPEAT_MARKERS
|
||||
|
|
||||
|
#include "repeat.h" |
||||
|
|
||||
|
#include "../gcode/gcode.h" |
||||
|
#include "../sd/cardreader.h" |
||||
|
|
||||
|
#define DEBUG_OUT ENABLED(DEBUG_GCODE_REPEAT_MARKERS) |
||||
|
#include "../core/debug_out.h" |
||||
|
|
||||
|
repeat_marker_t Repeat::marker[MAX_REPEAT_NESTING]; |
||||
|
uint8_t Repeat::index; |
||||
|
|
||||
|
void Repeat::add_marker(const uint32_t sdpos, const uint16_t count) { |
||||
|
if (index >= MAX_REPEAT_NESTING) |
||||
|
SERIAL_ECHO_MSG("!Too many markers."); |
||||
|
else { |
||||
|
marker[index].sdpos = sdpos; |
||||
|
marker[index].counter = count ?: -1; |
||||
|
index++; |
||||
|
DEBUG_ECHOLNPAIR("Add Marker ", int(index), " at ", sdpos, " (", count, ")"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void Repeat::loop() { |
||||
|
if (!index) // No marker?
|
||||
|
SERIAL_ECHO_MSG("!No marker set."); // Inform the user.
|
||||
|
else { |
||||
|
const uint8_t ind = index - 1; // Active marker's index
|
||||
|
if (!marker[ind].counter) { // Did its counter run out?
|
||||
|
DEBUG_ECHOLNPAIR("Pass Marker ", int(index)); |
||||
|
index--; // Carry on. Previous marker on the next 'M808'.
|
||||
|
} |
||||
|
else { |
||||
|
card.setIndex(marker[ind].sdpos); // Loop back to the marker.
|
||||
|
if (marker[ind].counter > 0) // Ignore a negative (or zero) counter.
|
||||
|
--marker[ind].counter; // Decrement the counter. If zero this 'M808' will be skipped next time.
|
||||
|
DEBUG_ECHOLNPAIR("Goto Marker ", int(index), " at ", marker[ind].sdpos, " (", marker[ind].counter, ")"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void Repeat::cancel() { LOOP_L_N(i, index) marker[i].counter = 0; } |
||||
|
|
||||
|
void Repeat::early_parse_M808(char * const cmd) { |
||||
|
if (is_command_M808(cmd)) { |
||||
|
DEBUG_ECHOLNPAIR("Parsing \"", cmd, "\""); |
||||
|
parser.parse(cmd); |
||||
|
if (parser.seen('L')) |
||||
|
add_marker(card.getIndex(), parser.value_ushort()); |
||||
|
else |
||||
|
Repeat::loop(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#endif // GCODE_REPEAT_MARKERS
|
@ -0,0 +1,49 @@ |
|||||
|
/**
|
||||
|
* 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 "../gcode/parser.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 { |
||||
|
private: |
||||
|
static repeat_marker_t marker[MAX_REPEAT_NESTING]; |
||||
|
static uint8_t index; |
||||
|
public: |
||||
|
static inline void reset() { index = 0; } |
||||
|
static bool is_command_M808(char * const cmd) { return cmd[0] == 'M' && cmd[1] == '8' && cmd[2] == '0' && cmd[3] == '8' && !NUMERIC(cmd[4]); } |
||||
|
static void early_parse_M808(char * const cmd); |
||||
|
static void add_marker(const uint32_t sdpos, const uint16_t count); |
||||
|
static void loop(); |
||||
|
static void cancel(); |
||||
|
}; |
||||
|
|
||||
|
extern Repeat repeat; |
@ -0,0 +1,51 @@ |
|||||
|
/**
|
||||
|
* 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" |
||||
|
|
||||
|
/**
|
||||
|
* M808: Set / Goto a repeat marker |
||||
|
* |
||||
|
* L<count> - Set a repeat marker with 'count' repetitions. If omitted, infinity. |
||||
|
* |
||||
|
* Examples: |
||||
|
* |
||||
|
* M808 L ; Set a loop marker with a count of infinity |
||||
|
* M808 L2 ; Set a loop marker with a count of 2 |
||||
|
* M808 ; Decrement and loop if not zero. |
||||
|
*/ |
||||
|
void GcodeSuite::M808() { |
||||
|
|
||||
|
// Handled early and ignored here in the queue.
|
||||
|
// Allowed to go into the queue for logging purposes.
|
||||
|
|
||||
|
// M808 K sent from the host to cancel all loops
|
||||
|
if (parser.seen('K')) repeat.cancel(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#endif // GCODE_REPEAT_MARKERS
|
@ -0,0 +1,16 @@ |
|||||
|
; |
||||
|
; M808 Repeat Marker Test |
||||
|
; |
||||
|
|
||||
|
M808 L3 ; Marker at 54 |
||||
|
|
||||
|
M118 Outer Loop |
||||
|
M300 S220 P100 |
||||
|
|
||||
|
M808 L5 ; Marker at 111 |
||||
|
|
||||
|
M118 Inner Loop |
||||
|
M300 S110 P100 |
||||
|
|
||||
|
M808 |
||||
|
M808 |
Loading…
Reference in new issue