瀏覽代碼

Merge pull request #9327 from thinkyhead/bf2_fix_parser_M118

[2.0.x] Fix parser.has_value, M118 parameters
Scott Lahteine 7 年之前
父節點
當前提交
70e4f12d2f
No account linked to committer's email address

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/include/Wire.h 查看文件

@@ -49,7 +49,7 @@ class TwoWire {
49 49
 
50 50
     uint8_t requestFrom(uint8_t, uint8_t);
51 51
     uint8_t requestFrom(int, int);
52
-    
52
+
53 53
     virtual size_t write(uint8_t);
54 54
     virtual size_t write(const uint8_t *, size_t);
55 55
     virtual int available(void);

+ 4
- 4
Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp 查看文件

@@ -107,7 +107,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
107 107
    SERIAL_PROTOCOLPAIR(" write_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
108 108
    SERIAL_PROTOCOLPAIR(",", (int)value);            // right now to see errors that are happening in the
109 109
    SERIAL_PROTOCOLPAIR(",", (int)size);             // read_data() and write_data() functions
110
-   SERIAL_PROTOCOL("...)\n");
110
+   SERIAL_PROTOCOLLNPGM("...)");
111 111
    SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
112 112
    return s;
113 113
   }
@@ -117,7 +117,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
117 117
    SERIAL_PROTOCOLPAIR(" write_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
118 118
    SERIAL_PROTOCOLPAIR(",", (int)value);            // right now to see errors that are happening in the
119 119
    SERIAL_PROTOCOLPAIR(",", size);             // read_data() and write_data() functions
120
-   SERIAL_PROTOCOLLN("...)");
120
+   SERIAL_PROTOCOLLNPGM("...)");
121 121
    SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s);
122 122
    SERIAL_PROTOCOLPAIR(" size=", size);
123 123
    SERIAL_PROTOCOLLNPAIR("\n bytes_written=", bytes_written);
@@ -136,7 +136,7 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
136 136
    SERIAL_PROTOCOLPAIR(" read_data(", pos);          // This extra chit-chat goes away soon.  But it is helpful
137 137
    SERIAL_PROTOCOLPAIR(",", (int)value);            // right now to see errors that are happening in the
138 138
    SERIAL_PROTOCOLPAIR(",", size);             // read_data() and write_data() functions
139
-   SERIAL_PROTOCOLLN("...)");
139
+   SERIAL_PROTOCOLLNPGM("...)");
140 140
    SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
141 141
    return true;
142 142
   }
@@ -153,7 +153,7 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
153 153
    SERIAL_PROTOCOLPAIR(" read_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
154 154
    SERIAL_PROTOCOLPAIR(",", (int)value);           // right now to see errors that are happening in the
155 155
    SERIAL_PROTOCOLPAIR(",", size);            // read_data() and write_data() functions
156
-   SERIAL_PROTOCOLLN("...)");
156
+   SERIAL_PROTOCOLLNPGM("...)");
157 157
    SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s);
158 158
    SERIAL_PROTOCOLPAIR(" size=", size);
159 159
    SERIAL_PROTOCOLLNPAIR("\n bytes_read=",  bytes_read);

+ 1
- 1
Marlin/src/HAL/HAL_STM32F7/HAL_STM32F7.h 查看文件

@@ -98,7 +98,7 @@
98 98
   #define NUM_SERIAL 1
99 99
 #endif
100 100
 
101
-#define _BV(bit) (1 << (bit))
101
+#define _BV(b) (1UL << (b))
102 102
 
103 103
 /**
104 104
  * TODO: review this to return 1 for pins that are not analog input

+ 1
- 1
Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h 查看文件

@@ -29,7 +29,7 @@
29 29
 #ifndef _FASTIO_STM32F7_H
30 30
 #define _FASTIO_STM32F7_H
31 31
 
32
-#define _BV(bit) (1 << (bit))
32
+#define _BV(b) (1UL << (b))
33 33
 
34 34
 #define READ(IO)              digitalRead(IO)
35 35
 #define WRITE(IO, v)          digitalWrite(IO,v)

+ 2
- 3
Marlin/src/core/macros.h 查看文件

@@ -95,9 +95,8 @@
95 95
 #define STRINGIFY(M) STRINGIFY_(M)
96 96
 
97 97
 // Macros for bit masks
98
-#ifndef _BV
99
-  #define _BV(n)  (1<<(n))
100
-#endif
98
+#undef _BV // Marlin needs 32-bit unsigned!
99
+#define _BV(b) (1UL << (b))
101 100
 #define TEST(n,b) (((n)&_BV(b))!=0)
102 101
 #define SBI(n,b) (n |= _BV(b))
103 102
 #define CBI(n,b) (n &= ~_BV(b))

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp 查看文件

@@ -1095,7 +1095,7 @@
1095 1095
     SERIAL_PROTOCOLLNPAIR("UBL object count: ", (int)ubl_cnt);
1096 1096
 
1097 1097
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1098
-      SERIAL_PROTOCOL("planner.z_fade_height : ");
1098
+      SERIAL_PROTOCOLPGM("planner.z_fade_height : ");
1099 1099
       SERIAL_PROTOCOL_F(planner.z_fade_height, 4);
1100 1100
       SERIAL_EOL();
1101 1101
     #endif

+ 1
- 1
Marlin/src/feature/dac/stepper_dac.cpp 查看文件

@@ -114,7 +114,7 @@ void dac_print_values() {
114 114
   SERIAL_ECHOPAIR(" (",   dac_amps(Z_AXIS));
115 115
   SERIAL_ECHOPAIR(") E:", dac_perc(E_AXIS));
116 116
   SERIAL_ECHOPAIR(" (",   dac_amps(E_AXIS));
117
-  SERIAL_ECHOLN(")");
117
+  SERIAL_ECHOLNPGM(")");
118 118
 }
119 119
 
120 120
 void dac_commit_eeprom() {

+ 1
- 1
Marlin/src/gcode/config/M301.cpp 查看文件

@@ -71,7 +71,7 @@ void GcodeSuite::M301() {
71 71
   }
72 72
   else {
73 73
     SERIAL_ERROR_START();
74
-    SERIAL_ERRORLN(MSG_INVALID_EXTRUDER);
74
+    SERIAL_ERRORLNPGM(MSG_INVALID_EXTRUDER);
75 75
   }
76 76
 }
77 77
 

+ 2
- 2
Marlin/src/gcode/feature/caselight/M355.cpp 查看文件

@@ -56,10 +56,10 @@ void GcodeSuite::M355() {
56 56
     // always report case light status
57 57
     SERIAL_ECHO_START();
58 58
     if (!case_light_on) {
59
-      SERIAL_ECHOLN("Case light: off");
59
+      SERIAL_ECHOLNPGM("Case light: off");
60 60
     }
61 61
     else {
62
-      if (!USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) SERIAL_ECHOLN("Case light: on");
62
+      if (!USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM("Case light: on");
63 63
       else SERIAL_ECHOLNPAIR("Case light: ", case_light_brightness);
64 64
     }
65 65
   #else

+ 1
- 1
Marlin/src/gcode/feature/i2c/M260_M261.cpp 查看文件

@@ -73,7 +73,7 @@ void GcodeSuite::M261() {
73 73
   }
74 74
   else {
75 75
     SERIAL_ERROR_START();
76
-    SERIAL_ERRORLN("Bad i2c request");
76
+    SERIAL_ERRORLNPGM("Bad i2c request");
77 77
   }
78 78
 }
79 79
 

+ 2
- 2
Marlin/src/gcode/host/M118.cpp 查看文件

@@ -29,7 +29,7 @@
29 29
  *  E1  Have the host 'echo:' the text
30 30
  */
31 31
 void GcodeSuite::M118() {
32
-  if (parser.boolval('E')) SERIAL_ECHO_START();
33
-  if (parser.boolval('A')) SERIAL_ECHOPGM("// ");
32
+  if (parser.seenval('E') && parser.value_bool()) SERIAL_ECHO_START();
33
+  if (parser.seenval('A') && parser.value_bool()) SERIAL_ECHOPGM("// ");
34 34
   SERIAL_ECHOLN(parser.string_arg);
35 35
 }

+ 4
- 17
Marlin/src/gcode/parser.cpp 查看文件

@@ -60,7 +60,7 @@ int GCodeParser::codenum;
60 60
 
61 61
 #if ENABLED(FASTER_GCODE_PARSER)
62 62
   // Optimized Parameters
63
-  byte GCodeParser::codebits[4];   // found bits
63
+  uint32_t GCodeParser::codebits;  // found bits
64 64
   uint8_t GCodeParser::param[26];  // parameter offsets from command_ptr
65 65
 #else
66 66
   char *GCodeParser::command_args; // start of parameters
@@ -83,7 +83,7 @@ void GCodeParser::reset() {
83 83
     subcode = 0;                        // No command sub-code
84 84
   #endif
85 85
   #if ENABLED(FASTER_GCODE_PARSER)
86
-    ZERO(codebits);                     // No codes yet
86
+    codebits = 0;                       // No codes yet
87 87
     //ZERO(param);                      // No parameters (should be safe to comment out this line)
88 88
   #endif
89 89
 }
@@ -196,14 +196,7 @@ void GCodeParser::parse(char *p) {
196 196
 
197 197
       while (*p == ' ') p++;                    // Skip spaces between parameters & values
198 198
 
199
-      const bool has_num = NUMERIC(p[0])                            // [0-9]
200
-                        || (p[0] == '.' && NUMERIC(p[1]))           // .[0-9]
201
-                        || (
202
-                              (p[0] == '-' || p[0] == '+') && (     // [-+]
203
-                                NUMERIC(p[1])                       //     [0-9]
204
-                                || (p[1] == '.' && NUMERIC(p[2]))   //     .[0-9]
205
-                              )
206
-                            );
199
+      const bool has_num = valid_float(p);
207 200
 
208 201
       #if ENABLED(DEBUG_GCODE_PARSER)
209 202
         if (debug) {
@@ -225,13 +218,7 @@ void GCodeParser::parse(char *p) {
225 218
       #endif
226 219
 
227 220
       #if ENABLED(FASTER_GCODE_PARSER)
228
-      {
229
-        set(code, has_num ? p : NULL            // Set parameter exists and pointer (NULL for no number)
230
-          #if ENABLED(DEBUG_GCODE_PARSER)
231
-            , debug
232
-          #endif
233
-        );
234
-      }
221
+        set(code, has_num ? p : NULL);          // Set parameter exists and pointer (NULL for no number)
235 222
       #endif
236 223
     }
237 224
     else if (!string_arg) {                     // Not A-Z? First time, keep as the string_arg

+ 42
- 36
Marlin/src/gcode/parser.h 查看文件

@@ -51,7 +51,7 @@ private:
51 51
   static char *value_ptr;           // Set by seen, used to fetch the value
52 52
 
53 53
   #if ENABLED(FASTER_GCODE_PARSER)
54
-    static byte codebits[4];        // Parameters pre-scanned
54
+    static uint32_t codebits;       // Parameters pre-scanned
55 55
     static uint8_t param[26];       // For A-Z, offsets into command args
56 56
   #else
57 57
     static char *command_args;      // Args start here, for slow scan
@@ -88,30 +88,34 @@ public:
88 88
   // Reset is done before parsing
89 89
   static void reset();
90 90
 
91
-  // Index so that 'X' falls on index 24
92
-  #define PARAM_IND(N)  ((N) >> 3)
93
-  #define PARAM_BIT(N)  ((N) & 0x7)
94
-  #define LETTER_OFF(N) ((N) - 'A')
95
-  #define LETTER_IND(N) PARAM_IND(LETTER_OFF(N))
96
-  #define LETTER_BIT(N) PARAM_BIT(LETTER_OFF(N))
91
+  #define LETTER_BIT(N) ((N) - 'A')
97 92
 
98 93
   #if ENABLED(FASTER_GCODE_PARSER)
99 94
 
95
+    FORCE_INLINE static bool valid_signless(const char * const p) {
96
+      return NUMERIC(p[0]) || (p[0] == '.' && NUMERIC(p[1])); // .?[0-9]
97
+    }
98
+
99
+    FORCE_INLINE static bool valid_float(const char * const p) {
100
+      return valid_signless(p) || ((p[0] == '-' || p[0] == '+') && valid_signless(&p[1])); // [-+]?.?[0-9]
101
+    }
102
+
103
+    FORCE_INLINE static bool valid_int(const char * const p) {
104
+      return NUMERIC(p[0]) || ((p[0] == '-' || p[0] == '+') && NUMERIC(p[1])); // [-+]?[0-9]
105
+    }
106
+
100 107
     // Set the flag and pointer for a parameter
101
-    static void set(const char c, char * const ptr
102
-      #if ENABLED(DEBUG_GCODE_PARSER)
103
-        , const bool debug=false
104
-      #endif
105
-    ) {
106
-      const uint8_t ind = LETTER_OFF(c);
108
+    static void set(const char c, char * const ptr) {
109
+      const uint8_t ind = LETTER_BIT(c);
107 110
       if (ind >= COUNT(param)) return;           // Only A-Z
108
-      SBI(codebits[PARAM_IND(ind)], PARAM_BIT(ind));        // parameter exists
111
+      SBI(codebits, ind);                        // parameter exists
109 112
       param[ind] = ptr ? ptr - command_ptr : 0;  // parameter offset or 0
110 113
       #if ENABLED(DEBUG_GCODE_PARSER)
111
-        if (debug) {
112
-          SERIAL_ECHOPAIR("Set bit ", (int)PARAM_BIT(ind));
113
-          SERIAL_ECHOPAIR(" of index ", (int)PARAM_IND(ind));
114
-          SERIAL_ECHOLNPAIR(" | param = ", (int)param[ind]);
114
+        if (codenum == 800) {
115
+          SERIAL_ECHOPAIR("Set bit ", (int)ind);
116
+          SERIAL_ECHOPAIR(" of codebits (", hex_address((void*)(codebits >> 16)));
117
+          print_hex_word((uint16_t)(codebits & 0xFFFF));
118
+          SERIAL_ECHOLNPAIR(") | param = ", (int)param[ind]);
115 119
         }
116 120
       #endif
117 121
     }
@@ -119,25 +123,28 @@ public:
119 123
     // Code seen bit was set. If not found, value_ptr is unchanged.
120 124
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
121 125
     static bool seen(const char c) {
122
-      const uint8_t ind = LETTER_OFF(c);
126
+      const uint8_t ind = LETTER_BIT(c);
123 127
       if (ind >= COUNT(param)) return false; // Only A-Z
124
-      const bool b = TEST(codebits[PARAM_IND(ind)], PARAM_BIT(ind));
125
-      if (b) value_ptr = param[ind] ? command_ptr + param[ind] : (char*)NULL;
128
+      const bool b = TEST(codebits, ind);
129
+      if (b) {
130
+        char * const ptr = command_ptr + param[ind];
131
+        value_ptr = param[ind] && valid_float(ptr) ? ptr : (char*)NULL;
132
+      }
126 133
       return b;
127 134
     }
128 135
 
129
-    static bool seen_any() { return codebits[3] || codebits[2] || codebits[1] || codebits[0]; }
136
+    static bool seen_any() { return !!codebits; }
130 137
 
131
-    #define SEEN_TEST(L) TEST(codebits[LETTER_IND(L)], LETTER_BIT(L))
138
+    #define SEEN_TEST(L) TEST(codebits, LETTER_BIT(L))
132 139
 
133 140
   #else // !FASTER_GCODE_PARSER
134 141
 
135 142
     // Code is found in the string. If not found, value_ptr is unchanged.
136 143
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
137 144
     static bool seen(const char c) {
138
-      char *p = strchr(command_args, c);
145
+      const char *p = strchr(command_args, c);
139 146
       const bool b = !!p;
140
-      if (b) value_ptr = DECIMAL_SIGNED(p[1]) ? &p[1] : (char*)NULL;
147
+      if (b) value_ptr = valid_float(&p[1]) ? &p[1] : (char*)NULL;
141 148
       return b;
142 149
     }
143 150
 
@@ -201,7 +208,7 @@ public:
201 208
   inline static uint8_t value_byte() { return (uint8_t)constrain(value_long(), 0, 255); }
202 209
 
203 210
   // Bool is true with no value or non-zero
204
-  inline static bool value_bool() { return !has_value() || value_byte(); }
211
+  inline static bool value_bool() { return !has_value() || !!value_byte(); }
205 212
 
206 213
   // Units modes: Inches, Fahrenheit, Kelvin
207 214
 
@@ -298,16 +305,15 @@ public:
298 305
   void unknown_command_error();
299 306
 
300 307
   // Provide simple value accessors with default option
301
-  FORCE_INLINE static float       floatval(const char c, const float dval=0.0)   { return seenval(c) ? value_float()        : dval; }
302
-  FORCE_INLINE static bool        boolval(const char c)                          { return seenval(c) ? value_bool()         : seen(c); }
303
-  FORCE_INLINE static uint8_t     byteval(const char c, const uint8_t dval=0)    { return seenval(c) ? value_byte()         : dval; }
304
-  FORCE_INLINE static int16_t     intval(const char c, const int16_t dval=0)     { return seenval(c) ? value_int()          : dval; }
305
-  FORCE_INLINE static uint16_t    ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort()       : dval; }
306
-  FORCE_INLINE static int32_t     longval(const char c, const int32_t dval=0)    { return seenval(c) ? value_long()         : dval; }
307
-  FORCE_INLINE static uint32_t    ulongval(const char c, const uint32_t dval=0)  { return seenval(c) ? value_ulong()        : dval; }
308
-  FORCE_INLINE static float       linearval(const char c, const float dval=0.0)  { return seenval(c) ? value_linear_units() : dval; }
309
-  FORCE_INLINE static float       celsiusval(const char c, const float dval=0.0) { return seenval(c) ? value_celsius()      : dval; }
310
-  FORCE_INLINE static const char* strval(const char c)                           { return seenval(c) ? value_ptr            : NULL; }
308
+  FORCE_INLINE static float    floatval(const char c, const float dval=0.0)   { return seenval(c) ? value_float()        : dval; }
309
+  FORCE_INLINE static bool     boolval(const char c)                          { return seenval(c) ? value_bool()         : seen(c); }
310
+  FORCE_INLINE static uint8_t  byteval(const char c, const uint8_t dval=0)    { return seenval(c) ? value_byte()         : dval; }
311
+  FORCE_INLINE static int16_t  intval(const char c, const int16_t dval=0)     { return seenval(c) ? value_int()          : dval; }
312
+  FORCE_INLINE static uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort()       : dval; }
313
+  FORCE_INLINE static int32_t  longval(const char c, const int32_t dval=0)    { return seenval(c) ? value_long()         : dval; }
314
+  FORCE_INLINE static uint32_t ulongval(const char c, const uint32_t dval=0)  { return seenval(c) ? value_ulong()        : dval; }
315
+  FORCE_INLINE static float    linearval(const char c, const float dval=0.0)  { return seenval(c) ? value_linear_units() : dval; }
316
+  FORCE_INLINE static float    celsiusval(const char c, const float dval=0.0) { return seenval(c) ? value_celsius()      : dval; }
311 317
 
312 318
 };
313 319
 

+ 2
- 2
Marlin/src/module/configuration_store.cpp 查看文件

@@ -1502,7 +1502,7 @@ void MarlinSettings::postprocess() {
1502 1502
         HAL::PersistentStore::access_finish();
1503 1503
 
1504 1504
         if (status)
1505
-          SERIAL_PROTOCOL("?Unable to save mesh data.\n");
1505
+          SERIAL_PROTOCOLPGM("?Unable to save mesh data.\n");
1506 1506
 
1507 1507
         // Write crc to MAT along with other data, or just tack on to the beginning or end
1508 1508
 
@@ -1540,7 +1540,7 @@ void MarlinSettings::postprocess() {
1540 1540
         HAL::PersistentStore::access_finish();
1541 1541
 
1542 1542
         if (status)
1543
-          SERIAL_PROTOCOL("?Unable to load mesh data.\n");
1543
+          SERIAL_PROTOCOLPGM("?Unable to load mesh data.\n");
1544 1544
 
1545 1545
         #if ENABLED(EEPROM_CHITCHAT)
1546 1546
           else

+ 2
- 2
Marlin/src/module/temperature.cpp 查看文件

@@ -266,11 +266,11 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
266 266
     #endif
267 267
 
268 268
     if (!WITHIN(hotend, _BOT_HOTEND, _TOP_HOTEND)) {
269
-      SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
269
+      SERIAL_ECHOLNPGM(MSG_PID_BAD_EXTRUDER_NUM);
270 270
       return;
271 271
     }
272 272
 
273
-    SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);
273
+    SERIAL_ECHOLNPGM(MSG_PID_AUTOTUNE_START);
274 274
 
275 275
     disable_all_heaters(); // switch off all heaters.
276 276
 

+ 1
- 1
Marlin/src/module/tool_change.cpp 查看文件

@@ -123,7 +123,7 @@ inline void invalid_extruder_error(const uint8_t e) {
123 123
   SERIAL_CHAR('T');
124 124
   SERIAL_ECHO_F(e, DEC);
125 125
   SERIAL_CHAR(' ');
126
-  SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
126
+  SERIAL_ECHOLNPGM(MSG_INVALID_EXTRUDER);
127 127
 }
128 128
 
129 129
 /**

+ 1
- 1
Marlin/src/sd/cardreader.cpp 查看文件

@@ -364,7 +364,7 @@ void CardReader::openFile(char* name, const bool read, const bool subcall/*=fals
364 364
       if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) {
365 365
         SERIAL_ERROR_START();
366 366
         SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:");
367
-        SERIAL_ERRORLN(SD_PROCEDURE_DEPTH);
367
+        SERIAL_ERRORLN((int)SD_PROCEDURE_DEPTH);
368 368
         kill(PSTR(MSG_KILLED));
369 369
         return;
370 370
       }

Loading…
取消
儲存