Jump to content

Sort array in displaying files on SD card


drayson

Recommended Posts

Posted · Sort array in displaying files on SD card

Hi communitiy!

Is there a way to influence the sorting (e.g. by alphabeth, newest file,...) of the files displayed at the ulticontroler?

Any hint appreciated :-)

 

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    Sometimes I get the impression it depends on the color of the left wing of a butterfly at the other end of the universe... :wacko:

    It can't be the filename (because it's chaos on my SD card) or the file date (sometimes new files show up on top, sometimes somewhere in the middle of other files).

     

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    Same at my card...

    As I'm not always deleating stuff, it's a bit anoying.

    Do you think we should place this question as request in eric's marlin fork?

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    I spent a little while looking at the code and trying to figure out the sort order, it has bugged me as well, and from my limited understanding no sorting at all is being performed (to preserve memory perhaps?). The files and directories are listed according to the index they receive in the Fat file system implementation on the Arduino. So the order is "random". If there's enough RAM available I'm sure it could be sorted but I imagine that is very low on the list of priorities.

    I'm sure someone who is a better code monkey than I can explain that better.

    My "workaround" is to dump old files in a directory I call, fittingly, "old" to keep the clutter down a bit.

     

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    I actually save the gcode first to the harddisk and then copy it to the sdcard. From time to time I perform a clean sweep of the sdcard.

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    Ok, never thought about the ram, but this sounds plausible...

    Think I have to cleanup my card soon :-)

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    The order on FAT devices, like our SD card, is the order in which the file was added to the directory structure. If you overwrite a file, it's sort position does not change. In order to sort the directory, you need to remove all the files and add them back in the order you wish them to be sorted.

    There are some utilities which can sort the SD card directory for you (usually used for MP3 players that play songs in the default sort order on the SD card).

    Here is a list someone compiled of the available options.

    http://www.murraymoffatt.com/software-problem-0010.html

    I looked at the firmware to see if there was an easy way to sort the directly list for user display, but reading the entire directory list at once in order to resorting it would take a lot of precious RAM.

     

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    I looked at the firmware to see if there was an easy way to sort the directly list for user display, but reading the entire directory list at once in order to resorting it would take a lot of precious RAM.

     

    You could sacrifice speed for RAM. As you could just keep indexes and sort those (reading the filename every time you need it). But that wouldn't improve the experience, as it would be slow.

    So it's best to keep it at "it depends on the color of the left wing of a butterfly at the other end of the universe... :wacko: "

     

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    OMG, that would take ages! :) I added a short delay in reading the file details (time, filament used, etc) when scrolling through the directory listing to make it more responsive -- I shudder at the idea of doing a list sort where it had to hit the SD card every time it did a comparison. :shock:

     

  • Link to post
    Share on other sites

    Posted · Sort array in displaying files on SD card

    You can get your new file on top with the following method. 

     

    1. Rename the current file shown on top of the list on um display  to a very long name (> 32 char)
    2. Copy your new file on the sd-card using a short name.
  • Link to post
    Share on other sites

    Posted (edited) · Sort array in displaying files on SD card

    I don't have an Ultimaker printer.

    However if it uses a version of Marlin firmware, Marlin has a setting in the "Configuration_adv.h" to alpha sort files on the SD card: 

       //#define SDCARD_SORT_ALPHA

    There is also a setting to sort most recent first: 

       //#define SDCARD_RATHERRECENTFIRST

     

    FYI...  It's not sorted correctly if the SD card goes over the max sort limit.

     

      // Reverse SD sort to show "more recent" files first, according to the card's FAT.
      // Since the FAT gets out of order with usage, SDCARD_SORT_ALPHA is recommended.
      //#define SDCARD_RATHERRECENTFIRST
    
      // Add an option in the menu to run all auto#.g files
      //#define MENU_ADDAUTOSTART
    
      /**
       * Continue after Power-Loss (Creality3D)
       *
       * Store the current state to the SD Card at the start of each layer
       * during SD printing. If the recovery file is found at boot time, present
       * an option on the LCD screen to continue the print from the last-known
       * point in the file.
       */
      //#define POWER_LOSS_RECOVERY
      #if ENABLED(POWER_LOSS_RECOVERY)
        //#define POWER_LOSS_PIN   44     // Pin to detect power loss
        //#define POWER_LOSS_STATE HIGH   // State of pin indicating power loss
      #endif
    
      /**
       * Sort SD file listings in alphabetical order.
       *
       * With this option enabled, items on SD cards will be sorted
       * by name for easier navigation.
       *
       * By default...
       *
       *  - Use the slowest -but safest- method for sorting.
       *  - Folders are sorted to the top.
       *  - The sort key is statically allocated.
       *  - No added G-code (M34) support.
       *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
       *
       * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
       * compiler to calculate the worst-case usage and throw an error if the SRAM
       * limit is exceeded.
       *
       *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
       *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
       *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
       *  - SDSORT_DYNAMIC_RAM only uses RAM when the SD menu is visible. (Use with caution!)
       */
      #define SDCARD_SORT_ALPHA
    
      // SD Card Sorting options
      #if ENABLED(SDCARD_SORT_ALPHA)
        #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256). Costs 27 bytes each.
        #define FOLDER_SORTING     1      // -1=above  0=none  1=below
        #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
        #define SDSORT_USES_RAM    true   // Pre-allocate a static array for faster pre-sorting.
        #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
        #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
        #define SDSORT_DYNAMIC_RAM false  // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use!
        #define SDSORT_CACHE_VFATS 2      // Maximum number of 13-byte VFAT entries to use for sorting.
                                          // Note: Only affects SCROLL_LONG_FILENAMES with SDSORT_CACHE_NAMES but not SDSORT_DYNAMIC_RAM.
      #endif

     

    Edited by MarkF
  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Like
        • 2 replies
      • UltiMaker Cura 5.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 26 replies
    ×
    ×
    • Create New...