My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

M17_M18_M84.cpp 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../gcode.h"
  23. #include "../../MarlinCore.h" // for stepper_inactive_time, disable_e_steppers
  24. #include "../../lcd/marlinui.h"
  25. #include "../../module/motion.h" // for e_axis_mask
  26. #include "../../module/planner.h"
  27. #include "../../module/stepper.h"
  28. #if ENABLED(AUTO_BED_LEVELING_UBL)
  29. #include "../../feature/bedlevel/bedlevel.h"
  30. #endif
  31. #define DEBUG_OUT ENABLED(MARLIN_DEV_MODE)
  32. #include "../../core/debug_out.h"
  33. #include "../../libs/hex_print.h"
  34. inline stepper_flags_t selected_axis_bits() {
  35. stepper_flags_t selected{0};
  36. #if HAS_EXTRUDERS
  37. if (parser.seen('E')) {
  38. if (E_TERN0(parser.has_value())) {
  39. const uint8_t e = parser.value_int();
  40. if (e < EXTRUDERS)
  41. selected.bits = _BV(INDEX_OF_AXIS(E_AXIS, e));
  42. }
  43. else
  44. selected.bits = e_axis_mask;
  45. }
  46. #endif
  47. selected.bits |= NUM_AXIS_GANG(
  48. (parser.seen_test('X') << X_AXIS),
  49. | (parser.seen_test('Y') << Y_AXIS),
  50. | (parser.seen_test('Z') << Z_AXIS),
  51. | (parser.seen_test(AXIS4_NAME) << I_AXIS),
  52. | (parser.seen_test(AXIS5_NAME) << J_AXIS),
  53. | (parser.seen_test(AXIS6_NAME) << K_AXIS),
  54. | (parser.seen_test(AXIS7_NAME) << U_AXIS),
  55. | (parser.seen_test(AXIS8_NAME) << V_AXIS),
  56. | (parser.seen_test(AXIS9_NAME) << W_AXIS)
  57. );
  58. return selected;
  59. }
  60. // Enable specified axes and warn about other affected axes
  61. void do_enable(const stepper_flags_t to_enable) {
  62. const ena_mask_t was_enabled = stepper.axis_enabled.bits,
  63. shall_enable = to_enable.bits & ~was_enabled;
  64. DEBUG_ECHOLNPGM("Now Enabled: ", hex_word(stepper.axis_enabled.bits), " Enabling: ", hex_word(to_enable.bits), " | ", shall_enable);
  65. if (!shall_enable) return; // All specified axes already enabled?
  66. ena_mask_t also_enabled = 0; // Track steppers enabled due to overlap
  67. // Enable all flagged axes
  68. LOOP_NUM_AXES(a) {
  69. if (TEST(shall_enable, a)) {
  70. stepper.enable_axis(AxisEnum(a)); // Mark and enable the requested axis
  71. DEBUG_ECHOLNPGM("Enabled ", AXIS_CHAR(a), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... Enabled: ", hex_word(stepper.axis_enabled.bits));
  72. also_enabled |= enable_overlap[a];
  73. }
  74. }
  75. #if HAS_EXTRUDERS
  76. EXTRUDER_LOOP() {
  77. const uint8_t a = INDEX_OF_AXIS(E_AXIS, e);
  78. if (TEST(shall_enable, a)) {
  79. stepper.ENABLE_EXTRUDER(e);
  80. DEBUG_ECHOLNPGM("Enabled E", AS_DIGIT(e), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... ", hex_word(stepper.axis_enabled.bits));
  81. also_enabled |= enable_overlap[a];
  82. }
  83. }
  84. #endif
  85. if ((also_enabled &= ~(shall_enable | was_enabled))) {
  86. SERIAL_CHAR('(');
  87. LOOP_NUM_AXES(a) if (TEST(also_enabled, a)) SERIAL_CHAR(AXIS_CHAR(a), ' ');
  88. #if HAS_EXTRUDERS
  89. #define _EN_ALSO(N) if (TEST(also_enabled, INDEX_OF_AXIS(E_AXIS, N))) SERIAL_CHAR('E', '0' + N, ' ');
  90. REPEAT(EXTRUDERS, _EN_ALSO)
  91. #endif
  92. SERIAL_ECHOLNPGM("also enabled)");
  93. }
  94. DEBUG_ECHOLNPGM("Enabled Now: ", hex_word(stepper.axis_enabled.bits));
  95. }
  96. /**
  97. * M17: Enable stepper motor power for one or more axes.
  98. * Print warnings for axes that share an ENABLE_PIN.
  99. *
  100. * Examples:
  101. *
  102. * M17 XZ ; Enable X and Z axes
  103. * M17 E ; Enable all E steppers
  104. * M17 E1 ; Enable just the E1 stepper
  105. */
  106. void GcodeSuite::M17() {
  107. if (parser.seen_axis()) {
  108. if (any_enable_overlap())
  109. do_enable(selected_axis_bits());
  110. else {
  111. #if HAS_EXTRUDERS
  112. if (parser.seen('E')) {
  113. if (parser.has_value()) {
  114. const uint8_t e = parser.value_int();
  115. if (e < EXTRUDERS) stepper.ENABLE_EXTRUDER(e);
  116. }
  117. else
  118. stepper.enable_e_steppers();
  119. }
  120. #endif
  121. LOOP_NUM_AXES(a)
  122. if (parser.seen_test(AXIS_CHAR(a))) stepper.enable_axis((AxisEnum)a);
  123. }
  124. }
  125. else {
  126. LCD_MESSAGE(MSG_NO_MOVE);
  127. stepper.enable_all_steppers();
  128. }
  129. }
  130. void try_to_disable(const stepper_flags_t to_disable) {
  131. ena_mask_t still_enabled = to_disable.bits & stepper.axis_enabled.bits;
  132. DEBUG_ECHOLNPGM("Enabled: ", hex_word(stepper.axis_enabled.bits), " To Disable: ", hex_word(to_disable.bits), " | ", hex_word(still_enabled));
  133. if (!still_enabled) return;
  134. // Attempt to disable all flagged axes
  135. LOOP_NUM_AXES(a)
  136. if (TEST(to_disable.bits, a)) {
  137. DEBUG_ECHOPGM("Try to disable ", AXIS_CHAR(a), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... ");
  138. if (stepper.disable_axis(AxisEnum(a))) { // Mark the requested axis and request to disable
  139. DEBUG_ECHOPGM("OK");
  140. still_enabled &= ~(_BV(a) | enable_overlap[a]); // If actually disabled, clear one or more tracked bits
  141. }
  142. else
  143. DEBUG_ECHOPGM("OVERLAP");
  144. DEBUG_ECHOLNPGM(" ... still_enabled=", hex_word(still_enabled));
  145. }
  146. #if HAS_EXTRUDERS
  147. EXTRUDER_LOOP() {
  148. const uint8_t a = INDEX_OF_AXIS(E_AXIS, e);
  149. if (TEST(to_disable.bits, a)) {
  150. DEBUG_ECHOPGM("Try to disable E", AS_DIGIT(e), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... ");
  151. if (stepper.DISABLE_EXTRUDER(e)) {
  152. DEBUG_ECHOPGM("OK");
  153. still_enabled &= ~(_BV(a) | enable_overlap[a]);
  154. }
  155. else
  156. DEBUG_ECHOPGM("OVERLAP");
  157. DEBUG_ECHOLNPGM(" ... still_enabled=", hex_word(still_enabled));
  158. }
  159. }
  160. #endif
  161. auto overlap_warning = [](const ena_mask_t axis_bits) {
  162. SERIAL_ECHOPGM(" not disabled. Shared with");
  163. LOOP_NUM_AXES(a) if (TEST(axis_bits, a)) SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a]));
  164. #if HAS_EXTRUDERS
  165. #define _EN_STILLON(N) if (TEST(axis_bits, INDEX_OF_AXIS(E_AXIS, N))) SERIAL_CHAR(' ', 'E', '0' + N);
  166. REPEAT(EXTRUDERS, _EN_STILLON)
  167. #endif
  168. SERIAL_ECHOLNPGM(".");
  169. };
  170. // If any of the requested axes are still enabled, give a warning
  171. LOOP_NUM_AXES(a) {
  172. if (TEST(still_enabled, a)) {
  173. SERIAL_CHAR(AXIS_CHAR(a));
  174. overlap_warning(stepper.axis_enabled.bits & enable_overlap[a]);
  175. }
  176. }
  177. #if HAS_EXTRUDERS
  178. EXTRUDER_LOOP() {
  179. const uint8_t a = INDEX_OF_AXIS(E_AXIS, e);
  180. if (TEST(still_enabled, a)) {
  181. SERIAL_CHAR('E', '0' + e);
  182. overlap_warning(stepper.axis_enabled.bits & enable_overlap[a]);
  183. }
  184. }
  185. #endif
  186. DEBUG_ECHOLNPGM("Enabled Now: ", hex_word(stepper.axis_enabled.bits));
  187. }
  188. /**
  189. * M18, M84: Disable stepper motor power for one or more axes.
  190. * Print warnings for axes that share an ENABLE_PIN.
  191. */
  192. void GcodeSuite::M18_M84() {
  193. if (parser.seenval('S')) {
  194. reset_stepper_timeout();
  195. #if HAS_DISABLE_INACTIVE_AXIS
  196. const millis_t ms = parser.value_millis_from_seconds();
  197. #if LASER_SAFETY_TIMEOUT_MS > 0
  198. if (ms && ms <= LASER_SAFETY_TIMEOUT_MS) {
  199. SERIAL_ECHO_MSG("M18 timeout must be > ", MS_TO_SEC(LASER_SAFETY_TIMEOUT_MS + 999), " s for laser safety.");
  200. return;
  201. }
  202. #endif
  203. stepper_inactive_time = ms;
  204. #endif
  205. }
  206. else {
  207. if (parser.seen_axis()) {
  208. planner.synchronize();
  209. if (any_enable_overlap())
  210. try_to_disable(selected_axis_bits());
  211. else {
  212. #if HAS_EXTRUDERS
  213. if (parser.seen('E')) {
  214. if (E_TERN0(parser.has_value()))
  215. stepper.DISABLE_EXTRUDER(parser.value_int());
  216. else
  217. stepper.disable_e_steppers();
  218. }
  219. #endif
  220. LOOP_NUM_AXES(a)
  221. if (parser.seen_test(AXIS_CHAR(a))) stepper.disable_axis((AxisEnum)a);
  222. }
  223. }
  224. else
  225. planner.finish_and_disable();
  226. TERN_(AUTO_BED_LEVELING_UBL, bedlevel.steppers_were_disabled());
  227. }
  228. }