瀏覽代碼

Apply Marlin coding standards to MBL class

Scott Lahteine 9 年之前
父節點
當前提交
c2362c1b3c
共有 6 個檔案被更改,包括 28 行新增26 行删除
  1. 9
    9
      Marlin/Marlin_main.cpp
  2. 8
    8
      Marlin/configuration_store.cpp
  3. 1
    1
      Marlin/mesh_bed_leveling.cpp
  4. 7
    5
      Marlin/mesh_bed_leveling.h
  5. 2
    2
      Marlin/planner.cpp
  6. 1
    1
      Marlin/ultralcd.cpp

+ 9
- 9
Marlin/Marlin_main.cpp 查看文件

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

+ 8
- 8
Marlin/configuration_store.cpp 查看文件

58
  *  188  M206 XYZ  home_offset (float x3)
58
  *  188  M206 XYZ  home_offset (float x3)
59
  *
59
  *
60
  * Mesh bed leveling:
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
  *  205            mesh_num_x (uint8 as set in firmware)
63
  *  205            mesh_num_x (uint8 as set in firmware)
64
  *  206            mesh_num_y (uint8 as set in firmware)
64
  *  206            mesh_num_y (uint8 as set in firmware)
65
  *  207 G29 S3 XYZ z_values[][] (float x9, by default)
65
  *  207 G29 S3 XYZ z_values[][] (float x9, by default)
187
   EEPROM_WRITE_VAR(i, planner.max_e_jerk);
187
   EEPROM_WRITE_VAR(i, planner.max_e_jerk);
188
   EEPROM_WRITE_VAR(i, home_offset);
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
   #if ENABLED(MESH_BED_LEVELING)
190
   #if ENABLED(MESH_BED_LEVELING)
194
     // Compile time test that sizeof(mbl.z_values) is as expected
191
     // Compile time test that sizeof(mbl.z_values) is as expected
195
     typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1];
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
     EEPROM_WRITE_VAR(i, dummy_uint8);
196
     EEPROM_WRITE_VAR(i, dummy_uint8);
200
     EEPROM_WRITE_VAR(i, mbl.z_offset);
197
     EEPROM_WRITE_VAR(i, mbl.z_offset);
201
     EEPROM_WRITE_VAR(i, mesh_num_x);
198
     EEPROM_WRITE_VAR(i, mesh_num_x);
202
     EEPROM_WRITE_VAR(i, mesh_num_y);
199
     EEPROM_WRITE_VAR(i, mesh_num_y);
203
     EEPROM_WRITE_VAR(i, mbl.z_values);
200
     EEPROM_WRITE_VAR(i, mbl.z_values);
204
   #else
201
   #else
202
+    uint8_t mesh_num_x = 3,
203
+            mesh_num_y = 3,
204
+            dummy_uint8 = 0;
205
     dummy = 0.0f;
205
     dummy = 0.0f;
206
     EEPROM_WRITE_VAR(i, dummy_uint8);
206
     EEPROM_WRITE_VAR(i, dummy_uint8);
207
     EEPROM_WRITE_VAR(i, dummy);
207
     EEPROM_WRITE_VAR(i, dummy);

+ 1
- 1
Marlin/mesh_bed_leveling.cpp 查看文件

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

+ 7
- 5
Marlin/mesh_bed_leveling.h 查看文件

24
 
24
 
25
 #if ENABLED(MESH_BED_LEVELING)
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
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X))/(MESH_NUM_X_POINTS - 1))
29
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X))/(MESH_NUM_X_POINTS - 1))
28
   #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y))/(MESH_NUM_Y_POINTS - 1))
30
   #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y))/(MESH_NUM_Y_POINTS - 1))
29
 
31
 
30
   class mesh_bed_leveling {
32
   class mesh_bed_leveling {
31
   public:
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
     float z_offset;
35
     float z_offset;
34
     float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
36
     float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
35
 
37
 
41
     static FORCE_INLINE float get_probe_y(int8_t i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
43
     static FORCE_INLINE float get_probe_y(int8_t i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
42
     void set_z(const int8_t px, const int8_t py, const float z) { z_values[py][px] = z; }
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
     inline void zigzag(int8_t index, int8_t &px, int8_t &py) {
51
     inline void zigzag(int8_t index, int8_t &px, int8_t &py) {
50
       px = index % (MESH_NUM_X_POINTS);
52
       px = index % (MESH_NUM_X_POINTS);

+ 2
- 2
Marlin/planner.cpp 查看文件

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

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

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

Loading…
取消
儲存