2017-09-06 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-17 08:20:32 +00:00
|
|
|
#include "../../../inc/MarlinConfig.h"
|
|
|
|
|
2019-02-14 21:09:35 +00:00
|
|
|
#if ENABLED(PHOTO_GCODE)
|
2017-09-17 08:20:32 +00:00
|
|
|
|
|
|
|
#include "../../gcode.h"
|
2019-02-14 21:09:35 +00:00
|
|
|
#include "../../../module/motion.h" // for active_extruder and current_position
|
2017-09-17 08:20:32 +00:00
|
|
|
|
2019-02-14 21:09:35 +00:00
|
|
|
#if PIN_EXISTS(CHDK)
|
|
|
|
millis_t chdk_timeout; // = 0
|
|
|
|
#endif
|
|
|
|
|
2019-12-15 17:16:36 +00:00
|
|
|
#if defined(PHOTO_POSITION) && PHOTO_DELAY_MS > 0
|
2020-01-03 01:01:38 +00:00
|
|
|
#include "../../../MarlinCore.h" // for idle()
|
2019-10-31 22:27:19 +00:00
|
|
|
#endif
|
|
|
|
|
2019-02-14 21:09:35 +00:00
|
|
|
#ifdef PHOTO_RETRACT_MM
|
|
|
|
|
|
|
|
#define _PHOTO_RETRACT_MM (PHOTO_RETRACT_MM + 0)
|
|
|
|
|
|
|
|
#include "../../../module/planner.h"
|
|
|
|
#include "../../../module/temperature.h"
|
|
|
|
|
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
|
#include "../../../feature/pause.h"
|
|
|
|
#endif
|
|
|
|
|
2019-02-14 22:41:46 +00:00
|
|
|
#ifdef PHOTO_RETRACT_MM
|
2019-09-26 06:28:09 +00:00
|
|
|
inline void e_move_m240(const float length, const feedRate_t &fr_mm_s) {
|
2019-02-14 22:41:46 +00:00
|
|
|
if (length && thermalManager.hotEnoughToExtrude(active_extruder)) {
|
2019-02-14 21:09:35 +00:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
2019-02-14 22:41:46 +00:00
|
|
|
do_pause_e_move(length, fr_mm_s);
|
2019-02-14 21:09:35 +00:00
|
|
|
#else
|
2019-09-29 09:25:39 +00:00
|
|
|
current_position.e += length / planner.e_factor[active_extruder];
|
|
|
|
line_to_current_position(fr_mm_s);
|
2019-02-14 21:09:35 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2019-02-14 22:41:46 +00:00
|
|
|
#endif
|
2019-02-14 21:09:35 +00:00
|
|
|
|
|
|
|
#endif
|
2018-11-05 07:08:40 +00:00
|
|
|
|
2019-02-14 22:41:46 +00:00
|
|
|
#if PIN_EXISTS(PHOTOGRAPH)
|
|
|
|
constexpr uint8_t NUM_PULSES = 16;
|
|
|
|
constexpr float PULSE_LENGTH = 0.01524;
|
|
|
|
inline void set_photo_pin(const uint8_t state) { WRITE(PHOTOGRAPH_PIN, state); _delay_ms(PULSE_LENGTH); }
|
|
|
|
inline void tweak_photo_pin() { set_photo_pin(HIGH); set_photo_pin(LOW); }
|
|
|
|
inline void spin_photo_pin() { for (uint8_t i = NUM_PULSES; i--;) tweak_photo_pin(); }
|
|
|
|
#endif
|
|
|
|
|
2017-09-06 11:28:31 +00:00
|
|
|
/**
|
2019-02-14 21:09:35 +00:00
|
|
|
* M240: Trigger a camera by...
|
|
|
|
*
|
|
|
|
* - CHDK : Emulate a Canon RC-1 with a configurable ON duration.
|
|
|
|
* http://captain-slow.dk/2014/03/09/3d-printing-timelapses/
|
|
|
|
* - PHOTOGRAPH_PIN : Pulse a digital pin 16 times.
|
|
|
|
* See http://www.doc-diy.net/photo/rc-1_hacked/
|
|
|
|
* - PHOTO_SWITCH_POSITION : Bump a physical switch with the X-carriage using a
|
|
|
|
* configured position, delay, and retract length.
|
2019-02-14 22:41:46 +00:00
|
|
|
*
|
|
|
|
* PHOTO_POSITION parameters:
|
2019-02-20 20:51:26 +00:00
|
|
|
* A - X offset to the return position
|
|
|
|
* B - Y offset to the return position
|
|
|
|
* F - Override the XY movement feedrate
|
2019-02-14 22:41:46 +00:00
|
|
|
* R - Retract/recover length (current units)
|
|
|
|
* S - Retract/recover feedrate (mm/m)
|
|
|
|
* X - Move to X before triggering the shutter
|
|
|
|
* Y - Move to Y before triggering the shutter
|
|
|
|
* Z - Raise Z by a distance before triggering the shutter
|
|
|
|
*
|
|
|
|
* PHOTO_SWITCH_POSITION parameters:
|
|
|
|
* D - Duration (ms) to hold down switch (Requires PHOTO_SWITCH_MS)
|
|
|
|
* P - Delay (ms) after triggering the shutter (Requires PHOTO_SWITCH_MS)
|
|
|
|
* I - Switch trigger position override X
|
|
|
|
* J - Switch trigger position override Y
|
2017-09-06 11:28:31 +00:00
|
|
|
*/
|
2017-09-17 08:20:32 +00:00
|
|
|
void GcodeSuite::M240() {
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2019-02-14 21:09:35 +00:00
|
|
|
#ifdef PHOTO_POSITION
|
|
|
|
|
2019-02-14 22:41:46 +00:00
|
|
|
if (axis_unhomed_error()) return;
|
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
const xyz_pos_t old_pos = {
|
|
|
|
current_position.x + parser.linearval('A'),
|
|
|
|
current_position.y + parser.linearval('B'),
|
|
|
|
current_position.z
|
2019-02-20 20:51:26 +00:00
|
|
|
};
|
2019-02-14 21:09:35 +00:00
|
|
|
|
|
|
|
#ifdef PHOTO_RETRACT_MM
|
2019-09-26 06:28:09 +00:00
|
|
|
const float rval = parser.seenval('R') ? parser.value_linear_units() : _PHOTO_RETRACT_MM;
|
|
|
|
feedRate_t sval = (
|
2019-02-14 22:41:46 +00:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
|
PAUSE_PARK_RETRACT_FEEDRATE
|
|
|
|
#elif ENABLED(FWRETRACT)
|
|
|
|
RETRACT_FEEDRATE
|
|
|
|
#else
|
|
|
|
45
|
|
|
|
#endif
|
2019-09-26 06:28:09 +00:00
|
|
|
);
|
|
|
|
if (parser.seenval('S')) sval = parser.value_feedrate();
|
2019-02-14 22:41:46 +00:00
|
|
|
e_move_m240(-rval, sval);
|
2019-02-14 21:09:35 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-26 06:28:09 +00:00
|
|
|
feedRate_t fr_mm_s = MMM_TO_MMS(parser.linearval('F'));
|
2019-02-20 20:51:26 +00:00
|
|
|
if (fr_mm_s) NOLESS(fr_mm_s, 10.0f);
|
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
constexpr xyz_pos_t photo_position = PHOTO_POSITION;
|
|
|
|
xyz_pos_t raw = {
|
|
|
|
parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : photo_position.x,
|
|
|
|
parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position.y,
|
|
|
|
(parser.seenval('Z') ? parser.value_linear_units() : photo_position.z) + current_position.z
|
2019-02-14 21:09:35 +00:00
|
|
|
};
|
2019-03-13 10:48:36 +00:00
|
|
|
apply_motion_limits(raw);
|
2019-02-20 20:51:26 +00:00
|
|
|
do_blocking_move_to(raw, fr_mm_s);
|
2019-02-14 21:09:35 +00:00
|
|
|
|
|
|
|
#ifdef PHOTO_SWITCH_POSITION
|
2019-09-29 09:25:39 +00:00
|
|
|
constexpr xy_pos_t photo_switch_position = PHOTO_SWITCH_POSITION;
|
|
|
|
const xy_pos_t sraw = {
|
|
|
|
parser.seenval('I') ? RAW_X_POSITION(parser.value_linear_units()) : photo_switch_position.x,
|
|
|
|
parser.seenval('J') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_switch_position.y
|
2019-02-14 22:41:46 +00:00
|
|
|
};
|
2019-09-29 09:25:39 +00:00
|
|
|
do_blocking_move_to_xy(sraw, get_homing_bump_feedrate(X_AXIS));
|
2019-02-14 21:09:35 +00:00
|
|
|
#if PHOTO_SWITCH_MS > 0
|
2019-02-14 22:41:46 +00:00
|
|
|
safe_delay(parser.intval('D', PHOTO_SWITCH_MS));
|
2019-02-14 21:09:35 +00:00
|
|
|
#endif
|
|
|
|
do_blocking_move_to(raw);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-11-05 07:08:40 +00:00
|
|
|
#if PIN_EXISTS(CHDK)
|
|
|
|
|
|
|
|
OUT_WRITE(CHDK_PIN, HIGH);
|
2019-10-31 22:14:11 +00:00
|
|
|
chdk_timeout = millis() + parser.intval('D', PHOTO_SWITCH_MS);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#elif HAS_PHOTOGRAPH
|
|
|
|
|
2019-02-14 22:41:46 +00:00
|
|
|
spin_photo_pin();
|
2017-09-06 11:28:31 +00:00
|
|
|
delay(7.33);
|
2019-02-14 22:41:46 +00:00
|
|
|
spin_photo_pin();
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#endif
|
2019-02-14 21:09:35 +00:00
|
|
|
|
|
|
|
#ifdef PHOTO_POSITION
|
|
|
|
#if PHOTO_DELAY_MS > 0
|
2019-10-31 22:14:11 +00:00
|
|
|
const millis_t timeout = millis() + parser.intval('P', PHOTO_DELAY_MS);
|
|
|
|
while (PENDING(millis(), timeout)) idle();
|
2019-02-14 21:09:35 +00:00
|
|
|
#endif
|
2019-02-20 20:51:26 +00:00
|
|
|
do_blocking_move_to(old_pos, fr_mm_s);
|
2019-02-14 21:09:35 +00:00
|
|
|
#ifdef PHOTO_RETRACT_MM
|
2019-02-14 22:41:46 +00:00
|
|
|
e_move_m240(rval, sval);
|
2019-02-14 21:09:35 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
2017-09-17 08:20:32 +00:00
|
|
|
|
2019-02-14 21:09:35 +00:00
|
|
|
#endif // PHOTO_GCODE
|