Skip to content

Commit

Permalink
Ender-5 S1 modified code
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 28, 2024
1 parent 3a51794 commit 157b939
Show file tree
Hide file tree
Showing 30 changed files with 1,274 additions and 66 deletions.
66 changes: 59 additions & 7 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

#include "MarlinCore.h"

#define DEBUG_OUT ENABLED(MARLIN_DEV_MODE)
#include "core/debug_out.h"

#include "HAL/shared/Delay.h"
#include "HAL/shared/esp_wifi.h"
#include "HAL/shared/cpu_exception/exception_hook.h"
Expand Down Expand Up @@ -82,6 +85,10 @@
#endif
#endif

#if ENABLED(CREALITY_RTS)
#include "lcd/rts/lcd_rts.h"
#endif

#if HAS_ETHERNET
#include "feature/ethernet.h"
#endif
Expand Down Expand Up @@ -378,7 +385,11 @@ void startOrResumeJob() {
TERN_(POWER_LOSS_RECOVERY, recovery.purge());

#ifdef EVENT_GCODE_SD_ABORT
queue.inject(F(EVENT_GCODE_SD_ABORT));
DEBUG_ECHOLNPGM("abortSDPrinting");
//queue.inject(F(EVENT_GCODE_SD_ABORT));
queue.enqueue_now(F(EVENT_GCODE_SD_ABORT));
report_current_position();
TERN_(CREALITY_RTS, RTS_UpdatePosition());
#endif

TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine());
Expand Down Expand Up @@ -424,7 +435,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
SERIAL_ERROR_START();
SERIAL_ECHOPGM(STR_KILL_PRE);
SERIAL_ECHOLNPGM(STR_KILL_INACTIVE_TIME, parser.command_ptr);
kill();
TERN(CREALITY_RTS, RTS_StepperTimeout(), kill());
}

const bool has_blocks = planner.has_blocks_queued(); // Any moves in the planner?
Expand Down Expand Up @@ -455,7 +466,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
TERN_(AUTO_BED_LEVELING_UBL, bedlevel.steppers_were_disabled());
}
}
else
else // if (!parked_or_ignoring && gcode.stepper_inactive_timeout() && !card.isPrinting() && !IS_SD_PAUSED()) // rock_20220815
already_shutdown_steppers = false;
}
#endif
Expand Down Expand Up @@ -810,7 +821,10 @@ void idle(const bool no_stepper_sleep/*=false*/) {
#endif

// Handle SD Card insert / remove
TERN_(HAS_MEDIA, card.manage_media());
#if HAS_MEDIA
if (TERN1(CREALITY_RTS, !home_flag && !G29_flag)) // Avoid the problem of leveling and returning to zero, plugging and unplugging the card will affect the probe and report error 203
card.manage_media();
#endif

// Handle USB Flash Drive insert / remove
TERN_(USB_FLASH_DRIVE_SUPPORT, card.diskIODriver()->idle());
Expand All @@ -825,7 +839,15 @@ void idle(const bool no_stepper_sleep/*=false*/) {
TERN_(HAS_BEEPER, buzzer.tick());

// Handle UI input / draw events
ui.update();
#if ENABLED(CREALITY_RTS)
RTS_Update();
#else
ui.update();
#endif

#if ENABLED(PROBE_ACTIVATION_SWITCH)
endstops.enable_z_probe(TERN1(CREALITY_RTS, (home_flag || G29_flag)) && (LOW == READ(PROBE_ACTIVATION_SWITCH_PIN)));
#endif

// Run i2c Position Encoders
#if ENABLED(I2C_POSITION_ENCODERS)
Expand Down Expand Up @@ -870,6 +892,24 @@ void idle(const bool no_stepper_sleep/*=false*/) {
// Direct Stepping
TERN_(DIRECT_STEPPING, page_manager.write_responses());

#if ENABLED(MENU_RESET_WIFI)
static uint32_t wifi_recordms = 0;

if (WIFI_STATE == PRESSED) {
wifi_recordms = millis();
wifi_recordms += 7000;
WIFI_STATE = RECORDTIME;
}

if (WIFI_STATE == RECORDTIME) {
if (wifi_recordms == millis()) {
OUT_WRITE(RESET_WIFI_PIN, HIGH);
WIFI_STATE = INITIAL;
SERIAL_ECHOPGM("wifi is reset");
}
}
#endif

// Update the LVGL interface
TERN_(HAS_TFT_LVGL_UI, LV_TASK_HANDLER());

Expand Down Expand Up @@ -1285,13 +1325,13 @@ void setup() {

// Identify myself as Marlin x.x.x
SERIAL_ECHOLNPGM("Marlin " SHORT_BUILD_VERSION);
#ifdef STRING_DISTRIBUTION_DATE
#if defined(STRING_DISTRIBUTION_DATE) && (DISABLED(CREALITY_RTS) || defined(STRING_CONFIG_H_AUTHOR))
SERIAL_ECHO_MSG(
" Last Updated: " STRING_DISTRIBUTION_DATE
" | Author: " STRING_CONFIG_H_AUTHOR
);
#endif
SERIAL_ECHO_MSG(" Compiled: " __DATE__);
SERIAL_ECHO_MSG(" Compiled: " __DATE__ " " __TIME__);
SERIAL_ECHO_MSG(STR_FREE_MEMORY, hal.freeMemory(), STR_PLANNER_BUFFER_BYTES, sizeof(block_t) * (BLOCK_BUFFER_SIZE));

// Some HAL need precise delay adjustment
Expand Down Expand Up @@ -1609,6 +1649,8 @@ void setup() {

#if ENABLED(DWIN_CREALITY_LCD)
SETUP_RUN(dwinInitScreen());
#elif ENABLED(CREALITY_RTS)
SETUP_RUN(rts.init());
#endif

#if HAS_SERVICE_INTERVALS && DISABLED(DWIN_CREALITY_LCD)
Expand Down Expand Up @@ -1715,3 +1757,13 @@ void loop() {

} while (ENABLED(__AVR__)); // Loop forever on slower (AVR) boards
}

//void HardFault_Handler(void) {
// SERIAL_ECHO_MSG("HardFault_Handler");
// OUT_WRITE(E0_AUTO_FAN_PIN, LOW);
// OUT_WRITE(FAN_PIN, LOW);
// for (int i = 0; i < 0xFFFF; i++) OUT_WRITE(FAN_PIN, HIGH);
// OUT_WRITE(E0_AUTO_FAN_PIN, HIGH);
// OUT_WRITE(FAN_PIN, HIGH);
// while(1);
//}
71 changes: 53 additions & 18 deletions Marlin/src/feature/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@

#include "../lcd/marlinui.h"

#if ENABLED(CREALITY_RTS)
#include "../lcd/rts/lcd_rts.h"
#endif

#if HAS_SOUND
#include "../libs/buzzer.h"
#endif
Expand Down Expand Up @@ -152,11 +156,13 @@ static bool ensure_safe_temperature(const bool wait=true, const PauseMode mode=P

if (wait) return thermalManager.wait_for_hotend(active_extruder);

// Allow interruption by Emergency Parser M108
wait_for_heatup = TERN1(PREVENT_COLD_EXTRUSION, !thermalManager.allow_cold_extrude);
while (wait_for_heatup && ABS(thermalManager.wholeDegHotend(active_extruder) - thermalManager.degTargetHotend(active_extruder)) > (TEMP_WINDOW))
idle();
wait_for_heatup = false;
#if DISABLED(CREALITY_RTS)
// Allow interruption by Emergency Parser M108
wait_for_heatup = TERN1(PREVENT_COLD_EXTRUSION, !thermalManager.allow_cold_extrude);
while (wait_for_heatup && ABS(thermalManager.wholeDegHotend(active_extruder) - thermalManager.degTargetHotend(active_extruder)) > (TEMP_WINDOW))
idle();
wait_for_heatup = false;
#endif

#if ENABLED(PREVENT_COLD_EXTRUSION)
// A user can cancel wait-for-heating with M108
Expand Down Expand Up @@ -415,6 +421,7 @@ bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool
#endif

TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_open(PROMPT_INFO, F("Pause"), FPSTR(DISMISS_STR)));
TERN_(CREALITY_RTS, RTS_PausedPrint());

// Indicate that the printer is paused
++did_pause_print;
Expand Down Expand Up @@ -463,25 +470,48 @@ bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool
TERN_(AUTO_BED_LEVELING_UBL, set_bed_leveling_enabled(leveling_was_enabled)); // restore leveling
}

// If axes don't need to home then the nozzle can park
if (do_park) nozzle.park(0, park_point); // Park the nozzle by doing a Minimum Z Raise followed by an XY Move
if (!do_park) LCD_MESSAGE(MSG_PARK_FAILED);
#if ENABLED(CREALITY_RTS)

while (planner.movesplanned() < 2 && destination != current_position) idle();

queue.clear();
delay(20);
if (!planner.has_blocks_queued()) {
if (axis_is_trusted(X_AXIS) && axis_is_trusted(Y_AXIS)) {
//if (!axes_need_homing())
nozzle.park(0, park_point);
}
}

#else

// If axes don't need to home then the nozzle can park
if (do_park) nozzle.park(0, park_point); // Park the nozzle by doing a Minimum Z Raise followed by an XY Move
if (!do_park) LCD_MESSAGE(MSG_PARK_FAILED);

#endif

TERN_(DWIN_LCD_PROUI, if (!do_park) ui.set_status(GET_TEXT_F(MSG_PARK_FAILED)));

#if ENABLED(DUAL_X_CARRIAGE)
const int8_t saved_ext = active_extruder;
const bool saved_ext_dup_mode = extruder_duplication_enabled;
set_duplication_enabled(false, DXC_ext);
#endif

// Unload the filament, if specified
if (unload_length)
unload_filament(unload_length, show_lcd, PAUSE_MODE_CHANGE_FILAMENT);
#if DISABLED(CREALITY_RTS)
// Unload the filament, if specified
if (unload_length)
unload_filament(unload_length, show_lcd, PAUSE_MODE_CHANGE_FILAMENT);
#endif

TERN_(DUAL_X_CARRIAGE, set_duplication_enabled(saved_ext_dup_mode, saved_ext));

// Disable the Extruder for manual change
disable_active_extruder();

TERN_(CREALITY_RTS, RTS_ReheatHotend(170));

return true;
}

Expand Down Expand Up @@ -586,6 +616,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
nozzle_timed_out = false;
first_impatient_beep(max_beep_count);
}
TERN_(CREALITY_RTS, wait_for_user = false);
idle_no_sleep();
}
TERN_(DUAL_X_CARRIAGE, set_duplication_enabled(saved_ext_dup_mode, saved_ext));
Expand Down Expand Up @@ -671,13 +702,17 @@ void resume_print(
unscaled_e_move(-(PAUSE_PARK_RETRACT_LENGTH), feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));

if (!axes_should_home()) {
// Move XY back to saved position
destination.set(resume_position.x, resume_position.y, current_position.z, current_position.e);
prepare_internal_move_to_destination(NOZZLE_PARK_XY_FEEDRATE);

// Move Z back to saved position
destination.z = resume_position.z;
prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE);
#if ENABLED(CREALITY_RTS)
destination.set(resume_position.x, resume_position.y, resume_position.z, current_position.e);
#else
// Move XY back to saved position
destination.set(resume_position.x, resume_position.y, current_position.z, current_position.e);
prepare_internal_move_to_destination(NOZZLE_PARK_XY_FEEDRATE);

// Move Z back to saved position
destination.z = resume_position.z;
prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE);
#endif
}

#if ENABLED(AUTO_BED_LEVELING_UBL)
Expand Down
Loading

0 comments on commit 157b939

Please sign in to comment.