Skip to content

Commit

Permalink
Extend M106/M107 for better laser module support (#16082)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
DrywFiltiarn and thinkyhead authored Mar 24, 2021
1 parent 3ae892b commit 30e7e2c
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 89 deletions.
12 changes: 12 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3217,6 +3217,18 @@
#endif
#endif

/**
* Synchronous Laser Control with M106/M107
*
* Marlin normally applies M106/M107 fan speeds at a time "soon after" processing
* a planner block. This is too inaccurate for a PWM/TTL laser attached to the fan
* header (as with some add-on laser kits). Enable this option to set fan/laser
* speeds with much more exact timing for improved print fidelity.
*
* NOTE: This option sacrifices some cooling fan speed options.
*/
//#define LASER_SYNCHRONOUS_M106_M107

/**
* Coolant Control
*
Expand Down
18 changes: 13 additions & 5 deletions Marlin/src/gcode/temp/M106_M107.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "../../module/motion.h"
#include "../../module/temperature.h"

#if ENABLED(LASER_SYNCHRONOUS_M106_M107)
#include "../../module/planner.h"
#endif

#if PREHEAT_COUNT
#include "../../lcd/marlinui.h"
#endif
Expand Down Expand Up @@ -82,6 +86,8 @@ void GcodeSuite::M106() {
// Set speed, with constraint
thermalManager.set_fan_speed(pfan, speed);

TERN_(LASER_SYNCHRONOUS_M106_M107, planner.buffer_sync_block(BLOCK_FLAG_SYNC_FANS));

if (TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())) // pfan == 0 when duplicating
thermalManager.set_fan_speed(1 - pfan, speed);
}
Expand All @@ -92,12 +98,14 @@ void GcodeSuite::M106() {
*/
void GcodeSuite::M107() {
const uint8_t pfan = parser.byteval('P', _ALT_P);
if (pfan < _CNT_P) {
thermalManager.set_fan_speed(pfan, 0);
if (pfan >= _CNT_P) return;

if (TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())) // pfan == 0 when duplicating
thermalManager.set_fan_speed(1 - pfan, 0);
}
thermalManager.set_fan_speed(pfan, 0);

if (TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())) // pfan == 0 when duplicating
thermalManager.set_fan_speed(1 - pfan, 0);

TERN_(LASER_SYNCHRONOUS_M106_M107, planner.buffer_sync_block(BLOCK_FLAG_SYNC_FANS));
}

#endif // HAS_FAN
11 changes: 11 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,17 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#error "To use BED_LIMIT_SWITCHING you must disable PIDTEMPBED."
#endif

/**
* Synchronous M106/M107 checks
*/
#if ENABLED(LASER_SYNCHRONOUS_M106_M107)
#if FAN_KICKSTART_TIME
#error "FAN_KICKSTART_TIME must be 0 with LASER_SYNCHRONOUS_M106_M107 (because the laser will always come on at FULL power)."
#elif FAN_MIN_PWM
#error "FAN_MIN_PWM must be 0 with LASER_SYNCHRONOUS_M106_M107 (otherwise the laser will never turn OFF)."
#endif
#endif

/**
* Chamber Heating Options - PID vs Limit Switching
*/
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ void MarlinUI::draw_status_screen() {
#endif
#endif // HAS_HEATED_BED

#if FAN_COUNT > 0
#if HAS_FAN
uint16_t spd = thermalManager.fan_speed[0];

#if ENABLED(ADAPTIVE_FAN_SLOWING)
Expand All @@ -783,7 +783,7 @@ void MarlinUI::draw_status_screen() {
else
picBits &= ~ICON_FAN;

#endif // FAN_COUNT > 0
#endif // HAS_FAN

//
// Line 9, 10 - icons
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dwin/e3v2/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ void HMI_SelectFile() {

card.openAndPrintFile(card.filename);

#if FAN_COUNT > 0
#if HAS_FAN
// All fans on for Ender 3 v2 ?
// The slicer should manage this for us.
//for (uint8_t i = 0; i < FAN_COUNT; i++)
Expand Down
29 changes: 16 additions & 13 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "../inc/MarlinConfig.h"

#include "../MarlinCore.h" // for printingIsPaused

#ifdef LED_BACKLIGHT_TIMEOUT
#include "../feature/leds/leds.h"
#endif
Expand All @@ -39,21 +41,21 @@
MarlinUI ui;

#if HAS_DISPLAY
#include "../module/printcounter.h"
#include "../MarlinCore.h"
#include "../gcode/queue.h"
#include "fontutils.h"
#include "../sd/cardreader.h"
#endif

#if ENABLED(DWIN_CREALITY_LCD)
#include "../module/printcounter.h"
#include "../MarlinCore.h"
#include "dwin/e3v2/dwin.h"
#endif

#if HAS_STATUS_MESSAGE
#define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80U)
#if ENABLED(LCD_PROGRESS_BAR) && !IS_TFTGLCD_PANEL
#define BASIC_PROGRESS_BAR 1
#endif

#if ANY(HAS_DISPLAY, HAS_STATUS_MESSAGE, BASIC_PROGRESS_BAR)
#include "../module/printcounter.h"
#endif

#if LCD_HAS_WAIT_FOR_MOVE
Expand Down Expand Up @@ -535,7 +537,7 @@ bool MarlinUI::get_blink() {
* This is very display-dependent, so the lcd implementation draws this.
*/

#if ENABLED(LCD_PROGRESS_BAR) && !IS_TFTGLCD_PANEL
#if BASIC_PROGRESS_BAR
millis_t MarlinUI::progress_bar_ms; // = 0
#if PROGRESS_MSG_EXPIRE > 0
millis_t MarlinUI::expire_status_ms; // = 0
Expand All @@ -546,7 +548,7 @@ void MarlinUI::status_screen() {

TERN_(HAS_LCD_MENU, ENCODER_RATE_MULTIPLY(false));

#if ENABLED(LCD_PROGRESS_BAR) && !IS_TFTGLCD_PANEL
#if BASIC_PROGRESS_BAR

//
// HD44780 implements the following message blinking and
Expand Down Expand Up @@ -586,7 +588,7 @@ void MarlinUI::status_screen() {

#endif // PROGRESS_MSG_EXPIRE

#endif // LCD_PROGRESS_BAR
#endif // BASIC_PROGRESS_BAR

#if HAS_LCD_MENU
if (use_click()) {
Expand Down Expand Up @@ -1353,6 +1355,7 @@ void MarlinUI::update() {
/**
* Reset the status message
*/

void MarlinUI::reset_status(const bool no_welcome) {
#if SERVICE_INTERVAL_1 > 0
static PGMSTR(service1, "> " SERVICE_NAME_1 "!");
Expand Down Expand Up @@ -1438,17 +1441,17 @@ void MarlinUI::update() {

void MarlinUI::finish_status(const bool persist) {

#if HAS_SPI_LCD
#if HAS_WIRED_LCD

#if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE) > 0)
#if !(BASIC_PROGRESS_BAR && (PROGRESS_MSG_EXPIRE) > 0)
UNUSED(persist);
#endif

#if ENABLED(LCD_PROGRESS_BAR) || BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
const millis_t ms = millis();
#endif

#if ENABLED(LCD_PROGRESS_BAR)
#if BASIC_PROGRESS_BAR
progress_bar_ms = ms;
#if PROGRESS_MSG_EXPIRE > 0
expire_status_ms = persist ? 0 : ms + PROGRESS_MSG_EXPIRE;
Expand All @@ -1462,7 +1465,7 @@ void MarlinUI::update() {
#if ENABLED(STATUS_MESSAGE_SCROLLING)
status_scroll_offset = 0;
#endif
#else // HAS_SPI_LCD
#else // HAS_WIRED_LCD
UNUSED(persist);
#endif

Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#include "../module/motion.h" // for active_extruder
#endif

#define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80U)

#if HAS_WIRED_LCD

enum LCDViewAction : uint8_t {
Expand Down
Loading

0 comments on commit 30e7e2c

Please sign in to comment.