본문 바로가기
3D프린팅

Marlin Autostart

by YJHTPII 2022. 5. 25.
반응형

https://marlinfw.org/docs/features/autostart.html

 

Autostart

Automatically execute G-code at startup

marlinfw.org

Autostart

If the printer has an SD card inserted at startup or reset, Marlin will look for the file auto0.g and execute it, followed in sequence by any other files with the same pattern (auto1.g, auto2.g, etc.) all the way up to auto9.g.

By default, Autostart is included in the firmware whenever SD card support is enabled. It can be disabled to save a little flash and SRAM if the feature is not needed.

Use-cases

  • Provide alternative settings for all the files on an SD Card.
  • Use the printer in “kiosk mode” to start a print simply by rebooting.
  • Set the printer to a fresh state after a reboot.
  • Run from the menu to set a fresh state at any time.

Configuration

  • NO_SD_AUTOSTART completely removes Autostart from the firmware.
  • MENU_ADDAUTOSTART adds a menu item that can be used to run all the auto#.g files at any time.

Credits

Originally created by bkubicek, Joris, and the Ultimaker guys in a pizza-powered hacking session at Protospace/Utrecht as a way to start a print as soon the printer is powered on.

 

void CardReader::checkautostart(bool force)
{
  if(!force)
  {
    if(!autostart_stilltocheck)
      return;
    if(autostart_atmillis<millis())
      return;
  }
  autostart_stilltocheck=false;
  if(!cardOK)
  {
    initsd();
    if(!cardOK) //fail
      return;
  }
  
  char autoname[30];
  sprintf_P(autoname, PSTR("auto%i.g"), lastnr);
  for(int8_t i=0;i<(int8_t)strlen(autoname);i++)
    autoname[i]=tolower(autoname[i]);
  dir_t p;

  root.rewind();
  
  bool found=false;
  while (root.readDir(p, NULL) > 0) 
  {
    for(int8_t i=0;i<(int8_t)strlen((char*)p.name);i++)
    p.name[i]=tolower(p.name[i]);
    //Serial.print((char*)p.name);
    //Serial.print(" ");
    //Serial.println(autoname);
    if(p.name[9]!='~') //skip safety copies
    if(strncmp((char*)p.name,autoname,5)==0)
    {
      char cmd[30];

      sprintf_P(cmd, PSTR("M23 %s"), autoname);
      enquecommand(cmd);
      enquecommand_P(PSTR("M24"));
      found=true;
    }
  }
  if(!found)
    lastnr=-1;
  else
    lastnr++;
}
반응형

댓글