瀏覽代碼

Support for Debug Codes - Dnnn (#19225)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Victor Oliveira 4 年之前
父節點
當前提交
631457ffea

+ 2
- 0
Marlin/src/HAL/AVR/HAL.h 查看文件

120
 inline void HAL_clear_reset_source() { MCUSR = 0; }
120
 inline void HAL_clear_reset_source() { MCUSR = 0; }
121
 inline uint8_t HAL_get_reset_source() { return MCUSR; }
121
 inline uint8_t HAL_get_reset_source() { return MCUSR; }
122
 
122
 
123
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
124
+
123
 #pragma GCC diagnostic push
125
 #pragma GCC diagnostic push
124
 #pragma GCC diagnostic ignored "-Wunused-function"
126
 #pragma GCC diagnostic ignored "-Wunused-function"
125
 extern "C" {
127
 extern "C" {

+ 2
- 0
Marlin/src/HAL/DUE/HAL.h 查看文件

105
 void HAL_clear_reset_source();  // clear reset reason
105
 void HAL_clear_reset_source();  // clear reset reason
106
 uint8_t HAL_get_reset_source(); // get reset reason
106
 uint8_t HAL_get_reset_source(); // get reset reason
107
 
107
 
108
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
109
+
108
 //
110
 //
109
 // ADC
111
 // ADC
110
 //
112
 //

+ 2
- 0
Marlin/src/HAL/ESP32/HAL.h 查看文件

96
 // reset reason
96
 // reset reason
97
 uint8_t HAL_get_reset_source();
97
 uint8_t HAL_get_reset_source();
98
 
98
 
99
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
100
+
99
 void _delay_ms(int delay);
101
 void _delay_ms(int delay);
100
 
102
 
101
 #pragma GCC diagnostic push
103
 #pragma GCC diagnostic push

+ 2
- 0
Marlin/src/HAL/LINUX/HAL.h 查看文件

101
 inline void HAL_clear_reset_source(void) {}
101
 inline void HAL_clear_reset_source(void) {}
102
 inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
102
 inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
103
 
103
 
104
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
105
+
104
 /* ---------------- Delay in cycles */
106
 /* ---------------- Delay in cycles */
105
 FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {
107
 FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {
106
   Clock::delayCycles(x);
108
   Clock::delayCycles(x);

+ 2
- 0
Marlin/src/HAL/LPC1768/HAL.h 查看文件

200
 void HAL_clear_reset_source(void);
200
 void HAL_clear_reset_source(void);
201
 uint8_t HAL_get_reset_source(void);
201
 uint8_t HAL_get_reset_source(void);
202
 
202
 
203
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
204
+
203
 // Add strcmp_P if missing
205
 // Add strcmp_P if missing
204
 #ifndef strcmp_P
206
 #ifndef strcmp_P
205
   #define strcmp_P(a, b) strcmp((a), (b))
207
   #define strcmp_P(a, b) strcmp((a), (b))

+ 2
- 0
Marlin/src/HAL/SAMD51/HAL.h 查看文件

88
 void HAL_clear_reset_source();  // clear reset reason
88
 void HAL_clear_reset_source();  // clear reset reason
89
 uint8_t HAL_get_reset_source(); // get reset reason
89
 uint8_t HAL_get_reset_source(); // get reset reason
90
 
90
 
91
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
92
+
91
 //
93
 //
92
 // ADC
94
 // ADC
93
 //
95
 //

+ 2
- 0
Marlin/src/HAL/STM32/HAL.h 查看文件

134
 // Reset reason
134
 // Reset reason
135
 uint8_t HAL_get_reset_source();
135
 uint8_t HAL_get_reset_source();
136
 
136
 
137
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
138
+
137
 void _delay_ms(const int delay);
139
 void _delay_ms(const int delay);
138
 
140
 
139
 extern "C" char* _sbrk(int incr);
141
 extern "C" char* _sbrk(int incr);

+ 2
- 0
Marlin/src/HAL/STM32F1/HAL.h 查看文件

185
 // Reset reason
185
 // Reset reason
186
 uint8_t HAL_get_reset_source();
186
 uint8_t HAL_get_reset_source();
187
 
187
 
188
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
189
+
188
 void _delay_ms(const int delay);
190
 void _delay_ms(const int delay);
189
 
191
 
190
 #pragma GCC diagnostic push
192
 #pragma GCC diagnostic push

+ 2
- 0
Marlin/src/HAL/STM32_F4_F7/HAL.h 查看文件

142
 // Reset reason
142
 // Reset reason
143
 uint8_t HAL_get_reset_source();
143
 uint8_t HAL_get_reset_source();
144
 
144
 
145
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
146
+
145
 void _delay_ms(const int delay);
147
 void _delay_ms(const int delay);
146
 
148
 
147
 /*
149
 /*

+ 2
- 0
Marlin/src/HAL/TEENSY31_32/HAL.h 查看文件

93
 // Get the reason for the reset
93
 // Get the reason for the reset
94
 uint8_t HAL_get_reset_source();
94
 uint8_t HAL_get_reset_source();
95
 
95
 
96
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
97
+
96
 FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
98
 FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
97
 
99
 
98
 #pragma GCC diagnostic push
100
 #pragma GCC diagnostic push

+ 2
- 0
Marlin/src/HAL/TEENSY35_36/HAL.h 查看文件

99
 // Reset reason
99
 // Reset reason
100
 uint8_t HAL_get_reset_source();
100
 uint8_t HAL_get_reset_source();
101
 
101
 
102
+inline void HAL_reboot() {}  // reboot the board or restart the bootloader
103
+
102
 FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
104
 FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
103
 
105
 
104
 #pragma GCC diagnostic push
106
 #pragma GCC diagnostic push

+ 1
- 0
Marlin/src/core/macros.h 查看文件

215
 #define WITHIN(N,L,H)       ((N) >= (L) && (N) <= (H))
215
 #define WITHIN(N,L,H)       ((N) >= (L) && (N) <= (H))
216
 #define NUMERIC(a)          WITHIN(a, '0', '9')
216
 #define NUMERIC(a)          WITHIN(a, '0', '9')
217
 #define DECIMAL(a)          (NUMERIC(a) || a == '.')
217
 #define DECIMAL(a)          (NUMERIC(a) || a == '.')
218
+#define HEXCHR(a)           (NUMERIC(a) ? (a) - '0' : WITHIN(a, 'a', 'f') ? ((a) - 'a' + 10)  : WITHIN(a, 'A', 'F') ? ((a) - 'A' + 10) : -1)
218
 #define NUMERIC_SIGNED(a)   (NUMERIC(a) || (a) == '-' || (a) == '+')
219
 #define NUMERIC_SIGNED(a)   (NUMERIC(a) || (a) == '-' || (a) == '+')
219
 #define DECIMAL_SIGNED(a)   (DECIMAL(a) || (a) == '-' || (a) == '+')
220
 #define DECIMAL_SIGNED(a)   (DECIMAL(a) || (a) == '-' || (a) == '+')
220
 #define COUNT(a)            (sizeof(a)/sizeof(*a))
221
 #define COUNT(a)            (sizeof(a)/sizeof(*a))

+ 3
- 8
Marlin/src/feature/e_parser.h 查看文件

88
 
88
 
89
       case EP_N:
89
       case EP_N:
90
         switch (c) {
90
         switch (c) {
91
-          case '0': case '1': case '2':
92
-          case '3': case '4': case '5':
93
-          case '6': case '7': case '8':
94
-          case '9': case '-': case ' ':   break;
91
+          case '0' ... '9':
92
+          case '-': case ' ':   break;
95
           case 'M': state = EP_M;      break;
93
           case 'M': state = EP_M;      break;
96
           default:  state = EP_IGNORE;
94
           default:  state = EP_IGNORE;
97
         }
95
         }
153
       case EP_M876S:
151
       case EP_M876S:
154
         switch (c) {
152
         switch (c) {
155
           case ' ': break;
153
           case ' ': break;
156
-          case '0': case '1': case '2':
157
-          case '3': case '4': case '5':
158
-          case '6': case '7': case '8':
159
-          case '9':
154
+          case '0' ... '9':
160
             state = EP_M876SN;
155
             state = EP_M876SN;
161
             M876_reason = (uint8_t)(c - '0');
156
             M876_reason = (uint8_t)(c - '0');
162
             break;
157
             break;

+ 1
- 1
Marlin/src/gcode/control/T.cpp 查看文件

46
  *   Tx   Same as T?, but nozzle doesn't have to be preheated. Tc requires a preheated nozzle to finish filament load.
46
  *   Tx   Same as T?, but nozzle doesn't have to be preheated. Tc requires a preheated nozzle to finish filament load.
47
  *   Tc   Load to nozzle after filament was prepared by Tc and nozzle is already heated.
47
  *   Tc   Load to nozzle after filament was prepared by Tc and nozzle is already heated.
48
  */
48
  */
49
-void GcodeSuite::T(const uint8_t tool_index) {
49
+void GcodeSuite::T(const int8_t tool_index) {
50
 
50
 
51
   DEBUG_SECTION(log_T, "T", DEBUGGING(LEVELING));
51
   DEBUG_SECTION(log_T, "T", DEBUGGING(LEVELING));
52
   if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("...(", tool_index, ")");
52
   if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("...(", tool_index, ")");

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

923
 
923
 
924
     case 'T': T(parser.codenum); break;                           // Tn: Tool Change
924
     case 'T': T(parser.codenum); break;                           // Tn: Tool Change
925
 
925
 
926
+    #if ENABLED(MARLIN_DEV_MODE)
927
+      case 'D': D(parser.codenum); break;                         // Dn: Debug codes
928
+    #endif
929
+
926
     default:
930
     default:
927
       #if ENABLED(WIFI_CUSTOM_COMMAND)
931
       #if ENABLED(WIFI_CUSTOM_COMMAND)
928
         if (wifi_custom_command(parser.command_ptr)) break;
932
         if (wifi_custom_command(parser.command_ptr)) break;

+ 4
- 1
Marlin/src/gcode/gcode.h 查看文件

285
  * M995 - Touch screen calibration for TFT display
285
  * M995 - Touch screen calibration for TFT display
286
  * M997 - Perform in-application firmware update
286
  * M997 - Perform in-application firmware update
287
  * M999 - Restart after being stopped by error
287
  * M999 - Restart after being stopped by error
288
+ * D... - Custom Development G-code. Add hooks to 'gcode_D.cpp' for developers to test features. (Requires MARLIN_DEV_MODE)
288
  *
289
  *
289
  * "T" Codes
290
  * "T" Codes
290
  *
291
  *
408
 
409
 
409
 private:
410
 private:
410
 
411
 
412
+  TERN_(MARLIN_DEV_MODE, static void D(const int16_t dcode));
413
+
411
   static void G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move=false));
414
   static void G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move=false));
412
 
415
 
413
   TERN_(ARC_SUPPORT, static void G2_G3(const bool clockwise));
416
   TERN_(ARC_SUPPORT, static void G2_G3(const bool clockwise));
882
 
885
 
883
   TERN_(CONTROLLER_FAN_EDITABLE, static void M710());
886
   TERN_(CONTROLLER_FAN_EDITABLE, static void M710());
884
 
887
 
885
-  static void T(const uint8_t tool_index);
888
+  static void T(const int8_t tool_index);
886
 
889
 
887
 };
890
 };
888
 
891
 

+ 173
- 0
Marlin/src/gcode/gcode_d.cpp 查看文件

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#include "../inc/MarlinConfigPre.h"
23
+
24
+#if ENABLED(MARLIN_DEV_MODE)
25
+
26
+  #include "gcode.h"
27
+  #include "../module/settings.h"
28
+  #include "../libs/hex_print.h"
29
+  #include "../HAL/shared/eeprom_if.h"
30
+
31
+  /**
32
+   * Dn: G-code for development and testing
33
+   *
34
+   * See https://reprap.org/wiki/G-code#D:_Debug_codes
35
+   *
36
+   * Put whatever else you need here to test ongoing development.
37
+   */
38
+  void GcodeSuite::D(const int16_t dcode) {
39
+    switch (dcode) {
40
+
41
+      case -1:
42
+        for (;;); // forever
43
+
44
+      case 0:
45
+        HAL_reboot();
46
+        break;
47
+
48
+      case 1: {
49
+        // Zero or pattern-fill the EEPROM data
50
+        #if ENABLED(EEPROM_SETTINGS)
51
+          persistentStore.access_start();
52
+          size_t total = persistentStore.capacity();
53
+          int pos = 0;
54
+          const uint8_t value = 0x0;
55
+          while(total--) {
56
+            persistentStore.write_data(pos, &value, 1);
57
+          }
58
+          persistentStore.access_finish();
59
+        #else
60
+          settings.reset();
61
+          settings.save();
62
+        #endif
63
+        HAL_reboot();
64
+      } break;
65
+
66
+      case 2: { // D2 Read / Write SRAM
67
+        #define SRAM_SIZE 8192
68
+        uint8_t *pointer = parser.hex_adr_val('A');
69
+        uint16_t len = parser.ushortval('C', 1);
70
+        uintptr_t addr = (uintptr_t)pointer;
71
+        NOMORE(addr, (size_t)(SRAM_SIZE - 1));
72
+        NOMORE(len, SRAM_SIZE - addr);
73
+        if (parser.seenval('X')) {
74
+          // Write the hex bytes after the X
75
+          uint16_t val = parser.hex_val('X');
76
+          while (len--) {
77
+            *pointer = val;
78
+            pointer++;
79
+          }
80
+        }
81
+        else {
82
+          while (len--) print_hex_byte(*(pointer++));
83
+          SERIAL_EOL();
84
+        }
85
+      } break;
86
+
87
+      case 3: { // D3 Read / Write EEPROM
88
+        uint8_t *pointer = parser.hex_adr_val('A');
89
+        uint16_t len = parser.ushortval('C', 1);
90
+        uintptr_t addr = (uintptr_t)pointer;
91
+        #ifndef MARLIN_EEPROM_SIZE
92
+          #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
93
+        #endif
94
+        NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1));
95
+        NOMORE(len, MARLIN_EEPROM_SIZE - addr);
96
+        if (parser.seenval('X')) {
97
+          uint16_t val = parser.hex_val('X');
98
+          #if ENABLED(EEPROM_SETTINGS)
99
+            persistentStore.access_start();
100
+            while(len--) {
101
+              int pos = 0;
102
+              persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val));
103
+            }
104
+            SERIAL_EOL();
105
+            persistentStore.access_finish();
106
+          #else
107
+            SERIAL_ECHOLN("NO EEPROM");
108
+          #endif
109
+        }
110
+        else {
111
+          while (len--) {
112
+            // Read bytes from EEPROM
113
+            #if ENABLED(EEPROM_SETTINGS)
114
+              persistentStore.access_start();
115
+              uint8_t val;
116
+              while(len--) {
117
+                int pos = 0;
118
+                if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) {
119
+                  print_hex_byte(val);
120
+                }
121
+              }
122
+              SERIAL_EOL();
123
+              persistentStore.access_finish();
124
+            #else
125
+              SERIAL_ECHOLN("NO EEPROM");
126
+            #endif
127
+          }
128
+          SERIAL_EOL();
129
+        }
130
+      } break;
131
+
132
+      case 4: { // D4 Read / Write PIN
133
+        // const uint8_t pin = parser.byteval('P');
134
+        // const bool is_out = parser.boolval('F'),
135
+        //            val = parser.byteval('V', LOW);
136
+        if (parser.seenval('X')) {
137
+          // TODO: Write the hex bytes after the X
138
+          //while (len--) {
139
+          //}
140
+        }
141
+        else {
142
+          // while (len--) {
143
+            // TODO: Read bytes from EEPROM
144
+            // print_hex_byte(eeprom_read_byte(*(adr++));
145
+          // }
146
+          SERIAL_EOL();
147
+        }
148
+      } break;
149
+
150
+      case 5: { // D4 Read / Write onboard Flash
151
+        #define FLASH_SIZE 1024
152
+        uint8_t *pointer = parser.hex_adr_val('A');
153
+        uint16_t len = parser.ushortval('C', 1);
154
+        uintptr_t addr = (uintptr_t)pointer;
155
+        NOMORE(addr, (size_t)(FLASH_SIZE - 1));
156
+        NOMORE(len, FLASH_SIZE - addr);
157
+        if (parser.seenval('X')) {
158
+          // TODO: Write the hex bytes after the X
159
+          //while (len--) {
160
+          //}
161
+        }
162
+        else {
163
+          // while (len--) {
164
+            // TODO: Read bytes from EEPROM
165
+            // print_hex_byte(eeprom_read_byte(adr++));
166
+          // }
167
+          SERIAL_EOL();
168
+        }
169
+      } break;
170
+    }
171
+  }
172
+
173
+#endif

+ 25
- 24
Marlin/src/gcode/parser.cpp 查看文件

147
     starpos[1] = '\0';
147
     starpos[1] = '\0';
148
   }
148
   }
149
 
149
 
150
-  #if ENABLED(GCODE_MOTION_MODES)
151
-    #if ENABLED(ARC_SUPPORT)
152
-      #define GTOP 3
153
-    #else
154
-      #define GTOP 1
155
-    #endif
150
+  #if ANY(MARLIN_DEV_MODE, SWITCHING_TOOLHEAD, MAGNETIC_SWITCHING_TOOLHEAD, ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
151
+    #define SIGNED_CODENUM 1
156
   #endif
152
   #endif
157
 
153
 
158
   // Bail if the letter is not G, M, or T
154
   // Bail if the letter is not G, M, or T
159
   // (or a valid parameter for the current motion mode)
155
   // (or a valid parameter for the current motion mode)
160
   switch (letter) {
156
   switch (letter) {
161
 
157
 
162
-    case 'G': case 'M': case 'T':
163
-    #if ENABLED(CANCEL_OBJECTS)
164
-      case 'O':
165
-    #endif
158
+    case 'G': case 'M': case 'T': TERN_(MARLIN_DEV_MODE, case 'D':)
166
       // Skip spaces to get the numeric part
159
       // Skip spaces to get the numeric part
167
       while (*p == ' ') p++;
160
       while (*p == ' ') p++;
168
 
161
 
178
       #endif
171
       #endif
179
 
172
 
180
       // Bail if there's no command code number
173
       // Bail if there's no command code number
181
-      if (!NUMERIC(*p)) return;
174
+      if (!TERN(SIGNED_CODENUM, NUMERIC_SIGNED(*p), NUMERIC(*p))) return;
182
 
175
 
183
       // Save the command letter at this point
176
       // Save the command letter at this point
184
       // A '?' signifies an unknown command
177
       // A '?' signifies an unknown command
185
       command_letter = letter;
178
       command_letter = letter;
186
 
179
 
187
-      // Get the code number - integer digits only
188
-      codenum = 0;
189
-      do { codenum *= 10, codenum += *p++ - '0'; } while (NUMERIC(*p));
180
+      {
181
+        #if ENABLED(SIGNED_CODENUM)
182
+          int sign = 1; // Allow for a negative code like D-1 or T-1
183
+          if (*p == '-') { sign = -1; ++p; }
184
+        #endif
185
+
186
+        // Get the code number - integer digits only
187
+        codenum = 0;
188
+
189
+        do { codenum = codenum * 10 + *p++ - '0'; } while (NUMERIC(*p));
190
+
191
+        // Apply the sign, if any
192
+        TERN_(SIGNED_CODENUM, codenum *= sign);
193
+      }
190
 
194
 
191
       // Allow for decimal point in command
195
       // Allow for decimal point in command
192
       #if ENABLED(USE_GCODE_SUBCODES)
196
       #if ENABLED(USE_GCODE_SUBCODES)
193
         if (*p == '.') {
197
         if (*p == '.') {
194
           p++;
198
           p++;
195
           while (NUMERIC(*p))
199
           while (NUMERIC(*p))
196
-          subcode *= 10, subcode += *p++ - '0';
200
+            subcode = subcode * 10 + *p++ - '0';
197
         }
201
         }
198
       #endif
202
       #endif
199
 
203
 
201
       while (*p == ' ') p++;
205
       while (*p == ' ') p++;
202
 
206
 
203
       #if ENABLED(GCODE_MOTION_MODES)
207
       #if ENABLED(GCODE_MOTION_MODES)
204
-        if (letter == 'G' && (codenum <= GTOP || codenum == 5
205
-                                #if ENABLED(G38_PROBE_TARGET)
206
-                                  || codenum == 38
207
-                                #endif
208
-                             )
208
+        if (letter == 'G'
209
+          && (codenum <= TERN(ARC_SUPPORT, 3, 1) || codenum == 5 || TERN0(G38_PROBE_TARGET, codenum == 38))
209
         ) {
210
         ) {
210
           motion_mode_codenum = codenum;
211
           motion_mode_codenum = codenum;
211
           TERN_(USE_GCODE_SUBCODES, motion_mode_subcode = subcode);
212
           TERN_(USE_GCODE_SUBCODES, motion_mode_subcode = subcode);
216
 
217
 
217
     #if ENABLED(GCODE_MOTION_MODES)
218
     #if ENABLED(GCODE_MOTION_MODES)
218
       #if ENABLED(ARC_SUPPORT)
219
       #if ENABLED(ARC_SUPPORT)
219
-        case 'I': case 'J': case 'R':
220
+        case 'I' ... 'J': case 'R':
220
           if (motion_mode_codenum != 2 && motion_mode_codenum != 3) return;
221
           if (motion_mode_codenum != 2 && motion_mode_codenum != 3) return;
221
       #endif
222
       #endif
222
-      case 'P': case 'Q':
223
+      case 'P' ... 'Q':
223
         if (motion_mode_codenum != 5) return;
224
         if (motion_mode_codenum != 5) return;
224
-      case 'X': case 'Y': case 'Z': case 'E': case 'F':
225
+      case 'X' ... 'Z': case 'E' ... 'F':
225
         if (motion_mode_codenum < 0) return;
226
         if (motion_mode_codenum < 0) return;
226
         command_letter = 'G';
227
         command_letter = 'G';
227
         codenum = motion_mode_codenum;
228
         codenum = motion_mode_codenum;
247
     #if ENABLED(EXPECTED_PRINTER_CHECK)
248
     #if ENABLED(EXPECTED_PRINTER_CHECK)
248
       case 16:
249
       case 16:
249
     #endif
250
     #endif
250
-    case 23: case 28: case 30: case 33: case 117: case 118: case 928:
251
+    case 23: case 28: case 30: case 117 ... 118: case 928:
251
       string_arg = unescape_string(p);
252
       string_arg = unescape_string(p);
252
       return;
253
       return;
253
     default: break;
254
     default: break;

+ 31
- 3
Marlin/src/gcode/parser.h 查看文件

114
     return valid_signless(p) || ((p[0] == '-' || p[0] == '+') && valid_signless(&p[1])); // [-+]?.?[0-9]
114
     return valid_signless(p) || ((p[0] == '-' || p[0] == '+') && valid_signless(&p[1])); // [-+]?.?[0-9]
115
   }
115
   }
116
 
116
 
117
+  FORCE_INLINE static bool valid_number(const char * const p) {
118
+    // TODO: With MARLIN_DEV_MODE allow HEX values starting with "x"
119
+    return valid_float(p);
120
+  }
121
+
117
   #if ENABLED(FASTER_GCODE_PARSER)
122
   #if ENABLED(FASTER_GCODE_PARSER)
118
 
123
 
119
     FORCE_INLINE static bool valid_int(const char * const p) {
124
     FORCE_INLINE static bool valid_int(const char * const p) {
142
       if (ind >= COUNT(param)) return false; // Only A-Z
147
       if (ind >= COUNT(param)) return false; // Only A-Z
143
       const bool b = TEST32(codebits, ind);
148
       const bool b = TEST32(codebits, ind);
144
       if (b) {
149
       if (b) {
145
-        char * const ptr = command_ptr + param[ind];
146
-        value_ptr = param[ind] && valid_float(ptr) ? ptr : nullptr;
150
+        if (param[ind]) {
151
+          char * const ptr = command_ptr + param[ind];
152
+          value_ptr = valid_number(ptr) ? ptr : nullptr;
153
+        }
154
+        else
155
+          value_ptr = nullptr;
147
       }
156
       }
148
       return b;
157
       return b;
149
     }
158
     }
198
     static inline bool seen(const char c) {
207
     static inline bool seen(const char c) {
199
       char *p = strgchr(command_args, c);
208
       char *p = strgchr(command_args, c);
200
       const bool b = !!p;
209
       const bool b = !!p;
201
-      if (b) value_ptr = valid_float(&p[1]) ? &p[1] : nullptr;
210
+      if (b) value_ptr = valid_number(&p[1]) ? &p[1] : nullptr;
202
       return b;
211
       return b;
203
     }
212
     }
204
 
213
 
401
   static inline float    linearval(const char c, const float dval=0)    { return seenval(c) ? value_linear_units() : dval; }
410
   static inline float    linearval(const char c, const float dval=0)    { return seenval(c) ? value_linear_units() : dval; }
402
   static inline float    celsiusval(const char c, const float dval=0)   { return seenval(c) ? value_celsius()      : dval; }
411
   static inline float    celsiusval(const char c, const float dval=0)   { return seenval(c) ? value_celsius()      : dval; }
403
 
412
 
413
+  #if ENABLED(MARLIN_DEV_MODE)
414
+
415
+    static inline uint8_t* hex_adr_val(const char c, uint8_t * const dval=nullptr) {
416
+      if (!seen(c) || *value_ptr != 'x') return dval;
417
+      uint8_t *out = nullptr;
418
+      for (char *vp = value_ptr + 1; HEXCHR(*vp) >= 0; vp++)
419
+        out = (uint8_t*)((uintptr_t(out) << 8) | HEXCHR(*vp));
420
+      return out;
421
+    }
422
+
423
+    static inline uint16_t hex_val(const char c, uint16_t const dval=0) {
424
+      if (!seen(c) || *value_ptr != 'x') return dval;
425
+      uint16_t out = 0;
426
+      for (char *vp = value_ptr + 1; HEXCHR(*vp) >= 0; vp++)
427
+        out = ((out) << 8) | HEXCHR(*vp);
428
+      return out;
429
+    }
430
+
431
+  #endif
404
 };
432
 };
405
 
433
 
406
 extern GCodeParser parser;
434
 extern GCodeParser parser;

+ 5
- 1
Marlin/src/lcd/ultralcd.cpp 查看文件

123
 #include "lcdprint.h"
123
 #include "lcdprint.h"
124
 
124
 
125
 #include "../sd/cardreader.h"
125
 #include "../sd/cardreader.h"
126
-#include "../module/settings.h"
126
+
127
 #include "../module/temperature.h"
127
 #include "../module/temperature.h"
128
 #include "../module/planner.h"
128
 #include "../module/planner.h"
129
 #include "../module/motion.h"
129
 #include "../module/motion.h"
130
 
130
 
131
+#if HAS_LCD_MENU
132
+  #include "../module/settings.h"
133
+#endif
134
+
131
 #if ENABLED(AUTO_BED_LEVELING_UBL)
135
 #if ENABLED(AUTO_BED_LEVELING_UBL)
132
   #include "../feature/bedlevel/bedlevel.h"
136
   #include "../feature/bedlevel/bedlevel.h"
133
 #endif
137
 #endif

Loading…
取消
儲存