Skip to content

Commit d516bd6

Browse files
committed
clean up
1 parent 6724a30 commit d516bd6

File tree

8 files changed

+91
-96
lines changed

8 files changed

+91
-96
lines changed

Marlin/Configuration.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,20 +2405,15 @@
24052405
#endif
24062406

24072407
/**
2408-
* Variable
2408+
* Variables
24092409
*
2410-
* Set a numerical values into L variables:
2410+
* Store values into variables with 'L' commands L100 - L115:
24112411
*
2412-
* The following L-codes can be used:
2413-
*
2414-
* L100 - L115
2415-
*
2416-
* The L variable can take a S, Position (X,Y,Z) or any int8_t number
2417-
* and store it within the L# pointer. Then be recalled in code for data
2418-
* comparison and or value recalls.
2412+
* The L variable can take S, a position (X, Y, Z, etc.) or any int8_t number
2413+
* and store it into an L variable with index 0 - 15.
2414+
* These can be recalled in code for value comparison or usage.
24192415
*/
2420-
#define Variable_Support
2421-
2416+
#define VARIABLE_SUPPORT
24222417

24232418
//=============================================================================
24242419
//============================= LCD and SD support ============================

Marlin/src/MarlinCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
492492
}
493493
#endif
494494

495-
#if HAS_FREEZE_PIN
495+
#if ENABLED(FREEZE_FEATURE)
496496
stepper.frozen = READ(FREEZE_PIN) == FREEZE_STATE;
497497
#endif
498498

Marlin/src/gcode/gcode.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ GcodeSuite gcode;
6969
#include "../feature/fancheck.h"
7070
#endif
7171

72+
#if ENABLED(VARIABLE_SUPPORT)
73+
#include "variables/variables.cpp"
74+
#endif
75+
7276
#include "../MarlinCore.h" // for idle, kill
7377

7478
// Inactivity shutdown
@@ -351,7 +355,6 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
351355

352356
switch (parser.command_letter) {
353357

354-
355358
case 'G': switch (parser.codenum) {
356359

357360
case 0: case 1: // G0: Fast Move, G1: Linear Move
@@ -480,10 +483,6 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
480483
}
481484
break;
482485

483-
#if ENABLED(VARIABLE_SUPPORT)
484-
#include "variables/variables.cpp"
485-
#endif
486-
487486
case 'M': switch (parser.codenum) {
488487

489488
#if HAS_RESUME_CONTINUE
@@ -1121,7 +1120,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
11211120
if (wifi_custom_command(parser.command_ptr)) break;
11221121
#endif
11231122
parser.unknown_command_warning();
1124-
}
1123+
}
11251124

11261125
if (!no_ok) queue.ok_to_send();
11271126

Marlin/src/gcode/gcode.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -357,31 +357,31 @@ class GcodeSuite {
357357
static axis_bits_t axis_relative;
358358

359359
static bool axis_is_relative(const AxisEnum a) {
360-
#if HAS_EXTRUDERS
361-
if (a == E_AXIS) {
362-
if (TEST(axis_relative, E_MODE_REL)) return true;
363-
if (TEST(axis_relative, E_MODE_ABS)) return false;
364-
}
365-
#endif
366-
return TEST(axis_relative, a);
360+
#if HAS_EXTRUDERS
361+
if (a == E_AXIS) {
362+
if (TEST(axis_relative, E_MODE_REL)) return true;
363+
if (TEST(axis_relative, E_MODE_ABS)) return false;
364+
}
365+
#endif
366+
return TEST(axis_relative, a);
367367
}
368368
static void set_relative_mode(const bool rel) {
369-
axis_relative = rel ? (0 LOGICAL_AXIS_GANG(
370-
| _BV(REL_E),
371-
| _BV(REL_X), | _BV(REL_Y), | _BV(REL_Z),
372-
| _BV(REL_I), | _BV(REL_J), | _BV(REL_K),
373-
| _BV(REL_U), | _BV(REL_V), | _BV(REL_W)
369+
axis_relative = rel ? (0 LOGICAL_AXIS_GANG(
370+
| _BV(REL_E),
371+
| _BV(REL_X), | _BV(REL_Y), | _BV(REL_Z),
372+
| _BV(REL_I), | _BV(REL_J), | _BV(REL_K),
373+
| _BV(REL_U), | _BV(REL_V), | _BV(REL_W)
374374
)) : 0;
375375
}
376376
#if HAS_EXTRUDERS
377-
static void set_e_relative() {
378-
CBI(axis_relative, E_MODE_ABS);
379-
SBI(axis_relative, E_MODE_REL);
380-
}
377+
static void set_e_relative() {
378+
CBI(axis_relative, E_MODE_ABS);
379+
SBI(axis_relative, E_MODE_REL);
380+
}
381381
static void set_e_absolute() {
382382
CBI(axis_relative, E_MODE_REL);
383383
SBI(axis_relative, E_MODE_ABS);
384-
}
384+
}
385385
#endif
386386

387387
#if ENABLED(CNC_WORKSPACE_PLANES)
@@ -438,7 +438,6 @@ class GcodeSuite {
438438
process_subcommands_now(keep_leveling ? FPSTR(G28_STR) : TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR)));
439439
}
440440

441-
442441
#if EITHER(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE)
443442
static bool autoreport_paused;
444443
static bool set_autoreport_paused(const bool p) {

Marlin/src/gcode/parser.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ bool GCodeParser::volumetric_enabled;
4141
TempUnit GCodeParser::input_temp_units = TEMPUNIT_C;
4242
#endif
4343

44-
4544
char *GCodeParser::command_ptr,
4645
*GCodeParser::string_arg,
4746
*GCodeParser::value_ptr;
@@ -127,7 +126,6 @@ void GCodeParser::reset() {
127126
//
128127
//#endif
129128

130-
131129
//Enable Math Functions and assigning values to variables in GCode
132130
//#if ENABLED(GCODE_MATH_STRINGS)
133131
//
@@ -170,7 +168,6 @@ void GCodeParser::reset() {
170168
//
171169
//#endif
172170

173-
174171
/**
175172
* Populate the command line state (command_letter, codenum, subcode, and string_arg)
176173
* by parsing a single line of GCode. 58 bytes of SRAM are used to speed up seen/value.
@@ -238,7 +235,9 @@ void GCodeParser::parse(char *p) {
238235
* With Motion Modes enabled any axis letter can come first.
239236
*/
240237
switch (letter) {
241-
case 'G': case 'M': case 'T': case 'L': TERN_(MARLIN_DEV_MODE, case 'D':) {
238+
TERN_(MARLIN_DEV_MODE, case 'D':)
239+
TERN_(VARIABLE_SUPPORT, case 'L':)
240+
case 'G': case 'M': case 'T': {
242241
// Skip spaces to get the numeric part
243242
while (*p == ' ') p++;
244243

@@ -341,13 +340,13 @@ void GCodeParser::parse(char *p) {
341340
default: break;
342341
}
343342

344-
// Only use string_arg for these L variables
345-
if (letter == 'L') switch (codenum) {
346-
TERN_(VARIABLE_SUPPORT, case 100 ... 115:)
347-
var_arg = input_var(p);
348-
return;
349-
default: break;
350-
}
343+
#if ENABLED(VARIABLE_SUPPORT)
344+
// Only use string_arg for these L variables
345+
if (letter == 'L') switch (codenum) {
346+
case 100 ... 115: var_arg = input_var(p); return;
347+
default: break;
348+
}
349+
#endif
351350

352351
#if ENABLED(DEBUG_GCODE_PARSER)
353352
const bool debug = codenum == 800;
@@ -407,25 +406,28 @@ void GCodeParser::parse(char *p) {
407406

408407
while (*p == ' ') p++; // Skip spaces between parameters & values
409408

409+
bool has_val = false;
410+
410411
#if ENABLED(GCODE_QUOTED_STRINGS)
411-
const bool is_str = (*p == '"'), has_val = is_str || valid_float(p);
412+
const bool is_str = (*p == '"');
413+
has_val = is_str || valid_float(p);
412414
char * const valptr = has_val ? is_str ? unescape_string(p) : p : nullptr;
413415
#else
414-
const bool has_val = valid_float(p);
415-
#if ENABLED(FASTER_GCODE_PARSER)
416-
char * const valptr = has_val ? p : nullptr;
417-
#endif
416+
has_val = valid_float(p);
417+
#if ENABLED(FASTER_GCODE_PARSER)
418+
char * const valptr = has_val ? p : nullptr;
419+
#endif
418420
#endif
419421

420-
421422
#if ENABLED(VARIABLE_SUPPORT)
422-
const bool is_var = (*p == 'L'), has_val = is_int || valid_float(p + 1);
423-
char * const varptr = has_val ? is_var ? input_var(p) : p+1 : nullptr;
423+
const bool is_var = (*p == 'L');
424+
has_val = is_int || valid_float(p + 1);
425+
char * const varptr = has_val ? is_var ? input_var(p) : p + 1 : nullptr;
424426
#else
425-
const bool has_val = valid_float(p);
426-
#if ENABLED(FASTER_GCODE_PARSER)
427-
char * const varptr = has_val ? p : nullptr;
428-
#endif
427+
has_val = valid_float(p);
428+
#if ENABLED(FASTER_GCODE_PARSER)
429+
char * const varptr = has_val ? p : nullptr;
430+
#endif
429431
#endif
430432

431433
#if ENABLED(DEBUG_GCODE_PARSER)

Marlin/src/gcode/parser.h

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,17 @@ class GCodeParser {
238238
FORCE_INLINE static char* unescape_string(char* &src) { return src; }
239239
#endif
240240

241-
// #if ENABLED(GCODE_MATHS_STRINGS)
242-
// static char* math_string(char* &src);
243-
// #else
244-
// FORCE_INLINE static char* math_string(char* &src) { return src; }
245-
// #endif
246-
247-
// #if ENABLED(GCODE_LOGIC_STRINGS)
248-
// static char* logic_string(char* &src);
249-
// #else
250-
// FORCE_INLINE static char* logic_string(char* &src) { return src; }
251-
// #endif
241+
//#if ENABLED(GCODE_MATHS_STRINGS)
242+
// static char* math_string(char* &src);
243+
//#else
244+
// FORCE_INLINE static char* math_string(char* &src) { return src; }
245+
//#endif
246+
247+
//#if ENABLED(GCODE_LOGIC_STRINGS)
248+
// static char* logic_string(char* &src);
249+
//#else
250+
// FORCE_INLINE static char* logic_string(char* &src) { return src; }
251+
//#endif
252252

253253
// Populate all fields by parsing a single line of GCode
254254
// This uses 54 bytes of SRAM to speed up seen/value
@@ -273,23 +273,21 @@ class GCodeParser {
273273

274274
// Float removes 'E' to prevent scientific notation interpretation
275275
static float value_float() {
276-
277-
if (!value_ptr) return 0;
278-
char *e = value_ptr;
279-
for (;;) {
280-
const char c = *e;
281-
if (c == '\0' || c == ' ') break;
282-
if (c == 'E' || c == 'e' || c == 'X' || c == 'x') {
283-
*e = '\0';
284-
const float ret = strtof(value_ptr, nullptr);
285-
*e = c;
286-
return ret;
287-
}
288-
++e;
276+
if (!value_ptr) return 0;
277+
char *e = value_ptr;
278+
for (;;) {
279+
const char c = *e;
280+
if (c == '\0' || c == ' ') break;
281+
if (c == 'E' || c == 'e' || c == 'X' || c == 'x') {
282+
*e = '\0';
283+
const float ret = strtof(value_ptr, nullptr);
284+
*e = c;
285+
return ret;
289286
}
290-
return strtof(value_ptr, nullptr);
287+
++e;
291288
}
292-
289+
return strtof(value_ptr, nullptr);
290+
}
293291

294292
// Code value as a long or ulong
295293
static int32_t value_long() { return value_ptr ? strtol(value_ptr, nullptr, 10) : 0L; }

Marlin/src/gcode/variables/variables.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
/**
21+
* variables.cpp
2122
* Copyright (c) 2022 Carlon LaMont
2223
*/
2324

@@ -35,24 +36,24 @@
3536

3637
void GcodeSuite::L.append(100)() {
3738
const uint8_t index = parser.codenum - 100;
38-
#if (parser.seenval(L)) {
39+
if (parser.seenval('L')) {
3940
bool used_var_arg = false;
4041
const int8_t q = parser.value_byte();
41-
*p = parser.string_arg
42-
const bool is_var = (*p == L);
42+
*p = parser.string_arg;
43+
const bool is_var = (*p == 'L');
4344
has_val = is_var || valid_int(p + 1);
44-
char * const varptr = has_val ? is_var ? input_var(p) : p+1:nullptr;
45+
char * const varptr = has_val ? (is_var ? input_var(p) : p + 1) : nullptr;
4546
#if (has_val = nul)
4647
export_val()
47-
#if (has_val = int)
48+
#elif (has_val = int)
4849
import_val()
4950
#else
50-
int bool has_val = valid_int(p);
51-
#if ENABLED(FASTER_GCODE_PARSER)
52-
char * const varptr = has_val ? p : nullptr;
53-
#endif
51+
bool has_val = valid_int(p);
52+
#if ENABLED(FASTER_GCODE_PARSER)
53+
char * const varptr = has_val ? p : nullptr;
54+
#endif
5455
#endif
55-
#endif
56+
}
5657
}
5758

5859
/**

Marlin/src/gcode/variables/variables.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
*/
2121

2222
/**
23-
* e_parser.cpp - Intercept special commands directly in the serial stream
23+
* variables.h
24+
* Copyright (c) 2022 Carlon LaMont
2425
*/
2526

2627
#include "../../inc/MarlinConfigPre.h"

0 commit comments

Comments
 (0)