Improve Power-loss Recovery (#15135)

This commit is contained in:
Scott Lahteine
2019-09-10 18:52:41 -05:00
committed by GitHub
parent 75927e17dd
commit c590e8ac05
9 changed files with 87 additions and 32 deletions

View File

@@ -92,13 +92,9 @@ typedef struct {
// Relative mode
bool relative_mode, relative_modes_e;
// Command queue
uint8_t queue_length, queue_index_r;
char queue_buffer[BUFSIZE][MAX_CMD_SIZE];
// SD Filename and position
char sd_filename[MAXPATHNAMELENGTH];
uint32_t sdpos;
volatile uint32_t sdpos;
// Job elapsed time
millis_t print_job_elapsed;
@@ -114,7 +110,12 @@ class PrintJobRecovery {
static SdFile file;
static job_recovery_info_t info;
static uint8_t queue_index_r; //!< Queue index of the active command
static uint32_t cmd_sdpos, //!< SD position of the next command
sdpos[BUFSIZE]; //!< SD positions of queued commands
static void init();
static void prepare();
static inline void setup() {
#if PIN_EXISTS(POWER_LOSS)
@@ -130,6 +131,10 @@ class PrintJobRecovery {
#endif
}
// Track each command's file offsets
static inline uint32_t command_sdpos() { return sdpos[queue_index_r]; }
static inline void commit_sdpos(const uint8_t index_w) { sdpos[index_w] = cmd_sdpos; }
static bool enabled;
static void enable(const bool onoff);
static void changed();
@@ -152,6 +157,13 @@ class PrintJobRecovery {
, const bool save_queue=true
);
#if PIN_EXISTS(POWER_LOSS)
static inline void outage() {
if (enabled && IS_SD_PRINTING() && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE)
_outage();
}
#endif
static inline bool valid() { return info.valid_head && info.valid_head == info.valid_foot; }
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
@@ -162,6 +174,10 @@ class PrintJobRecovery {
private:
static void write();
#if PIN_EXISTS(POWER_LOSS)
static void _outage();
#endif
};
extern PrintJobRecovery recovery;