Welcome! Log In Create A New Profile

Advanced

Help understanding SD printing Code

Posted by FiftyFive 
Help understanding SD printing Code
February 12, 2021 07:23PM
Hello,

I am trying to learn how Marlin reads from the SD and prints the GCODE files. I'm am a beginner with c++, I have gotten this far,

Selecting the file from the menu in menu_media.cpp

inline void sdcard_start_selected_file() {
  card.openAndPrintFile(card.filename);
  ui.return_to_status();
  ui.reset_status();
}

This goes to the openAndPrintFile() in cardreader.cpp

void CardReader:: openAndPrintFile(const char *name) {
  char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
  extern const char M23_STR[];
  sprintf_P(cmd, M23_STR, name);
  for (char *c = &cmd[4]; *c; c++) *c = tolower(*c);
  queue.enqueue_one_now(cmd);
  queue.enqueue_now_P(M24_STR);
}

This sends the M23 command with the file name to open the file, followed by the M24 command to start printing from the file.
From M24_25.cpp

if (card.isFileOpen()) {
    card.startFileprint();            // SD card will now be read for commands
    startOrResumeJob();               // Start (or resume) the print job timer
    TERN_(POWER_LOSS_RECOVERY, recovery.prepare());
  }

The startFileprint() in cardreader.cpp

void CardReader::startFileprint() {
  if (isMounted()) {
    flag.sdprinting = true;
    TERN_(SD_RESORT, flush_presort());
  }
}

this seems to set the sdprinting flag to true but that seems to be it, i could not find this flag getting picked up anywhere.

Any help would be appreciated.
Re: Help understanding SD printing Code
February 12, 2021 08:31PM
main part is in src/gcode/queue.cpp eg get_sdcard_commands and get_available_commands

the link to the flag is
#define IS_SD_PRINTING()  card.flag.sdprinting


so calls to IS_SD_PRINTING is really checking sdprinting flag

Edited 2 time(s). Last edit at 02/12/2021 08:36PM by Dust.
Re: Help understanding SD printing Code
February 12, 2021 08:53PM
Quote
Dust
so calls to IS_SD_PRINTING is really checking sdprinting flag

Awesome, thanks i completely missed this.

Edited 2 time(s). Last edit at 02/12/2021 08:55PM by FiftyFive.
Sorry, only registered users may post in this forum.

Click here to login