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.

queue.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * queue.h - The G-code command queue, which holds commands before they
  25. * go to the parser and dispatcher.
  26. */
  27. #include "../inc/MarlinConfig.h"
  28. class GCodeQueue {
  29. public:
  30. /**
  31. * GCode line number handling. Hosts may include line numbers when sending
  32. * commands to Marlin, and lines will be checked for sequentiality.
  33. * M110 N<int> sets the current line number.
  34. */
  35. static long last_N;
  36. /**
  37. * GCode Command Queue
  38. * A simple ring buffer of BUFSIZE command strings.
  39. *
  40. * Commands are copied into this buffer by the command injectors
  41. * (immediate, serial, sd card) and they are processed sequentially by
  42. * the main loop. The gcode.process_next_command method parses the next
  43. * command and hands off execution to individual handler functions.
  44. */
  45. static uint8_t length, // Count of commands in the queue
  46. index_r; // Ring buffer read position
  47. static char command_buffer[BUFSIZE][MAX_CMD_SIZE];
  48. /*
  49. * The port that the command was received on
  50. */
  51. #if NUM_SERIAL > 1
  52. static int16_t port[BUFSIZE];
  53. #endif
  54. GCodeQueue();
  55. /**
  56. * Clear the Marlin command queue
  57. */
  58. static void clear();
  59. /**
  60. * Enqueue one or many commands to run from program memory.
  61. * Aborts the current queue, if any.
  62. * Note: process_injected_command() will process them.
  63. */
  64. static void inject_P(PGM_P const pgcode);
  65. /**
  66. * Enqueue and return only when commands are actually enqueued
  67. */
  68. static void enqueue_one_now(const char* cmd);
  69. /**
  70. * Attempt to enqueue a single G-code command
  71. * and return 'true' if successful.
  72. */
  73. static bool enqueue_one_P(PGM_P const pgcode);
  74. /**
  75. * Enqueue from program memory and return only when commands are actually enqueued
  76. */
  77. static void enqueue_now_P(PGM_P const cmd);
  78. /**
  79. * Check whether there are any commands yet to be executed
  80. */
  81. static bool has_commands_queued();
  82. /**
  83. * Get the next command in the queue, optionally log it to SD, then dispatch it
  84. */
  85. static void advance();
  86. /**
  87. * Add to the circular command queue the next command from:
  88. * - The command-injection queue (injected_commands_P)
  89. * - The active serial input (usually USB)
  90. * - The SD card file being actively printed
  91. */
  92. static void get_available_commands();
  93. /**
  94. * Send an "ok" message to the host, indicating
  95. * that a command was successfully processed.
  96. *
  97. * If ADVANCED_OK is enabled also include:
  98. * N<int> Line number of the command, if any
  99. * P<int> Planner space remaining
  100. * B<int> Block queue space remaining
  101. */
  102. static void ok_to_send();
  103. /**
  104. * Clear the serial line and request a resend of
  105. * the next expected line number.
  106. */
  107. static void flush_and_request_resend();
  108. private:
  109. static uint8_t index_w; // Ring buffer write position
  110. static void get_serial_commands();
  111. #if ENABLED(SDSUPPORT)
  112. static void get_sdcard_commands();
  113. #endif
  114. static void _commit_command(bool say_ok
  115. #if NUM_SERIAL > 1
  116. , int16_t p=-1
  117. #endif
  118. );
  119. static bool _enqueue(const char* cmd, bool say_ok=false
  120. #if NUM_SERIAL > 1
  121. , int16_t p=-1
  122. #endif
  123. );
  124. // Process the next "immediate" command
  125. static bool process_injected_command();
  126. /**
  127. * Enqueue with Serial Echo
  128. * Return true on success
  129. */
  130. static bool enqueue_one(const char* cmd);
  131. static void gcode_line_error(PGM_P const err, const int8_t pn);
  132. };
  133. extern GCodeQueue queue;