Skip to content

Commit

Permalink
🎨 Apply F() to G-code subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 25, 2021
1 parent 433a27e commit 2b9ae0c
Show file tree
Hide file tree
Showing 28 changed files with 136 additions and 134 deletions.
14 changes: 7 additions & 7 deletions Marlin/src/feature/bedlevel/ubl/ubl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,20 @@ bool unified_bed_leveling::sanity_check() {
}
#endif

process_subcommands_now_P(G28_STR); // Home
process_subcommands_now_P(PSTR(ALIGN_GCODE "\n" // Align multi z axis if available
PROBE_GCODE "\n" // Build mesh with available hardware
"G29P3\nG29P3")); // Ensure mesh is complete by running smart fill twice
process_subcommands_now(FPSTR(G28_STR)); // Home
process_subcommands_now(F(ALIGN_GCODE "\n" // Align multi z axis if available
PROBE_GCODE "\n" // Build mesh with available hardware
"G29P3\nG29P3")); // Ensure mesh is complete by running smart fill twice

if (parser.seenval('S')) {
char umw_gcode[32];
sprintf_P(umw_gcode, PSTR("G29S%i"), parser.value_int());
queue.inject(umw_gcode);
}

process_subcommands_now_P(PSTR("G29A\nG29F10\n" // Set UBL Active & Fade 10
"M140S0\nM104S0\n" // Turn off heaters
"M500")); // Store settings
process_subcommands_now(F("G29A\nG29F10\n" // Set UBL Active & Fade 10
"M140S0\nM104S0\n" // Turn off heaters
"M500")); // Store settings
}

#endif // UBL_MESH_WIZARD
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ void unified_bed_leveling::G29() {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
if (probe_deployed) {
planner.synchronize();
gcode.process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT));
gcode.process_subcommands_now(F(Z_PROBE_END_SCRIPT));
}
#else
UNUSED(probe_deployed);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Power::power_on() {
TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));

#ifdef PSU_POWERUP_GCODE
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWERUP_GCODE));
gcode.process_subcommands_now(F(PSU_POWERUP_GCODE));
#endif
}

Expand All @@ -95,7 +95,7 @@ void Power::power_off() {
if (!psu_on) return;

#ifdef PSU_POWEROFF_GCODE
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWEROFF_GCODE));
gcode.process_subcommands_now(F(PSU_POWEROFF_GCODE));
#endif

#if ENABLED(PS_OFF_SOUND)
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW

#if POWER_LOSS_RETRACT_LEN
// Retract filament now
gcode.process_subcommands_now_P(PSTR("G1 F3000 E-" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
gcode.process_subcommands_now(F("G1 F3000 E-" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
#endif

#if POWER_LOSS_ZRAISE
Expand Down Expand Up @@ -337,7 +337,7 @@ void PrintJobRecovery::resume() {

#if HAS_LEVELING
// Make sure leveling is off before any G92 and G28
gcode.process_subcommands_now_P(PSTR("M420 S0 Z0"));
gcode.process_subcommands_now(F("M420 S0 Z0"));
#endif

#if HAS_HEATED_BED
Expand Down Expand Up @@ -373,7 +373,7 @@ void PrintJobRecovery::resume() {
// establish the current position as best we can.
//

gcode.process_subcommands_now_P(PSTR("G92.9E0")); // Reset E to 0
gcode.process_subcommands_now(F("G92.9E0")); // Reset E to 0

#if Z_HOME_TO_MAX

Expand Down Expand Up @@ -410,7 +410,7 @@ void PrintJobRecovery::resume() {
}

// Home XY with no Z raise, and also home Z here if Z isn't homing down below.
gcode.process_subcommands_now_P(PSTR("G28R0" TERN_(HOME_XY_ONLY, "XY"))); // No raise during G28
gcode.process_subcommands_now(F("G28R0" TERN_(HOME_XY_ONLY, "XY"))); // No raise during G28

#endif

Expand Down Expand Up @@ -513,7 +513,7 @@ void PrintJobRecovery::resume() {

// Un-retract if there was a retract at outage
#if ENABLED(BACKUP_POWER_SUPPLY) && POWER_LOSS_RETRACT_LEN > 0
gcode.process_subcommands_now_P(PSTR("G1E" STRINGIFY(POWER_LOSS_RETRACT_LEN) "F3000"));
gcode.process_subcommands_now(F("G1E" STRINGIFY(POWER_LOSS_RETRACT_LEN) "F3000"));
#endif

// Additional purge on resume if configured
Expand All @@ -523,7 +523,7 @@ void PrintJobRecovery::resume() {
#endif

#if ENABLED(NOZZLE_CLEAN_FEATURE)
gcode.process_subcommands_now_P(PSTR("G12"));
gcode.process_subcommands_now(F("G12"));
#endif

// Move back over to the saved XY
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/G35.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void GcodeSuite::G35() {
TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false));

// Home only Z axis when X and Y is trusted, otherwise all axes, if needed before this procedure
if (!all_axes_trusted()) process_subcommands_now_P(PSTR("G28Z"));
if (!all_axes_trusted()) process_subcommands_now(F("G28Z"));

bool err_break = false;

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ G29_TYPE GcodeSuite::G29() {

// Send 'N' to force homing before G29 (internal only)
if (parser.seen_test('N'))
process_subcommands_now_P(TERN(CAN_SET_LEVELING_AFTER_G28, PSTR("G28L0"), G28_STR));
process_subcommands_now(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR)));

// Don't allow auto-leveling without homing first
if (homing_needed_error()) G29_RETURN(false);
Expand Down Expand Up @@ -882,7 +882,7 @@ G29_TYPE GcodeSuite::G29() {
#ifdef Z_PROBE_END_SCRIPT
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
planner.synchronize();
process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT));
process_subcommands_now(F(Z_PROBE_END_SCRIPT));
#endif

TERN_(HAS_DWIN_E3V2_BASIC, DWIN_CompletedLeveling());
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/calibrate/G34.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void GcodeSuite::G34() {
TemporaryGlobalEndstopsState unlock_z(false);

#ifdef GANTRY_CALIBRATION_COMMANDS_PRE
gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_PRE));
process_subcommands_now(F(GANTRY_CALIBRATION_COMMANDS_PRE));
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Sub Commands Processed");
#endif

Expand Down Expand Up @@ -148,7 +148,7 @@ void GcodeSuite::G34() {

#ifdef GANTRY_CALIBRATION_COMMANDS_POST
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands");
gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_POST));
process_subcommands_now(F(GANTRY_CALIBRATION_COMMANDS_POST));
#endif

SET_SOFT_ENDSTOP_LOOSE(false);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G34_M422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void GcodeSuite::G34() {
// After this operation the z position needs correction
set_axis_never_homed(Z_AXIS);
// Home Z after the alignment procedure
process_subcommands_now_P(PSTR("G28Z"));
process_subcommands_now(F("G28Z"));
#else
// Use the probed height from the last iteration to determine the Z height.
// z_measured_min is used, because all steppers are aligned to z_measured_min.
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/calibrate/G425.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ inline void calibrate_all() {
void GcodeSuite::G425() {

#ifdef CALIBRATION_SCRIPT_PRE
GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_PRE));
process_subcommands_now(F(CALIBRATION_SCRIPT_PRE));
#endif

if (homing_needed_error()) return;
Expand Down Expand Up @@ -745,7 +745,7 @@ void GcodeSuite::G425() {
SET_SOFT_ENDSTOP_LOOSE(false);

#ifdef CALIBRATION_SCRIPT_POST
GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_POST));
process_subcommands_now(F(CALIBRATION_SCRIPT_POST));
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G76_M192_M871.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void GcodeSuite::G76() {
return;
}

process_subcommands_now_P(G28_STR);
process_subcommands_now(FPSTR(G28_STR));
}

remember_feedrate_scaling_off();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/control/M605.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
set_duplication_enabled(false);

#ifdef EVENT_GCODE_IDEX_AFTER_MODECHANGE
gcode.process_subcommands_now_P(PSTR(EVENT_GCODE_IDEX_AFTER_MODECHANGE));
process_subcommands_now(F(EVENT_GCODE_IDEX_AFTER_MODECHANGE));
#endif
}
else if (!parser.seen('W')) // if no S or W parameter, the DXC mode gets reset to the user's default
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/gcode/feature/L6470/M916-918.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ void GcodeSuite::M916() {
do {
// turn the motor(s) both directions
sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_min), uint16_t(final_feedrate));
gcode.process_subcommands_now_P(gcode_string);
process_subcommands_now(gcode_string);

sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_max), uint16_t(final_feedrate));
gcode.process_subcommands_now_P(gcode_string);
process_subcommands_now(gcode_string);

// get the status after the motors have stopped
planner.synchronize();
Expand Down Expand Up @@ -266,10 +266,10 @@ void GcodeSuite::M917() {
DEBUG_ECHOLNPGM(" OCD threshold : ", (OCD_TH_val + 1) * 375);

sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_min), uint16_t(final_feedrate));
gcode.process_subcommands_now_P(gcode_string);
process_subcommands_now(gcode_string);

sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_max), uint16_t(final_feedrate));
gcode.process_subcommands_now_P(gcode_string);
process_subcommands_now(gcode_string);

planner.synchronize();

Expand Down Expand Up @@ -308,7 +308,7 @@ void GcodeSuite::M917() {
L64xxManager.set_param(axis_index[j], L6470_KVAL_HOLD, kval_hold);
}
DEBUG_ECHOLNPGM(".");
gcode.reset_stepper_timeout(); // keep steppers powered
reset_stepper_timeout(); // keep steppers powered
watchdog_refresh();
safe_delay(5000);
status_composite_temp = 0;
Expand Down Expand Up @@ -615,10 +615,10 @@ void GcodeSuite::M918() {
DEBUG_ECHOLNPGM("...feedrate = ", current_feedrate);

sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_min), uint16_t(current_feedrate));
gcode.process_subcommands_now_P(gcode_string);
process_subcommands_now(gcode_string);

sprintf_P(gcode_string, PSTR("G0 %s%03d F%03d"), temp_axis_string, uint16_t(position_max), uint16_t(current_feedrate));
gcode.process_subcommands_now_P(gcode_string);
process_subcommands_now(gcode_string);

planner.synchronize();

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/feature/clean/G12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void GcodeSuite::G12() {

#ifdef WIPE_SEQUENCE_COMMANDS
if (!parser.seen_any()) {
gcode.process_subcommands_now_P(PSTR(WIPE_SEQUENCE_COMMANDS));
process_subcommands_now(F(WIPE_SEQUENCE_COMMANDS));
return;
}
#endif
Expand Down
9 changes: 5 additions & 4 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void GcodeSuite::dwell(millis_t time) {
host_action(PSTR(ACTION_ON_G29_RECOVER));
#endif
#ifdef G29_RECOVER_COMMANDS
process_subcommands_now_P(PSTR(G29_RECOVER_COMMANDS));
process_subcommands_now(F(G29_RECOVER_COMMANDS));
#endif
}

Expand All @@ -256,7 +256,7 @@ void GcodeSuite::dwell(millis_t time) {
host_action(PSTR(ACTION_ON_G29_FAILURE));
#endif
#ifdef G29_FAILURE_COMMANDS
process_subcommands_now_P(PSTR(G29_FAILURE_COMMANDS));
process_subcommands_now(F(G29_FAILURE_COMMANDS));
#endif
#if ENABLED(G29_HALT_ON_FAILURE)
#ifdef ACTION_ON_CANCEL
Expand Down Expand Up @@ -286,7 +286,7 @@ void GcodeSuite::dwell(millis_t time) {
TERN_(HOST_PROMPT_SUPPORT, host_action_prompt_end());

#ifdef G29_SUCCESS_COMMANDS
process_subcommands_now_P(PSTR(G29_SUCCESS_COMMANDS));
process_subcommands_now(F(G29_SUCCESS_COMMANDS));
#endif
}

Expand Down Expand Up @@ -1101,7 +1101,8 @@ void GcodeSuite::process_next_command() {
* G-code "macros" to be called from within other G-code handlers.
*/

void GcodeSuite::process_subcommands_now_P(PGM_P pgcode) {
void GcodeSuite::process_subcommands_now(FSTR_P fgcode) {
PGM_P pgcode = FTOP(fgcode);
char * const saved_cmd = parser.command_ptr; // Save the parser state
for (;;) {
PGM_P const delim = strchr_P(pgcode, '\n'); // Get address of next newline
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ class GcodeSuite {
static void process_next_command();

// Execute G-code in-place, preserving current G-code parameters
static void process_subcommands_now_P(PGM_P pgcode);
static void process_subcommands_now(FSTR_P fgcode);
static void process_subcommands_now(char * gcode);

static inline void home_all_axes(const bool keep_leveling=false) {
process_subcommands_now_P(keep_leveling ? G28_STR : TERN(CAN_SET_LEVELING_AFTER_G28, PSTR("G28L0"), G28_STR));
process_subcommands_now(keep_leveling ? FPSTR(G28_STR) : TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR)));
}

#if EITHER(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/motion/G2_G3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void GcodeSuite::G2_G3(const bool clockwise) {
else {
#if ENABLED(CNC_WORKSPACE_PLANES)
char achar, bchar;
switch (gcode.workspace_plane) {
switch (workspace_plane) {
default:
case GcodeSuite::PLANE_XY: achar = 'I'; bchar = 'J'; break;
case GcodeSuite::PLANE_YZ: achar = 'J'; bchar = 'K'; break;
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ void GCodeQueue::advance() {

void GCodeQueue::report_buffer_statistics() {
SERIAL_ECHOLNPGM("D576"
" P:", planner.moves_free(), " ", -queue.planner_buffer_underruns, " (", queue.max_planner_buffer_empty_duration, ")"
" B:", BUFSIZE - ring_buffer.length, " ", -queue.command_buffer_underruns, " (", queue.max_command_buffer_empty_duration, ")"
" P:", planner.moves_free(), " ", -planner_buffer_underruns, " (", max_planner_buffer_empty_duration, ")"
" B:", BUFSIZE - ring_buffer.length, " ", -command_buffer_underruns, " (", max_command_buffer_empty_duration, ")"
);
command_buffer_underruns = planner_buffer_underruns = 0;
max_command_buffer_empty_duration = max_planner_buffer_empty_duration = 0;
Expand All @@ -717,8 +717,8 @@ void GCodeQueue::advance() {
NOLESS(max_planner_buffer_empty_duration, planner_buffer_empty_duration); // if it's longer than the currently tracked max duration, replace it
}

if (queue.auto_buffer_report_interval && ELAPSED(ms, queue.next_buffer_report_ms)) {
queue.next_buffer_report_ms = ms + 1000UL * queue.auto_buffer_report_interval;
if (auto_buffer_report_interval && ELAPSED(ms, next_buffer_report_ms)) {
next_buffer_report_ms = ms + 1000UL * auto_buffer_report_interval;
PORT_REDIRECT(SERIAL_BOTH);
report_buffer_statistics();
PORT_RESTORE();
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/sd/M1001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ void GcodeSuite::M1001() {

// Report total print time
const bool long_print = print_job_timer.duration() > 60;
if (long_print) gcode.process_subcommands_now_P(PSTR("M31"));
if (long_print) process_subcommands_now(F("M31"));

// Stop the print job timer
gcode.process_subcommands_now_P(PSTR("M77"));
process_subcommands_now(F("M77"));

// Set the progress bar "done" state
TERN_(LCD_SET_PROGRESS_MANUALLY, ui.set_progress_done());
Expand All @@ -105,7 +105,7 @@ void GcodeSuite::M1001() {

// Inject SD_FINISHED_RELEASECOMMAND, if any
#ifdef SD_FINISHED_RELEASECOMMAND
gcode.process_subcommands_now_P(PSTR(SD_FINISHED_RELEASECOMMAND));
process_subcommands_now(F(SD_FINISHED_RELEASECOMMAND));
#endif

TERN_(EXTENSIBLE_UI, ExtUI::onPrintFinished());
Expand Down
Loading

0 comments on commit 2b9ae0c

Please sign in to comment.