瀏覽代碼

Merge pull request #2001 from thinkyhead/thermal_protection_on

Add M428 to set home_offset logically
Scott Lahteine 10 年之前
父節點
當前提交
b12bcd0f92
共有 6 個文件被更改,包括 71 次插入20 次删除
  1. 58
    4
      Marlin/Marlin_main.cpp
  2. 1
    1
      Marlin/configuration_store.cpp
  3. 1
    0
      Marlin/configurator/config/language.h
  4. 1
    0
      Marlin/language.h
  5. 9
    14
      Marlin/ultralcd.cpp
  6. 1
    1
      Marlin/ultralcd.h

+ 58
- 4
Marlin/Marlin_main.cpp 查看文件

@@ -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
@@ -189,6 +190,7 @@
189 190
  * M410 - Quickstop. Abort all the planned moves
190 191
  * M420 - Enable/Disable Mesh Leveling (with current values) S1=enable S0=disable
191 192
  * M421 - Set a single Z coordinate in the Mesh Leveling grid. X<mm> Y<mm> Z<mm>
193
+ * M428 - Set the home_offset logically based on the current_position
192 194
  * M500 - Store parameters in EEPROM
193 195
  * M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
194 196
  * M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
@@ -4090,7 +4092,7 @@ inline void gcode_M226() {
4090 4092
 
4091 4093
 #endif // NUM_SERVOS > 0
4092 4094
 
4093
-#if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
4095
+#if HAS_LCD_BUZZ
4094 4096
 
4095 4097
   /**
4096 4098
    * M300: Play beep sound S<frequency Hz> P<duration ms>
@@ -4102,7 +4104,7 @@ inline void gcode_M226() {
4102 4104
     lcd_buzz(beepP, beepS);
4103 4105
   }
4104 4106
 
4105
-#endif // BEEPER>0 || ULTRALCD || LCD_USE_I2C_BUZZER
4107
+#endif // HAS_LCD_BUZZ
4106 4108
 
4107 4109
 #ifdef PIDTEMP
4108 4110
 
@@ -4505,6 +4507,54 @@ inline void gcode_M410() { quickStop(); }
4505 4507
 #endif
4506 4508
 
4507 4509
 /**
4510
+ * M428: Set home_offset based on the distance between the
4511
+ *       current_position and the nearest "reference point."
4512
+ *       If an axis is past center its endstop position
4513
+ *       is the reference-point. Otherwise it uses 0. This allows
4514
+ *       the Z offset to be set near the bed when using a max endstop.
4515
+ *
4516
+ *       M428 can't be used more than 2cm away from 0 or an endstop.
4517
+ *
4518
+ *       Use M206 to set these values directly.
4519
+ */
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));
4525
+  for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
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
+      }
4543
+    }
4544
+  }
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
+  }
4555
+}
4556
+
4557
+/**
4508 4558
  * M500: Store settings in EEPROM
4509 4559
  */
4510 4560
 inline void gcode_M500() {
@@ -5251,11 +5301,11 @@ void process_commands() {
5251 5301
           break;
5252 5302
       #endif // NUM_SERVOS > 0
5253 5303
 
5254
-      #if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
5304
+      #if HAS_LCD_BUZZ
5255 5305
         case 300: // M300 - Play beep tone
5256 5306
           gcode_M300();
5257 5307
           break;
5258
-      #endif // BEEPER > 0 || ULTRALCD || LCD_USE_I2C_BUZZER
5308
+      #endif // HAS_LCD_BUZZ
5259 5309
 
5260 5310
       #ifdef PIDTEMP
5261 5311
         case 301: // M301
@@ -5353,6 +5403,10 @@ void process_commands() {
5353 5403
           break;
5354 5404
       #endif
5355 5405
 
5406
+      case 428: // M428 Apply current_position to home_offset
5407
+        gcode_M428();
5408
+        break;
5409
+
5356 5410
       case 500: // M500 Store settings in EEPROM
5357 5411
         gcode_M500();
5358 5412
         break;

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

@@ -676,7 +676,7 @@ void Config_PrintSettings(bool forReplay) {
676 676
       SERIAL_ECHOLNPGM("Mesh bed leveling:");
677 677
       CONFIG_ECHO_START;
678 678
     }
679
-    SERIAL_ECHOPAIR("  M420 S", (int32_t)mbl.active);
679
+    SERIAL_ECHOPAIR("  M420 S", (unsigned long)mbl.active);
680 680
     SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
681 681
     SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
682 682
     SERIAL_EOL;

+ 1
- 0
Marlin/configurator/config/language.h 查看文件

@@ -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
- 0
Marlin/language.h 查看文件

@@ -162,6 +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 reference point"
165 166
 #define MSG_M119_REPORT                     "Reporting endstop status"
166 167
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
167 168
 #define MSG_ENDSTOP_OPEN                    "open"

+ 9
- 14
Marlin/ultralcd.cpp 查看文件

@@ -438,17 +438,12 @@ static void lcd_main_menu() {
438 438
   }
439 439
 #endif
440 440
 
441
+/**
442
+ * Set the home offset based on the current_position
443
+ */
441 444
 void lcd_set_home_offsets() {
442
-  for (int8_t i=0; i < NUM_AXIS; i++) {
443
-    if (i != E_AXIS) {
444
-      home_offset[i] -= current_position[i];
445
-      current_position[i] = 0.0;
446
-    }
447
-  }
448
-  plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
449
-
450
-  // Audio feedback
451
-  enqueuecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
445
+  // M428 Command
446
+  enqueuecommands_P(PSTR("M428"));
452 447
   lcd_return_to_status();
453 448
 }
454 449
 
@@ -1290,7 +1285,7 @@ void lcd_quick_feedback() {
1290 1285
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
1291 1286
     #endif    
1292 1287
     lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1293
-  #elif defined(BEEPER) && BEEPER > -1
1288
+  #elif defined(BEEPER) && BEEPER >= 0
1294 1289
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1295 1290
       #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1296 1291
     #endif
@@ -1723,12 +1718,12 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
1723 1718
 
1724 1719
   void lcd_buzz(long duration, uint16_t freq) {
1725 1720
     if (freq > 0) {
1726
-      #if BEEPER > 0
1721
+      #ifdef LCD_USE_I2C_BUZZER
1722
+        lcd.buzz(duration, freq);
1723
+      #elif defined(BEEPER) && BEEPER >= 0
1727 1724
         SET_OUTPUT(BEEPER);
1728 1725
         tone(BEEPER, freq, duration);
1729 1726
         delay(duration);
1730
-      #elif defined(LCD_USE_I2C_BUZZER)
1731
-        lcd.buzz(duration, freq);
1732 1727
       #else
1733 1728
         delay(duration);
1734 1729
       #endif

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

@@ -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…
取消
儲存