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
   #endif
36
   #endif
37
 #endif // ENABLE_AUTO_BED_LEVELING
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
 #define SERVO_LEVELING (defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0)
40
 #define SERVO_LEVELING (defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0)
40
 
41
 
41
 #ifdef MESH_BED_LEVELING
42
 #ifdef MESH_BED_LEVELING
4091
 
4092
 
4092
 #endif // NUM_SERVOS > 0
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
    * M300: Play beep sound S<frequency Hz> P<duration ms>
4098
    * M300: Play beep sound S<frequency Hz> P<duration ms>
4103
     lcd_buzz(beepP, beepS);
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
 #ifdef PIDTEMP
4109
 #ifdef PIDTEMP
4109
 
4110
 
4507
 
4508
 
4508
 /**
4509
 /**
4509
  * M428: Set home_offset based on the distance between the
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
  *       is the reference-point. Otherwise it uses 0. This allows
4513
  *       is the reference-point. Otherwise it uses 0. This allows
4513
  *       the Z offset to be set near the bed when using a max endstop.
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
  *       Use M206 to set these values directly.
4518
  *       Use M206 to set these values directly.
4516
  */
4519
  */
4517
 inline void gcode_M428() {
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
   for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
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
           break;
5301
           break;
5278
       #endif // NUM_SERVOS > 0
5302
       #endif // NUM_SERVOS > 0
5279
 
5303
 
5280
-      #if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
5304
+      #if HAS_LCD_BUZZ
5281
         case 300: // M300 - Play beep tone
5305
         case 300: // M300 - Play beep tone
5282
           gcode_M300();
5306
           gcode_M300();
5283
           break;
5307
           break;
5284
-      #endif // BEEPER > 0 || ULTRALCD || LCD_USE_I2C_BUZZER
5308
+      #endif // HAS_LCD_BUZZ
5285
 
5309
 
5286
       #ifdef PIDTEMP
5310
       #ifdef PIDTEMP
5287
         case 301: // M301
5311
         case 301: // M301

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

161
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
161
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
162
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
162
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
163
 #define MSG_ERR_MESH_INDEX_OOB              "Mesh XY index is out of bounds"
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
 #define MSG_M119_REPORT                     "Reporting endstop status"
165
 #define MSG_M119_REPORT                     "Reporting endstop status"
165
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
166
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
166
 #define MSG_ENDSTOP_OPEN                    "open"
167
 #define MSG_ENDSTOP_OPEN                    "open"

+ 1
- 1
Marlin/language.h View File

162
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
162
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
163
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
163
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
164
 #define MSG_ERR_MESH_INDEX_OOB              "Mesh XY index is out of bounds"
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
 #define MSG_M119_REPORT                     "Reporting endstop status"
166
 #define MSG_M119_REPORT                     "Reporting endstop status"
167
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
167
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
168
 #define MSG_ENDSTOP_OPEN                    "open"
168
 #define MSG_ENDSTOP_OPEN                    "open"

+ 6
- 6
Marlin/ultralcd.cpp View File

442
  * Set the home offset based on the current_position
442
  * Set the home offset based on the current_position
443
  */
443
  */
444
 void lcd_set_home_offsets() {
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
   lcd_return_to_status();
447
   lcd_return_to_status();
448
 }
448
 }
449
 
449
 
1285
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
1285
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
1286
     #endif    
1286
     #endif    
1287
     lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
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
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1289
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1290
       #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1290
       #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1291
     #endif
1291
     #endif
1718
 
1718
 
1719
   void lcd_buzz(long duration, uint16_t freq) {
1719
   void lcd_buzz(long duration, uint16_t freq) {
1720
     if (freq > 0) {
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
         SET_OUTPUT(BEEPER);
1724
         SET_OUTPUT(BEEPER);
1723
         tone(BEEPER, freq, duration);
1725
         tone(BEEPER, freq, duration);
1724
         delay(duration);
1726
         delay(duration);
1725
-      #elif defined(LCD_USE_I2C_BUZZER)
1726
-        lcd.buzz(duration, freq);
1727
       #else
1727
       #else
1728
         delay(duration);
1728
         delay(duration);
1729
       #endif
1729
       #endif

+ 1
- 1
Marlin/ultralcd.h View File

106
   FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {}
106
   FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {}
107
   FORCE_INLINE void lcd_buttons_update() {}
107
   FORCE_INLINE void lcd_buttons_update() {}
108
   FORCE_INLINE void lcd_reset_alert_level() {}
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
   FORCE_INLINE bool lcd_detected(void) { return true; }
110
   FORCE_INLINE bool lcd_detected(void) { return true; }
111
 
111
 
112
   #define LCD_MESSAGEPGM(x) do{}while(0)
112
   #define LCD_MESSAGEPGM(x) do{}while(0)

Loading…
Cancel
Save