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

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