Prusa MINI Firmware overview
|
Go to the documentation of this file.
30 #include "../inc/MarlinConfig.h"
33 #if ENABLED(DEBUG_GCODE_PARSER)
34 #include "../libs/hex_print_routines.h"
37 #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
38 typedef enum :
uint8_t { TEMPUNIT_C, TEMPUNIT_K, TEMPUNIT_F } TempUnit;
41 #if ENABLED(INCH_MODE_SUPPORT)
42 typedef enum :
uint8_t { LINEARUNIT_MM, LINEARUNIT_INCH } LinearUnit;
60 static char *value_ptr;
62 #if ENABLED(FASTER_GCODE_PARSER)
63 static uint32_t codebits;
66 static char *command_args;
75 #if ENABLED(INCH_MODE_SUPPORT)
76 static float linear_unit_factor, volumetric_unit_factor;
79 #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
80 static TempUnit input_temp_units;
88 #if USE_GCODE_SUBCODES
92 #if ENABLED(GCODE_MOTION_MODES)
93 static int16_t motion_mode_codenum;
94 #if USE_GCODE_SUBCODES
95 static uint8_t motion_mode_subcode;
97 FORCE_INLINE static void cancel_motion_mode() { motion_mode_codenum = -1; }
100 #if ENABLED(DEBUG_GCODE_PARSER)
107 #define LETTER_BIT(N) ((N) - 'A')
117 #if ENABLED(FASTER_GCODE_PARSER)
119 FORCE_INLINE static bool valid_int(
const char *
const p) {
120 return NUMERIC(p[0]) || ((p[0] ==
'-' || p[0] ==
'+') &&
NUMERIC(p[1]));
124 static inline void set(
const char c,
char *
const ptr) {
126 if (ind >=
COUNT(param))
return;
127 SBI32(codebits, ind);
129 #if ENABLED(DEBUG_GCODE_PARSER)
140 static inline bool seen(
const char c) {
142 if (ind >=
COUNT(param))
return false;
143 const bool b =
TEST32(codebits, ind);
146 value_ptr = param[ind] &&
valid_float(ptr) ? ptr :
nullptr;
151 FORCE_INLINE static constexpr uint32_t letter_bits(
const char *
const str) {
162 : 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0);
167 FORCE_INLINE static bool seen(
const char *
const str) {
return !!(codebits & letter_bits(str)); }
171 const uint32_t letrbits = letter_bits(str);
174 return (cb[0] & lb[0]) || (cb[1] & lb[1]) || (cb[2] & lb[2]) || (cb[3] & lb[3]);
178 static inline bool seen_any() {
return !!codebits; }
180 #define SEEN_TEST(L) TEST32(codebits, LETTER_BIT(L))
182 #else // !FASTER_GCODE_PARSER
186 static inline bool seen(
const char c) {
187 char *p = strchr(command_args, c);
189 if (
b) value_ptr =
valid_float(&p[1]) ? &p[1] :
nullptr;
193 static inline bool seen_any() {
return *command_args ==
'\0'; }
195 #define SEEN_TEST(L) !!strchr(command_args, L)
198 static inline bool seen(
const char *
const str) {
199 for (
uint8_t i = 0;
const char c = str[
i];
i++)
204 #endif // !FASTER_GCODE_PARSER
213 static void parse(
char * p);
215 #if ENABLED(CNC_COORDINATE_SYSTEMS)
232 if (c ==
'\0' || c ==
' ')
break;
233 if (c ==
'E' || c ==
'e') {
235 const float ret =
strtof(value_ptr,
nullptr);
241 return strtof(value_ptr,
nullptr);
247 static inline int32_t
value_long() {
return value_ptr ? strtol(value_ptr,
nullptr, 10) : 0
L; }
248 static inline uint32_t
value_ulong() {
return value_ptr ? strtoul(value_ptr,
nullptr, 10) : 0UL; }
264 #if ENABLED(INCH_MODE_SUPPORT)
265 static inline float mm_to_linear_unit(
const float mm) {
return mm / linear_unit_factor; }
269 GCodeParser() { set_input_linear_units(LINEARUNIT_MM); }
271 static inline void set_input_linear_units(
const LinearUnit units) {
274 case LINEARUNIT_MM: linear_unit_factor = 1.0f;
break;
275 case LINEARUNIT_INCH: linear_unit_factor = 25.4f;
break;
277 volumetric_unit_factor =
POW(linear_unit_factor, 3);
280 static inline float axis_unit_factor(
const AxisEnum axis) {
284 static inline float linear_value_to_mm(
const float v) {
return v * linear_unit_factor; }
286 static inline float per_axis_value(
const AxisEnum axis,
const float v) {
return v / axis_unit_factor(axis); }
299 #define LINEAR_UNIT(V) parser.mm_to_linear_unit(V)
300 #define VOLUMETRIC_UNIT(V) parser.mm_to_volumetric_unit(V)
306 #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
308 static inline void set_input_temp_units(
const TempUnit units) { input_temp_units = units; }
310 #if HAS_LCD_MENU && DISABLED(DISABLE_M503)
312 static inline char temp_units_code() {
313 return input_temp_units == TEMPUNIT_K ?
'K' : input_temp_units == TEMPUNIT_F ?
'F' :
'C';
315 static inline PGM_P temp_units_name() {
316 return input_temp_units == TEMPUNIT_K ?
PSTR(
"Kelvin") : input_temp_units == TEMPUNIT_F ?
PSTR(
"Fahrenheit") :
PSTR(
"Celsius");
318 static inline float to_temp_units(
const float &f) {
319 switch (input_temp_units) {
321 return f * 0.5555555556f + 32;
330 #endif // HAS_LCD_MENU && !DISABLE_M503
334 switch (input_temp_units) {
336 return (f - 32) * 0.5555555556f;
346 switch (input_temp_units) {
356 #define TEMP_UNIT(N) parser.to_temp_units(N)
358 #else // !TEMPERATURE_UNITS_SUPPORT
363 #define TEMP_UNIT(N) (N)
365 #endif // !TEMPERATURE_UNITS_SUPPORT
#define WITHIN(N, L, H)
Definition: macros.h:195
static int16_t value_int()
Definition: parser.h:255
T z
Definition: types.h:286
static bool seen(const char *const str)
Definition: parser.h:198
static char command_letter
Definition: parser.h:84
#define SERIAL_CHAR(x)
Definition: serial.h:69
#define NOLESS(v, n)
Definition: macros.h:127
T a
Definition: types.h:186
#define _BV32(b)
Definition: macros.h:92
#define sq(x)
Definition: wiring_constants.h:83
static void synchronize()
Definition: planner.cpp:1556
#define ATAN2(y, x)
Definition: macros.h:279
GCodeParser parser
Definition: createSpeedLookupTable.py:14
#define MSG_Z_MOVE_COMP
Definition: language.h:180
#define SERIAL_ECHO(x)
Definition: serial.h:70
#define NUMERIC(a)
Definition: macros.h:196
#define MSG_ERR_ARC_ARGS
Definition: language.h:207
static float linearval(const char c, const float dval=0)
Definition: parser.h:379
constexpr xyz_pos_t probe_offset
Definition: probe.h:58
static float per_axis_value(const AxisEnum, const float v)
Definition: parser.h:295
static float value_celsius_diff()
Definition: parser.h:361
list gcode
Definition: g29_auto.py:44
static bool volumetric_enabled
Definition: parser.h:73
static void parse(char *p)
Definition: parser.cpp:97
static FORCE_INLINE bool valid_signless(const char *const p)
Definition: parser.h:109
static float floatval(const char c, const float dval=0.0)
Definition: parser.h:372
#define SERIAL_ECHOPAIR(V...)
Definition: serial.h:114
#define PGM_P
Definition: pgmspace.h:30
T e
Definition: types.h:383
#define SEEN_TEST(L)
Definition: parser.h:195
static int32_t value_long()
Definition: parser.h:247
uint8_t i
Definition: screen_test_graph.c:72
AxisEnum
Definition: types.h:36
xyze_pos_t destination
Definition: motion.cpp:110
uint32_t millis(void)
Definition: wiring_time.c:29
static bool seenval(const char c)
Definition: parser.h:224
void unknown_command_error()
Definition: parser.cpp:327
static float linear_value_to_mm(const float v)
Definition: parser.h:293
static uint8_t byteval(const char c, const uint8_t dval=0)
Definition: parser.h:374
static void manage_heater() _O2
Definition: temperature.cpp:975
#define SERIAL_ECHO_START()
Definition: serial.h:179
float feedRate_t
Definition: types.h:80
#define strtof
Definition: HAL.h:374
static float value_per_axis_units(const AxisEnum axis)
Definition: parser.h:304
bool IsRunning()
Definition: Marlin.h:331
#define LETTER_BIT(N)
Definition: parser.h:107
static float value_axis_units(const AxisEnum axis)
Definition: parser.h:303
#define BS_TODO_AXIS(A)
Definition: babystep.h:29
#define POW(x, y)
Definition: macros.h:280
static bool seen_axis()
Definition: parser.h:207
#define ABS(a)
Definition: macros.h:266
static FORCE_INLINE bool valid_float(const char *const p)
Definition: parser.h:113
static uint32_t ulongval(const char c, const uint32_t dval=0)
Definition: parser.h:378
static int codenum
Definition: parser.h:87
static bool boolval(const char c, const bool dval=false)
Definition: parser.h:373
void cubic_b_spline(const xyze_pos_t &position, const xyze_pos_t &target, const xy_pos_t(&offsets)[2], const feedRate_t &scaled_fr_mm_s, const uint8_t extruder)
T b
Definition: types.h:186
#define FORCE_INLINE
Definition: macros.h:40
#define RADIANS(d)
Definition: macros.h:98
#define PSTR(str)
Definition: pgmspace.h:31
static feedRate_t value_feedrate()
Definition: parser.h:367
xyze_pos_t current_position
Definition: motion.cpp:102
static FORCE_INLINE bool has_value()
Definition: parser.h:221
FI T magnitude() const
Definition: types.h:192
#define COUNT(a)
Definition: macros.h:200
static void dwell(millis_t time)
Definition: gcode.cpp:149
#define FLOOR(x)
Definition: macros.h:284
void sync_plan_position_e()
Definition: motion.cpp:221
#define CEIL(x)
Definition: macros.h:283
#define SBI32(n, b)
Definition: macros.h:94
static uint8_t subcode
Definition: parser.h:89
static float value_float()
Definition: parser.h:227
#define constrain(amt, low, high)
Definition: wiring_constants.h:79
static void reset()
Definition: parser.cpp:82
#define SERIAL_ECHOPGM(S)
Definition: serial.h:173
static int32_t longval(const char c, const int32_t dval=0)
Definition: parser.h:377
static bool buffer_line(const float &rx, const float &ry, const float &rz, const float &e, const feedRate_t &fr_mm_s, const uint8_t extruder, const float millimeters=0.0)
Definition: planner.cpp:2663
feedRate_t feedrate_mm_s
Definition: motion.cpp:138
static millis_t value_millis()
Definition: parser.h:251
static uint32_t value_ulong()
Definition: parser.h:248
#define SERIAL_ECHOLNPAIR(V...)
Definition: serial.h:144
list a
Definition: createSpeedLookupTable.py:29
#define L(CODE)
Definition: macros.h:76
#define MOTION_CONDITIONS
Definition: motion.h:233
#define MSG_Z
Definition: language.h:321
#define SQRT(x)
Definition: macros.h:281
static int16_t intval(const char c, const int16_t dval=0)
Definition: parser.h:375
T x
Definition: types.h:185
#define ELAPSED(NOW, SOON)
Definition: millis_t.h:29
static millis_t value_millis_from_seconds()
Definition: parser.h:252
const uint8_t[]
Definition: 404_html.c:3
#define MSG_UNKNOWN_COMMAND
Definition: language.h:182
static float z_offset
Definition: mesh_bed_leveling.h:43
bool axis_unhomed_error(uint8_t axis_bits)
Definition: motion.cpp:1054
static void get_destination_from_command()
Definition: gcode.cpp:115
static char * string_arg
Definition: parser.h:84
#define HYPOT(x, y)
Definition: macros.h:287
#define _BV(bit)
Definition: wiring_constants.h:99
#define NUMERIC_SIGNED(a)
Definition: macros.h:198
static float value_celsius()
Definition: parser.h:360
static float celsiusval(const char c, const float dval=0)
Definition: parser.h:380
static bool value_bool()
Definition: parser.h:260
#define IS_SCARA
Definition: Conditionals_LCD.h:544
#define SERIAL_ERROR_MSG(S)
Definition: serial.h:184
#define TEST32(n, b)
Definition: macros.h:93
#define DECIMAL_SIGNED(a)
Definition: macros.h:199
constexpr xyz_pos_t hotend_offset[1]
Definition: motion.h:136
void prepare_move_to_destination()
Definition: motion.cpp:984
static bool seen(const char c)
Definition: parser.h:186
static float value_linear_units()
Definition: parser.h:302
static uint16_t ushortval(const char c, const uint16_t dval=0)
Definition: parser.h:376
static char * command_ptr
Definition: parser.h:84
void apply_motion_limits(xyz_pos_t &target)
Definition: motion.cpp:589
#define MSG_PROBE_OFFSET
Definition: language.h:200
static FORCE_INLINE void reset_stepper_timeout()
Definition: gcode.h:330
static float mm_to_linear_unit(const float mm)
Definition: parser.h:290
void print_hex_word(const uint16_t w)
Definition: hex_print_routines.cpp:78
#define SERIAL_EOL()
Definition: serial.h:181
static void add_mm(const AxisEnum axis, const float &mm)
#define MMM_TO_MMS(MM_M)
Definition: types.h:83
T y
Definition: types.h:185
static float axis_value_to_mm(const AxisEnum, const float v)
Definition: parser.h:294
char * hex_address(const void *const w)
Definition: hex_print_routines.cpp:67
bool relative_mode
Definition: motion.cpp:94
Definition: inftrees.h:24
static uint16_t value_ushort()
Definition: parser.h:256
const xyze_char_t axis_codes
Definition: types.h:486
#define SERIAL_ECHOLNPGM(S)
Definition: serial.h:174
static void apply_leveling(xyz_pos_t &raw)
Definition: planner.cpp:1381
list b
Definition: createSpeedLookupTable.py:30
#define MMS_SCALED(V)
Definition: types.h:85
void idle()
Definition: Marlin.cpp:629
static uint8_t value_byte()
Definition: parser.h:257
Temperature thermalManager
Definition: temperature.cpp:89
#define UNUSED(X)
Definition: stm32f4xx_hal_def.h:74
static bool seen_any()
Definition: parser.h:193
static float mm_to_volumetric_unit(const float mm)
Definition: parser.h:291
uint32_t millis_t
Definition: millis_t.h:26
GCodeParser parser
Definition: parser.cpp:74
constexpr uint8_t active_extruder
Definition: motion.h:107
#define ENABLED(V...)
Definition: macros.h:177
Planner planner
Definition: planner.cpp:111
#define MSG_ERR_BAD_PLANE_MODE
Definition: language.h:205
parser
Definition: createSpeedLookupTable.py:14