15 #include <util/delay.h>
16 #include <avr/pgmspace.h>
17 #include <avr/eeprom.h>
18 #include <avr/interrupt.h>
21 #include "Configuration.h"
28 #define HardwareSerial_h
34 # include "WProgram.h"
38 #ifndef analogInputToDigitalPin
39 # define analogInputToDigitalPin(p) ((p) + A0)
43 #include "HardwareSerial.h"
46 #include "MarlinSerial.h"
49 #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
52 #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
61 #define MYSERIAL Serial
64 #define MYSERIAL MSerial
69 #define SERIAL_PROTOCOL(x) (MYSERIAL.print(x))
70 #define SERIAL_PROTOCOL_F(x,y) (MYSERIAL.print(x,y))
71 #define SERIAL_PROTOCOLPGM(x) (serialprintPGM(PSTR(x)))
72 #define SERIAL_PROTOCOLRPGM(x) (serialprintPGM((x)))
73 #define SERIAL_PROTOCOLLN(x) (MYSERIAL.println(x))
74 #define SERIAL_PROTOCOLLNPGM(x) (serialprintlnPGM(PSTR(x)))
75 #define SERIAL_PROTOCOLLNRPGM(x) (serialprintlnPGM((x)))
78 extern const char errormagic[] PROGMEM;
79 extern const char echomagic[] PROGMEM;
81 #define SERIAL_ERROR_START (serialprintPGM(errormagic))
82 #define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
83 #define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
84 #define SERIAL_ERRORRPGM(x) SERIAL_PROTOCOLRPGM(x)
85 #define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
86 #define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
87 #define SERIAL_ERRORLNRPGM(x) SERIAL_PROTOCOLLNRPGM(x)
89 #define SERIAL_ECHO_START (serialprintPGM(echomagic))
90 #define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
91 #define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
92 #define SERIAL_ECHORPGM(x) SERIAL_PROTOCOLRPGM(x)
93 #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
94 #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
95 #define SERIAL_ECHOLNRPGM(x) SERIAL_PROTOCOLLNRPGM(x)
97 #define SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value)))
99 void serial_echopair_P(
const char *s_P,
float v);
100 void serial_echopair_P(
const char *s_P,
double v);
101 void serial_echopair_P(
const char *s_P,
unsigned long v);
107 void serialprintPGM(
const char *str);
110 void serialprintlnPGM(
const char *str);
112 bool is_buffer_empty();
113 void process_commands();
116 void manage_inactivity(
bool ignore_stepper_queue=
false);
118 #if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1
119 #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
120 #define disable_x() { WRITE(X_ENABLE_PIN,!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }
123 #define disable_x() ;
126 #if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1
127 #ifdef Y_DUAL_STEPPER_DRIVERS
128 #define enable_y() { WRITE(Y_ENABLE_PIN, Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, Y_ENABLE_ON); }
129 #define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, !Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
131 #define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
132 #define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
136 #define disable_y() ;
139 #if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
140 #if defined(Z_AXIS_ALWAYS_ON)
141 #ifdef Z_DUAL_STEPPER_DRIVERS
142 #define poweron_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
143 #define poweroff_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
145 #define poweron_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
146 #define poweroff_z() {}
149 #ifdef Z_DUAL_STEPPER_DRIVERS
150 #define poweron_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
151 #define poweroff_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
153 #define poweron_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
154 #define poweroff_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
158 #define poweron_z() {}
159 #define poweroff_z() {}
163 #define enable_z() poweron_z()
164 #define disable_z() poweroff_z()
166 extern bool bEnableForce_z;
168 void check_force_z();
169 void enable_force_z();
170 void disable_force_z();
171 #define enable_z() enable_force_z()
172 #define disable_z() disable_force_z()
175 #if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
176 #define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON)
177 #define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON)
183 enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
184 #define X_AXIS_MASK 1
185 #define Y_AXIS_MASK 2
186 #define Z_AXIS_MASK 4
187 #define E_AXIS_MASK 8
188 #define X_HEAD_MASK 16
189 #define Y_HEAD_MASK 32
192 void FlushSerialRequestResend();
194 void update_currents();
196 void kill(
const char *full_screen_message = NULL);
197 void finishAndDisableSteppers();
199 void UnconditionalStop();
200 void ConditionalStop();
201 void ThermalStop(
bool allow_pause =
false);
206 #define enquecommand_P(cmd) enquecommand(cmd, true)
209 #define enquecommand_front_P(cmd) enquecommand_front(cmd, true)
211 void clamp_to_software_endstops(
float target[3]);
212 void refresh_cmd_timeout(
void);
215 void setPwmFrequency(uint8_t pin,
int val);
218 enum class HeatingStatus : uint8_t
221 EXTRUDER_HEATING = 1,
222 EXTRUDER_HEATING_COMPLETE = 2,
224 BED_HEATING_COMPLETE = 4,
227 extern HeatingStatus heating_status;
229 extern bool fans_check_enabled;
230 constexpr
float homing_feedrate[] = HOMING_FEEDRATE;
231 extern uint8_t axis_relative_modes;
232 extern float feedrate;
233 extern int feedmultiply;
234 extern int extrudemultiply;
235 extern float extruder_multiplier[EXTRUDERS];
236 extern float current_position[NUM_AXIS] ;
237 extern float destination[NUM_AXIS] ;
238 extern float min_pos[3];
239 extern float max_pos[3];
240 extern bool axis_known_position[3];
242 extern uint8_t newFanSpeed;
243 extern float default_retraction;
245 void get_coordinates();
246 void prepare_move(uint16_t start_segment_idx = 0);
247 void prepare_arc_move(
bool isclockwise, uint16_t start_segment_idx = 0);
248 uint16_t restore_interrupted_gcode();
253 float __attribute__((noinline)) get_feedrate_mm_s(
const float feedrate_mm_min);
256 void check_Z_crash(
void);
257 void homeaxis(uint8_t axis, uint8_t cnt = 1, uint8_t* pstep = 0);
259 void homeaxis(uint8_t axis, uint8_t cnt = 1);
263 extern bool retracted[EXTRUDERS];
264 extern float retract_length_swap;
265 extern float retract_recover_length_swap;
269 extern bool processing_tcode;
270 extern bool homing_flag;
271 extern uint32_t total_filament_used;
274 void save_statistics();
276 extern int fan_edge_counter[2];
277 extern int fan_speed[2];
281 #define active_extruder 0
283 extern bool mesh_bed_leveling_flag;
284 extern bool did_pause_print;
289 extern uint8_t saved_printing_type;
293 extern bool saved_extruder_relative_mode;
295 extern float saved_pos[NUM_AXIS];
299 extern uint8_t print_percent_done_normal;
300 extern uint8_t print_percent_done_silent;
301 extern uint16_t print_time_remaining_normal;
302 extern uint16_t print_time_remaining_silent;
303 extern uint16_t print_time_to_change_normal;
304 extern uint16_t print_time_to_change_silent;
306 #define PRINT_TIME_REMAINING_INIT 0xffff
310 #define PRINT_PERCENT_DONE_INIT 0xff
314 bool printJobOngoing();
317 #ifdef DEBUG_PRINTER_STATES
322 bool printingIsPaused();
324 bool printer_active();
326 bool printer_recovering();
345 bool babystep_allowed();
350 bool babystep_allowed_strict();
352 extern void calculate_extruder_multipliers();
356 extern void delay_keep_alive(
unsigned int ms);
358 extern void check_babystep();
360 extern void long_pause();
361 extern void crashdet_stop_and_save_print();
363 #ifdef HEATBED_ANALYSIS
366 void bed_analysis(
float x_dimension,
float y_dimension,
int x_points_num,
int y_points_num,
float shift_x,
float shift_y);
367 void bed_check(
float x_dimension,
float y_dimension,
int x_points_num,
int y_points_num,
float shift_x,
float shift_y);
369 float temp_comp_interpolation(
float temperature);
371 void show_fw_version_warnings();
373 uint8_t check_printer_version();
375 #ifdef PINDA_THERMISTOR
376 float temp_compensation_pinda_thermistor_offset(
float temperature_pinda);
379 void serialecho_temperatures();
380 bool check_commands();
382 extern void print_world_coordinates();
383 extern void print_physical_coordinates();
384 extern void print_mesh_bed_leveling_table();
386 void save_print_file_state();
387 void restore_print_file_state();
388 void save_planner_global_state();
389 void refresh_print_state_in_ram();
393 void refresh_saved_feedrate_multiplier_in_ram();
394 void clear_print_state_in_ram();
395 extern void stop_and_save_print_to_ram(
float z_move,
float e_move);
396 void restore_file_from_sd();
397 void restore_extruder_temperature_from_ram();
398 extern void restore_print_from_ram_and_continue(
float e_move);
399 extern void cancel_saved_printing();
403 #define X_COORD_INVALID (X_MIN_POS-1)
404 #define SAVED_START_POSITION_UNSET X_COORD_INVALID
405 extern float saved_start_position[NUM_AXIS];
406 extern uint16_t saved_segment_idx;
407 extern bool isPartialBackupAvailable;
411 extern uint8_t calc_percent_done();
428 #define PAUSED_FOR_USER 4
429 #define PAUSED_FOR_INPUT 5
431 #define KEEPALIVE_STATE(n) do { busy_state = n;} while (0)
435 extern int8_t busy_state;
440 #define FORCE_HIGH_POWER_START force_high_power_mode(true)
441 #define FORCE_HIGH_POWER_END force_high_power_mode(false)
443 void force_high_power_mode(
bool start_high_power_section);
444 void change_power_mode_live(uint8_t mode);
450 bool gcode_M45(
bool onlyZ, int8_t verbosity_level);
452 #if (defined(FANCHECK) && (((defined(TACH_0) && (TACH_0 >-1)) || (defined(TACH_1) && (TACH_1 > -1)))))
455 void gcode_M701(
float fastLoadLength, uint8_t mmuSlotIndex);
457 #define UVLO !(PINE & (1<<4))
460 void M600_load_filament();
461 void M600_load_filament_movements();
462 void M600_wait_for_user();
463 bool M600_check_state_and_repeat();
464 void load_filament_final_feed();
465 void marlin_wait_for_click();
467 void raise_z_above(
float target);
469 extern "C" void softReset();
472 extern uint32_t IP_address;
uint32_t saved_sdpos
SD card position, or line number in case of USB printing.
Definition: Marlin_main.cpp:314
uint16_t saved_extruder_temperature
Active extruder temperature.
Definition: Marlin_main.cpp:319
void debug_printer_states()
debug printer states
Definition: Marlin_main.cpp:538
uint8_t saved_bed_temperature
Bed temperature.
Definition: Marlin_main.cpp:320
float raise_z(float delta)
Safely move Z-axis by distance delta (mm)
Definition: Marlin_main.cpp:2146
bool check_fsensor()
Definition: Marlin_main.cpp:586
void host_keepalive()
Definition: Marlin_main.cpp:1746
bool saved_printing
Print is paused and saved in RAM.
Definition: Marlin_main.cpp:313
void host_autoreport()
Definition: Marlin_main.cpp:1721
uint8_t fanSpeed
Print fan speed, ranges from 0 to 255.
Definition: Marlin_main.cpp:207
uint16_t saved_feedrate2
Default feedrate (truncated from float)
Definition: Marlin_main.cpp:317
uint8_t saved_fan_speed
Print fan speed, ranges from 0 to 255.
Definition: Marlin_main.cpp:322
static constexpr float __attribute__((noinline)) count_e(float layer_height
Count extrude length.