Fix kill() and ExtensibleUI (#12160)

* Fix to isPrintingFromMedia()

  - isPrintingFromMedia() will now return true even if SD print is paused.
  - isPrintingFromMediaPaused() allows UI to determine if the print is paused.

* Don't use _delay_us in minkill (#12145)

  - In HAL_DUE, _delay_us is simply an alias for delay, which causes the board to hang and subsequently reboot due to the watchdog timer.

* Shorten code with IFSD macro
This commit is contained in:
Marcio Teixeira 2018-10-20 00:44:46 -06:00 committed by Scott Lahteine
parent b381cad399
commit 2e5e689a7f
3 changed files with 27 additions and 54 deletions

View File

@ -42,6 +42,8 @@
#include "module/printcounter.h" // PrintCounter or Stopwatch #include "module/printcounter.h" // PrintCounter or Stopwatch
#include "feature/closedloop.h" #include "feature/closedloop.h"
#include "HAL/shared/Delay.h"
#ifdef ARDUINO #ifdef ARDUINO
#include <pins_arduino.h> #include <pins_arduino.h>
#endif #endif
@ -610,7 +612,6 @@ void idle(
* After this the machine will need to be reset. * After this the machine will need to be reset.
*/ */
void kill(PGM_P const lcd_msg/*=NULL*/) { void kill(PGM_P const lcd_msg/*=NULL*/) {
thermalManager.disable_all_heaters(); thermalManager.disable_all_heaters();
SERIAL_ERROR_START(); SERIAL_ERROR_START();
@ -633,11 +634,14 @@ void kill(PGM_P const lcd_msg/*=NULL*/) {
void minkill() { void minkill() {
_delay_ms(600); // Wait a short time (allows messages to get out before shutting down. // Wait a short time (allows messages to get out before shutting down.
cli(); // Stop interrupts DELAY_US(600000);
_delay_ms(250); // Wait to ensure all interrupts stopped
cli(); // Stop interrupts
// Wait to ensure all interrupts stopped
DELAY_US(250000);
disable_all_steppers();
thermalManager.disable_all_heaters(); // turn off heaters again thermalManager.disable_all_heaters(); // turn off heaters again
#if HAS_POWER_SWITCH #if HAS_POWER_SWITCH

View File

@ -37,6 +37,9 @@
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
#include "../../sd/cardreader.h" #include "../../sd/cardreader.h"
#include "../../feature/emergency_parser.h" #include "../../feature/emergency_parser.h"
#define IFSD(A,B) (A)
#else
#define IFSD(A,B) (B)
#endif #endif
#if ENABLED(PRINTCOUNTER) #if ENABLED(PRINTCOUNTER)
@ -352,11 +355,7 @@ namespace UI {
#endif #endif
uint8_t getProgress_percent() { uint8_t getProgress_percent() {
#if ENABLED(SDSUPPORT) return IFSD(card.percentDone(), 0);
return card.percentDone();
#else
return 0;
#endif
} }
uint32_t getProgress_seconds_elapsed() { uint32_t getProgress_seconds_elapsed() {
@ -415,35 +414,23 @@ namespace UI {
} }
void printFile(const char *filename) { void printFile(const char *filename) {
#if ENABLED(SDSUPPORT) IFSD(card.openAndPrintFile(filename), NOOP);
card.openAndPrintFile(filename); }
#endif
bool isPrintingFromMediaPaused() {
return IFSD(isPrintingFromMedia() && !card.sdprinting, false);
} }
bool isPrintingFromMedia() { bool isPrintingFromMedia() {
#if ENABLED(SDSUPPORT) return IFSD(card.cardOK && card.isFileOpen(), false);
return card.cardOK && card.isFileOpen() && card.sdprinting;
#else
return false;
#endif
} }
bool isPrinting() { bool isPrinting() {
return (planner.movesplanned() || IS_SD_PRINTING() || return (planner.movesplanned() || IS_SD_PRINTING() || isPrintingFromMedia());
#if ENABLED(SDSUPPORT)
(card.cardOK && card.isFileOpen())
#else
false
#endif
);
} }
bool isMediaInserted() { bool isMediaInserted() {
#if ENABLED(SDSUPPORT) return IFSD(IS_SD_INSERTED() && card.cardOK, false);
return IS_SD_INSERTED() && card.cardOK;
#else
return false;
#endif
} }
void pausePrint() { void pausePrint() {
@ -504,42 +491,23 @@ namespace UI {
} }
const char* FileList::filename() { const char* FileList::filename() {
#if ENABLED(SDSUPPORT) return IFSD(card.longFilename && card.longFilename[0]) ? card.longFilename : card.filename, "");
return (card.longFilename && card.longFilename[0]) ? card.longFilename : card.filename;
#else
return "";
#endif
} }
const char* FileList::shortFilename() { const char* FileList::shortFilename() {
#if ENABLED(SDSUPPORT) return IFSD(card.filename, "");
return card.filename;
#else
return "";
#endif
} }
const char* FileList::longFilename() { const char* FileList::longFilename() {
#if ENABLED(SDSUPPORT) return IFSD(card.longFilename, "");
return card.longFilename;
#else
return "";
#endif
} }
bool FileList::isDir() { bool FileList::isDir() {
#if ENABLED(SDSUPPORT) return IFSD(card.filenameIsDir, false);
return card.filenameIsDir;
#else
return false;
#endif
} }
uint16_t FileList::count() { uint16_t FileList::count() {
#if ENABLED(SDSUPPORT) return IFSD((num_files = (num_files == 0xFFFF ? card.get_num_Files() : num_files)), 0);
if (num_files == 0xFFFF) num_files = card.get_num_Files();
return num_files;
#endif
} }
bool FileList::isAtRootDir() { bool FileList::isAtRootDir() {

View File

@ -133,6 +133,7 @@ namespace UI {
void enqueueCommands(progmem_str gcode); void enqueueCommands(progmem_str gcode);
void printFile(const char *filename); void printFile(const char *filename);
bool isPrintingFromMediaPaused();
bool isPrintingFromMedia(); bool isPrintingFromMedia();
bool isPrinting(); bool isPrinting();
void stopPrint(); void stopPrint();