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