Browse Source

Merge pull request #6367 from thinkyhead/rc_cleanup_followup

Cleanup after some direct commits
Scott Lahteine 7 years ago
parent
commit
55f9e76610

+ 83
- 92
Marlin/M100_Free_Mem_Chk.cpp View File

@@ -40,8 +40,8 @@
40 40
  *
41 41
  * Also, there are two support functions that can be called from a developer's C code.
42 42
  *
43
- *    uint16_t check_for_free_memory_corruption(char * const ptr);
44
- *    void M100_dump_routine( char *title, char *start, char *end);
43
+ *    uint16_t check_for_free_memory_corruption(const char * const ptr);
44
+ *    void M100_dump_routine(const char * const title, const char *start, const char *end);
45 45
  *
46 46
  * Initial version by Roxy-3D
47 47
  */
@@ -68,7 +68,7 @@ extern char __bss_end;
68 68
 //
69 69
 
70 70
 #define END_OF_HEAP() (__brkval ? __brkval : &__bss_end)
71
-int check_for_free_memory_corruption(char *title);
71
+int check_for_free_memory_corruption(const char * const title);
72 72
 
73 73
 // Location of a variable on its stack frame. Returns a value above
74 74
 // the stack (once the function returns to the caller).
@@ -86,7 +86,6 @@ int16_t count_test_bytes(const uint8_t * const ptr) {
86 86
   return -1;
87 87
 }
88 88
 
89
-
90 89
 //
91 90
 // M100 sub-commands
92 91
 //
@@ -101,7 +100,7 @@ int16_t count_test_bytes(const uint8_t * const ptr) {
101 100
    *  the block. If so, it may indicate memory corruption due to a bad pointer.
102 101
    *  Unexpected bytes are flagged in the right column.
103 102
    */
104
-  void dump_free_memory(uint8_t *ptr, uint8_t *sp) {
103
+  void dump_free_memory(const uint8_t *ptr, const uint8_t *sp) {
105 104
     //
106 105
     // Start and end the dump on a nice 16 byte boundary
107 106
     // (even though the values are not 16-byte aligned).
@@ -121,17 +120,13 @@ int16_t count_test_bytes(const uint8_t * const ptr) {
121 120
       safe_delay(25);
122 121
       SERIAL_CHAR('|');                   // Point out non test bytes
123 122
       for (uint8_t i = 0; i < 16; i++) {
124
-        char ccc;
125
-        ccc = (char) ptr[i];                     
126
-        if ( &ptr[i]>=&command_queue[0][0] && &ptr[i]<&command_queue[BUFSIZE][MAX_CMD_SIZE]) { // Print out ASCII in the command
127
-          if ( ccc<' ' || ccc>0x7e)                                                            // buffer area
128
-            ccc = ' ';
129
-        } 
130
-        else
131
-          if (ccc != TEST_BYTE)           // If not display data in the command buffer
132
-            ccc = '?';                    // area, we flag bytes that don't match the test byte
133
-          else
134
-            ccc = ' ';
123
+        char ccc = (char)ptr[i]; // cast to char before automatically casting to char on assignment, in case the compiler is broken
124
+        if (&ptr[i] >= command_queue && &ptr[i] < &command_queue[BUFSIZE][MAX_CMD_SIZE]) { // Print out ASCII in the command buffer area
125
+          if (!WITHIN(ccc, ' ', 0x7E)) ccc = ' ';
126
+        }
127
+        else { // If not in the command buffer area, flag bytes that don't match the test byte
128
+          ccc = (ccc == TEST_BYTE) ? ' ' : '?';
129
+        }
135 130
         SERIAL_CHAR(ccc);
136 131
       }
137 132
       SERIAL_EOL;
@@ -141,19 +136,16 @@ int16_t count_test_bytes(const uint8_t * const ptr) {
141 136
     }
142 137
   }
143 138
 
144
-void M100_dump_routine( char *title, char *start, char *end) {
145
-unsigned char c;
146
-int i;
147
-
148
-//
149
-// Round the start and end locations to produce full lines of output
150
-//
151
-      start = (char*) ((uint16_t) start & 0xfff0);
152
-      end   = (char*) ((uint16_t) end   | 0x000f);
153
-
154
-      SERIAL_ECHOLN(title);
155
-      dump_free_memory( start, end );
139
+void M100_dump_routine(const char * const title, const char *start, const char *end) {
140
+  SERIAL_ECHOLN(title);
141
+  //
142
+  // Round the start and end locations to produce full lines of output
143
+  //
144
+  start = (char*)((uint16_t) start & 0xfff0);
145
+  end   = (char*)((uint16_t) end   | 0x000f);
146
+  dump_free_memory(start, end);
156 147
 }
148
+
157 149
 #endif // M100_FREE_MEMORY_DUMPER
158 150
 
159 151
 /**
@@ -172,7 +164,7 @@ void free_memory_pool_report(const char * const ptr, const uint16_t size) {
172 164
       const uint16_t j = count_test_bytes(addr);
173 165
       if (j > 8) {
174 166
         SERIAL_ECHOPAIR("Found ", j);
175
-        SERIAL_ECHOLNPAIR(" bytes free at 0x", hex_word((uint16_t)addr));
167
+        SERIAL_ECHOLNPAIR(" bytes free at ", hex_address(addr));
176 168
         if (j > max_cnt) {
177 169
           max_cnt  = j;
178 170
           max_addr = addr;
@@ -185,7 +177,7 @@ void free_memory_pool_report(const char * const ptr, const uint16_t size) {
185 177
   if (block_cnt > 1) {
186 178
     SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
187 179
     SERIAL_ECHOPAIR("\nLargest free block is ", max_cnt);
188
-    SERIAL_ECHOLNPAIR(" bytes at 0x", hex_word((uint16_t)max_addr));
180
+    SERIAL_ECHOLNPAIR(" bytes at ", hex_address(max_addr));
189 181
   }
190 182
   SERIAL_ECHOLNPAIR("check_for_free_memory_corruption() = ", check_for_free_memory_corruption("M100 F "));
191 183
 }
@@ -206,7 +198,7 @@ void free_memory_pool_report(const char * const ptr, const uint16_t size) {
206 198
       for (uint16_t i = 1; i <= size; i++) {
207 199
         char * const addr = ptr + i * j;
208 200
         *addr = i;
209
-        SERIAL_ECHOPAIR("\nCorrupting address: 0x", hex_word((uint16_t)addr));
201
+        SERIAL_ECHOPAIR("\nCorrupting address: ", hex_address(addr));
210 202
       }
211 203
       SERIAL_EOL;
212 204
     }
@@ -234,9 +226,10 @@ void init_free_memory(uint8_t *ptr, int16_t size) {
234 226
   SERIAL_ECHOLNPGM(" bytes of memory initialized.\n");
235 227
 
236 228
   for (uint16_t i = 0; i < size; i++) {
237
-    if (((char) ptr[i]) != TEST_BYTE) {
238
-      SERIAL_ECHOPAIR("? address : 0x", hex_word((uint16_t)ptr + i));
229
+    if ((char)ptr[i] != TEST_BYTE) {
230
+      SERIAL_ECHOPAIR("? address : ", hex_address(ptr + i));
239 231
       SERIAL_ECHOLNPAIR("=", hex_byte(ptr[i]));
232
+      SERIAL_EOL;
240 233
     }
241 234
   }
242 235
 }
@@ -245,13 +238,13 @@ void init_free_memory(uint8_t *ptr, int16_t size) {
245 238
  * M100: Free Memory Check
246 239
  */
247 240
 void gcode_M100() {
248
-  SERIAL_ECHOPAIR("\n__brkval : 0x", hex_word((uint16_t)__brkval));
249
-  SERIAL_ECHOPAIR("\n__bss_end: 0x", hex_word((uint16_t)&__bss_end));
241
+  SERIAL_ECHOPAIR("\n__brkval : ", hex_address(__brkval));
242
+  SERIAL_ECHOPAIR("\n__bss_end : ", hex_address(&__bss_end));
250 243
 
251 244
   uint8_t *ptr = END_OF_HEAP(), *sp = top_of_stack();
252 245
 
253
-  SERIAL_ECHOPAIR("\nstart of free space : 0x", hex_word((uint16_t)ptr));
254
-  SERIAL_ECHOLNPAIR("\nStack Pointer : 0x", hex_word((uint16_t)sp));
246
+  SERIAL_ECHOPAIR("\nstart of free space : ", hex_address(ptr));
247
+  SERIAL_ECHOLNPAIR("\nStack Pointer : ", hex_address(sp));
255 248
 
256 249
   // Always init on the first invocation of M100
257 250
   static bool m100_not_initialized = true;
@@ -276,68 +269,66 @@ void gcode_M100() {
276 269
   #endif
277 270
 }
278 271
 
279
-int check_for_free_memory_corruption(char *title) {
280
-  char *sp, *ptr;
281
-  int block_cnt = 0, i, j, n;
282
-
283
-    SERIAL_ECHO(title);
284
-
285
-    ptr = __brkval ? __brkval : &__bss_end;    
286
-    sp = top_of_stack();
287
-
288
-    n = sp - ptr;
289
-    SERIAL_ECHOPAIR("\nfmc() n=", n);
290
-    SERIAL_ECHOPAIR("\n&__brkval: 0x", hex_word((uint16_t)&__brkval));
291
-    SERIAL_ECHOPAIR("=0x",             hex_word((uint16_t)__brkval));
292
-    SERIAL_ECHOPAIR("\n__bss_end: 0x", hex_word((uint16_t)&__bss_end));
293
-    SERIAL_ECHOPAIR(" sp=", hex_word(sp));
294
-
295
-    if (sp < ptr)  {
296
-        SERIAL_ECHOPGM(" sp < Heap ");
297
-//      SET_INPUT_PULLUP(63);		// if the developer has a switch wired up to their controller board
298
-//      safe_delay(5);                  // this code can be enabled to pause the display as soon as the 
299
-//      while ( READ(63))               // malfunction is detected.   It is currently defaulting to a switch
300
-//        idle();                       // being on pin-63 which is unassigend and available on most controller 
301
-//      safe_delay(20);                 // boards.
302
-//      while ( !READ(63))
303
-//        idle();
304
-        safe_delay(20);
305
-        #ifdef M100_FREE_MEMORY_DUMPER  
306
-        M100_dump_routine( "   Memory corruption detected with sp<Heap\n", (char *)0x1b80,  0x21ff );
307
-        #endif
308
-    }
272
+int check_for_free_memory_corruption(const char * const title) {
273
+  SERIAL_ECHO(title);
274
+
275
+  char *ptr = END_OF_HEAP(), *sp = top_of_stack();
276
+  int n = sp - ptr;
277
+
278
+  SERIAL_ECHOPAIR("\nfmc() n=", n);
279
+  SERIAL_ECHOPAIR("\n&__brkval: ", hex_address(&__brkval));
280
+  SERIAL_ECHOPAIR("=",             hex_address(__brkval));
281
+  SERIAL_ECHOPAIR("\n__bss_end: ", hex_address(&__bss_end));
282
+  SERIAL_ECHOPAIR(" sp=",          hex_address(sp));
283
+
284
+  if (sp < ptr)  {
285
+    SERIAL_ECHOPGM(" sp < Heap ");
286
+    // SET_INPUT_PULLUP(63);           // if the developer has a switch wired up to their controller board
287
+    // safe_delay(5);                  // this code can be enabled to pause the display as soon as the
288
+    // while ( READ(63))               // malfunction is detected.   It is currently defaulting to a switch
289
+    //   idle();                       // being on pin-63 which is unassigend and available on most controller
290
+    // safe_delay(20);                 // boards.
291
+    // while ( !READ(63))
292
+    //   idle();
293
+    safe_delay(20);
294
+    #ifdef M100_FREE_MEMORY_DUMPER
295
+      M100_dump_routine("   Memory corruption detected with sp<Heap\n", (char*)0x1B80, 0x21FF);
296
+    #endif
297
+  }
309 298
 
310
-    // Scan through the range looking for the biggest block of 0xE5's we can find
311
-    for (i = 0; i < n; i++) {
312
-      if (*(ptr + i) == (char)0xe5) {
313
-        j = count_test_bytes(ptr + i);
314
-        if (j > 8) {
315
-//        SERIAL_ECHOPAIR("Found ", j);
316
-//        SERIAL_ECHOLNPAIR(" bytes free at 0x", hex_word((uint16_t)(ptr + i)));
317
-
318
-          i += j;
319
-          block_cnt++;
320
-          SERIAL_ECHOPAIR(" (", block_cnt);
321
-          SERIAL_ECHOPAIR(") found=", j);
322
-          SERIAL_ECHOPGM("   ");
323
-        }
299
+  // Scan through the range looking for the biggest block of 0xE5's we can find
300
+  int block_cnt = 0;
301
+  for (int i = 0; i < n; i++) {
302
+    if (ptr[i] == TEST_BYTE) {
303
+      int16_t j = count_test_bytes(ptr + i);
304
+      if (j > 8) {
305
+        // SERIAL_ECHOPAIR("Found ", j);
306
+        // SERIAL_ECHOLNPAIR(" bytes free at ", hex_address(ptr + i));
307
+        i += j;
308
+        block_cnt++;
309
+        SERIAL_ECHOPAIR(" (", block_cnt);
310
+        SERIAL_ECHOPAIR(") found=", j);
311
+        SERIAL_ECHOPGM("   ");
324 312
       }
325 313
     }
326
-    SERIAL_ECHOPAIR("  block_found=", block_cnt);
314
+  }
315
+  SERIAL_ECHOPAIR("  block_found=", block_cnt);
327 316
 
328
-    if ((block_cnt!=1) || (__brkval != 0x0000)) 
329
-      SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
317
+  if (block_cnt != 1 || __brkval != 0x0000)
318
+    SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
330 319
 
331
-    if ((block_cnt==0))		       // Make sure the special case of no free blocks shows up as an
332
-      block_cnt = -1;                  // error to the calling code!
320
+  if (block_cnt == 0)       // Make sure the special case of no free blocks shows up as an
321
+    block_cnt = -1;         // error to the calling code!
333 322
 
334
-    if (block_cnt==1) {              
335
-      SERIAL_ECHOPGM(" return=0\n");  // if the block_cnt is 1, nothing has broken up the free memory
336
-      return 0;                       // area and it is appropriate to say 'no corruption'.
337
-    }
338
-    SERIAL_ECHOPGM(" return=true\n");
339
-    return block_cnt;
323
+  SERIAL_ECHOPGM(" return=");
324
+  if (block_cnt == 1) {
325
+    SERIAL_CHAR('0');       // if the block_cnt is 1, nothing has broken up the free memory
326
+    SERIAL_EOL;             // area and it is appropriate to say 'no corruption'.
327
+    return 0;
340 328
   }
329
+  SERIAL_ECHOLNPGM("true");
330
+  return block_cnt;
331
+}
341 332
 
342 333
 #endif // M100_FREE_MEMORY_WATCHER
343 334
 

+ 183
- 153
Marlin/Marlin_main.cpp View File

@@ -284,7 +284,7 @@
284 284
 
285 285
 #if ENABLED(M100_FREE_MEMORY_WATCHER)
286 286
   void gcode_M100();
287
-  void M100_dump_routine( char *title, char *start, char *end); 
287
+  void M100_dump_routine(const char * const title, const char *start, const char *end);
288 288
 #endif
289 289
 
290 290
 #if ENABLED(SDSUPPORT)
@@ -1091,7 +1091,7 @@ inline void get_serial_commands() {
1091 1091
       if (IsStopped()) {
1092 1092
         char* gpos = strchr(command, 'G');
1093 1093
         if (gpos) {
1094
-          int codenum = strtol(gpos + 1, NULL, 10);
1094
+          const int codenum = strtol(gpos + 1, NULL, 10);
1095 1095
           switch (codenum) {
1096 1096
             case 0:
1097 1097
             case 1:
@@ -4167,17 +4167,25 @@ inline void gcode_G28() {
4167 4167
       #define ABL_VAR
4168 4168
     #endif
4169 4169
 
4170
-    ABL_VAR int verbose_level, abl_probe_index;
4170
+    ABL_VAR int verbose_level;
4171 4171
     ABL_VAR float xProbe, yProbe, measured_z;
4172 4172
     ABL_VAR bool dryrun, abl_should_enable;
4173 4173
 
4174
+    #if ENABLED(PROBE_MANUALLY) || ENABLED(AUTO_BED_LEVELING_LINEAR)
4175
+      ABL_VAR int abl_probe_index;
4176
+    #endif
4177
+
4174 4178
     #if HAS_SOFTWARE_ENDSTOPS
4175 4179
       ABL_VAR bool enable_soft_endstops = true;
4176 4180
     #endif
4177 4181
 
4178 4182
     #if ABL_GRID
4179
-      ABL_VAR uint8_t PR_OUTER_VAR;
4180
-      ABL_VAR  int8_t PR_INNER_VAR;
4183
+
4184
+      #if ENABLED(PROBE_MANUALLY)
4185
+        ABL_VAR uint8_t PR_OUTER_VAR;
4186
+        ABL_VAR  int8_t PR_INNER_VAR;
4187
+      #endif
4188
+
4181 4189
       ABL_VAR int left_probe_bed_position, right_probe_bed_position, front_probe_bed_position, back_probe_bed_position;
4182 4190
       ABL_VAR float xGridSpacing, yGridSpacing;
4183 4191
 
@@ -4186,13 +4194,18 @@ inline void gcode_G28() {
4186 4194
       #if ABL_PLANAR
4187 4195
         ABL_VAR uint8_t abl_grid_points_x = GRID_MAX_POINTS_X,
4188 4196
                         abl_grid_points_y = GRID_MAX_POINTS_Y;
4189
-        ABL_VAR int abl2;
4190 4197
         ABL_VAR bool do_topography_map;
4191 4198
       #else // 3-point
4192 4199
         uint8_t constexpr abl_grid_points_x = GRID_MAX_POINTS_X,
4193 4200
                           abl_grid_points_y = GRID_MAX_POINTS_Y;
4201
+      #endif
4194 4202
 
4195
-        int constexpr abl2 = ABL_GRID_MAX;
4203
+      #if ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(PROBE_MANUALLY)
4204
+        #if ABL_PLANAR
4205
+          ABL_VAR int abl2;
4206
+        #else // 3-point
4207
+          int constexpr abl2 = ABL_GRID_MAX;
4208
+        #endif
4196 4209
       #endif
4197 4210
 
4198 4211
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@@ -4224,7 +4237,10 @@ inline void gcode_G28() {
4224 4237
      */
4225 4238
     if (!g29_in_progress) {
4226 4239
 
4227
-      abl_probe_index = 0;
4240
+      #if ENABLED(PROBE_MANUALLY) || ENABLED(AUTO_BED_LEVELING_LINEAR)
4241
+        abl_probe_index = 0;
4242
+      #endif
4243
+
4228 4244
       abl_should_enable = planner.abl_enabled;
4229 4245
 
4230 4246
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@@ -4284,7 +4300,7 @@ inline void gcode_G28() {
4284 4300
         return;
4285 4301
       }
4286 4302
 
4287
-      dryrun = code_seen('D') ? code_value_bool() : false;
4303
+      dryrun = code_seen('D') && code_value_bool();
4288 4304
 
4289 4305
       #if ENABLED(AUTO_BED_LEVELING_LINEAR)
4290 4306
 
@@ -4455,7 +4471,7 @@ inline void gcode_G28() {
4455 4471
       g29_in_progress = true;
4456 4472
 
4457 4473
       if (abl_probe_index == 0) {
4458
-        // For the initial G29 S2 save software endstop state
4474
+        // For the initial G29 save software endstop state
4459 4475
         #if HAS_SOFTWARE_ENDSTOPS
4460 4476
           enable_soft_endstops = soft_endstops_enabled;
4461 4477
         #endif
@@ -4586,7 +4602,6 @@ inline void gcode_G28() {
4586 4602
 
4587 4603
     #else // !PROBE_MANUALLY
4588 4604
 
4589
-
4590 4605
       bool stow_probe_after_each = code_seen('E');
4591 4606
 
4592 4607
       #if ABL_GRID
@@ -4927,14 +4942,12 @@ inline void gcode_G28() {
4927 4942
    *     S = Stows the probe if 1 (default=1)
4928 4943
    */
4929 4944
   inline void gcode_G30() {
4930
-    float X_probe_location = code_seen('X') ? code_value_linear_units() : current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
4931
-          Y_probe_location = code_seen('Y') ? code_value_linear_units() : current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER;
4945
+    const float xpos = code_seen('X') ? code_value_linear_units() : current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
4946
+                ypos = code_seen('Y') ? code_value_linear_units() : current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
4947
+                pos[XYZ] = { xpos, ypos, LOGICAL_Z_POSITION(0) };
4932 4948
 
4933
-    float pos[XYZ] = { X_probe_location, Y_probe_location, LOGICAL_Z_POSITION(0) };
4934 4949
     if (!position_is_reachable(pos, true)) return;
4935 4950
 
4936
-    bool stow = code_seen('S') ? code_value_bool() : true;
4937
-
4938 4951
     // Disable leveling so the planner won't mess with us
4939 4952
     #if PLANNER_LEVELING
4940 4953
       set_bed_leveling_enabled(false);
@@ -4942,14 +4955,11 @@ inline void gcode_G28() {
4942 4955
 
4943 4956
     setup_for_endstop_or_probe_move();
4944 4957
 
4945
-    float measured_z = probe_pt(X_probe_location, Y_probe_location, stow, 1);
4958
+    const float measured_z = probe_pt(xpos, ypos, !code_seen('S') || code_value_bool(), 1);
4946 4959
 
4947
-    SERIAL_PROTOCOLPGM("Bed X: ");
4948
-    SERIAL_PROTOCOL(FIXFLOAT(X_probe_location));
4949
-    SERIAL_PROTOCOLPGM(" Y: ");
4950
-    SERIAL_PROTOCOL(FIXFLOAT(Y_probe_location));
4951
-    SERIAL_PROTOCOLPGM(" Z: ");
4952
-    SERIAL_PROTOCOLLN(FIXFLOAT(measured_z));
4960
+    SERIAL_PROTOCOLPAIR("Bed X: ", FIXFLOAT(xpos));
4961
+    SERIAL_PROTOCOLPAIR(" Y: ", FIXFLOAT(ypos));
4962
+    SERIAL_PROTOCOLLNPAIR(" Z: ", FIXFLOAT(measured_z));
4953 4963
 
4954 4964
     clean_up_after_endstop_or_probe_move();
4955 4965
 
@@ -5466,7 +5476,7 @@ inline void gcode_G92() {
5466 5476
    * M1: Conditional stop   - Wait for user button press on LCD
5467 5477
    */
5468 5478
   inline void gcode_M0_M1() {
5469
-    char* args = current_command_args;
5479
+    const char * const args = current_command_args;
5470 5480
 
5471 5481
     millis_t codenum = 0;
5472 5482
     bool hasP = false, hasS = false;
@@ -5524,7 +5534,7 @@ inline void gcode_G92() {
5524 5534
     KEEPALIVE_STATE(IN_HANDLER);
5525 5535
   }
5526 5536
 
5527
-#endif // EMERGENCY_PARSER || ULTIPANEL
5537
+#endif // HAS_RESUME_CONTINUE
5528 5538
 
5529 5539
 /**
5530 5540
  * M17: Enable power on all stepper motors
@@ -5806,70 +5816,94 @@ inline void gcode_M42() {
5806 5816
   #include "pinsDebug.h"
5807 5817
 
5808 5818
   inline void toggle_pins() {
5809
-    int pin, j;
5810
-
5811
-    bool I_flag = code_seen('I') ? code_value_bool() : false;
5812
-
5813
-    int repeat = code_seen('R') ? code_value_int() : 1,
5814
-        start = code_seen('S') ? code_value_int() : 0,
5815
-        end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
5816
-        wait = code_seen('W') ? code_value_int() : 500;
5819
+    const bool I_flag = code_seen('I') && code_value_bool();
5820
+    const int repeat = code_seen('R') ? code_value_int() : 1,
5821
+              start = code_seen('S') ? code_value_int() : 0,
5822
+              end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
5823
+              wait = code_seen('W') ? code_value_int() : 500;
5817 5824
 
5818
-    for (pin = start; pin <= end; pin++) {
5819
-        if (!I_flag && pin_is_protected(pin)) {
5820
-          SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
5821
-          SERIAL_ECHOPGM(" untouched.\n");
5822
-        }
5823
-        else {
5824
-          SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
5825
-          pinMode(pin, OUTPUT);
5826
-          for(j = 0; j < repeat; j++) {
5827
-            digitalWrite(pin, 0);
5828
-            safe_delay(wait);
5829
-            digitalWrite(pin, 1);
5830
-            safe_delay(wait);
5831
-            digitalWrite(pin, 0);
5832
-            safe_delay(wait);
5833
-          }
5825
+    for (uint8_t pin = start; pin <= end; pin++) {
5826
+      if (!I_flag && pin_is_protected(pin)) {
5827
+        SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
5828
+        SERIAL_ECHOLNPGM(" untouched.");
5829
+      }
5830
+      else {
5831
+        SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
5832
+        pinMode(pin, OUTPUT);
5833
+        for (int16_t j = 0; j < repeat; j++) {
5834
+          digitalWrite(pin, 0);
5835
+          safe_delay(wait);
5836
+          digitalWrite(pin, 1);
5837
+          safe_delay(wait);
5838
+          digitalWrite(pin, 0);
5839
+          safe_delay(wait);
5834 5840
         }
5835
-      SERIAL_ECHOPGM("\n");
5841
+      }
5842
+      SERIAL_CHAR('\n');
5836 5843
     }
5837
-    SERIAL_ECHOPGM("Done\n");
5844
+    SERIAL_ECHOLNPGM("Done.");
5845
+
5838 5846
   } // toggle_pins
5839 5847
 
5840
-  inline void servo_probe_test(){
5841
-    #if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
5848
+  inline void servo_probe_test() {
5849
+    #if !(NUM_SERVOS > 0 && HAS_SERVO_0)
5850
+
5842 5851
       SERIAL_ERROR_START;
5843 5852
       SERIAL_ERRORLNPGM("SERVO not setup");
5853
+
5844 5854
     #elif !HAS_Z_SERVO_ENDSTOP
5855
+
5845 5856
       SERIAL_ERROR_START;
5846 5857
       SERIAL_ERRORLNPGM("Z_ENDSTOP_SERVO_NR not setup");
5858
+
5847 5859
     #else
5848
-      uint8_t probe_index = code_seen('P') ? code_value_byte() : Z_ENDSTOP_SERVO_NR;
5860
+
5861
+      #if !defined(z_servo_angle)
5862
+        const int z_servo_angle[2] = Z_SERVO_ANGLES;
5863
+      #endif
5864
+
5865
+      const uint8_t probe_index = code_seen('P') ? code_value_byte() : Z_ENDSTOP_SERVO_NR;
5866
+
5849 5867
       SERIAL_PROTOCOLLNPGM("Servo probe test");
5850 5868
       SERIAL_PROTOCOLLNPAIR(".  using index:  ", probe_index);
5851 5869
       SERIAL_PROTOCOLLNPAIR(".  deploy angle: ", z_servo_angle[0]);
5852 5870
       SERIAL_PROTOCOLLNPAIR(".  stow angle:   ", z_servo_angle[1]);
5871
+
5853 5872
       bool probe_inverting;
5873
+
5854 5874
       #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
5875
+
5855 5876
         #define PROBE_TEST_PIN Z_MIN_PIN
5877
+
5856 5878
         SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
5857 5879
         SERIAL_PROTOCOLLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
5858 5880
         SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: ");
5859
-        if (Z_MIN_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
5860
-        else  SERIAL_PROTOCOLLNPGM("false");
5881
+
5882
+        #if Z_MIN_ENDSTOP_INVERTING
5883
+          SERIAL_PROTOCOLLNPGM("true");
5884
+        #else
5885
+          SERIAL_PROTOCOLLNPGM("false");
5886
+        #endif
5887
+
5861 5888
         probe_inverting = Z_MIN_ENDSTOP_INVERTING;
5889
+
5862 5890
       #elif ENABLED(Z_MIN_PROBE_ENDSTOP)
5891
+
5863 5892
         #define PROBE_TEST_PIN Z_MIN_PROBE_PIN
5864 5893
         SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
5865 5894
         SERIAL_PROTOCOLLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
5866 5895
         SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
5867
-        if (Z_MIN_PROBE_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
5868
-        else  SERIAL_PROTOCOLLNPGM("false");
5896
+
5897
+        #if Z_MIN_PROBE_ENDSTOP_INVERTING
5898
+          SERIAL_PROTOCOLLNPGM("true");
5899
+        #else
5900
+          SERIAL_PROTOCOLLNPGM("false");
5901
+        #endif
5902
+
5869 5903
         probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
5870
-      #else
5871
-        #error "ERROR - probe pin not defined - strange, SANITY_CHECK should have caught this"
5904
+
5872 5905
       #endif
5906
+
5873 5907
       SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times");
5874 5908
       pinMode(PROBE_TEST_PIN, INPUT_PULLUP);
5875 5909
       bool deploy_state;
@@ -5883,7 +5917,9 @@ inline void gcode_M42() {
5883 5917
         stow_state = digitalRead(PROBE_TEST_PIN);
5884 5918
       }
5885 5919
       if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
5920
+
5886 5921
       refresh_cmd_timeout();
5922
+
5887 5923
       if (deploy_state != stow_state) {
5888 5924
         SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
5889 5925
         if (deploy_state) {
@@ -5900,32 +5936,43 @@ inline void gcode_M42() {
5900 5936
 
5901 5937
       }
5902 5938
       else {                                           // measure active signal length
5903
-        servo[probe_index].move(z_servo_angle[0]); //deploy
5939
+        servo[probe_index].move(z_servo_angle[0]);     // deploy
5904 5940
         safe_delay(500);
5905 5941
         SERIAL_PROTOCOLLNPGM("please trigger probe");
5906 5942
         uint16_t probe_counter = 0;
5907
-        for (uint16_t j = 0; j < 500*30 && probe_counter == 0 ; j++) {   // allow 30 seconds max for operator to trigger probe
5943
+
5944
+        // Allow 30 seconds max for operator to trigger probe
5945
+        for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
5946
+
5908 5947
           safe_delay(2);
5909
-          if ( 0 == j%(500*1)) {refresh_cmd_timeout(); watchdog_reset();}  // beat the dog every 45 seconds
5910
-          if (deploy_state != digitalRead(PROBE_TEST_PIN)) {             // probe triggered
5911
-            for (probe_counter = 1; probe_counter < 50 && (deploy_state != digitalRead(PROBE_TEST_PIN)); probe_counter ++) {
5948
+
5949
+          if (0 == j % (500 * 1)) // keep cmd_timeout happy
5950
+            refresh_cmd_timeout();
5951
+
5952
+          if (deploy_state != digitalRead(PROBE_TEST_PIN)) { // probe triggered
5953
+
5954
+            for (probe_counter = 1; probe_counter < 50 && deploy_state != digitalRead(PROBE_TEST_PIN); ++probe_counter)
5912 5955
               safe_delay(2);
5913
-            }
5914
-            if (probe_counter == 50) {
5915
-              SERIAL_PROTOCOLLNPGM("Z Servo Probe detected");   // >= 100mS active time
5916
-            }
5917
-            else if (probe_counter >= 2 ) {
5918
-              SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2 );   // allow 4 - 100mS pulse
5919
-            }
5920
-            else {
5921
-              SERIAL_PROTOCOLLNPGM("noise detected - please re-run test");   // less than 2mS pulse
5922
-            }
5956
+
5957
+            if (probe_counter == 50)
5958
+              SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time
5959
+            else if (probe_counter >= 2)
5960
+              SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
5961
+            else
5962
+              SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
5963
+
5923 5964
             servo[probe_index].move(z_servo_angle[1]); //stow
5965
+
5924 5966
           }  // pulse detected
5925
-        }    // for loop waiting for trigger
5967
+
5968
+        } // for loop waiting for trigger
5969
+
5926 5970
         if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected");
5927
-      }      // measure active signal length
5971
+
5972
+      } // measure active signal length
5973
+
5928 5974
     #endif
5975
+
5929 5976
   } // servo_probe_test
5930 5977
 
5931 5978
   /**
@@ -5977,39 +6024,43 @@ inline void gcode_M42() {
5977 6024
     }
5978 6025
 
5979 6026
     // Get the range of pins to test or watch
5980
-    int first_pin = 0, last_pin = NUM_DIGITAL_PINS - 1;
5981
-    if (code_seen('P')) {
5982
-      first_pin = last_pin = code_value_byte();
5983
-      if (first_pin > NUM_DIGITAL_PINS - 1) return;
5984
-    }
6027
+    const uint8_t first_pin = code_seen('P') ? code_value_byte() : 0,
6028
+                  last_pin = code_seen('P') ? first_pin : NUM_DIGITAL_PINS - 1;
5985 6029
 
5986
-    bool ignore_protection = code_seen('I') ? code_value_bool() : false;
6030
+    if (first_pin > last_pin) return;
6031
+
6032
+    const bool ignore_protection = code_seen('I') && code_value_bool();
5987 6033
 
5988 6034
     // Watch until click, M108, or reset
5989
-    if (code_seen('W') && code_value_bool()) { // watch digital pins
6035
+    if (code_seen('W') && code_value_bool()) {
5990 6036
       SERIAL_PROTOCOLLNPGM("Watching pins");
5991 6037
       byte pin_state[last_pin - first_pin + 1];
5992 6038
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {
5993 6039
         if (pin_is_protected(pin) && !ignore_protection) continue;
5994 6040
         pinMode(pin, INPUT_PULLUP);
5995
-        // if (IS_ANALOG(pin))
5996
-        //   pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
5997
-        // else
5998
-          pin_state[pin - first_pin] = digitalRead(pin);
6041
+        /*
6042
+          if (IS_ANALOG(pin))
6043
+            pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
6044
+          else
6045
+        //*/
6046
+            pin_state[pin - first_pin] = digitalRead(pin);
5999 6047
       }
6000 6048
 
6001 6049
       #if HAS_RESUME_CONTINUE
6002 6050
         wait_for_user = true;
6051
+        KEEPALIVE_STATE(PAUSED_FOR_USER);
6003 6052
       #endif
6004 6053
 
6005
-      for(;;) {
6054
+      for (;;) {
6006 6055
         for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6007 6056
           if (pin_is_protected(pin)) continue;
6008
-          byte val;
6009
-          // if (IS_ANALOG(pin))
6010
-          //   val = analogRead(pin - analogInputToDigitalPin(0)); // int16_t val
6011
-          // else
6012
-            val = digitalRead(pin);
6057
+          const byte val =
6058
+            /*
6059
+              IS_ANALOG(pin)
6060
+                ? analogRead(pin - analogInputToDigitalPin(0)) : // int16_t val
6061
+                :
6062
+            //*/
6063
+              digitalRead(pin);
6013 6064
           if (val != pin_state[pin - first_pin]) {
6014 6065
             report_pin_state(pin);
6015 6066
             pin_state[pin - first_pin] = val;
@@ -6017,7 +6068,10 @@ inline void gcode_M42() {
6017 6068
         }
6018 6069
 
6019 6070
         #if HAS_RESUME_CONTINUE
6020
-          if (!wait_for_user) break;
6071
+          if (!wait_for_user) {
6072
+            KEEPALIVE_STATE(IN_HANDLER);
6073
+            break;
6074
+          }
6021 6075
         #endif
6022 6076
 
6023 6077
         safe_delay(500);
@@ -9571,8 +9625,8 @@ void process_next_command() {
9571 9625
     SERIAL_ECHO_START;
9572 9626
     SERIAL_ECHOLN(current_command);
9573 9627
     #if ENABLED(M100_FREE_MEMORY_WATCHER)
9574
-      SERIAL_ECHOPAIR("slot:", cmd_queue_index_r);                                                
9575
-      M100_dump_routine( "   Command Queue:", &command_queue[0][0], &command_queue[BUFSIZE][MAX_CMD_SIZE] );  
9628
+      SERIAL_ECHOPAIR("slot:", cmd_queue_index_r);
9629
+      M100_dump_routine("   Command Queue:", &command_queue[0][0], &command_queue[BUFSIZE][MAX_CMD_SIZE]);
9576 9630
     #endif
9577 9631
   }
9578 9632
 
@@ -11166,19 +11220,20 @@ void prepare_move_to_destination() {
11166 11220
    */
11167 11221
   void plan_arc(
11168 11222
     float logical[XYZE], // Destination position
11169
-    float* offset,           // Center of rotation relative to current_position
11170
-    uint8_t clockwise        // Clockwise?
11223
+    float *offset,       // Center of rotation relative to current_position
11224
+    uint8_t clockwise    // Clockwise?
11171 11225
   ) {
11172 11226
 
11173
-    float radius = HYPOT(offset[X_AXIS], offset[Y_AXIS]),
11174
-          center_X = current_position[X_AXIS] + offset[X_AXIS],
11175
-          center_Y = current_position[Y_AXIS] + offset[Y_AXIS],
11176
-          linear_travel = logical[Z_AXIS] - current_position[Z_AXIS],
11177
-          extruder_travel = logical[E_AXIS] - current_position[E_AXIS],
11178
-          r_X = -offset[X_AXIS],  // Radius vector from center to current location
11179
-          r_Y = -offset[Y_AXIS],
11180
-          rt_X = logical[X_AXIS] - center_X,
11181
-          rt_Y = logical[Y_AXIS] - center_Y;
11227
+    float r_X = -offset[X_AXIS],  // Radius vector from center to current location
11228
+          r_Y = -offset[Y_AXIS];
11229
+
11230
+    const float radius = HYPOT(r_X, r_Y),
11231
+                center_X = current_position[X_AXIS] - r_X,
11232
+                center_Y = current_position[Y_AXIS] - r_Y,
11233
+                rt_X = logical[X_AXIS] - center_X,
11234
+                rt_Y = logical[Y_AXIS] - center_Y,
11235
+                linear_travel = logical[Z_AXIS] - current_position[Z_AXIS],
11236
+                extruder_travel = logical[E_AXIS] - current_position[E_AXIS];
11182 11237
 
11183 11238
     // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
11184 11239
     float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
@@ -11222,12 +11277,12 @@ void prepare_move_to_destination() {
11222 11277
      * This is important when there are successive arc motions.
11223 11278
      */
11224 11279
     // Vector rotation matrix values
11225
-    float arc_target[XYZE],
11226
-          theta_per_segment = angular_travel / segments,
11227
-          linear_per_segment = linear_travel / segments,
11228
-          extruder_per_segment = extruder_travel / segments,
11229
-          sin_T = theta_per_segment,
11230
-          cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
11280
+    float arc_target[XYZE];
11281
+    const float theta_per_segment = angular_travel / segments,
11282
+                linear_per_segment = linear_travel / segments,
11283
+                extruder_per_segment = extruder_travel / segments,
11284
+                sin_T = theta_per_segment,
11285
+                cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
11231 11286
 
11232 11287
     // Initialize the linear axis
11233 11288
     arc_target[Z_AXIS] = current_position[Z_AXIS];
@@ -11235,7 +11290,7 @@ void prepare_move_to_destination() {
11235 11290
     // Initialize the extruder axis
11236 11291
     arc_target[E_AXIS] = current_position[E_AXIS];
11237 11292
 
11238
-    float fr_mm_s = MMS_SCALED(feedrate_mm_s);
11293
+    const float fr_mm_s = MMS_SCALED(feedrate_mm_s);
11239 11294
 
11240 11295
     millis_t next_idle_ms = millis() + 200UL;
11241 11296
 
@@ -11250,7 +11305,7 @@ void prepare_move_to_destination() {
11250 11305
 
11251 11306
       if (++count < N_ARC_CORRECTION) {
11252 11307
         // Apply vector rotation matrix to previous r_X / 1
11253
-        float r_new_Y = r_X * sin_T + r_Y * cos_T;
11308
+        const float r_new_Y = r_X * sin_T + r_Y * cos_T;
11254 11309
         r_X = r_X * cos_T - r_Y * sin_T;
11255 11310
         r_Y = r_new_Y;
11256 11311
       }
@@ -11259,8 +11314,8 @@ void prepare_move_to_destination() {
11259 11314
         // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
11260 11315
         // To reduce stuttering, the sin and cos could be computed at different times.
11261 11316
         // For now, compute both at the same time.
11262
-        float cos_Ti = cos(i * theta_per_segment),
11263
-              sin_Ti = sin(i * theta_per_segment);
11317
+        const float cos_Ti = cos(i * theta_per_segment),
11318
+                    sin_Ti = sin(i * theta_per_segment);
11264 11319
         r_X = -offset[X_AXIS] * cos_Ti + offset[Y_AXIS] * sin_Ti;
11265 11320
         r_Y = -offset[X_AXIS] * sin_Ti - offset[Y_AXIS] * cos_Ti;
11266 11321
         count = 0;
@@ -11774,30 +11829,15 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
11774 11829
         enable_E0();
11775 11830
       #else // !SWITCHING_EXTRUDER
11776 11831
         switch (active_extruder) {
11777
-          case 0:
11778
-            oldstatus = E0_ENABLE_READ;
11779
-            enable_E0();
11780
-            break;
11832
+          case 0: oldstatus = E0_ENABLE_READ; enable_E0(); break;
11781 11833
           #if E_STEPPERS > 1
11782
-            case 1:
11783
-              oldstatus = E1_ENABLE_READ;
11784
-              enable_E1();
11785
-              break;
11834
+            case 1: oldstatus = E1_ENABLE_READ; enable_E1(); break;
11786 11835
             #if E_STEPPERS > 2
11787
-              case 2:
11788
-                oldstatus = E2_ENABLE_READ;
11789
-                enable_E2();
11790
-                break;
11836
+              case 2: oldstatus = E2_ENABLE_READ; enable_E2(); break;
11791 11837
               #if E_STEPPERS > 3
11792
-                case 3:
11793
-                  oldstatus = E3_ENABLE_READ;
11794
-                  enable_E3();
11795
-                  break;
11838
+                case 3: oldstatus = E3_ENABLE_READ; enable_E3(); break;
11796 11839
                 #if E_STEPPERS > 4
11797
-                  case 4:
11798
-                    oldstatus = E4_ENABLE_READ;
11799
-                    enable_E4();
11800
-                    break;
11840
+                  case 4: oldstatus = E4_ENABLE_READ; enable_E4(); break;
11801 11841
                 #endif // E_STEPPERS > 4
11802 11842
               #endif // E_STEPPERS > 3
11803 11843
             #endif // E_STEPPERS > 2
@@ -11817,25 +11857,15 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
11817 11857
         E0_ENABLE_WRITE(oldstatus);
11818 11858
       #else
11819 11859
         switch (active_extruder) {
11820
-          case 0:
11821
-            E0_ENABLE_WRITE(oldstatus);
11822
-            break;
11860
+          case 0: E0_ENABLE_WRITE(oldstatus); break;
11823 11861
           #if E_STEPPERS > 1
11824
-            case 1:
11825
-              E1_ENABLE_WRITE(oldstatus);
11826
-              break;
11862
+            case 1: E1_ENABLE_WRITE(oldstatus); break;
11827 11863
             #if E_STEPPERS > 2
11828
-              case 2:
11829
-                E2_ENABLE_WRITE(oldstatus);
11830
-                break;
11864
+              case 2: E2_ENABLE_WRITE(oldstatus); break;
11831 11865
               #if E_STEPPERS > 3
11832
-                case 3:
11833
-                  E3_ENABLE_WRITE(oldstatus);
11834
-                  break;
11866
+                case 3: E3_ENABLE_WRITE(oldstatus); break;
11835 11867
                 #if E_STEPPERS > 4
11836
-                  case 4:
11837
-                    E4_ENABLE_WRITE(oldstatus);
11838
-                    break;
11868
+                  case 4: E4_ENABLE_WRITE(oldstatus); break;
11839 11869
                 #endif // E_STEPPERS > 4
11840 11870
               #endif // E_STEPPERS > 3
11841 11871
             #endif // E_STEPPERS > 2

+ 8
- 2
Marlin/configuration_store.cpp View File

@@ -339,7 +339,10 @@ void MarlinSettings::postprocess() {
339 339
 
340 340
     #if ENABLED(MESH_BED_LEVELING)
341 341
       // Compile time test that sizeof(mbl.z_values) is as expected
342
-      typedef char c_assert[(sizeof(mbl.z_values) == (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y) * sizeof(dummy)) ? 1 : -1];
342
+      static_assert(
343
+        sizeof(mbl.z_values) == (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y) * sizeof(mbl.z_values[0][0]),
344
+        "MBL Z array is the wrong size."
345
+      );
343 346
       const bool leveling_is_on = TEST(mbl.status, MBL_STATUS_HAS_MESH_BIT);
344 347
       const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
345 348
       EEPROM_WRITE(leveling_is_on);
@@ -381,7 +384,10 @@ void MarlinSettings::postprocess() {
381 384
 
382 385
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
383 386
       // Compile time test that sizeof(bed_level_grid) is as expected
384
-      typedef char c_assert[(sizeof(bed_level_grid) == (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y) * sizeof(dummy)) ? 1 : -1];
387
+      static_assert(
388
+        sizeof(bed_level_grid) == (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y) * sizeof(bed_level_grid[0][0]),
389
+        "Bilinear Z array is the wrong size."
390
+      );
385 391
       const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y;
386 392
       EEPROM_WRITE(grid_max_x);            // 1 byte
387 393
       EEPROM_WRITE(grid_max_y);            // 1 byte

+ 17
- 14
Marlin/hex_print_routines.cpp View File

@@ -19,32 +19,35 @@
19 19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 20
  *
21 21
  */
22
-
23
-
24 22
 #include "Marlin.h"
25 23
 #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(M100_FREE_MEMORY_WATCHER)
26 24
 
27 25
 #include "hex_print_routines.h"
28 26
 
29
-static char _hex[5] = { 0 };
27
+static char _hex[7] = "0x0000";
30 28
 
31 29
 char* hex_byte(const uint8_t b) {
32
-  _hex[0] = hex_nybble(b >> 4);
33
-  _hex[1] = hex_nybble(b);
34
-  _hex[2] = '\0';
35
-  return _hex;
30
+  _hex[4] = hex_nybble(b >> 4);
31
+  _hex[5] = hex_nybble(b);
32
+  return &_hex[4];
36 33
 }
37 34
 
38 35
 char* hex_word(const uint16_t w) {
39
-  _hex[0] = hex_nybble(w >> 12);
40
-  _hex[1] = hex_nybble(w >> 8);
41
-  _hex[2] = hex_nybble(w >> 4);
42
-  _hex[3] = hex_nybble(w);
36
+  _hex[2] = hex_nybble(w >> 12);
37
+  _hex[3] = hex_nybble(w >> 8);
38
+  _hex[4] = hex_nybble(w >> 4);
39
+  _hex[5] = hex_nybble(w);
40
+  return &_hex[2];
41
+}
42
+
43
+char* hex_address(const void * const w) {
44
+  (void)hex_word((uint16_t)w);
43 45
   return _hex;
44 46
 }
45 47
 
46
-void print_hex_nybble(const uint8_t n) { SERIAL_CHAR(hex_nybble(n)); }
47
-void print_hex_byte(const uint8_t b)   { SERIAL_ECHO(hex_byte(b)); }
48
-void print_hex_word(const uint16_t w)  { SERIAL_ECHO(hex_word(w)); }
48
+void print_hex_nybble(const uint8_t n)       { SERIAL_CHAR(hex_nybble(n));  }
49
+void print_hex_byte(const uint8_t b)         { SERIAL_ECHO(hex_byte(b));    }
50
+void print_hex_word(const uint16_t w)        { SERIAL_ECHO(hex_word(w));    }
51
+void print_hex_address(const void * const w) { SERIAL_ECHO(hex_address(w)); }
49 52
 
50 53
 #endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER

+ 2
- 0
Marlin/hex_print_routines.h View File

@@ -36,10 +36,12 @@ inline char hex_nybble(const uint8_t n) {
36 36
 }
37 37
 char* hex_byte(const uint8_t b);
38 38
 char* hex_word(const uint16_t w);
39
+char* hex_address(const void * const w);
39 40
 
40 41
 void print_hex_nybble(const uint8_t n);
41 42
 void print_hex_byte(const uint8_t b);
42 43
 void print_hex_word(const uint16_t w);
44
+void print_hex_address(const void * const w);
43 45
 
44 46
 #endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER
45 47
 #endif // HEX_PRINT_ROUTINES_H

+ 2
- 6
Marlin/pinsDebug.h View File

@@ -255,12 +255,11 @@ static void err_is_counter() {
255 255
   SERIAL_PROTOCOLPGM("   non-standard PWM mode");
256 256
 }
257 257
 static void err_is_interrupt() {
258
-  SERIAL_PROTOCOLPGM("   compare interrupt enabled ");
258
+  SERIAL_PROTOCOLPGM("   compare interrupt enabled");
259 259
 }
260 260
 static void err_prob_interrupt() {
261 261
   SERIAL_PROTOCOLPGM("   overflow interrupt enabled");
262 262
 }
263
-static void can_be_used() { SERIAL_PROTOCOLPGM("   can be used as PWM   "); }
264 263
 
265 264
 void com_print(uint8_t N, uint8_t Z) {
266 265
   uint8_t *TCCRA = (uint8_t*) TCCR_A(N);
@@ -325,9 +324,6 @@ void timer_prefix(uint8_t T, char L, uint8_t N) {  // T - timer    L - pwm  n -
325 324
 }
326 325
 
327 326
 static void pwm_details(uint8_t pin) {
328
-  char buffer[20];   // for the sprintf statements
329
-  uint8_t WGM;
330
-
331 327
   switch(digitalPinToTimer(pin)) {
332 328
 
333 329
     #if defined(TCCR0A) && defined(COM0A1)
@@ -524,7 +520,7 @@ inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = t
524 520
 
525 521
       SERIAL_PROTOCOLPAIR("   Input  = ", digitalRead_mod(pin));
526 522
     }
527
-    //if (!pwm_status(pin)) SERIAL_ECHOCHAR(' ');    // add padding if it's not a PWM pin
523
+    //if (!pwm_status(pin)) SERIAL_CHAR(' ');    // add padding if it's not a PWM pin
528 524
     if (extended) pwm_details(pin);  // report PWM capabilities only if doing an extended report
529 525
     SERIAL_EOL;
530 526
   }

+ 2
- 2
Marlin/ubl.cpp View File

@@ -118,7 +118,7 @@
118 118
     eeprom_read_block((void *)&z_values, (void *)j, sizeof(z_values));
119 119
 
120 120
     SERIAL_PROTOCOLPAIR("Mesh loaded from slot ", m);
121
-    SERIAL_PROTOCOLLNPAIR(" at offset 0x", hex_word(j));
121
+    SERIAL_PROTOCOLLNPAIR(" at offset ", hex_address((void*)j));
122 122
   }
123 123
 
124 124
   void unified_bed_leveling::store_mesh(const int16_t m) {
@@ -140,7 +140,7 @@
140 140
     eeprom_write_block((const void *)&z_values, (void *)j, sizeof(z_values));
141 141
 
142 142
     SERIAL_PROTOCOLPAIR("Mesh saved in slot ", m);
143
-    SERIAL_PROTOCOLLNPAIR(" at offset 0x", hex_word(j));
143
+    SERIAL_PROTOCOLLNPAIR(" at offset ", hex_address((void*)j));
144 144
   }
145 145
 
146 146
   void unified_bed_leveling::reset() {

+ 9
- 13
Marlin/ubl_G29.cpp View File

@@ -35,7 +35,6 @@
35 35
 
36 36
   #include <math.h>
37 37
 
38
-  void lcd_babystep_z();
39 38
   void lcd_return_to_status();
40 39
   bool lcd_clicked();
41 40
   void lcd_implementation_clear();
@@ -305,7 +304,7 @@
305 304
 
306 305
   // The simple parameter flags and values are 'static' so parameter parsing can be in a support routine.
307 306
   static int g29_verbose_level, phase_value = -1, repetition_cnt,
308
-             storage_slot=0, map_type, grid_size;
307
+             storage_slot = 0, map_type, grid_size;
309 308
   static bool repeat_flag, c_flag, x_flag, y_flag;
310 309
   static float x_pos, y_pos, measured_z, card_thickness = 0.0, ubl_constant = 0.0;
311 310
 
@@ -330,13 +329,10 @@
330 329
     // Invalidate Mesh Points. This command is a little bit asymetrical because
331 330
     // it directly specifies the repetition count and does not use the 'R' parameter.
332 331
     if (code_seen('I')) {
333
-      int cnt = 0;
332
+      uint8_t cnt = 0;
334 333
       repetition_cnt = code_has_value() ? code_value_int() : 1;
335 334
       while (repetition_cnt--) {
336
-        if (cnt>20) {
337
-          cnt = 0;
338
-          idle();
339
-        }
335
+        if (cnt > 20) { cnt = 0; idle(); }
340 336
         const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, x_pos, y_pos, 0, NULL, false);  // The '0' says we want to use the nozzle's position
341 337
         if (location.x_index < 0) {
342 338
           SERIAL_PROTOCOLLNPGM("Entire Mesh invalidated.\n");
@@ -381,7 +377,7 @@
381 377
     }
382 378
 
383 379
     if (code_seen('J')) {
384
-      if (grid_size<2 || grid_size>5) {
380
+      if (!WITHIN(grid_size, 2, 5)) {
385 381
         SERIAL_PROTOCOLLNPGM("ERROR - grid size must be between 2 and 5");
386 382
         return;
387 383
       }
@@ -996,7 +992,7 @@
996 992
     repetition_cnt = 0;
997 993
     repeat_flag = code_seen('R');
998 994
     if (repeat_flag) {
999
-      repetition_cnt = code_has_value() ? code_value_int() : GRID_MAX_POINTS_X*GRID_MAX_POINTS_Y;
995
+      repetition_cnt = code_has_value() ? code_value_int() : (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y);
1000 996
       if (repetition_cnt < 1) {
1001 997
         SERIAL_PROTOCOLLNPGM("Invalid Repetition count.\n");
1002 998
         return UBL_ERR;
@@ -1206,9 +1202,9 @@
1206 1202
     SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1207 1203
     SERIAL_EOL;
1208 1204
     safe_delay(50);
1209
-    SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: 0x", hex_word(ubl.eeprom_start));
1205
+    SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: ", hex_address((void*)ubl.eeprom_start));
1210 1206
 
1211
-    SERIAL_PROTOCOLLNPAIR("end of EEPROM              : 0x", hex_word(E2END));
1207
+    SERIAL_PROTOCOLLNPAIR("end of EEPROM              : ", hex_address((void*)E2END));
1212 1208
     safe_delay(50);
1213 1209
 
1214 1210
     SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
@@ -1217,7 +1213,7 @@
1217 1213
     SERIAL_EOL;
1218 1214
     safe_delay(50);
1219 1215
 
1220
-    SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: 0x", hex_word(k));
1216
+    SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)k));
1221 1217
     safe_delay(50);
1222 1218
 
1223 1219
     SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(ubl.z_values));
@@ -1295,7 +1291,7 @@
1295 1291
     eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values));
1296 1292
 
1297 1293
     SERIAL_ECHOPAIR("Subtracting Mesh ", storage_slot);
1298
-    SERIAL_PROTOCOLLNPAIR(" loaded from EEPROM address 0x", hex_word(j)); // Soon, we can remove the extra clutter of printing
1294
+    SERIAL_PROTOCOLLNPAIR(" loaded from EEPROM address ", hex_address((void*)j)); // Soon, we can remove the extra clutter of printing
1299 1295
                                                                         // the address in the EEPROM where the Mesh is stored.
1300 1296
 
1301 1297
     for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)

Loading…
Cancel
Save