ソースを参照

Merge pull request #2001 from thinkyhead/thermal_protection_on

Add M428 to set home_offset logically
Scott Lahteine 10年前
コミット
b12bcd0f92

+ 58
- 4
Marlin/Marlin_main.cpp ファイルの表示

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
189
  * M410 - Quickstop. Abort all the planned moves
190
  * M410 - Quickstop. Abort all the planned moves
190
  * M420 - Enable/Disable Mesh Leveling (with current values) S1=enable S0=disable
191
  * M420 - Enable/Disable Mesh Leveling (with current values) S1=enable S0=disable
191
  * M421 - Set a single Z coordinate in the Mesh Leveling grid. X<mm> Y<mm> Z<mm>
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
  * M500 - Store parameters in EEPROM
194
  * M500 - Store parameters in EEPROM
193
  * M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
195
  * M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
194
  * M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
196
  * M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
4090
 
4092
 
4091
 #endif // NUM_SERVOS > 0
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
    * M300: Play beep sound S<frequency Hz> P<duration ms>
4098
    * M300: Play beep sound S<frequency Hz> P<duration ms>
4102
     lcd_buzz(beepP, beepS);
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
 #ifdef PIDTEMP
4109
 #ifdef PIDTEMP
4108
 
4110
 
4505
 #endif
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
  * M500: Store settings in EEPROM
4558
  * M500: Store settings in EEPROM
4509
  */
4559
  */
4510
 inline void gcode_M500() {
4560
 inline void gcode_M500() {
5251
           break;
5301
           break;
5252
       #endif // NUM_SERVOS > 0
5302
       #endif // NUM_SERVOS > 0
5253
 
5303
 
5254
-      #if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
5304
+      #if HAS_LCD_BUZZ
5255
         case 300: // M300 - Play beep tone
5305
         case 300: // M300 - Play beep tone
5256
           gcode_M300();
5306
           gcode_M300();
5257
           break;
5307
           break;
5258
-      #endif // BEEPER > 0 || ULTRALCD || LCD_USE_I2C_BUZZER
5308
+      #endif // HAS_LCD_BUZZ
5259
 
5309
 
5260
       #ifdef PIDTEMP
5310
       #ifdef PIDTEMP
5261
         case 301: // M301
5311
         case 301: // M301
5353
           break;
5403
           break;
5354
       #endif
5404
       #endif
5355
 
5405
 
5406
+      case 428: // M428 Apply current_position to home_offset
5407
+        gcode_M428();
5408
+        break;
5409
+
5356
       case 500: // M500 Store settings in EEPROM
5410
       case 500: // M500 Store settings in EEPROM
5357
         gcode_M500();
5411
         gcode_M500();
5358
         break;
5412
         break;

+ 1
- 1
Marlin/configuration_store.cpp ファイルの表示

676
       SERIAL_ECHOLNPGM("Mesh bed leveling:");
676
       SERIAL_ECHOLNPGM("Mesh bed leveling:");
677
       CONFIG_ECHO_START;
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
     SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
680
     SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
681
     SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
681
     SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
682
     SERIAL_EOL;
682
     SERIAL_EOL;

+ 1
- 0
Marlin/configurator/config/language.h ファイルの表示

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
- 0
Marlin/language.h ファイルの表示

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

+ 9
- 14
Marlin/ultralcd.cpp ファイルの表示

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

+ 1
- 1
Marlin/ultralcd.h ファイルの表示

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)

読み込み中…
キャンセル
保存