2018-04-22 00:41:26 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-04-22 00:41:26 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2018-04-22 00:41:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-10-28 03:48:28 +00:00
|
|
|
#pragma once
|
2018-04-22 00:41:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* power_loss_recovery.h - Resume an SD print after power-loss
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../sd/cardreader.h"
|
2019-08-20 07:40:44 +00:00
|
|
|
#include "../inc/MarlinConfig.h"
|
2018-04-22 00:41:26 +00:00
|
|
|
|
2019-02-10 10:54:23 +00:00
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#include "../feature/mixing.h"
|
|
|
|
#endif
|
|
|
|
|
2019-08-20 07:40:44 +00:00
|
|
|
#if !defined(POWER_LOSS_STATE) && PIN_EXISTS(POWER_LOSS)
|
|
|
|
#define POWER_LOSS_STATE HIGH
|
|
|
|
#endif
|
|
|
|
|
2018-04-22 00:41:26 +00:00
|
|
|
//#define DEBUG_POWER_LOSS_RECOVERY
|
2019-05-08 01:38:40 +00:00
|
|
|
//#define SAVE_EACH_CMD_MODE
|
|
|
|
//#define SAVE_INFO_INTERVAL_MS 0
|
2018-04-22 00:41:26 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t valid_head;
|
|
|
|
|
|
|
|
// Machine state
|
2018-11-17 02:47:07 +00:00
|
|
|
float current_position[NUM_AXIS];
|
|
|
|
|
2019-04-15 23:53:39 +00:00
|
|
|
#if HAS_HOME_OFFSET
|
|
|
|
float home_offset[XYZ];
|
|
|
|
#endif
|
|
|
|
#if HAS_POSITION_SHIFT
|
|
|
|
float position_shift[XYZ];
|
|
|
|
#endif
|
|
|
|
|
2018-11-17 02:47:07 +00:00
|
|
|
uint16_t feedrate;
|
2018-07-03 04:21:28 +00:00
|
|
|
|
2019-05-17 23:47:15 +00:00
|
|
|
#if EXTRUDERS > 1
|
|
|
|
uint8_t active_extruder;
|
2018-07-03 04:21:28 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-10 07:20:49 +00:00
|
|
|
#if HOTENDS
|
|
|
|
int16_t target_temperature[HOTENDS];
|
|
|
|
#endif
|
2018-04-22 00:41:26 +00:00
|
|
|
|
2018-04-23 22:13:01 +00:00
|
|
|
#if HAS_HEATED_BED
|
|
|
|
int16_t target_temperature_bed;
|
|
|
|
#endif
|
|
|
|
|
2018-07-02 21:42:13 +00:00
|
|
|
#if FAN_COUNT
|
2018-10-07 20:34:41 +00:00
|
|
|
uint8_t fan_speed[FAN_COUNT];
|
2018-07-02 21:42:13 +00:00
|
|
|
#endif
|
|
|
|
|
2018-04-22 00:41:26 +00:00
|
|
|
#if HAS_LEVELING
|
|
|
|
bool leveling;
|
|
|
|
float fade;
|
|
|
|
#endif
|
|
|
|
|
2018-09-17 02:24:15 +00:00
|
|
|
#if ENABLED(FWRETRACT)
|
|
|
|
float retract[EXTRUDERS], retract_hop;
|
|
|
|
#endif
|
|
|
|
|
2019-02-10 10:54:23 +00:00
|
|
|
// Mixing extruder and gradient
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
//uint_fast8_t selected_vtool;
|
|
|
|
//mixer_comp_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
|
|
|
|
#if ENABLED(GRADIENT_MIX)
|
|
|
|
gradient_t gradient;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-03-29 18:40:42 +00:00
|
|
|
// Relative mode
|
|
|
|
bool relative_mode, relative_modes_e;
|
|
|
|
|
2018-04-22 00:41:26 +00:00
|
|
|
// Command queue
|
2019-06-19 05:00:19 +00:00
|
|
|
uint8_t queue_length, queue_index_r;
|
|
|
|
char queue_buffer[BUFSIZE][MAX_CMD_SIZE];
|
2018-04-22 00:41:26 +00:00
|
|
|
|
2018-06-30 03:41:02 +00:00
|
|
|
// SD Filename and position
|
2018-11-20 11:36:19 +00:00
|
|
|
char sd_filename[MAXPATHNAMELENGTH];
|
2018-04-22 00:41:26 +00:00
|
|
|
uint32_t sdpos;
|
|
|
|
|
|
|
|
// Job elapsed time
|
|
|
|
millis_t print_job_elapsed;
|
|
|
|
|
|
|
|
uint8_t valid_foot;
|
2018-11-17 02:47:07 +00:00
|
|
|
|
2018-04-22 00:41:26 +00:00
|
|
|
} job_recovery_info_t;
|
|
|
|
|
2018-11-17 02:47:07 +00:00
|
|
|
class PrintJobRecovery {
|
|
|
|
public:
|
2019-08-02 10:21:44 +00:00
|
|
|
static const char filename[5];
|
2019-08-02 07:22:09 +00:00
|
|
|
|
2018-11-17 02:47:07 +00:00
|
|
|
static SdFile file;
|
|
|
|
static job_recovery_info_t info;
|
2018-04-22 00:41:26 +00:00
|
|
|
|
2018-11-17 02:47:07 +00:00
|
|
|
static void init();
|
|
|
|
|
2019-08-20 07:40:44 +00:00
|
|
|
static inline void setup() {
|
|
|
|
#if PIN_EXISTS(POWER_LOSS)
|
|
|
|
#if ENABLED(POWER_LOSS_PULL)
|
|
|
|
#if POWER_LOSS_STATE == LOW
|
|
|
|
SET_INPUT_PULLUP(POWER_LOSS_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT_PULLDOWN(POWER_LOSS_PIN);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
SET_INPUT(POWER_LOSS_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-17 02:47:07 +00:00
|
|
|
static bool enabled;
|
|
|
|
static void enable(const bool onoff);
|
|
|
|
static void changed();
|
|
|
|
|
|
|
|
static void check();
|
|
|
|
static void resume();
|
2018-04-22 00:41:26 +00:00
|
|
|
|
2018-11-17 02:47:07 +00:00
|
|
|
static inline bool exists() { return card.jobRecoverFileExists(); }
|
|
|
|
static inline void open(const bool read) { card.openJobRecoveryFile(read); }
|
|
|
|
static inline void close() { file.close(); }
|
2018-04-22 00:41:26 +00:00
|
|
|
|
2018-11-17 02:47:07 +00:00
|
|
|
static void purge();
|
|
|
|
static void load();
|
|
|
|
static void save(const bool force=
|
|
|
|
#if ENABLED(SAVE_EACH_CMD_MODE)
|
|
|
|
true
|
|
|
|
#else
|
|
|
|
false
|
|
|
|
#endif
|
2018-11-27 20:40:40 +00:00
|
|
|
, const bool save_queue=true
|
2018-11-17 02:47:07 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static inline bool valid() { return info.valid_head && info.valid_head == info.valid_foot; }
|
|
|
|
|
2019-04-06 01:02:46 +00:00
|
|
|
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
|
|
|
static void debug(PGM_P const prefix);
|
|
|
|
#else
|
2019-04-04 20:22:13 +00:00
|
|
|
static inline void debug(PGM_P const prefix) { UNUSED(prefix); }
|
2019-04-06 01:02:46 +00:00
|
|
|
#endif
|
2018-11-17 02:47:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static void write();
|
|
|
|
};
|
2018-04-22 00:41:26 +00:00
|
|
|
|
2018-11-17 02:47:07 +00:00
|
|
|
extern PrintJobRecovery recovery;
|