Parcourir la source

Apply Marlin coding standards to MBL class

Scott Lahteine il y a 9 ans
Parent
révision
c2362c1b3c

+ 9
- 9
Marlin/Marlin_main.cpp Voir le fichier

@@ -2645,14 +2645,14 @@ inline void gcode_G28() {
2645 2645
    */
2646 2646
   #if ENABLED(MESH_BED_LEVELING)
2647 2647
     float pre_home_z = MESH_HOME_SEARCH_Z;
2648
-    if (mbl.is_active()) {
2648
+    if (mbl.active()) {
2649 2649
       // Save known Z position if already homed
2650 2650
       if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
2651 2651
         pre_home_z = current_position[Z_AXIS];
2652 2652
         pre_home_z += mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
2653 2653
                                 current_position[Y_AXIS] - home_offset[Y_AXIS]);
2654 2654
       }
2655
-      mbl.is_active(false);
2655
+      mbl.set_active(false);
2656 2656
     }
2657 2657
   #endif
2658 2658
 
@@ -2957,7 +2957,7 @@ inline void gcode_G28() {
2957 2957
       if (home_all_axis || (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && homeZ)) {
2958 2958
         current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2959 2959
         sync_plan_position();
2960
-        mbl.is_active(true);
2960
+        mbl.set_active(true);
2961 2961
         #if ENABLED(MESH_G28_REST_ORIGIN)
2962 2962
           current_position[Z_AXIS] = 0.0;
2963 2963
           set_destination_to_current();
@@ -2973,7 +2973,7 @@ inline void gcode_G28() {
2973 2973
       else if ((axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) && (homeX || homeY)) {
2974 2974
         current_position[Z_AXIS] = pre_home_z;
2975 2975
         sync_plan_position();
2976
-        mbl.is_active(true);
2976
+        mbl.set_active(true);
2977 2977
         current_position[Z_AXIS] = pre_home_z -
2978 2978
           mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
2979 2979
                     current_position[Y_AXIS] - home_offset[Y_AXIS]);
@@ -3060,7 +3060,7 @@ inline void gcode_G28() {
3060 3060
       case MeshReport:
3061 3061
         if (mbl.has_mesh()) {
3062 3062
           SERIAL_PROTOCOLPGM("State: ");
3063
-          if (mbl.is_active())
3063
+          if (mbl.active())
3064 3064
             SERIAL_PROTOCOLPGM("On");
3065 3065
           else
3066 3066
             SERIAL_PROTOCOLPGM("Off");
@@ -3125,7 +3125,7 @@ inline void gcode_G28() {
3125 3125
           // After recording the last point, activate the mbl and home
3126 3126
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
3127 3127
           probe_point = -1;
3128
-          mbl.has_mesh(true);
3128
+          mbl.set_has_mesh(true);
3129 3129
           enqueue_and_echo_commands_P(PSTR("G28"));
3130 3130
         }
3131 3131
         break;
@@ -3175,7 +3175,7 @@ inline void gcode_G28() {
3175 3175
         break;
3176 3176
 
3177 3177
       case MeshReset:
3178
-        if (mbl.is_active()) {
3178
+        if (mbl.active()) {
3179 3179
           current_position[Z_AXIS] +=
3180 3180
             mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
3181 3181
                       current_position[Y_AXIS] - home_offset[Y_AXIS]) - MESH_HOME_SEARCH_Z;
@@ -5982,7 +5982,7 @@ inline void gcode_M410() {
5982 5982
   /**
5983 5983
    * M420: Enable/Disable Mesh Bed Leveling
5984 5984
    */
5985
-  inline void gcode_M420() { if (code_seen('S') && code_has_value()) mbl.has_mesh(!!code_value_short()); }
5985
+  inline void gcode_M420() { if (code_seen('S') && code_has_value()) mbl.set_has_mesh(!!code_value_short()); }
5986 5986
 
5987 5987
   /**
5988 5988
    * M421: Set a single Mesh Bed Leveling Z coordinate
@@ -7373,7 +7373,7 @@ void clamp_to_software_endstops(float target[3]) {
7373 7373
 
7374 7374
 // This function is used to split lines on mesh borders so each segment is only part of one mesh area
7375 7375
 void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7376
-  if (!mbl.is_active()) {
7376
+  if (!mbl.active()) {
7377 7377
     planner.buffer_line(x, y, z, e, feed_rate, extruder);
7378 7378
     set_current_to_destination();
7379 7379
     return;

+ 8
- 8
Marlin/configuration_store.cpp Voir le fichier

@@ -58,8 +58,8 @@
58 58
  *  188  M206 XYZ  home_offset (float x3)
59 59
  *
60 60
  * Mesh bed leveling:
61
- *  200  M420 S    status (0 = empty, 1 = has mesh numbers)
62
- *  201            z_offset (float) (added in V23)
61
+ *  200  M420 S    status (uint8)
62
+ *  201            z_offset (float)
63 63
  *  205            mesh_num_x (uint8 as set in firmware)
64 64
  *  206            mesh_num_y (uint8 as set in firmware)
65 65
  *  207 G29 S3 XYZ z_values[][] (float x9, by default)
@@ -187,21 +187,21 @@ void Config_StoreSettings()  {
187 187
   EEPROM_WRITE_VAR(i, planner.max_e_jerk);
188 188
   EEPROM_WRITE_VAR(i, home_offset);
189 189
 
190
-  uint8_t dummy_uint8 = 0;
191
-  uint8_t mesh_num_x = 3;
192
-  uint8_t mesh_num_y = 3;
193 190
   #if ENABLED(MESH_BED_LEVELING)
194 191
     // Compile time test that sizeof(mbl.z_values) is as expected
195 192
     typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1];
196
-    mesh_num_x = MESH_NUM_X_POINTS;
197
-    mesh_num_y = MESH_NUM_Y_POINTS;
198
-    dummy_uint8 = mbl.status & 0x01; // Do not save 'is active'
193
+    uint8_t mesh_num_x = MESH_NUM_X_POINTS,
194
+            mesh_num_y = MESH_NUM_Y_POINTS,
195
+            dummy_uint8 = mbl.status & _BV(MBL_STATUS_HAS_MESH_BIT);
199 196
     EEPROM_WRITE_VAR(i, dummy_uint8);
200 197
     EEPROM_WRITE_VAR(i, mbl.z_offset);
201 198
     EEPROM_WRITE_VAR(i, mesh_num_x);
202 199
     EEPROM_WRITE_VAR(i, mesh_num_y);
203 200
     EEPROM_WRITE_VAR(i, mbl.z_values);
204 201
   #else
202
+    uint8_t mesh_num_x = 3,
203
+            mesh_num_y = 3,
204
+            dummy_uint8 = 0;
205 205
     dummy = 0.0f;
206 206
     EEPROM_WRITE_VAR(i, dummy_uint8);
207 207
     EEPROM_WRITE_VAR(i, dummy);

+ 1
- 1
Marlin/mesh_bed_leveling.cpp Voir le fichier

@@ -29,7 +29,7 @@
29 29
   mesh_bed_leveling::mesh_bed_leveling() { reset(); }
30 30
 
31 31
   void mesh_bed_leveling::reset() {
32
-    status = 0;
32
+    status = MBL_STATUS_NONE;
33 33
     z_offset = 0;
34 34
     for (int8_t y = MESH_NUM_Y_POINTS; y--;)
35 35
       for (int8_t x = MESH_NUM_X_POINTS; x--;)

+ 7
- 5
Marlin/mesh_bed_leveling.h Voir le fichier

@@ -24,12 +24,14 @@
24 24
 
25 25
 #if ENABLED(MESH_BED_LEVELING)
26 26
 
27
+  enum MBLStatus { MBL_STATUS_NONE = 0, MBL_STATUS_HAS_MESH_BIT = 0, MBL_STATUS_ACTIVE_BIT = 1 };
28
+
27 29
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X))/(MESH_NUM_X_POINTS - 1))
28 30
   #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y))/(MESH_NUM_Y_POINTS - 1))
29 31
 
30 32
   class mesh_bed_leveling {
31 33
   public:
32
-    uint8_t status; // Bit 0 = has mesh numbers, Bit 1 = compensation active
34
+    uint8_t status; // Has Mesh and Is Active bits
33 35
     float z_offset;
34 36
     float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
35 37
 
@@ -41,10 +43,10 @@
41 43
     static FORCE_INLINE float get_probe_y(int8_t i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
42 44
     void set_z(const int8_t px, const int8_t py, const float z) { z_values[py][px] = z; }
43 45
 
44
-    bool has_mesh() { return TEST(status, 0); }
45
-    void has_mesh(bool onOff) { if (onOff) SBI(status, 0); else CBI(status, 0); }
46
-    bool is_active() { return TEST(status, 1); }
47
-    void is_active(bool onOff) { if (onOff) SBI(status, 1); else CBI(status, 1); }
46
+    bool active()                 { return TEST(status, MBL_STATUS_ACTIVE_BIT); }
47
+    void set_active(bool onOff)   { if (onOff) SBI(status, MBL_STATUS_ACTIVE_BIT); else CBI(status, MBL_STATUS_ACTIVE_BIT); }
48
+    bool has_mesh()               { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
49
+    void set_has_mesh(bool onOff) { if (onOff) SBI(status, MBL_STATUS_HAS_MESH_BIT); else CBI(status, MBL_STATUS_HAS_MESH_BIT); }
48 50
 
49 51
     inline void zigzag(int8_t index, int8_t &px, int8_t &py) {
50 52
       px = index % (MESH_NUM_X_POINTS);

+ 2
- 2
Marlin/planner.cpp Voir le fichier

@@ -539,7 +539,7 @@ void Planner::check_axes_activity() {
539 539
   while (block_buffer_tail == next_buffer_head) idle();
540 540
 
541 541
   #if ENABLED(MESH_BED_LEVELING)
542
-    if (mbl.is_active()) 
542
+    if (mbl.active()) 
543 543
       z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
544 544
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
545 545
     apply_rotation_xyz(bed_level_matrix, x, y, z);
@@ -1121,7 +1121,7 @@ void Planner::check_axes_activity() {
1121 1121
 #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
1122 1122
   {
1123 1123
     #if ENABLED(MESH_BED_LEVELING)
1124
-      if (mbl.is_active())
1124
+      if (mbl.active())
1125 1125
         z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
1126 1126
     #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
1127 1127
       apply_rotation_xyz(bed_level_matrix, x, y, z);

+ 1
- 1
Marlin/ultralcd.cpp Voir le fichier

@@ -970,7 +970,7 @@ void lcd_cooldown() {
970 970
           line_to_current(Z_AXIS);
971 971
           stepper.synchronize();
972 972
 
973
-          mbl.has_mesh(true);
973
+          mbl.set_has_mesh(true);
974 974
           enqueue_and_echo_commands_P(PSTR("G28"));
975 975
           lcd_return_to_status();
976 976
           //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);

Chargement…
Annuler
Enregistrer