My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M810-M819.cpp 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfig.h"
  23. #if ENABLED(GCODE_MACROS)
  24. #include "../../gcode.h"
  25. #include "../../queue.h"
  26. #include "../../parser.h"
  27. char gcode_macros[GCODE_MACROS_SLOTS][GCODE_MACROS_SLOT_SIZE + 1] = {{ 0 }};
  28. /**
  29. * M810_819: Set/execute a G-code macro.
  30. *
  31. * Usage:
  32. * M810 <command>|... Set Macro 0 to the given commands, separated by the pipe character
  33. * M810 Execute Macro 0
  34. */
  35. void GcodeSuite::M810_819() {
  36. const uint8_t index = parser.codenum - 810;
  37. if (index >= GCODE_MACROS_SLOTS) return;
  38. const size_t len = strlen(parser.string_arg);
  39. if (len) {
  40. // Set a macro
  41. if (len > GCODE_MACROS_SLOT_SIZE)
  42. SERIAL_ERROR_MSG("Macro too long.");
  43. else {
  44. char c, *s = parser.string_arg, *d = gcode_macros[index];
  45. do {
  46. c = *s++;
  47. *d++ = c == '|' ? '\n' : c;
  48. } while (c);
  49. }
  50. }
  51. else {
  52. // Execute a macro
  53. char * const cmd = gcode_macros[index];
  54. if (strlen(cmd)) process_subcommands_now(cmd);
  55. }
  56. }
  57. #endif // GCODE_MACROS