Skip to content

Commit

Permalink
🎨 Apply F() to G-code suite and queue
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 25, 2021
1 parent 2b9ae0c commit 46c53f6
Show file tree
Hide file tree
Showing 39 changed files with 136 additions and 134 deletions.
10 changes: 5 additions & 5 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,15 @@ void startOrResumeJob() {
TERN_(POWER_LOSS_RECOVERY, recovery.purge());

#ifdef EVENT_GCODE_SD_ABORT
queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT));
queue.inject(F(EVENT_GCODE_SD_ABORT));
#endif

TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine());
}

inline void finishSDPrinting() {
if (queue.enqueue_one_P(PSTR("M1001"))) { // Keep trying until it gets queued
marlin_state = MF_RUNNING; // Signal to stop trying
if (queue.enqueue_one(F("M1001"))) { // Keep trying until it gets queued
marlin_state = MF_RUNNING; // Signal to stop trying
TERN_(PASSWORD_AFTER_SD_PRINT_END, password.lock_machine());
TERN_(DGUS_LCD_UI_MKS, ScreenHandler.SDPrintingFinished());
}
Expand Down Expand Up @@ -493,7 +493,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
if (ELAPSED(ms, next_cub_ms_##N)) { \
next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \
CODE; \
queue.inject_P(PSTR(BUTTON##N##_GCODE)); \
queue.inject(F(BUTTON##N##_GCODE)); \
TERN_(HAS_LCD_MENU, ui.quick_feedback()); \
} \
} \
Expand Down Expand Up @@ -1521,7 +1521,7 @@ void setup() {

#ifdef STARTUP_COMMANDS
SETUP_LOG("STARTUP_COMMANDS");
queue.inject_P(PSTR(STARTUP_COMMANDS));
queue.inject(F(STARTUP_COMMANDS));
#endif

#if ENABLED(HOST_PROMPT_SUPPORT)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/mmu/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ void MMU2::set_filament_type(const uint8_t index, const uint8_t filamentType) {
}

void MMU2::filament_runout() {
queue.inject_P(PSTR(MMU2_FILAMENT_RUNOUT_SCRIPT));
queue.inject(F(MMU2_FILAMENT_RUNOUT_SCRIPT));
planner.synchronize();
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void PrintJobRecovery::check() {
if (card.isMounted()) {
load();
if (!valid()) return cancel();
queue.inject_P(PSTR("M1000S"));
queue.inject(F("M1000S"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/runout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void event_filament_runout(const uint8_t extruder) {
SERIAL_ECHOPGM("Runout Command: ");
SERIAL_ECHOLNPGM(FILAMENT_RUNOUT_SCRIPT);
#endif
queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
queue.inject(F(FILAMENT_RUNOUT_SCRIPT));
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/mbl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void GcodeSuite::G29() {
mbl.reset();
mbl_probe_index = 0;
if (!ui.wait_for_move) {
queue.inject_P(parser.seen_test('N') ? PSTR("G28" TERN(CAN_SET_LEVELING_AFTER_G28, "L0", "") "\nG29S2") : PSTR("G29S2"));
queue.inject(parser.seen_test('N') ? F("G28" TERN(CAN_SET_LEVELING_AFTER_G28, "L0", "") "\nG29S2") : F("G29S2"));
TERN_(EXTENSIBLE_UI, ExtUI::onMeshLevelingStart());
return;
}
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 @@ -126,7 +126,7 @@ bool GCodeQueue::RingBuffer::enqueue(const char *cmd, bool skip_ok/*=true*/
* Enqueue with Serial Echo
* Return true if the command was consumed
*/
bool GCodeQueue::enqueue_one(const char *cmd) {
bool GCodeQueue::enqueue_one(const char * const cmd) {
//SERIAL_ECHOLNPGM("enqueue_one(\"", cmd, "\")");

if (*cmd == 0 || ISEOL(*cmd)) return true;
Expand Down Expand Up @@ -195,15 +195,15 @@ bool GCodeQueue::process_injected_command() {
* Enqueue and return only when commands are actually enqueued.
* Never call this from a G-code handler!
*/
void GCodeQueue::enqueue_one_now(const char *cmd) { while (!enqueue_one(cmd)) idle(); }
void GCodeQueue::enqueue_one_now(const char * const cmd) { while (!enqueue_one(cmd)) idle(); }

/**
* Attempt to enqueue a single G-code command
* and return 'true' if successful.
*/
bool GCodeQueue::enqueue_one_P(PGM_P const pgcode) {
bool GCodeQueue::enqueue_one(FSTR_P const fgcode) {
size_t i = 0;
PGM_P p = pgcode;
PGM_P p = FTOP(fgcode);
char c;
while ((c = pgm_read_byte(&p[i])) && c != '\n') i++;
char cmd[i + 1];
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/gcode/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class GCodeQueue {
* Aborts the current PROGMEM queue so only use for one or two commands.
*/
static inline void inject_P(PGM_P const pgcode) { injected_commands_P = pgcode; }
static inline void inject(FSTR_P const fgcode) { inject_P(FTOP(fgcode)); }

/**
* Enqueue command(s) to run from SRAM. Drained by process_injected_command().
Expand All @@ -139,18 +140,19 @@ class GCodeQueue {
/**
* Enqueue and return only when commands are actually enqueued
*/
static void enqueue_one_now(const char *cmd);
static void enqueue_one_now(const char * const cmd);

/**
* Attempt to enqueue a single G-code command
* and return 'true' if successful.
*/
static bool enqueue_one_P(PGM_P const pgcode);
static bool enqueue_one(FSTR_P const fgcode);

/**
* Enqueue from program memory and return only when commands are actually enqueued
*/
static void enqueue_now_P(PGM_P const cmd);
static void enqueue_now_P(PGM_P const pcmd);
static inline void enqueue_now(FSTR_P const fcmd) { enqueue_now_P(FTOP(fcmd)); }

/**
* Check whether there are any commands yet to be executed
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/lcd/e3v2/creality/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,7 @@ void HMI_PauseOrStop() {
if (select_print.now == PRINT_PAUSE_RESUME) {
if (HMI_flag.select_flag) {
HMI_flag.pause_action = true;
queue.inject_P(PSTR("M25"));
queue.inject(F("M25"));
}
Goto_PrintProcess();
}
Expand Down Expand Up @@ -2711,7 +2711,7 @@ void HMI_Prepare() {
#endif
break;

case PREPARE_CASE_DISA: queue.inject_P(PSTR("M84")); break;
case PREPARE_CASE_DISA: queue.inject(F("M84")); break;

case PREPARE_CASE_HOME: // Homing
checkkey = Last_Prepare;
Expand All @@ -2729,7 +2729,7 @@ void HMI_Prepare() {
EncoderRate.enabled = true;
#else
// Apply workspace offset, making the current position 0,0,0
queue.inject_P(PSTR("G92 X0 Y0 Z0"));
queue.inject(F("G92 X0 Y0 Z0"));
HMI_AudioFeedback();
#endif
break;
Expand Down Expand Up @@ -2944,7 +2944,7 @@ void HMI_Control() {
void HMI_Leveling() {
Popup_Window_Leveling();
DWIN_UpdateLCD();
queue.inject_P(PSTR("G28O\nG29"));
queue.inject(F("G28O\nG29"));
}
#endif

Expand Down Expand Up @@ -3803,7 +3803,7 @@ void HMI_Tune() {
EncoderRate.enabled = true;
#else
// Apply workspace offset, making the current position 0,0,0
queue.inject_P(PSTR("G92 X0 Y0 Z0"));
queue.inject(F("G92 X0 Y0 Z0"));
HMI_AudioFeedback();
#endif
break;
Expand Down Expand Up @@ -4112,7 +4112,7 @@ void EachMomentUpdate() {
TERN_(HAS_HEATED_BED, resume_bed_temp = thermalManager.degTargetBed());
thermalManager.disable_all_heaters();
#endif
queue.inject_P(PSTR("G1 F1200 X0 Y0"));
queue.inject(F("G1 F1200 X0 Y0"));
}

if (card.isPrinting() && checkkey == PrintProcess) { // print process
Expand Down Expand Up @@ -4182,7 +4182,7 @@ void EachMomentUpdate() {
if (encoder_diffState == ENCODER_DIFF_ENTER) {
recovery_flag = false;
if (HMI_flag.select_flag) break;
TERN_(POWER_LOSS_RECOVERY, queue.inject_P(PSTR("M1000C")));
TERN_(POWER_LOSS_RECOVERY, queue.inject(F("M1000C")));
HMI_StartFrame(true);
return;
}
Expand All @@ -4195,7 +4195,7 @@ void EachMomentUpdate() {

select_print.set(0);
HMI_ValueStruct.show_mode = 0;
queue.inject_P(PSTR("M1000"));
queue.inject(F("M1000"));
Goto_PrintProcess();
Draw_Status_Area(true);
}
Expand Down
26 changes: 13 additions & 13 deletions Marlin/src/lcd/e3v2/enhanced/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ void HMI_MainMenu() {

case PAGE_INFO_LEVELING:
#if HAS_ONESTEP_LEVELING
queue.inject_P(PSTR("G28XYO\nG28Z\nG29")); // TODO: 'G29' should be homing when needed. Does it make sense for every LCD to do this differently?
queue.inject(F("G28XYO\nG28Z\nG29")); // TODO: 'G29' should be homing when needed. Does it make sense for every LCD to do this differently?
#else
checkkey = Info;
Draw_Info_Menu();
Expand Down Expand Up @@ -1376,7 +1376,7 @@ void HMI_PauseOrStop() {
if (HMI_flag.select_flag) {
HMI_flag.pause_action = true;
ICON_Resume();
queue.inject_P(PSTR("M25"));
queue.inject(F("M25"));
}
else {
// cancel pause
Expand Down Expand Up @@ -1510,7 +1510,7 @@ void EachMomentUpdate() {
TERN_(HAS_FAN, resume_fan = thermalManager.fan_speed[0]);
#endif
IF_DISABLED(ADVANCED_PAUSE_FEATURE, thermalManager.disable_all_heaters());
IF_DISABLED(PARK_HEAD_ON_PAUSE, queue.inject_P(PSTR("G1 F1200 X0 Y0")));
IF_DISABLED(PARK_HEAD_ON_PAUSE, queue.inject(F("G1 F1200 X0 Y0")));
}

if (checkkey == PrintProcess) { // print process
Expand Down Expand Up @@ -1588,7 +1588,7 @@ void EachMomentUpdate() {
if (encoder_diffState == ENCODER_DIFF_ENTER) {
recovery_flag = false;
if (HMI_flag.select_flag) break;
TERN_(POWER_LOSS_RECOVERY, queue.inject_P(PSTR("M1000C")));
TERN_(POWER_LOSS_RECOVERY, queue.inject(F("M1000C")));
return HMI_StartFrame(true);
}
else
Expand All @@ -1600,7 +1600,7 @@ void EachMomentUpdate() {
}

select_print.set(PRINT_SETUP);
queue.inject_P(PSTR("M1000"));
queue.inject(F("M1000"));
sdprint = true;
Goto_PrintProcess();
Draw_Status_Area(true);
Expand Down Expand Up @@ -2088,13 +2088,13 @@ void Goto_InfoMenu(){
Draw_Info_Menu();
}

void DisableMotors() { queue.inject_P(PSTR("M84")); }
void DisableMotors() { queue.inject(F("M84")); }

void AutoHome() { queue.inject_P(G28_STR); }

void SetHome() {
// Apply workspace offset, making the current position 0,0,0
queue.inject_P(PSTR("G92 X0 Y0 Z0"));
queue.inject(F("G92 X0 Y0 Z0"));
HMI_AudioFeedback();
}

Expand Down Expand Up @@ -2241,7 +2241,7 @@ void Goto_LockScreen() { DWIN_LockScreen(true); }
void SetProbeOffsetZ() { SetPFloatOnClick(-10, 10, 2); }
void ProbeTest() {
ui.set_status_P(GET_TEXT(MSG_M48_TEST));
queue.inject_P(PSTR("G28O\nM48 P10"));
queue.inject(F("G28O\nM48 P10"));
}
#endif

Expand Down Expand Up @@ -2321,23 +2321,23 @@ void SetSpeed() { SetPIntOnClick(MIN_PRINT_SPEED, MAX_PRINT_SPEED); }

void ChangeFilament() {
HMI_SaveProcessID(NothingToDo);
queue.inject_P(PSTR("M600 B2"));
queue.inject(F("M600 B2"));
}

void ParkHead(){
ui.set_status_P(GET_TEXT(MSG_FILAMENT_PARK_ENABLED));
queue.inject_P(PSTR("G28O\nG27"));
queue.inject(F("G28O\nG27"));
}

#if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
void UnloadFilament(){
ui.set_status_P(GET_TEXT(MSG_FILAMENTUNLOAD));
queue.inject_P(PSTR("M702 Z20"));
queue.inject(F("M702 Z20"));
}

void LoadFilament(){
ui.set_status_P(GET_TEXT(MSG_FILAMENTLOAD));
queue.inject_P(PSTR("M701 Z20"));
queue.inject(F("M701 Z20"));
}
#endif

Expand Down Expand Up @@ -2436,7 +2436,7 @@ void LevBedC () { LevBed(4); }

void ManualMeshSave(){
ui.set_status_P(GET_TEXT(MSG_UBL_STORAGE_MESH_MENU));
queue.inject_P(PSTR("M211 S1\nM500"));
queue.inject(F("M211 S1\nM500"));
}

#endif // MESH_BED_LEVELING
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (draw)
Draw_Menu_Item(row, ICON_CloseMotor, F("Disable Stepper"));
else
queue.inject_P(PSTR("M84"));
queue.inject(F("M84"));
break;
case PREPARE_HOME:
if (draw)
Expand Down Expand Up @@ -4499,7 +4499,7 @@ void CrealityDWINClass::Print_Screen_Control() {
#endif
TERN_(HAS_FAN, thermalManager.fan_speed[0] = pausefan);
planner.synchronize();
TERN_(SDSUPPORT, queue.inject_P(PSTR("M24")));
TERN_(SDSUPPORT, queue.inject(F("M24")));
#endif
}
else {
Expand Down Expand Up @@ -4541,10 +4541,10 @@ void CrealityDWINClass::Popup_Control() {
if (IS_SD_PRINTING()) card.pauseSDPrint();
#endif
planner.synchronize();
queue.inject_P(PSTR("M125"));
queue.inject(F("M125"));
planner.synchronize();
#else
queue.inject_P(PSTR("M25"));
queue.inject(F("M25"));
TERN_(HAS_HOTEND, pausetemp = thermalManager.temp_hotend[0].target);
TERN_(HAS_HEATED_BED, pausebed = thermalManager.temp_bed.target);
TERN_(HAS_FAN, pausefan = thermalManager.fan_speed[0]);
Expand Down Expand Up @@ -4574,9 +4574,9 @@ void CrealityDWINClass::Popup_Control() {
break;
case Resume:
if (selection == 0)
queue.inject_P(PSTR("M1000"));
queue.inject(F("M1000"));
else {
queue.inject_P(PSTR("M1000 C"));
queue.inject(F("M1000 C"));
Draw_Main_Menu();
}
break;
Expand Down Expand Up @@ -5008,7 +5008,7 @@ void CrealityDWINClass::Load_Settings(const char *buff) {
static bool init = true;
if (init) {
init = false;
queue.inject_P(PSTR("M1000 S"));
queue.inject(F("M1000 S"));
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ void DGUSScreenHandler::HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr
void DGUSScreenHandler::HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t value = swap16(*(uint16_t*)val_ptr);
if (value) {
queue.inject_P(PSTR("M1000"));
queue.inject(F("M1000"));
dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), 32, true);
GotoScreen(PLR_SCREEN_RECOVER);
}
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
bool old_relative_mode = relative_mode;
if (!relative_mode) {
//DEBUG_ECHOPGM(" G91");
queue.enqueue_now_P(PSTR("G91"));
queue.enqueue_now(F("G91"));
//DEBUG_ECHOPGM(" ✓ ");
}
char buf[32]; // G1 X9999.99 F12345
Expand All @@ -227,7 +227,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
//DEBUG_ECHOLNPGM(" ✓ ");
if (!old_relative_mode) {
//DEBUG_ECHOPGM("G90");
queue.enqueue_now_P(PSTR("G90"));
queue.enqueue_now(F("G90"));
//DEBUG_ECHOPGM(" ✓ ");
}
}
Expand Down
Loading

0 comments on commit 46c53f6

Please sign in to comment.