Bläddra i källkod

Merge pull request #7165 from thinkyhead/bf_parser_shorthand

Use parser.seenval, add shorthand functions
Scott Lahteine 7 år sedan
förälder
incheckning
f4246dc8ff

+ 11
- 11
Marlin/G26_Mesh_Validation_Tool.cpp Visa fil

@@ -638,11 +638,11 @@
638 638
     g26_hotend_temp           = HOTEND_TEMP;
639 639
     g26_prime_flag            = 0;
640 640
 
641
-    g26_ooze_amount           = parser.seen('O') && parser.has_value() ? parser.value_linear_units() : OOZE_AMOUNT;
642
-    g26_keep_heaters_on       = parser.seen('K') && parser.value_bool();
643
-    g26_continue_with_closest = parser.seen('C') && parser.value_bool();
641
+    g26_ooze_amount           = parser.linearval('O', OOZE_AMOUNT);
642
+    g26_keep_heaters_on       = parser.boolval('K');
643
+    g26_continue_with_closest = parser.boolval('C');
644 644
 
645
-    if (parser.seen('B')) {
645
+    if (parser.seenval('B')) {
646 646
       g26_bed_temp = parser.value_celsius();
647 647
       if (!WITHIN(g26_bed_temp, 15, 140)) {
648 648
         SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible.");
@@ -650,7 +650,7 @@
650 650
       }
651 651
     }
652 652
 
653
-    if (parser.seen('L')) {
653
+    if (parser.seenval('L')) {
654 654
       g26_layer_height = parser.value_linear_units();
655 655
       if (!WITHIN(g26_layer_height, 0.0, 2.0)) {
656 656
         SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible.");
@@ -672,7 +672,7 @@
672 672
       }
673 673
     }
674 674
 
675
-    if (parser.seen('S')) {
675
+    if (parser.seenval('S')) {
676 676
       g26_nozzle = parser.value_float();
677 677
       if (!WITHIN(g26_nozzle, 0.1, 1.0)) {
678 678
         SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible.");
@@ -699,7 +699,7 @@
699 699
       }
700 700
     }
701 701
 
702
-    if (parser.seen('F')) {
702
+    if (parser.seenval('F')) {
703 703
       g26_filament_diameter = parser.value_linear_units();
704 704
       if (!WITHIN(g26_filament_diameter, 1.0, 4.0)) {
705 705
         SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible.");
@@ -712,7 +712,7 @@
712 712
 
713 713
     g26_extrusion_multiplier *= g26_filament_diameter * sq(g26_nozzle) / sq(0.3); // Scale up by nozzle size
714 714
 
715
-    if (parser.seen('H')) {
715
+    if (parser.seenval('H')) {
716 716
       g26_hotend_temp = parser.value_celsius();
717 717
       if (!WITHIN(g26_hotend_temp, 165, 280)) {
718 718
         SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible.");
@@ -727,7 +727,7 @@
727 727
     }
728 728
 
729 729
     #if ENABLED(NEWPANEL)
730
-      g26_repeats = parser.seen('R') && parser.has_value() ? parser.value_int() : GRID_MAX_POINTS + 1;
730
+      g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1);
731 731
     #else
732 732
       if (!parser.seen('R')) {
733 733
         SERIAL_PROTOCOLLNPGM("?(R)epeat must be specified when not using an LCD.");
@@ -741,8 +741,8 @@
741 741
       return UBL_ERR;
742 742
     }
743 743
 
744
-    g26_x_pos = parser.seen('X') ? parser.value_linear_units() : current_position[X_AXIS];
745
-    g26_y_pos = parser.seen('Y') ? parser.value_linear_units() : current_position[Y_AXIS];
744
+    g26_x_pos = parser.linearval('X', current_position[X_AXIS]);
745
+    g26_y_pos = parser.linearval('Y', current_position[Y_AXIS]);
746 746
     if (!position_is_reachable_xy(g26_x_pos, g26_y_pos)) {
747 747
       SERIAL_PROTOCOLLNPGM("?Specified X,Y coordinate out of bounds.");
748 748
       return UBL_ERR;

+ 10
- 12
Marlin/M100_Free_Mem_Chk.cpp Visa fil

@@ -189,19 +189,17 @@ void free_memory_pool_report(char * const ptr, const int16_t size) {
189 189
    *  This is useful to check the correctness of the M100 D and the M100 F commands.
190 190
    */
191 191
   void corrupt_free_memory(char *ptr, const uint16_t size) {
192
-    if (parser.seen('C')) {
193
-      ptr += 8;
194
-      const uint16_t near_top = top_of_stack() - ptr - 250, // -250 to avoid interrupt activity that's altered the stack.
195
-                     j = near_top / (size + 1);
196
-
197
-      SERIAL_ECHOLNPGM("Corrupting free memory block.\n");
198
-      for (uint16_t i = 1; i <= size; i++) {
199
-        char * const addr = ptr + i * j;
200
-        *addr = i;
201
-        SERIAL_ECHOPAIR("\nCorrupting address: ", hex_address(addr));
202
-      }
203
-      SERIAL_EOL();
192
+    ptr += 8;
193
+    const uint16_t near_top = top_of_stack() - ptr - 250, // -250 to avoid interrupt activity that's altered the stack.
194
+                   j = near_top / (size + 1);
195
+
196
+    SERIAL_ECHOLNPGM("Corrupting free memory block.\n");
197
+    for (uint16_t i = 1; i <= size; i++) {
198
+      char * const addr = ptr + i * j;
199
+      *addr = i;
200
+      SERIAL_ECHOPAIR("\nCorrupting address: ", hex_address(addr));
204 201
     }
202
+    SERIAL_EOL();
205 203
   }
206 204
 #endif // M100_FREE_MEMORY_CORRUPTOR
207 205
 

+ 202
- 207
Marlin/Marlin_main.cpp
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 1
- 1
Marlin/SdFatStructs.h Visa fil

@@ -523,7 +523,7 @@ struct directoryEntry {
523 523
   uint8_t  reservedNT;
524 524
           /**
525 525
            * The granularity of the seconds part of creationTime is 2 seconds
526
-           * so this field is a count of tenths of a second and its valid
526
+           * so this field is a count of tenths of a second and it's valid
527 527
            * value range is 0-199 inclusive. (WHG note - seems to be hundredths)
528 528
            */
529 529
   uint8_t  creationTimeTenths;

+ 1
- 1
Marlin/example_configurations/K8400/README.md Visa fil

@@ -2,7 +2,7 @@
2 2
 http://www.k8400.eu/
3 3
 
4 4
 Configuration files for the K8400, ported upstream from the official Velleman firmware.
5
-Like it's predecessor, (K8200), the K8400 is a 3Drag clone. There are some minor differences, documented in pins_K8400.h.
5
+Like its predecessor, (K8200), the K8400 is a 3Drag clone. There are some minor differences, documented in pins_K8400.h.
6 6
 
7 7
 Single and dual head configurations provided. Copy the correct Configuration.h and Configuration_adv.h to the /Marlin/ directory.
8 8
 

+ 51
- 26
Marlin/gcode.h Visa fil

@@ -97,6 +97,13 @@ public:
97 97
   // Reset is done before parsing
98 98
   static void reset();
99 99
 
100
+  // Index so that 'X' falls on index 24
101
+  #define PARAM_IND(N)  ((N) >> 3)
102
+  #define PARAM_BIT(N)  ((N) & 0x7)
103
+  #define LETTER_OFF(N) ((N) - 'A' + 1)
104
+  #define LETTER_IND(N) PARAM_IND(LETTER_OFF(N))
105
+  #define LETTER_BIT(N) PARAM_BIT(LETTER_OFF(N))
106
+
100 107
   #if ENABLED(FASTER_GCODE_PARSER)
101 108
 
102 109
     // Set the flag and pointer for a parameter
@@ -105,14 +112,14 @@ public:
105 112
         , const bool debug=false
106 113
       #endif
107 114
     ) {
108
-      const uint8_t ind = c - 'A';
115
+      const uint8_t ind = LETTER_OFF(c);
109 116
       if (ind >= COUNT(param)) return;           // Only A-Z
110
-      SBI(codebits[ind >> 3], ind & 0x7);        // parameter exists
117
+      SBI(codebits[PARAM_IND(ind)], PARAM_BIT(ind));        // parameter exists
111 118
       param[ind] = ptr ? ptr - command_ptr : 0;  // parameter offset or 0
112 119
       #if ENABLED(DEBUG_GCODE_PARSER)
113 120
         if (debug) {
114
-          SERIAL_ECHOPAIR("Set bit ", (int)(ind & 0x7));
115
-          SERIAL_ECHOPAIR(" of index ", (int)(ind >> 3));
121
+          SERIAL_ECHOPAIR("Set bit ", (int)PARAM_BIT(ind));
122
+          SERIAL_ECHOPAIR(" of index ", (int)PARAM_IND(ind));
116 123
           SERIAL_ECHOLNPAIR(" | param = ", hex_address((void*)param[ind]));
117 124
         }
118 125
       #endif
@@ -120,22 +127,28 @@ public:
120 127
 
121 128
     // Code seen bit was set. If not found, value_ptr is unchanged.
122 129
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
130
+    // This is volatile because its side-effects are important
123 131
     static volatile bool seen(const char c) {
124
-      const uint8_t ind = c - 'A';
132
+      const uint8_t ind = LETTER_OFF(c);
125 133
       if (ind >= COUNT(param)) return false; // Only A-Z
126
-      const bool b = TEST(codebits[ind >> 3], ind & 0x7);
134
+      const bool b = TEST(codebits[PARAM_IND(ind)], PARAM_BIT(ind));
127 135
       if (b) value_ptr = command_ptr + param[ind];
128 136
       return b;
129 137
     }
130 138
 
131
-    static volatile bool seen_any() { return codebits[3] || codebits[2] || codebits[1] || codebits[0]; }
139
+    static bool seen_any() { return codebits[3] || codebits[2] || codebits[1] || codebits[0]; }
132 140
 
133
-    #define SEEN_TEST(L) TEST(codebits[(L - 'A') >> 3], (L - 'A') & 0x7)
141
+    #define SEEN_TEST(L) TEST(codebits[LETTER_IND(L)], LETTER_BIT(L))
134 142
 
135
-  #else
143
+    // Seen any axis parameter
144
+    // Optimized by moving 'X' up to index 24
145
+    FORCE_INLINE bool seen_axis() { return codebits[3] || SEEN_TEST('E'); }
146
+
147
+  #else // !FASTER_GCODE_PARSER
136 148
 
137 149
     // Code is found in the string. If not found, value_ptr is unchanged.
138 150
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
151
+    // This is volatile because its side-effects are important
139 152
     static volatile bool seen(const char c) {
140 153
       const char *p = strchr(command_args, c);
141 154
       const bool b = !!p;
@@ -143,25 +156,26 @@ public:
143 156
       return b;
144 157
     }
145 158
 
146
-    static volatile bool seen_any() { return *command_args == '\0'; }
159
+    static bool seen_any() { return *command_args == '\0'; }
147 160
 
148 161
     #define SEEN_TEST(L) !!strchr(command_args, L)
149 162
 
150
-  #endif // FASTER_GCODE_PARSER
163
+    // Seen any axis parameter
164
+    static bool seen_axis() {
165
+      return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
166
+    }
167
+
168
+  #endif // !FASTER_GCODE_PARSER
151 169
 
152 170
   // Populate all fields by parsing a single line of GCode
153 171
   // This uses 54 bytes of SRAM to speed up seen/value
154 172
   static void parse(char * p);
155 173
 
156
-  // Code value pointer was set
174
+  // The code value pointer was set
157 175
   FORCE_INLINE static bool has_value() { return value_ptr != NULL; }
158 176
 
159
-  // Seen and has value
160
-  FORCE_INLINE static bool seenval(const char c) { return seen(c) && has_value(); }
161
-
162
-  static volatile bool seen_axis() {
163
-    return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
164
-  }
177
+  // Seen a parameter with a value
178
+  inline static bool seenval(const char c) { return seen(c) && has_value(); }
165 179
 
166 180
   // Float removes 'E' to prevent scientific notation interpretation
167 181
   inline static float value_float() {
@@ -184,20 +198,20 @@ public:
184 198
   }
185 199
 
186 200
   // Code value as a long or ulong
187
-  inline          static long value_long()  { return value_ptr ? strtol(value_ptr, NULL, 10) : 0L; }
188
-  inline unsigned static long value_ulong() { return value_ptr ? strtoul(value_ptr, NULL, 10) : 0UL; }
201
+  inline static int32_t value_long() { return value_ptr ? strtol(value_ptr, NULL, 10) : 0L; }
202
+  inline static uint32_t value_ulong() { return value_ptr ? strtoul(value_ptr, NULL, 10) : 0UL; }
189 203
 
190 204
   // Code value for use as time
191 205
   FORCE_INLINE static millis_t value_millis() { return value_ulong(); }
192 206
   FORCE_INLINE static millis_t value_millis_from_seconds() { return value_float() * 1000UL; }
193 207
 
194 208
   // Reduce to fewer bits
195
-  FORCE_INLINE static int value_int()    { return (int)value_long(); }
196
-  FORCE_INLINE uint16_t value_ushort()   { return (uint16_t)value_long(); }
197
-  inline static uint8_t value_byte()     { return (uint8_t)(constrain(value_long(), 0, 255)); }
209
+  FORCE_INLINE static int16_t value_int() { return (int16_t)value_long(); }
210
+  FORCE_INLINE static uint16_t value_ushort() { return (uint16_t)value_long(); }
211
+  inline static uint8_t value_byte() { return (uint8_t)constrain(value_long(), 0, 255); }
198 212
 
199 213
   // Bool is true with no value or non-zero
200
-  inline static bool value_bool()        { return !has_value() || value_byte(); }
214
+  inline static bool value_bool() { return !has_value() || value_byte(); }
201 215
 
202 216
   // Units modes: Inches, Fahrenheit, Kelvin
203 217
 
@@ -282,17 +296,28 @@ public:
282 296
       }
283 297
     }
284 298
 
285
-  #else
299
+  #else // !TEMPERATURE_UNITS_SUPPORT
286 300
 
287 301
     FORCE_INLINE static float value_celsius()      { return value_float(); }
288 302
     FORCE_INLINE static float value_celsius_diff() { return value_float(); }
289 303
 
290
-  #endif
304
+  #endif // !TEMPERATURE_UNITS_SUPPORT
291 305
 
292 306
   FORCE_INLINE static float value_feedrate() { return value_linear_units(); }
293 307
 
294 308
   void unknown_command_error();
295 309
 
310
+  // Provide simple value accessors with default option
311
+  FORCE_INLINE static float    floatval(const char c, const float dval=0.0)   { return seenval(c) ? value_float()        : dval; }
312
+  FORCE_INLINE static bool     boolval(const char c, const bool dval=false)   { return seen(c)    ? value_bool()         : dval; }
313
+  FORCE_INLINE static uint8_t  byteval(const char c, const uint8_t dval=0)    { return seenval(c) ? value_byte()         : dval; }
314
+  FORCE_INLINE static int16_t  intval(const char c, const int16_t dval=0)     { return seenval(c) ? value_int()          : dval; }
315
+  FORCE_INLINE static uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort()       : dval; }
316
+  FORCE_INLINE static int32_t  longval(const char c, const int32_t dval=0)    { return seenval(c) ? value_long()         : dval; }
317
+  FORCE_INLINE static uint32_t ulongval(const char c, const uint32_t dval=0)  { return seenval(c) ? value_ulong()        : dval; }
318
+  FORCE_INLINE static float    linearval(const char c, const float dval=0.0)  { return seenval(c) ? value_linear_units() : dval; }
319
+  FORCE_INLINE static float    celsiusval(const char c, const float dval=0.0) { return seenval(c) ? value_celsius()      : dval; }
320
+
296 321
 };
297 322
 
298 323
 extern GCodeParser parser;

+ 1
- 1
Marlin/servo.cpp Visa fil

@@ -95,7 +95,7 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
95 95
   if (SERVO_INDEX(timer, Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) {
96 96
     *OCRnA = *TCNTn + SERVO(timer, Channel[timer]).ticks;
97 97
     if (SERVO(timer, Channel[timer]).Pin.isActive)    // check if activated
98
-      digitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, HIGH); // its an active channel so pulse it high
98
+      digitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, HIGH); // it's an active channel so pulse it high
99 99
   }
100 100
   else {
101 101
     // finished all channels so wait for the refresh period to expire before starting over

+ 11
- 11
Marlin/twibus.h Visa fil

@@ -38,18 +38,18 @@ typedef void (*twiRequestFunc_t)();
38 38
 /**
39 39
  * TWIBUS class
40 40
  *
41
- * This class implements a wrapper around the two wire (I2C) bus, it allows
42
- * Marlin to send and request data from any slave device on the bus. This is
43
- * an experimental feature and it's inner workings as well as public facing
44
- * interface are prune to change in the future.
41
+ * This class implements a wrapper around the two wire (I2C) bus, allowing
42
+ * Marlin to send and request data from any slave device on the bus.
45 43
  *
46
- * The two main consumers of this class are M260 and M261, where M260 allows
47
- * Marlin to send a I2C packet to a device (please be aware that no repeated
48
- * starts are possible), this can be done in caching method by calling multiple
49
- * times M260 B<byte-1 value in base 10> or a one liner M260, have a look at
50
- * the gcode_M260() function for more information. M261 allows Marlin to
51
- * request data from a device, the received data is then relayed into the serial
52
- * line for host interpretation.
44
+ * The two main consumers of this class are M260 and M261. M260 provides a way
45
+ * to send an I2C packet to a device (no repeated starts) by caching up to 32
46
+ * bytes in a buffer and then sending the buffer.
47
+ * M261 requests data from a device. The received data is relayed to serial out
48
+ * for the host to interpret.
49
+ *
50
+ *  For more information see
51
+ *    - http://marlinfw.org/docs/gcode/M260.html 
52
+ *    - http://marlinfw.org/docs/gcode/M261.html 
53 53
  *
54 54
  */
55 55
 class TWIBus {

+ 6
- 6
Marlin/ubl_G29.cpp Visa fil

@@ -314,7 +314,7 @@
314 314
 
315 315
     // Check for commands that require the printer to be homed
316 316
     if (axis_unhomed_error()) {
317
-      const int8_t p_val = parser.seen('P') && parser.has_value() ? parser.value_int() : -1;
317
+      const int8_t p_val = parser.intval('P', -1);
318 318
       if (p_val == 1 || p_val == 2 || p_val == 4 || parser.seen('J'))
319 319
         home_all_axes();
320 320
     }
@@ -492,7 +492,7 @@
492 492
               return;
493 493
             }
494 494
 
495
-            const float height = parser.seen('H') && parser.has_value() ? parser.value_float() : Z_CLEARANCE_BETWEEN_PROBES;
495
+            const float height = parser.floatval('H', Z_CLEARANCE_BETWEEN_PROBES);
496 496
             manually_probe_remaining_mesh(g29_x_pos, g29_y_pos, height, g29_card_thickness, parser.seen('T'));
497 497
 
498 498
             SERIAL_PROTOCOLLNPGM("G29 P2 finished.");
@@ -1094,9 +1094,9 @@
1094 1094
     g29_constant = 0.0;
1095 1095
     g29_repetition_cnt = 0;
1096 1096
 
1097
-    g29_x_flag = parser.seen('X') && parser.has_value();
1097
+    g29_x_flag = parser.seenval('X');
1098 1098
     g29_x_pos = g29_x_flag ? parser.value_float() : current_position[X_AXIS];
1099
-    g29_y_flag = parser.seen('Y') && parser.has_value();
1099
+    g29_y_flag = parser.seenval('Y');
1100 1100
     g29_y_pos = g29_y_flag ? parser.value_float() : current_position[Y_AXIS];
1101 1101
 
1102 1102
     if (parser.seen('R')) {
@@ -1170,7 +1170,7 @@
1170 1170
       g29_constant = parser.value_float();
1171 1171
 
1172 1172
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1173
-      if (parser.seen('F') && parser.has_value()) {
1173
+      if (parser.seenval('F')) {
1174 1174
         const float fh = parser.value_float();
1175 1175
         if (!WITHIN(fh, 0.0, 100.0)) {
1176 1176
           SERIAL_PROTOCOLLNPGM("?(F)ade height for Bed Level Correction not plausible.\n");
@@ -1180,7 +1180,7 @@
1180 1180
       }
1181 1181
     #endif
1182 1182
 
1183
-    g29_map_type = parser.seen('T') && parser.has_value() ? parser.value_int() : 0;
1183
+    g29_map_type = parser.intval('T');
1184 1184
     if (!WITHIN(g29_map_type, 0, 2)) {
1185 1185
       SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1186 1186
       return UBL_ERR;

Laddar…
Avbryt
Spara