cmdqueue.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef CMDQUEUE_H
  2. #define CMDQUEUE_H
  3. #include "Marlin.h"
  4. #include "language_all.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. // How much space to reserve for the chained commands
  19. // of type CMDBUFFER_CURRENT_TYPE_CHAINED,
  20. // which are pushed to the front of the queue?
  21. // Maximum 5 commands of max length 20 + null terminator.
  22. #define CMDBUFFER_RESERVE_FRONT (5*21)
  23. extern char cmdbuffer[BUFSIZE * (MAX_CMD_SIZE + 1) + CMDBUFFER_RESERVE_FRONT];
  24. extern int bufindr;
  25. extern int bufindw;
  26. extern int buflen;
  27. extern bool cmdbuffer_front_already_processed;
  28. // Type of a command, which is to be executed right now.
  29. #define CMDBUFFER_CURRENT_TYPE (cmdbuffer[bufindr])
  30. // String of a command, which is to be executed right now.
  31. #define CMDBUFFER_CURRENT_STRING (cmdbuffer+bufindr+CMDHDRSIZE)
  32. // Enable debugging of the command buffer.
  33. // Debugging information will be sent to serial line.
  34. //#define CMDBUFFER_DEBUG
  35. extern int serial_count;
  36. extern boolean comment_mode;
  37. extern char *strchr_pointer;
  38. extern unsigned long TimeSent;
  39. extern unsigned long TimeNow;
  40. extern long gcode_N;
  41. extern long gcode_LastN;
  42. extern long Stopped_gcode_LastN;
  43. extern bool cmdqueue_pop_front();
  44. extern void cmdqueue_reset();
  45. extern bool cmdqueue_could_enqueue_front(int len_asked);
  46. extern bool cmdqueue_could_enqueue_back(int len_asked, bool atomic_update = false);
  47. #ifdef CMDBUFFER_DEBUG
  48. extern void cmdqueue_dump_to_serial_single_line(int nr, const char *p);
  49. extern void cmdqueue_dump_to_serial();
  50. #endif /* CMDBUFFER_DEBUG */
  51. extern bool cmd_buffer_empty();
  52. extern void enquecommand(const char *cmd, bool from_progmem);
  53. extern void enquecommand_front(const char *cmd, bool from_progmem);
  54. extern void repeatcommand_front();
  55. extern bool is_buffer_empty();
  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(const char *code) { return (strchr_pointer = strstr(CMDBUFFER_CURRENT_STRING, code)) != 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