Browse Source

Have M206 alter current_position, M428 use new function

Scott Lahteine 8 years ago
parent
commit
f3562dd895
1 changed files with 17 additions and 16 deletions
  1. 17
    16
      Marlin/Marlin_main.cpp

+ 17
- 16
Marlin/Marlin_main.cpp View File

4975
   if (code_seen('E')) max_e_jerk = code_value();
4975
   if (code_seen('E')) max_e_jerk = code_value();
4976
 }
4976
 }
4977
 
4977
 
4978
+static void set_home_offset(AxisEnum axis, float v) {
4979
+  min_pos[axis] = base_min_pos(axis) + v;
4980
+  max_pos[axis] = base_max_pos(axis) + v;
4981
+  current_position[axis] += v - home_offset[axis];
4982
+  home_offset[axis] = v;
4983
+}
4984
+
4978
 /**
4985
 /**
4979
  * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
4986
  * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
4980
  */
4987
  */
4981
 inline void gcode_M206() {
4988
 inline void gcode_M206() {
4982
-  for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
4983
-    if (code_seen(axis_codes[i])) {
4984
-      home_offset[i] = code_value();
4985
-    }
4986
-  }
4989
+  for (int8_t i = X_AXIS; i <= Z_AXIS; i++)
4990
+    if (code_seen(axis_codes[i]))
4991
+      set_home_offset((AxisEnum)i, code_value());
4992
+
4987
   #if ENABLED(SCARA)
4993
   #if ENABLED(SCARA)
4988
-    if (code_seen('T')) home_offset[X_AXIS] = code_value(); // Theta
4989
-    if (code_seen('P')) home_offset[Y_AXIS] = code_value(); // Psi
4994
+    if (code_seen('T')) set_home_offset(X_AXIS, code_value()); // Theta
4995
+    if (code_seen('P')) set_home_offset(Y_AXIS, code_value()); // Psi
4990
   #endif
4996
   #endif
4997
+  sync_plan_position();
4991
 }
4998
 }
4992
 
4999
 
4993
 #if ENABLED(DELTA)
5000
 #if ENABLED(DELTA)
5674
  */
5681
  */
5675
 inline void gcode_M428() {
5682
 inline void gcode_M428() {
5676
   bool err = false;
5683
   bool err = false;
5677
-  float new_offs[3], new_pos[3];
5678
-  memcpy(new_pos, current_position, sizeof(new_pos));
5679
-  memcpy(new_offs, home_offset, sizeof(new_offs));
5680
   for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
5684
   for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
5681
     if (axis_homed[i]) {
5685
     if (axis_homed[i]) {
5682
-      float base = (new_pos[i] > (min_pos[i] + max_pos[i]) / 2) ? base_home_pos(i) : 0,
5683
-            diff = new_pos[i] - base;
5686
+      float base = (current_position[i] > (min_pos[i] + max_pos[i]) / 2) ? base_home_pos(i) : 0,
5687
+            diff = current_position[i] - base;
5684
       if (diff > -20 && diff < 20) {
5688
       if (diff > -20 && diff < 20) {
5685
-        new_offs[i] -= diff;
5686
-        new_pos[i] = base;
5689
+        set_home_offset((AxisEnum)i, home_offset[i] - diff);
5687
       }
5690
       }
5688
       else {
5691
       else {
5689
         SERIAL_ERROR_START;
5692
         SERIAL_ERROR_START;
5699
   }
5702
   }
5700
 
5703
 
5701
   if (!err) {
5704
   if (!err) {
5702
-    memcpy(current_position, new_pos, sizeof(new_pos));
5703
-    memcpy(home_offset, new_offs, sizeof(new_offs));
5704
     sync_plan_position();
5705
     sync_plan_position();
5705
     LCD_ALERTMESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
5706
     LCD_ALERTMESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
5706
     #if HAS_BUZZER
5707
     #if HAS_BUZZER

Loading…
Cancel
Save