My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M240.cpp 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfig.h"
  23. #if ENABLED(PHOTO_GCODE)
  24. #include "../../gcode.h"
  25. #include "../../../module/motion.h" // for active_extruder and current_position
  26. #if PIN_EXISTS(CHDK)
  27. millis_t chdk_timeout; // = 0
  28. #endif
  29. #if defined(PHOTO_POSITION) && PHOTO_DELAY_MS > 0
  30. #include "../../../MarlinCore.h" // for idle()
  31. #endif
  32. #ifdef PHOTO_RETRACT_MM
  33. #define _PHOTO_RETRACT_MM (PHOTO_RETRACT_MM + 0)
  34. #include "../../../module/planner.h"
  35. #include "../../../module/temperature.h"
  36. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  37. #include "../../../feature/pause.h"
  38. #endif
  39. #ifdef PHOTO_RETRACT_MM
  40. inline void e_move_m240(const float length, const feedRate_t &fr_mm_s) {
  41. if (length && thermalManager.hotEnoughToExtrude(active_extruder)) {
  42. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  43. do_pause_e_move(length, fr_mm_s);
  44. #else
  45. current_position.e += length / planner.e_factor[active_extruder];
  46. line_to_current_position(fr_mm_s);
  47. #endif
  48. }
  49. }
  50. #endif
  51. #endif
  52. #if PIN_EXISTS(PHOTOGRAPH)
  53. constexpr uint8_t NUM_PULSES = 16;
  54. constexpr float PULSE_LENGTH = 0.01524;
  55. inline void set_photo_pin(const uint8_t state) { WRITE(PHOTOGRAPH_PIN, state); _delay_ms(PULSE_LENGTH); }
  56. inline void tweak_photo_pin() { set_photo_pin(HIGH); set_photo_pin(LOW); }
  57. inline void spin_photo_pin() { for (uint8_t i = NUM_PULSES; i--;) tweak_photo_pin(); }
  58. #endif
  59. /**
  60. * M240: Trigger a camera by...
  61. *
  62. * - CHDK : Emulate a Canon RC-1 with a configurable ON duration.
  63. * http://captain-slow.dk/2014/03/09/3d-printing-timelapses/
  64. * - PHOTOGRAPH_PIN : Pulse a digital pin 16 times.
  65. * See http://www.doc-diy.net/photo/rc-1_hacked/
  66. * - PHOTO_SWITCH_POSITION : Bump a physical switch with the X-carriage using a
  67. * configured position, delay, and retract length.
  68. *
  69. * PHOTO_POSITION parameters:
  70. * A - X offset to the return position
  71. * B - Y offset to the return position
  72. * F - Override the XY movement feedrate
  73. * R - Retract/recover length (current units)
  74. * S - Retract/recover feedrate (mm/m)
  75. * X - Move to X before triggering the shutter
  76. * Y - Move to Y before triggering the shutter
  77. * Z - Raise Z by a distance before triggering the shutter
  78. *
  79. * PHOTO_SWITCH_POSITION parameters:
  80. * D - Duration (ms) to hold down switch (Requires PHOTO_SWITCH_MS)
  81. * P - Delay (ms) after triggering the shutter (Requires PHOTO_SWITCH_MS)
  82. * I - Switch trigger position override X
  83. * J - Switch trigger position override Y
  84. */
  85. void GcodeSuite::M240() {
  86. #ifdef PHOTO_POSITION
  87. if (axis_unhomed_error()) return;
  88. const xyz_pos_t old_pos = {
  89. current_position.x + parser.linearval('A'),
  90. current_position.y + parser.linearval('B'),
  91. current_position.z
  92. };
  93. #ifdef PHOTO_RETRACT_MM
  94. const float rval = parser.seenval('R') ? parser.value_linear_units() : _PHOTO_RETRACT_MM;
  95. feedRate_t sval = (
  96. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  97. PAUSE_PARK_RETRACT_FEEDRATE
  98. #elif ENABLED(FWRETRACT)
  99. RETRACT_FEEDRATE
  100. #else
  101. 45
  102. #endif
  103. );
  104. if (parser.seenval('S')) sval = parser.value_feedrate();
  105. e_move_m240(-rval, sval);
  106. #endif
  107. feedRate_t fr_mm_s = MMM_TO_MMS(parser.linearval('F'));
  108. if (fr_mm_s) NOLESS(fr_mm_s, 10.0f);
  109. constexpr xyz_pos_t photo_position = PHOTO_POSITION;
  110. xyz_pos_t raw = {
  111. parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : photo_position.x,
  112. parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position.y,
  113. (parser.seenval('Z') ? parser.value_linear_units() : photo_position.z) + current_position.z
  114. };
  115. apply_motion_limits(raw);
  116. do_blocking_move_to(raw, fr_mm_s);
  117. #ifdef PHOTO_SWITCH_POSITION
  118. constexpr xy_pos_t photo_switch_position = PHOTO_SWITCH_POSITION;
  119. const xy_pos_t sraw = {
  120. parser.seenval('I') ? RAW_X_POSITION(parser.value_linear_units()) : photo_switch_position.x,
  121. parser.seenval('J') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_switch_position.y
  122. };
  123. do_blocking_move_to_xy(sraw, get_homing_bump_feedrate(X_AXIS));
  124. #if PHOTO_SWITCH_MS > 0
  125. safe_delay(parser.intval('D', PHOTO_SWITCH_MS));
  126. #endif
  127. do_blocking_move_to(raw);
  128. #endif
  129. #endif
  130. #if PIN_EXISTS(CHDK)
  131. OUT_WRITE(CHDK_PIN, HIGH);
  132. chdk_timeout = millis() + parser.intval('D', PHOTO_SWITCH_MS);
  133. #elif HAS_PHOTOGRAPH
  134. spin_photo_pin();
  135. delay(7.33);
  136. spin_photo_pin();
  137. #endif
  138. #ifdef PHOTO_POSITION
  139. #if PHOTO_DELAY_MS > 0
  140. const millis_t timeout = millis() + parser.intval('P', PHOTO_DELAY_MS);
  141. while (PENDING(millis(), timeout)) idle();
  142. #endif
  143. do_blocking_move_to(old_pos, fr_mm_s);
  144. #ifdef PHOTO_RETRACT_MM
  145. e_move_m240(rval, sval);
  146. #endif
  147. #endif
  148. }
  149. #endif // PHOTO_GCODE