From d7b7b570c77d2725877124661167224dcf72be5d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 6 Jan 2022 05:07:47 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Misc.=20cleanup,=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration.h | 2 +- Marlin/src/feature/easythreed_ui.cpp | 10 +++--- Marlin/src/feature/power.h | 2 +- Marlin/src/gcode/bedlevel/abl/G29.cpp | 6 ++++ Marlin/src/lcd/e3v2/creality/dwin.cpp | 5 ++- Marlin/src/lcd/touch/touch_buttons.cpp | 2 +- Marlin/src/module/endstops.cpp | 15 +++++---- Marlin/src/module/stepper.cpp | 10 ++---- Marlin/src/sd/cardreader.cpp | 43 +++++++++----------------- Marlin/src/sd/cardreader.h | 3 +- 10 files changed, 45 insertions(+), 53 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index ea89cb2f59..768654f97a 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -390,7 +390,7 @@ #define POWER_TIMEOUT 30 // (s) Turn off power if the machine is idle for this duration //#define POWER_OFF_DELAY 60 // (s) Delay of poweroff after M81 command. Useful to let fans run for extra time. #endif - #if EITHER(AUTO_POWER_CONTROL, POWER_OFF_WAIT_FOR_COOLDOWN) + #if EITHER(AUTO_POWER_CONTROL, POWER_OFF_WAIT_FOR_COOLDOWN) //#define AUTO_POWER_E_TEMP 50 // (°C) PSU on if any extruder is over this temperature //#define AUTO_POWER_CHAMBER_TEMP 30 // (°C) PSU on if the chamber is over this temperature //#define AUTO_POWER_COOLER_TEMP 26 // (°C) PSU on if the cooler is over this temperature diff --git a/Marlin/src/feature/easythreed_ui.cpp b/Marlin/src/feature/easythreed_ui.cpp index 9f8af03947..b15daffc09 100644 --- a/Marlin/src/feature/easythreed_ui.cpp +++ b/Marlin/src/feature/easythreed_ui.cpp @@ -194,11 +194,11 @@ void EasythreedUI::printButton() { print_key_flag = PF_START; return; // Bail out } - card.ls(); // List all files to serial output - const uint16_t filecnt = card.countFilesInWorkDir(); // Count printable files in cwd - if (filecnt == 0) return; // None are printable? - card.selectFileByIndex(filecnt); // Select the last file according to current sort options - card.openAndPrintFile(card.filename); // Start printing it + card.ls(); // List all files to serial output + const uint16_t filecnt = card.countFilesInWorkDir(); // Count printable files in cwd + if (filecnt == 0) return; // None are printable? + card.selectFileByIndex(filecnt); // Select the last file according to current sort options + card.openAndPrintFile(card.filename); // Start printing it break; } case PF_PAUSE: { // Pause printing (not currently firing) diff --git a/Marlin/src/feature/power.h b/Marlin/src/feature/power.h index 38f7ed6ce7..9ecd832afc 100644 --- a/Marlin/src/feature/power.h +++ b/Marlin/src/feature/power.h @@ -36,7 +36,7 @@ class Power { static void init(); static void power_on(); static void power_off(); - + #if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN) #if ENABLED(POWER_OFF_TIMER) static millis_t power_off_time; diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 6765ec86a6..eea5d4a7f2 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -290,6 +290,9 @@ G29_TYPE GcodeSuite::G29() { ry = RAW_Y_POSITION(parser.linearval('Y', NAN)); int8_t i = parser.byteval('I', -1), j = parser.byteval('J', -1); + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + if (!isnan(rx) && !isnan(ry)) { // Get nearest i / j from rx / ry i = (rx - bilinear_start.x + 0.5 * abl.gridSpacing.x) / abl.gridSpacing.x; @@ -297,6 +300,9 @@ G29_TYPE GcodeSuite::G29() { LIMIT(i, 0, (GRID_MAX_POINTS_X) - 1); LIMIT(j, 0, (GRID_MAX_POINTS_Y) - 1); } + + #pragma GCC diagnostic pop + if (WITHIN(i, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(j, 0, (GRID_MAX_POINTS_Y) - 1)) { set_bed_leveling_enabled(false); z_values[i][j] = rz; diff --git a/Marlin/src/lcd/e3v2/creality/dwin.cpp b/Marlin/src/lcd/e3v2/creality/dwin.cpp index f312976ddc..03f08ac184 100644 --- a/Marlin/src/lcd/e3v2/creality/dwin.cpp +++ b/Marlin/src/lcd/e3v2/creality/dwin.cpp @@ -2762,7 +2762,10 @@ void HMI_Prepare() { #endif #if HAS_HOTEND || HAS_HEATED_BED - case PREPARE_CASE_COOL: thermalManager.cooldown(); break; + case PREPARE_CASE_COOL: + thermalManager.cooldown(); + ui.reset_status(); + break; #endif case PREPARE_CASE_LANG: diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index c15bb08281..dcdc7def86 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -79,7 +79,7 @@ uint8_t TouchButtons::read_buttons() { #if ENABLED(TOUCH_SCREEN_CALIBRATION) const calibrationState state = touch_calibration.get_calibration_state(); - if (state >= CALIBRATION_TOP_LEFT && state <= CALIBRATION_BOTTOM_RIGHT) { + if (WITHIN(state, CALIBRATION_TOP_LEFT, CALIBRATION_BOTTOM_RIGHT)) { if (touch_calibration.handleTouch(x, y)) ui.refresh(); return 0; } diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 98fd524f9e..939dd6d537 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -593,9 +593,6 @@ void _O2 Endstops::report_states() { } // Endstops::report_states -// The following routines are called from an ISR context. It could be the temperature ISR, the -// endstop ISR or the Stepper ISR. - #if HAS_DELTA_SENSORLESS_PROBING #define __ENDSTOP(AXIS, ...) AXIS ##_MAX #define _ENDSTOP_PIN(AXIS, ...) AXIS ##_MAX_PIN @@ -607,13 +604,18 @@ void _O2 Endstops::report_states() { #endif #define _ENDSTOP(AXIS, MINMAX) __ENDSTOP(AXIS, MINMAX) -// Check endstops - Could be called from Temperature ISR! +/** + * Called from interrupt context by the Endstop ISR or Stepper ISR! + * Read endstops to get their current states, register hits for all + * axes moving in the direction of their endstops, and abort moves. + */ void Endstops::update() { - #if !ENDSTOP_NOISE_THRESHOLD - if (!abort_enabled()) return; + #if !ENDSTOP_NOISE_THRESHOLD // If not debouncing... + if (!abort_enabled()) return; // ...and not enabled, exit. #endif + // Macros to update / copy the live_state #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX))) #define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT)) @@ -1107,6 +1109,7 @@ void Endstops::update() { #if ENABLED(SPI_ENDSTOPS) + // Called from idle() to read Trinamic stall states bool Endstops::tmc_spi_homing_check() { bool hit = false; #if X_SPI_SENSORLESS diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index b61f36bbb4..9a1c8278ba 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2346,13 +2346,9 @@ uint32_t Stepper::block_phase_isr() { #endif #endif // LASER_POWER_INLINE - // At this point, we must ensure the movement about to execute isn't - // trying to force the head against a limit switch. If using interrupt- - // driven change detection, and already against a limit then no call to - // the endstop_triggered method will be done and the movement will be - // done against the endstop. So, check the limits here: If the movement - // is against the limits, the block will be marked as to be killed, and - // on the next call to this ISR, will be discarded. + // If the endstop is already pressed, endstop interrupts won't invoke + // endstop_triggered and the move will grind. So check here for a + // triggered endstop, which marks the block for discard on the next ISR. endstops.update(); #if ENABLED(Z_LATE_ENABLE) diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index da6e84c759..66c08b6455 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -271,9 +271,8 @@ void CardReader::selectByName(SdFile dir, const char * const match) { * good addition. */ void CardReader::printListing( - SdFile parent + SdFile parent, const char * const prepend OPTARG(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames/*=false*/) - , const char * const prepend/*=nullptr*/ OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/) ) { dir_t p; @@ -283,61 +282,47 @@ void CardReader::printListing( size_t lenPrepend = prepend ? strlen(prepend) + 1 : 0; // Allocate enough stack space for the full path including / separator char path[lenPrepend + FILENAME_LENGTH]; - if (prepend) { - strcpy(path, prepend); - path[lenPrepend - 1] = '/'; - } + if (prepend) { strcpy(path, prepend); path[lenPrepend - 1] = '/'; } char* dosFilename = path + lenPrepend; createFilename(dosFilename, p); // Get a new directory object using the full path // and dive recursively into it. SdFile child; // child.close() in destructor - if (child.open(&parent, dosFilename, O_READ)) + if (child.open(&parent, dosFilename, O_READ)) { #if ENABLED(LONG_FILENAME_HOST_SUPPORT) if (includeLongNames) { size_t lenPrependLong = prependLong ? strlen(prependLong) + 1 : 0; // Allocate enough stack space for the full long path including / separator char pathLong[lenPrependLong + strlen(longFilename) + 1]; - if (prependLong) { - strcpy(pathLong, prependLong); - pathLong[lenPrependLong - 1] = '/'; - } + if (prependLong) { strcpy(pathLong, prependLong); pathLong[lenPrependLong - 1] = '/'; } strcpy(pathLong + lenPrependLong, longFilename); - printListing(child, true, path, pathLong); + printListing(child, path, true, pathLong); } else - printListing(child, false, path); + printListing(child, path); #else printListing(child, path); #endif + } else { SERIAL_ECHO_MSG(STR_SD_CANT_OPEN_SUBDIR, dosFilename); return; } } else if (is_dir_or_gcode(p)) { - if (prepend) { - SERIAL_ECHO(prepend); - SERIAL_CHAR('/'); - } + if (prepend) { SERIAL_ECHO(prepend); SERIAL_CHAR('/'); } SERIAL_ECHO(createFilename(filename, p)); SERIAL_CHAR(' '); + SERIAL_ECHO(p.fileSize); #if ENABLED(LONG_FILENAME_HOST_SUPPORT) - if (!includeLongNames) - #endif - SERIAL_ECHOLN(p.fileSize); - #if ENABLED(LONG_FILENAME_HOST_SUPPORT) - else { - SERIAL_ECHO(p.fileSize); + if (includeLongNames) { SERIAL_CHAR(' '); - if (prependLong) { - SERIAL_ECHO(prependLong); - SERIAL_CHAR('/'); - } - SERIAL_ECHOLN(longFilename[0] ? longFilename : "???"); + if (prependLong) { SERIAL_ECHO(prependLong); SERIAL_CHAR('/'); } + SERIAL_ECHO(longFilename[0] ? longFilename : "???"); } #endif + SERIAL_EOL(); } } } @@ -348,7 +333,7 @@ void CardReader::printListing( void CardReader::ls(TERN_(LONG_FILENAME_HOST_SUPPORT, bool includeLongNames/*=false*/)) { if (flag.mounted) { root.rewind(); - printListing(root OPTARG(LONG_FILENAME_HOST_SUPPORT, includeLongNames)); + printListing(root, nullptr OPTARG(LONG_FILENAME_HOST_SUPPORT, includeLongNames)); } } diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 97e9bba867..8761f57de5 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -336,9 +336,8 @@ private: static void selectByIndex(SdFile dir, const uint8_t index); static void selectByName(SdFile dir, const char * const match); static void printListing( - SdFile parent + SdFile parent, const char * const prepend OPTARG(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames=false) - , const char * const prepend=nullptr OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong=nullptr) );