Refactor SD detect handler (#17380)

Co-Authored-By: Eric Ptak <trouch@users.noreply.github.com>
This commit is contained in:
Scott Lahteine
2020-04-04 00:08:25 -05:00
committed by GitHub
parent bc01d8d023
commit 65f6a373b0
6 changed files with 156 additions and 119 deletions

View File

@@ -443,7 +443,6 @@ void startOrResumeJob() {
/**
* Minimal management of Marlin's core activities:
* - Check for Filament Runout
* - Keep the command buffer full
* - Check for maximum inactive time between commands
* - Check for maximum inactive time between stepper commands
@@ -454,13 +453,8 @@ void startOrResumeJob() {
* - Check if an idle but hot extruder needs filament extruded (EXTRUDER_RUNOUT_PREVENT)
* - Pulse FET_SAFETY_PIN if it exists
*/
inline void manage_inactivity(const bool ignore_stepper_queue=false) {
#if HAS_FILAMENT_SENSOR
runout.run();
#endif
if (queue.length < BUFSIZE) queue.get_available_commands();
const millis_t ms = millis();
@@ -644,9 +638,53 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
}
/**
* Standard idle routine keeps the machine alive
* Standard idle routine keeps the machine alive:
* - Core Marlin activities
* - Manage heaters (and Watchdog)
* - Max7219 heartbeat, animation, etc.
*
* Only after setup() is complete:
* - Handle filament runout sensors
* - Run HAL idle tasks
* - Handle Power-Loss Recovery
* - Run StallGuard endstop checks
* - Handle SD Card insert / remove
* - Handle USB Flash Drive insert / remove
* - Announce Host Keepalive state (if any)
* - Update the Print Job Timer state
* - Update the Beeper queue
* - Read Buttons and Update the LCD
* - Run i2c Position Encoders
* - Auto-report Temperatures / SD Status
* - Update the Prusa MMU2
* - Handle Joystick jogging
*/
void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
// Core Marlin activities
manage_inactivity(TERN_(ADVANCED_PAUSE_FEATURE, no_stepper_sleep));
// Manage Heaters (and Watchdog)
thermalManager.manage_heater();
// Max7219 heartbeat, animation, etc
#if ENABLED(MAX7219_DEBUG)
max7219.idle_tasks();
#endif
// Return if setup() isn't completed
if (marlin_state == MF_INITIALIZING) return;
// Handle filament runout sensors
#if HAS_FILAMENT_SENSOR
runout.run();
#endif
// Run HAL idle tasks
#ifdef HAL_IDLETASK
HAL_idletask();
#endif
// Handle Power-Loss Recovery
#if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
recovery.outage();
@@ -660,29 +698,21 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
if (endstops.tmc_spi_homing_check()) break;
#endif
// Max7219 heartbeat, animation, etc.
#if ENABLED(MAX7219_DEBUG)
max7219.idle_tasks();
// Handle SD Card insert / remove
#if ENABLED(SDSUPPORT)
card.manage_media();
#endif
// Read Buttons and Update the LCD
ui.update();
// Handle USB Flash Drive insert / remove
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
Sd2Card::idle();
#endif
// Announce Host Keepalive state (if any)
#if ENABLED(HOST_KEEPALIVE_FEATURE)
gcode.host_keepalive();
#endif
// Core Marlin activities
manage_inactivity(
#if ENABLED(ADVANCED_PAUSE_FEATURE)
no_stepper_sleep
#endif
);
// Manage heaters (and Watchdog)
thermalManager.manage_heater();
// Update the Print Job Timer state
#if ENABLED(PRINTCOUNTER)
print_job_timer.tick();
@@ -693,6 +723,9 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
buzzer.tick();
#endif
// Read Buttons and Update the LCD
ui.update();
// Run i2c Position Encoders
#if ENABLED(I2C_POSITION_ENCODERS)
static millis_t i2cpem_next_update_ms;
@@ -705,11 +738,6 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
}
#endif
// Run HAL idle tasks
#ifdef HAL_IDLETASK
HAL_idletask();
#endif
// Auto-report Temperatures / SD Status
#if HAS_AUTO_REPORTING
if (!gcode.autoreport_paused) {
@@ -722,11 +750,6 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
}
#endif
// Handle USB Flash Drive insert / remove
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
Sd2Card::idle();
#endif
// Update the Prusa MMU2
#if ENABLED(PRUSA_MMU2)
mmu2.mmu_loop();
@@ -983,8 +1006,8 @@ void setup() {
SETUP_RUN(ui.show_bootscreen());
#endif
#if ENABLED(SDSUPPORT) && defined(SDCARD_CONNECTION) && !SD_CONNECTION_IS(LCD)
SETUP_RUN(card.mount()); // Mount onboard / custom SD card before settings.first_load
#if BOTH(SDSUPPORT, SDCARD_EEPROM_EMULATION)
SETUP_RUN(card.mount()); // Mount media with settings before first_load
#endif
SETUP_RUN(settings.first_load()); // Load data from EEPROM if available (or use defaults)
@@ -1151,10 +1174,6 @@ void setup() {
queue.inject_P(PSTR(STARTUP_COMMANDS));
#endif
#if ENABLED(INIT_SDCARD_ON_BOOT) && !HAS_SPI_LCD
SETUP_RUN(card.beginautostart());
#endif
#if ENABLED(HOST_PROMPT_SUPPORT)
SETUP_RUN(host_action_prompt_end());
#endif