Add PHOTO_GCODE option, photo trigger physical move (#13168)
This commit is contained in:
@ -22,24 +22,99 @@
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#if PIN_EXISTS(CHDK) || HAS_PHOTOGRAPH
|
||||
#if ENABLED(PHOTO_GCODE)
|
||||
|
||||
#include "../../gcode.h"
|
||||
#include "../../../module/motion.h" // for active_extruder and current_position
|
||||
|
||||
bool chdk_active; // = false
|
||||
millis_t chdk_timeout;
|
||||
#if PIN_EXISTS(CHDK)
|
||||
millis_t chdk_timeout; // = 0
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
inline void e_move_m240(const float length) {
|
||||
if (_PHOTO_RETRACT_MM) {
|
||||
constexpr float rfr = (MMS_TO_MMM(
|
||||
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
||||
PAUSE_PARK_RETRACT_FEEDRATE
|
||||
#elif ENABLED(FWRETRACT)
|
||||
RETRACT_FEEDRATE
|
||||
#else
|
||||
45
|
||||
#endif
|
||||
));
|
||||
if (thermalManager.hotEnoughToExtrude(active_extruder)) {
|
||||
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
||||
do_pause_e_move(length, rfr);
|
||||
#else
|
||||
current_position[E_AXIS] += length / planner.e_factor[active_extruder];
|
||||
planner.buffer_line(current_position, MMM_TO_MMS(rfr), active_extruder);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* M240: Trigger a camera by emulating a Canon RC-1
|
||||
* See http://www.doc-diy.net/photo/rc-1_hacked/
|
||||
* 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.
|
||||
* Parameters:
|
||||
* X - Move to X before triggering the shutter (Requires PHOTO_POSITION)
|
||||
* Y - Move to Y before triggering the shutter (Requires PHOTO_POSITION)
|
||||
* Z - Raise Z by a distance before triggering the shutter (Requires PHOTO_POSITION)
|
||||
* P - Delay (ms) after triggering the shutter
|
||||
*/
|
||||
void GcodeSuite::M240() {
|
||||
|
||||
#ifdef PHOTO_POSITION
|
||||
|
||||
const float old_pos[XYZ] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
|
||||
|
||||
#ifdef PHOTO_RETRACT_MM
|
||||
e_move_m240(-(_PHOTO_RETRACT_MM));
|
||||
#endif
|
||||
|
||||
constexpr float photo_position[XYZ] = PHOTO_POSITION;
|
||||
float raw[XYZ] = {
|
||||
parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : photo_position[X_AXIS],
|
||||
parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position[X_AXIS],
|
||||
(parser.seenval('Z') ? parser.value_linear_units() : photo_position[Z_AXIS]) + current_position[Z_AXIS]
|
||||
};
|
||||
clamp_to_software_endstops(raw);
|
||||
do_blocking_move_to(raw);
|
||||
|
||||
#ifdef PHOTO_SWITCH_POSITION
|
||||
const float photo_switch_position[2] = PHOTO_SWITCH_POSITION;
|
||||
do_blocking_move_to_xy(photo_switch_position[X_AXIS], photo_switch_position[Y_AXIS], get_homing_bump_feedrate(X_AXIS));
|
||||
#if PHOTO_SWITCH_MS > 0
|
||||
safe_delay(PHOTO_SWITCH_MS);
|
||||
#endif
|
||||
do_blocking_move_to(raw);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if PIN_EXISTS(CHDK)
|
||||
|
||||
OUT_WRITE(CHDK_PIN, HIGH);
|
||||
chdk_timeout = millis() + CHDK_DELAY;
|
||||
chdk_active = true;
|
||||
chdk_timeout = millis() + PHOTO_SWITCH_MS;
|
||||
|
||||
#elif HAS_PHOTOGRAPH
|
||||
|
||||
@ -60,6 +135,16 @@ void GcodeSuite::M240() {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PHOTO_POSITION
|
||||
#if PHOTO_DELAY_MS > 0
|
||||
safe_delay(parser.intval('P', PHOTO_DELAY_MS));
|
||||
#endif
|
||||
do_blocking_move_to(old_pos);
|
||||
#ifdef PHOTO_RETRACT_MM
|
||||
e_move_m240(_PHOTO_RETRACT_MM);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // CHDK_PIN || HAS_PHOTOGRAPH
|
||||
#endif // PHOTO_GCODE
|
||||
|
@ -524,8 +524,8 @@ void GcodeSuite::process_parsed_command(
|
||||
case 304: M304(); break; // M304: Set bed PID parameters
|
||||
#endif
|
||||
|
||||
#if PIN_EXISTS(CHDK) || HAS_PHOTOGRAPH
|
||||
case 240: M240(); break; // M240: Trigger a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/
|
||||
#if ENABLED(PHOTO_GCODE)
|
||||
case 240: M240(); break; // M240: Trigger a camera
|
||||
#endif
|
||||
|
||||
#if HAS_LCD_CONTRAST
|
||||
|
@ -172,7 +172,7 @@
|
||||
* M220 - Set Feedrate Percentage: "M220 S<percent>" (i.e., "FR" on the LCD)
|
||||
* M221 - Set Flow Percentage: "M221 S<percent>"
|
||||
* M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>"
|
||||
* M240 - Trigger a camera to take a photograph. (Requires CHDK_PIN or PHOTOGRAPH_PIN)
|
||||
* M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
|
||||
* M250 - Set LCD contrast: "M250 C<contrast>" (0-63). (Requires LCD support)
|
||||
* M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
|
||||
* M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
|
||||
@ -639,7 +639,7 @@ private:
|
||||
static void M221();
|
||||
static void M226();
|
||||
|
||||
#if PIN_EXISTS(CHDK) || HAS_PHOTOGRAPH
|
||||
#if ENABLED(PHOTO_GCODE)
|
||||
static void M240();
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user