This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/src/feature/powerloss.h

192 lines
4.6 KiB
C
Raw Normal View History

2018-04-22 02:41:26 +02:00
/**
* Marlin 3D Printer Firmware
2020-02-03 15:00:57 +01:00
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2018-04-22 02:41:26 +02:00
*
* Based on Sprinter and grbl.
2019-06-28 06:57:50 +02:00
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
2018-04-22 02:41:26 +02: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 04:48:28 +01:00
#pragma once
2018-04-22 02:41:26 +02:00
/**
* power_loss_recovery.h - Resume an SD print after power-loss
*/
#include "../sd/cardreader.h"
#include "../inc/MarlinConfig.h"
2018-04-22 02:41:26 +02:00
#if ENABLED(MIXING_EXTRUDER)
#include "../feature/mixing.h"
#endif
#if !defined(POWER_LOSS_STATE) && PIN_EXISTS(POWER_LOSS)
#define POWER_LOSS_STATE HIGH
#endif
2018-04-22 02:41:26 +02:00
//#define DEBUG_POWER_LOSS_RECOVERY
//#define SAVE_EACH_CMD_MODE
//#define SAVE_INFO_INTERVAL_MS 0
2018-04-22 02:41:26 +02:00
typedef struct {
uint8_t valid_head;
// Machine state
2019-09-29 11:25:39 +02:00
xyze_pos_t current_position;
2018-11-17 03:47:07 +01:00
#if HAS_HOME_OFFSET
2019-09-29 11:25:39 +02:00
xyz_pos_t home_offset;
#endif
#if HAS_POSITION_SHIFT
2019-09-29 11:25:39 +02:00
xyz_pos_t position_shift;
#endif
2018-11-17 03:47:07 +01:00
uint16_t feedrate;
#if EXTRUDERS > 1
uint8_t active_extruder;
#endif
#if DISABLED(NO_VOLUMETRICS)
bool volumetric_enabled;
#if EXTRUDERS > 1
2019-11-04 20:23:26 +01:00
float filament_size[EXTRUDERS];
#else
2019-11-04 20:23:26 +01:00
float filament_size;
#endif
#endif
2020-04-20 06:56:55 +02:00
#if HAS_HOTEND
2019-09-10 09:20:49 +02:00
int16_t target_temperature[HOTENDS];
#endif
2018-04-22 02:41:26 +02:00
#if HAS_HEATED_BED
int16_t target_temperature_bed;
#endif
2018-07-02 23:42:13 +02:00
#if FAN_COUNT
uint8_t fan_speed[FAN_COUNT];
2018-07-02 23:42:13 +02:00
#endif
2018-04-22 02:41:26 +02:00
#if HAS_LEVELING
bool leveling;
float fade;
#endif
#if ENABLED(FWRETRACT)
float retract[EXTRUDERS], retract_hop;
#endif
// 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
// Relative axis modes
uint8_t axis_relative;
// SD Filename and position
2018-11-20 12:36:19 +01:00
char sd_filename[MAXPATHNAMELENGTH];
2019-09-11 01:52:41 +02:00
volatile uint32_t sdpos;
2018-04-22 02:41:26 +02:00
// Job elapsed time
millis_t print_job_elapsed;
uint8_t valid_foot;
2018-11-17 03:47:07 +01:00
2018-04-22 02:41:26 +02:00
} job_recovery_info_t;
2018-11-17 03:47:07 +01:00
class PrintJobRecovery {
public:
2019-08-02 12:21:44 +02:00
static const char filename[5];
2019-08-02 09:22:09 +02:00
2018-11-17 03:47:07 +01:00
static SdFile file;
static job_recovery_info_t info;
2018-04-22 02:41:26 +02:00
2019-09-11 01:52:41 +02:00
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
2018-11-17 03:47:07 +01:00
static void init();
2019-09-11 01:52:41 +02:00
static void prepare();
2018-11-17 03:47:07 +01: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
}
2019-09-11 01:52:41 +02:00
// 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; }
2018-11-17 03:47:07 +01:00
static bool enabled;
static void enable(const bool onoff);
static void changed();
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 02:41:26 +02:00
2020-01-14 03:52:24 +01:00
static void check();
static void resume();
2018-11-17 03:47:07 +01:00
static void purge();
2020-01-14 03:52:24 +01:00
static inline void cancel() { purge(); card.autostart_index = 0; }
2018-11-17 03:47:07 +01:00
static void load();
static void save(const bool force=ENABLED(SAVE_EACH_CMD_MODE));
2018-11-17 03:47:07 +01:00
2019-09-11 01:52:41 +02:00
#if PIN_EXISTS(POWER_LOSS)
static inline void outage() {
if (enabled && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE)
2019-09-11 01:52:41 +02:00
_outage();
}
#endif
2018-11-17 03:47:07 +01:00
static inline bool valid() { return info.valid_head && info.valid_head == info.valid_foot; }
2019-04-06 03:02:46 +02:00
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
static void debug(PGM_P const prefix);
#else
2019-10-01 04:44:07 +02:00
static inline void debug(PGM_P const) {}
2019-04-06 03:02:46 +02:00
#endif
2018-11-17 03:47:07 +01:00
private:
static void write();
2019-09-11 01:52:41 +02:00
#if ENABLED(BACKUP_POWER_SUPPLY)
static void raise_z();
#endif
2019-09-11 01:52:41 +02:00
#if PIN_EXISTS(POWER_LOSS)
static void _outage();
#endif
2018-11-17 03:47:07 +01:00
};
2018-04-22 02:41:26 +02:00
2018-11-17 03:47:07 +01:00
extern PrintJobRecovery recovery;