Browse Source

Apply const, spacing to Marlin_main.cpp

Scott Lahteine 7 years ago
parent
commit
4ce2a63db0
1 changed files with 42 additions and 71 deletions
  1. 42
    71
      Marlin/Marlin_main.cpp

+ 42
- 71
Marlin/Marlin_main.cpp View File

1091
       if (IsStopped()) {
1091
       if (IsStopped()) {
1092
         char* gpos = strchr(command, 'G');
1092
         char* gpos = strchr(command, 'G');
1093
         if (gpos) {
1093
         if (gpos) {
1094
-          int codenum = strtol(gpos + 1, NULL, 10);
1094
+          const int codenum = strtol(gpos + 1, NULL, 10);
1095
           switch (codenum) {
1095
           switch (codenum) {
1096
             case 0:
1096
             case 0:
1097
             case 1:
1097
             case 1:
4927
    *     S = Stows the probe if 1 (default=1)
4927
    *     S = Stows the probe if 1 (default=1)
4928
    */
4928
    */
4929
   inline void gcode_G30() {
4929
   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;
4930
+    const float xpos = code_seen('X') ? code_value_linear_units() : current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
4931
+                ypos = code_seen('Y') ? code_value_linear_units() : current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
4932
+                pos[XYZ] = { xpos, ypos, LOGICAL_Z_POSITION(0) };
4932
 
4933
 
4933
-    float pos[XYZ] = { X_probe_location, Y_probe_location, LOGICAL_Z_POSITION(0) };
4934
     if (!position_is_reachable(pos, true)) return;
4934
     if (!position_is_reachable(pos, true)) return;
4935
 
4935
 
4936
-    bool stow = code_seen('S') ? code_value_bool() : true;
4937
-
4938
     // Disable leveling so the planner won't mess with us
4936
     // Disable leveling so the planner won't mess with us
4939
     #if PLANNER_LEVELING
4937
     #if PLANNER_LEVELING
4940
       set_bed_leveling_enabled(false);
4938
       set_bed_leveling_enabled(false);
4942
 
4940
 
4943
     setup_for_endstop_or_probe_move();
4941
     setup_for_endstop_or_probe_move();
4944
 
4942
 
4945
-    float measured_z = probe_pt(X_probe_location, Y_probe_location, stow, 1);
4943
+    const float measured_z = probe_pt(xpos, ypos, !code_seen('S') || code_value_bool(), 1);
4946
 
4944
 
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));
4945
+    SERIAL_PROTOCOLPAIR("Bed X: ", FIXFLOAT(xpos));
4946
+    SERIAL_PROTOCOLPAIR(" Y: ", FIXFLOAT(ypos));
4947
+    SERIAL_PROTOCOLLNPAIR(" Z: ", FIXFLOAT(measured_z));
4953
 
4948
 
4954
     clean_up_after_endstop_or_probe_move();
4949
     clean_up_after_endstop_or_probe_move();
4955
 
4950
 
5466
    * M1: Conditional stop   - Wait for user button press on LCD
5461
    * M1: Conditional stop   - Wait for user button press on LCD
5467
    */
5462
    */
5468
   inline void gcode_M0_M1() {
5463
   inline void gcode_M0_M1() {
5469
-    char* args = current_command_args;
5464
+    const char * const args = current_command_args;
5470
 
5465
 
5471
     millis_t codenum = 0;
5466
     millis_t codenum = 0;
5472
     bool hasP = false, hasS = false;
5467
     bool hasP = false, hasS = false;
5524
     KEEPALIVE_STATE(IN_HANDLER);
5519
     KEEPALIVE_STATE(IN_HANDLER);
5525
   }
5520
   }
5526
 
5521
 
5527
-#endif // EMERGENCY_PARSER || ULTIPANEL
5522
+#endif // HAS_RESUME_CONTINUE
5528
 
5523
 
5529
 /**
5524
 /**
5530
  * M17: Enable power on all stepper motors
5525
  * M17: Enable power on all stepper motors
11210
    */
11205
    */
11211
   void plan_arc(
11206
   void plan_arc(
11212
     float logical[XYZE], // Destination position
11207
     float logical[XYZE], // Destination position
11213
-    float* offset,           // Center of rotation relative to current_position
11214
-    uint8_t clockwise        // Clockwise?
11208
+    float *offset,       // Center of rotation relative to current_position
11209
+    uint8_t clockwise    // Clockwise?
11215
   ) {
11210
   ) {
11216
 
11211
 
11217
-    float radius = HYPOT(offset[X_AXIS], offset[Y_AXIS]),
11218
-          center_X = current_position[X_AXIS] + offset[X_AXIS],
11219
-          center_Y = current_position[Y_AXIS] + offset[Y_AXIS],
11220
-          linear_travel = logical[Z_AXIS] - current_position[Z_AXIS],
11221
-          extruder_travel = logical[E_AXIS] - current_position[E_AXIS],
11222
-          r_X = -offset[X_AXIS],  // Radius vector from center to current location
11223
-          r_Y = -offset[Y_AXIS],
11224
-          rt_X = logical[X_AXIS] - center_X,
11225
-          rt_Y = logical[Y_AXIS] - center_Y;
11212
+    float r_X = -offset[X_AXIS],  // Radius vector from center to current location
11213
+          r_Y = -offset[Y_AXIS];
11214
+
11215
+    const float radius = HYPOT(r_X, r_Y),
11216
+                center_X = current_position[X_AXIS] - r_X,
11217
+                center_Y = current_position[Y_AXIS] - r_Y,
11218
+                rt_X = logical[X_AXIS] - center_X,
11219
+                rt_Y = logical[Y_AXIS] - center_Y,
11220
+                linear_travel = logical[Z_AXIS] - current_position[Z_AXIS],
11221
+                extruder_travel = logical[E_AXIS] - current_position[E_AXIS];
11226
 
11222
 
11227
     // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
11223
     // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
11228
     float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
11224
     float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
11266
      * This is important when there are successive arc motions.
11262
      * This is important when there are successive arc motions.
11267
      */
11263
      */
11268
     // Vector rotation matrix values
11264
     // Vector rotation matrix values
11269
-    float arc_target[XYZE],
11270
-          theta_per_segment = angular_travel / segments,
11271
-          linear_per_segment = linear_travel / segments,
11272
-          extruder_per_segment = extruder_travel / segments,
11273
-          sin_T = theta_per_segment,
11274
-          cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
11265
+    float arc_target[XYZE];
11266
+    const float theta_per_segment = angular_travel / segments,
11267
+                linear_per_segment = linear_travel / segments,
11268
+                extruder_per_segment = extruder_travel / segments,
11269
+                sin_T = theta_per_segment,
11270
+                cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
11275
 
11271
 
11276
     // Initialize the linear axis
11272
     // Initialize the linear axis
11277
     arc_target[Z_AXIS] = current_position[Z_AXIS];
11273
     arc_target[Z_AXIS] = current_position[Z_AXIS];
11279
     // Initialize the extruder axis
11275
     // Initialize the extruder axis
11280
     arc_target[E_AXIS] = current_position[E_AXIS];
11276
     arc_target[E_AXIS] = current_position[E_AXIS];
11281
 
11277
 
11282
-    float fr_mm_s = MMS_SCALED(feedrate_mm_s);
11278
+    const float fr_mm_s = MMS_SCALED(feedrate_mm_s);
11283
 
11279
 
11284
     millis_t next_idle_ms = millis() + 200UL;
11280
     millis_t next_idle_ms = millis() + 200UL;
11285
 
11281
 
11294
 
11290
 
11295
       if (++count < N_ARC_CORRECTION) {
11291
       if (++count < N_ARC_CORRECTION) {
11296
         // Apply vector rotation matrix to previous r_X / 1
11292
         // Apply vector rotation matrix to previous r_X / 1
11297
-        float r_new_Y = r_X * sin_T + r_Y * cos_T;
11293
+        const float r_new_Y = r_X * sin_T + r_Y * cos_T;
11298
         r_X = r_X * cos_T - r_Y * sin_T;
11294
         r_X = r_X * cos_T - r_Y * sin_T;
11299
         r_Y = r_new_Y;
11295
         r_Y = r_new_Y;
11300
       }
11296
       }
11303
         // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
11299
         // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
11304
         // To reduce stuttering, the sin and cos could be computed at different times.
11300
         // To reduce stuttering, the sin and cos could be computed at different times.
11305
         // For now, compute both at the same time.
11301
         // For now, compute both at the same time.
11306
-        float cos_Ti = cos(i * theta_per_segment),
11307
-              sin_Ti = sin(i * theta_per_segment);
11302
+        const float cos_Ti = cos(i * theta_per_segment),
11303
+                    sin_Ti = sin(i * theta_per_segment);
11308
         r_X = -offset[X_AXIS] * cos_Ti + offset[Y_AXIS] * sin_Ti;
11304
         r_X = -offset[X_AXIS] * cos_Ti + offset[Y_AXIS] * sin_Ti;
11309
         r_Y = -offset[X_AXIS] * sin_Ti - offset[Y_AXIS] * cos_Ti;
11305
         r_Y = -offset[X_AXIS] * sin_Ti - offset[Y_AXIS] * cos_Ti;
11310
         count = 0;
11306
         count = 0;
11818
         enable_E0();
11814
         enable_E0();
11819
       #else // !SWITCHING_EXTRUDER
11815
       #else // !SWITCHING_EXTRUDER
11820
         switch (active_extruder) {
11816
         switch (active_extruder) {
11821
-          case 0:
11822
-            oldstatus = E0_ENABLE_READ;
11823
-            enable_E0();
11824
-            break;
11817
+          case 0: oldstatus = E0_ENABLE_READ; enable_E0(); break;
11825
           #if E_STEPPERS > 1
11818
           #if E_STEPPERS > 1
11826
-            case 1:
11827
-              oldstatus = E1_ENABLE_READ;
11828
-              enable_E1();
11829
-              break;
11819
+            case 1: oldstatus = E1_ENABLE_READ; enable_E1(); break;
11830
             #if E_STEPPERS > 2
11820
             #if E_STEPPERS > 2
11831
-              case 2:
11832
-                oldstatus = E2_ENABLE_READ;
11833
-                enable_E2();
11834
-                break;
11821
+              case 2: oldstatus = E2_ENABLE_READ; enable_E2(); break;
11835
               #if E_STEPPERS > 3
11822
               #if E_STEPPERS > 3
11836
-                case 3:
11837
-                  oldstatus = E3_ENABLE_READ;
11838
-                  enable_E3();
11839
-                  break;
11823
+                case 3: oldstatus = E3_ENABLE_READ; enable_E3(); break;
11840
                 #if E_STEPPERS > 4
11824
                 #if E_STEPPERS > 4
11841
-                  case 4:
11842
-                    oldstatus = E4_ENABLE_READ;
11843
-                    enable_E4();
11844
-                    break;
11825
+                  case 4: oldstatus = E4_ENABLE_READ; enable_E4(); break;
11845
                 #endif // E_STEPPERS > 4
11826
                 #endif // E_STEPPERS > 4
11846
               #endif // E_STEPPERS > 3
11827
               #endif // E_STEPPERS > 3
11847
             #endif // E_STEPPERS > 2
11828
             #endif // E_STEPPERS > 2
11861
         E0_ENABLE_WRITE(oldstatus);
11842
         E0_ENABLE_WRITE(oldstatus);
11862
       #else
11843
       #else
11863
         switch (active_extruder) {
11844
         switch (active_extruder) {
11864
-          case 0:
11865
-            E0_ENABLE_WRITE(oldstatus);
11866
-            break;
11845
+          case 0: E0_ENABLE_WRITE(oldstatus); break;
11867
           #if E_STEPPERS > 1
11846
           #if E_STEPPERS > 1
11868
-            case 1:
11869
-              E1_ENABLE_WRITE(oldstatus);
11870
-              break;
11847
+            case 1: E1_ENABLE_WRITE(oldstatus); break;
11871
             #if E_STEPPERS > 2
11848
             #if E_STEPPERS > 2
11872
-              case 2:
11873
-                E2_ENABLE_WRITE(oldstatus);
11874
-                break;
11849
+              case 2: E2_ENABLE_WRITE(oldstatus); break;
11875
               #if E_STEPPERS > 3
11850
               #if E_STEPPERS > 3
11876
-                case 3:
11877
-                  E3_ENABLE_WRITE(oldstatus);
11878
-                  break;
11851
+                case 3: E3_ENABLE_WRITE(oldstatus); break;
11879
                 #if E_STEPPERS > 4
11852
                 #if E_STEPPERS > 4
11880
-                  case 4:
11881
-                    E4_ENABLE_WRITE(oldstatus);
11882
-                    break;
11853
+                  case 4: E4_ENABLE_WRITE(oldstatus); break;
11883
                 #endif // E_STEPPERS > 4
11854
                 #endif // E_STEPPERS > 4
11884
               #endif // E_STEPPERS > 3
11855
               #endif // E_STEPPERS > 3
11885
             #endif // E_STEPPERS > 2
11856
             #endif // E_STEPPERS > 2

Loading…
Cancel
Save