Browse Source

Don't apply M428 if an error occurs

- Also move audio feedback into the command
- Added shorthand for `lcd_buzz` availability
Scott Lahteine 9 years ago
parent
commit
d4c74b8f8c
5 changed files with 49 additions and 24 deletions
  1. 40
    16
      Marlin/Marlin_main.cpp
  2. 1
    0
      Marlin/configurator/config/language.h
  3. 1
    1
      Marlin/language.h
  4. 6
    6
      Marlin/ultralcd.cpp
  5. 1
    1
      Marlin/ultralcd.h

+ 40
- 16
Marlin/Marlin_main.cpp View File

@@ -36,6 +36,7 @@
36 36
   #endif
37 37
 #endif // ENABLE_AUTO_BED_LEVELING
38 38
 
39
+#define HAS_LCD_BUZZ (defined(ULTRALCD) || (defined(BEEPER) && BEEPER >= 0) || defined(LCD_USE_I2C_BUZZER))
39 40
 #define SERVO_LEVELING (defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0)
40 41
 
41 42
 #ifdef MESH_BED_LEVELING
@@ -4091,7 +4092,7 @@ inline void gcode_M226() {
4091 4092
 
4092 4093
 #endif // NUM_SERVOS > 0
4093 4094
 
4094
-#if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
4095
+#if HAS_LCD_BUZZ
4095 4096
 
4096 4097
   /**
4097 4098
    * M300: Play beep sound S<frequency Hz> P<duration ms>
@@ -4103,7 +4104,7 @@ inline void gcode_M226() {
4103 4104
     lcd_buzz(beepP, beepS);
4104 4105
   }
4105 4106
 
4106
-#endif // BEEPER>0 || ULTRALCD || LCD_USE_I2C_BUZZER
4107
+#endif // HAS_LCD_BUZZ
4107 4108
 
4108 4109
 #ifdef PIDTEMP
4109 4110
 
@@ -4507,27 +4508,50 @@ inline void gcode_M410() { quickStop(); }
4507 4508
 
4508 4509
 /**
4509 4510
  * M428: Set home_offset based on the distance between the
4510
- *       current_position and the nearest "reference position."
4511
- *       If an axis is past center the endstop position
4511
+ *       current_position and the nearest "reference point."
4512
+ *       If an axis is past center its endstop position
4512 4513
  *       is the reference-point. Otherwise it uses 0. This allows
4513 4514
  *       the Z offset to be set near the bed when using a max endstop.
4514 4515
  *
4516
+ *       M428 can't be used more than 2cm away from 0 or an endstop.
4517
+ *
4515 4518
  *       Use M206 to set these values directly.
4516 4519
  */
4517 4520
 inline void gcode_M428() {
4521
+  bool err = false;
4522
+  float new_offs[3], new_pos[3];
4523
+  memcpy(new_pos, current_position, sizeof(new_pos));
4524
+  memcpy(new_offs, home_offset, sizeof(new_offs));
4518 4525
   for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
4519
-    float base = (current_position[i] > (min_pos[i] + max_pos[i]) / 2) ? base_home_pos(i) : 0,
4520
-          diff = current_position[i] - base;
4521
-    if (diff > -20 && diff < 20) {
4522
-      home_offset[i] -= diff;
4523
-      current_position[i] = base;
4524
-    }
4525
-    else {
4526
-      SERIAL_ERROR_START;
4527
-      SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
4526
+    if (axis_known_position[i]) {
4527
+      float base = (new_pos[i] > (min_pos[i] + max_pos[i]) / 2) ? base_home_pos(i) : 0,
4528
+            diff = new_pos[i] - base;
4529
+      if (diff > -20 && diff < 20) {
4530
+        new_offs[i] -= diff;
4531
+        new_pos[i] = base;
4532
+      }
4533
+      else {
4534
+        SERIAL_ERROR_START;
4535
+        SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
4536
+        LCD_ALERTMESSAGEPGM("Err: Too far!");
4537
+        #if HAS_LCD_BUZZ
4538
+          enqueuecommands_P(PSTR("M300 S40 P200"));
4539
+        #endif
4540
+        err = true;
4541
+        break;
4542
+      }
4528 4543
     }
4529 4544
   }
4530
-  sync_plan_position();
4545
+
4546
+  if (!err) {
4547
+    memcpy(current_position, new_pos, sizeof(new_pos));
4548
+    memcpy(home_offset, new_offs, sizeof(new_offs));
4549
+    sync_plan_position();
4550
+    LCD_ALERTMESSAGEPGM("Offset applied.");
4551
+    #if HAS_LCD_BUZZ
4552
+      enqueuecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
4553
+    #endif
4554
+  }
4531 4555
 }
4532 4556
 
4533 4557
 /**
@@ -5277,11 +5301,11 @@ void process_commands() {
5277 5301
           break;
5278 5302
       #endif // NUM_SERVOS > 0
5279 5303
 
5280
-      #if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
5304
+      #if HAS_LCD_BUZZ
5281 5305
         case 300: // M300 - Play beep tone
5282 5306
           gcode_M300();
5283 5307
           break;
5284
-      #endif // BEEPER > 0 || ULTRALCD || LCD_USE_I2C_BUZZER
5308
+      #endif // HAS_LCD_BUZZ
5285 5309
 
5286 5310
       #ifdef PIDTEMP
5287 5311
         case 301: // M301

+ 1
- 0
Marlin/configurator/config/language.h View File

@@ -161,6 +161,7 @@
161 161
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
162 162
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
163 163
 #define MSG_ERR_MESH_INDEX_OOB              "Mesh XY index is out of bounds"
164
+#define MSG_ERR_M428_TOO_FAR                "Too far from reference point"
164 165
 #define MSG_M119_REPORT                     "Reporting endstop status"
165 166
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
166 167
 #define MSG_ENDSTOP_OPEN                    "open"

+ 1
- 1
Marlin/language.h View File

@@ -162,7 +162,7 @@
162 162
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
163 163
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
164 164
 #define MSG_ERR_MESH_INDEX_OOB              "Mesh XY index is out of bounds"
165
-#define MSG_ERR_M428_TOO_FAR                "Too far from home or origin position"
165
+#define MSG_ERR_M428_TOO_FAR                "Too far from reference point"
166 166
 #define MSG_M119_REPORT                     "Reporting endstop status"
167 167
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
168 168
 #define MSG_ENDSTOP_OPEN                    "open"

+ 6
- 6
Marlin/ultralcd.cpp View File

@@ -442,8 +442,8 @@ static void lcd_main_menu() {
442 442
  * Set the home offset based on the current_position
443 443
  */
444 444
 void lcd_set_home_offsets() {
445
-  // Command with Audio feedback
446
-  enqueuecommands_P(PSTR("M428\nM300 S659 P200\nM300 S698 P200"));
445
+  // M428 Command
446
+  enqueuecommands_P(PSTR("M428"));
447 447
   lcd_return_to_status();
448 448
 }
449 449
 
@@ -1285,7 +1285,7 @@ void lcd_quick_feedback() {
1285 1285
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
1286 1286
     #endif    
1287 1287
     lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1288
-  #elif defined(BEEPER) && BEEPER > -1
1288
+  #elif defined(BEEPER) && BEEPER >= 0
1289 1289
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1290 1290
       #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1291 1291
     #endif
@@ -1718,12 +1718,12 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
1718 1718
 
1719 1719
   void lcd_buzz(long duration, uint16_t freq) {
1720 1720
     if (freq > 0) {
1721
-      #if BEEPER > 0
1721
+      #ifdef LCD_USE_I2C_BUZZER
1722
+        lcd.buzz(duration, freq);
1723
+      #elif defined(BEEPER) && BEEPER >= 0
1722 1724
         SET_OUTPUT(BEEPER);
1723 1725
         tone(BEEPER, freq, duration);
1724 1726
         delay(duration);
1725
-      #elif defined(LCD_USE_I2C_BUZZER)
1726
-        lcd.buzz(duration, freq);
1727 1727
       #else
1728 1728
         delay(duration);
1729 1729
       #endif

+ 1
- 1
Marlin/ultralcd.h View File

@@ -106,7 +106,7 @@
106 106
   FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {}
107 107
   FORCE_INLINE void lcd_buttons_update() {}
108 108
   FORCE_INLINE void lcd_reset_alert_level() {}
109
-  FORCE_INLINE void lcd_buzz(long duration,uint16_t freq) {}
109
+  FORCE_INLINE void lcd_buzz(long duration, uint16_t freq) {}
110 110
   FORCE_INLINE bool lcd_detected(void) { return true; }
111 111
 
112 112
   #define LCD_MESSAGEPGM(x) do{}while(0)

Loading…
Cancel
Save