My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

repeat.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #if ENABLED(GCODE_REPEAT_MARKERS)
  24. //#define DEBUG_GCODE_REPEAT_MARKERS
  25. #include "repeat.h"
  26. #include "../gcode/gcode.h"
  27. #include "../sd/cardreader.h"
  28. #define DEBUG_OUT ENABLED(DEBUG_GCODE_REPEAT_MARKERS)
  29. #include "../core/debug_out.h"
  30. repeat_marker_t Repeat::marker[MAX_REPEAT_NESTING];
  31. uint8_t Repeat::index;
  32. void Repeat::add_marker(const uint32_t sdpos, const uint16_t count) {
  33. if (index >= MAX_REPEAT_NESTING)
  34. SERIAL_ECHO_MSG("!Too many markers.");
  35. else {
  36. marker[index].sdpos = sdpos;
  37. marker[index].counter = count ?: -1;
  38. index++;
  39. DEBUG_ECHOLNPAIR("Add Marker ", int(index), " at ", sdpos, " (", count, ")");
  40. }
  41. }
  42. void Repeat::loop() {
  43. if (!index) // No marker?
  44. SERIAL_ECHO_MSG("!No marker set."); // Inform the user.
  45. else {
  46. const uint8_t ind = index - 1; // Active marker's index
  47. if (!marker[ind].counter) { // Did its counter run out?
  48. DEBUG_ECHOLNPAIR("Pass Marker ", int(index));
  49. index--; // Carry on. Previous marker on the next 'M808'.
  50. }
  51. else {
  52. card.setIndex(marker[ind].sdpos); // Loop back to the marker.
  53. if (marker[ind].counter > 0) // Ignore a negative (or zero) counter.
  54. --marker[ind].counter; // Decrement the counter. If zero this 'M808' will be skipped next time.
  55. DEBUG_ECHOLNPAIR("Goto Marker ", int(index), " at ", marker[ind].sdpos, " (", marker[ind].counter, ")");
  56. }
  57. }
  58. }
  59. void Repeat::cancel() { LOOP_L_N(i, index) marker[i].counter = 0; }
  60. void Repeat::early_parse_M808(char * const cmd) {
  61. if (is_command_M808(cmd)) {
  62. DEBUG_ECHOLNPAIR("Parsing \"", cmd, "\"");
  63. parser.parse(cmd);
  64. if (parser.seen('L'))
  65. add_marker(card.getIndex(), parser.value_ushort());
  66. else
  67. Repeat::loop();
  68. }
  69. }
  70. #endif // GCODE_REPEAT_MARKERS