Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #if DISABLED(NO_SD_AUTOSTART)
  2.   /**
  3.    * Run all the auto#.g files. Called:
  4.    * - On boot after successful card init.
  5.    * - From the LCD command to Run Auto Files
  6.    */
  7.   void CardReader::autofile_begin() {
  8.     autofile_index = 1;
  9.     (void)autofile_check();
  10.   }
  11.   /**
  12.    * Run the next auto#.g file. Called:
  13.    *   - On boot after successful card init
  14.    *   - After finishing the previous auto#.g file
  15.    *   - From the LCD command to begin the auto#.g files
  16.    *
  17.    * Return 'true' if an auto file was started
  18.    */
  19.   bool CardReader::autofile_check() {
  20.     if (!autofile_index) return false;
  21.  
  22.     if (!isMounted())
  23.       mount();
  24.     else if (ENABLED(SDCARD_EEPROM_EMULATION))
  25.       settings.first_load();
  26.  
  27.     // Don't run auto#.g when a PLR file exists
  28.     if (isMounted() && TERN1(POWER_LOSS_RECOVERY, !recovery.valid())) {
  29.       char autoname[10];
  30.       sprintf_P(autoname, PSTR("/auto%c.g"), '0' + autofile_index - 1);
  31.       if (fileExists(autoname)) {
  32.         cdroot();
  33.         openAndPrintFile(autoname);
  34.         // Generate a random number between 2 and 10
  35.         int randomNumber = random(2,10);
  36.         autofile_index = randomNumber;
  37.         //
  38.         return true;
  39.       }
  40.     }
  41.     autofile_cancel();
  42.     return false;
  43.   }
  44. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement