cmdqueue.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef CMDQUEUE_H
  2. #define CMDQUEUE_H
  3. #include "Marlin.h"
  4. #include "language.h"
  5. // String circular buffer. Commands may be pushed to the buffer from both sides:
  6. // Chained commands will be pushed to the front, interactive (from LCD menu)
  7. // and printing commands (from serial line or from SD card) are pushed to the tail.
  8. // First character of each entry indicates the type of the entry:
  9. #define CMDBUFFER_CURRENT_TYPE_UNKNOWN 0
  10. // Command in cmdbuffer was sent over USB.
  11. #define CMDBUFFER_CURRENT_TYPE_USB 1
  12. // Command in cmdbuffer was read from SDCARD.
  13. #define CMDBUFFER_CURRENT_TYPE_SDCARD 2
  14. // Command in cmdbuffer was generated by the UI.
  15. #define CMDBUFFER_CURRENT_TYPE_UI 3
  16. // Command in cmdbuffer was generated by another G-code.
  17. #define CMDBUFFER_CURRENT_TYPE_CHAINED 4
  18. // Command has been processed and its SD card length has been possibly pushed
  19. // to the planner queue, but not yet removed from the cmdqueue.
  20. // This is a temporary state to reduce stepper interrupt locking time.
  21. #define CMDBUFFER_CURRENT_TYPE_TO_BE_REMOVED 5
  22. //Command in cmdbuffer was sent over USB and contains line number
  23. #define CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR 6
  24. // How much space to reserve for the chained commands
  25. // of type CMDBUFFER_CURRENT_TYPE_CHAINED,
  26. // which are pushed to the front of the queue?
  27. // Maximum 5 commands of max length 20 + null terminator.
  28. #define CMDBUFFER_RESERVE_FRONT (5*21)
  29. extern char cmdbuffer[BUFSIZE * (MAX_CMD_SIZE + 1) + CMDBUFFER_RESERVE_FRONT];
  30. extern size_t bufindr;
  31. extern int buflen;
  32. extern bool cmdbuffer_front_already_processed;
  33. extern bool cmdqueue_serial_disabled;
  34. // Type of a command, which is to be executed right now.
  35. #define CMDBUFFER_CURRENT_TYPE (cmdbuffer[bufindr])
  36. // String of a command, which is to be executed right now.
  37. #define CMDBUFFER_CURRENT_STRING (cmdbuffer+bufindr+CMDHDRSIZE)
  38. // Enable debugging of the command buffer.
  39. // Debugging information will be sent to serial line.
  40. //#define CMDBUFFER_DEBUG
  41. extern uint32_t sdpos_atomic;
  42. extern int serial_count;
  43. extern bool comment_mode;
  44. extern char *strchr_pointer;
  45. extern long gcode_LastN;
  46. extern bool cmdqueue_pop_front();
  47. extern void cmdqueue_reset();
  48. #ifdef CMDBUFFER_DEBUG
  49. extern void cmdqueue_dump_to_serial_single_line(int nr, const char *p);
  50. extern void cmdqueue_dump_to_serial();
  51. #endif /* CMDBUFFER_DEBUG */
  52. extern bool cmd_buffer_empty();
  53. extern void enquecommand(const char *cmd, bool from_progmem = false);
  54. extern void enquecommand_front(const char *cmd, bool from_progmem = false);
  55. extern void repeatcommand_front();
  56. extern void get_command();
  57. extern uint16_t cmdqueue_calc_sd_length();
  58. // Return True if a character was found
  59. static inline bool code_seen(char code) { return (strchr_pointer = strchr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }
  60. static inline bool code_seen_P(const char *code_PROGMEM) { return (strchr_pointer = strstr_P(CMDBUFFER_CURRENT_STRING, code_PROGMEM)) != NULL; }
  61. static inline float code_value() { return strtod(strchr_pointer+1, NULL);}
  62. static inline long code_value_long() { return strtol(strchr_pointer+1, NULL, 10); }
  63. static inline int16_t code_value_short() { return int16_t(strtol(strchr_pointer+1, NULL, 10)); };
  64. static inline uint8_t code_value_uint8() { return uint8_t(strtol(strchr_pointer+1, NULL, 10)); };
  65. static inline float code_value_float()
  66. {
  67. char* e = strchr(strchr_pointer, 'E');
  68. if (!e) return strtod(strchr_pointer + 1, NULL);
  69. *e = 0;
  70. float ret = strtod(strchr_pointer + 1, NULL);
  71. *e = 'E';
  72. return ret;
  73. }
  74. #endif //CMDQUEUE_H