Prusa MINI Firmware overview
window_file_list.h File Reference
#include "window.h"
#include "ffconf.h"
#include "ff.h"

Go to the source code of this file.

Classes

struct  _window_class_file_list_t
 
struct  _window_file_list_t
 

Macros

#define SDSORT_LIMIT   64
 
#define FOLDER_SORTING   -1
 
#define MAX_DIR_DEPTH   10
 
#define F_MAXDIRNAMELENGTH   _MAX_LFN + 1
 
#define F_MAXPATHNAMELENGTH   (1 + (F_MAXDIRNAMELENGTH + 1) * (MAX_DIR_DEPTH) + 1 + _MAX_LFN)
 

Typedefs

typedef struct _window_file_list_t window_file_list_t
 
typedef struct _window_class_file_list_t window_class_file_list_t
 

Enumerations

enum  WF_Sort_t { WF_SORT_BY_TIME, WF_SORT_BY_NAME }
 

Functions

void window_file_list_load (window_file_list_t *window, const char **filters, size_t filters_cnt, WF_Sort_t sort)
 
void window_file_set_item_index (window_file_list_t *window, int index)
 

Variables

int16_t WINDOW_CLS_FILE_LIST
 
const window_class_file_list_t window_class_file_list
 

Macro Definition Documentation

◆ SDSORT_LIMIT

#define SDSORT_LIMIT   64

◆ FOLDER_SORTING

#define FOLDER_SORTING   -1

◆ MAX_DIR_DEPTH

#define MAX_DIR_DEPTH   10

◆ F_MAXDIRNAMELENGTH

#define F_MAXDIRNAMELENGTH   _MAX_LFN + 1

◆ F_MAXPATHNAMELENGTH

#define F_MAXPATHNAMELENGTH   (1 + (F_MAXDIRNAMELENGTH + 1) * (MAX_DIR_DEPTH) + 1 + _MAX_LFN)

Typedef Documentation

◆ window_file_list_t

◆ window_class_file_list_t

Enumeration Type Documentation

◆ WF_Sort_t

enum WF_Sort_t
Enumerator
WF_SORT_BY_TIME 
WF_SORT_BY_NAME 
80  {
83 
84 } WF_Sort_t;

Function Documentation

◆ window_file_list_load()

void window_file_list_load ( window_file_list_t window,
const char **  filters,
size_t  filters_cnt,
WF_Sort_t  sort 
)
64  {
65  DIR dir;
66  FRESULT fres;
67  FILINFO info;
68  int i = 0;
69 
70  memset(window->file_items, '\0', SDSORT_LIMIT * sizeof(FILINFO));
71 
72  strcpy(window->file_items[i].fname, "..");
73  window->file_items[i].fattrib |= AM_DIR;
74  window->file_items[i].ftime = UINT16_MAX;
75  window->file_items[i++].fdate = UINT16_MAX;
76 
77  fres = f_findfirst(&dir, &info, window->altpath, "*");
78  if (fres != FR_OK) {
79  _dbg("Findfirst error: %d", fres);
80  }
81 
82  int pattern_match;
83  while (fres == FR_OK && info.fname[0] && i < SDSORT_LIMIT) { /* Repeat while an item is found */
84  pattern_match = info.fattrib & AM_DIR; //print directory
85  for (size_t filt_no = 0; (!pattern_match) && (filt_no < filters_cnt); ++filt_no) {
86  if (pattern_matching(filters[filt_no], info.fname, 0, 0))
87  pattern_match = 1;
88  }
89 
90  if (info.fattrib & AM_SYS)
91  pattern_match = 0; //skip sys files
92  if (info.fattrib & AM_HID)
93  pattern_match = 0; //skip hidden files
94 
95  if (pattern_match) {
96  window->file_items[i++] = info;
97  }
98 
99  fres = f_findnext(&dir, &info);
100  }
101  if (i == SDSORT_LIMIT) {
102  // TODO: Notification
103  }
104 
105  f_closedir(&dir);
106  if (sort == WF_SORT_BY_NAME) {
107  qsort(window->file_items, i, sizeof(window->file_items[0]), file_item_cmp_by_name);
108  } else {
109  qsort(window->file_items, i, sizeof(window->file_items[0]), file_item_cmp_by_time);
110  }
111 
112  window->count = i;
113  window->index = 0;
114  window->top_index = 0;
115  _window_invalidate((window_t *)window);
116 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_file_set_item_index()

void window_file_set_item_index ( window_file_list_t window,
int  index 
)
118  {
119  if (window->count > index) {
120  window->index = index;
121  _window_invalidate((window_t *)window);
122  }
123 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ WINDOW_CLS_FILE_LIST

int16_t WINDOW_CLS_FILE_LIST

◆ window_class_file_list

const window_class_file_list_t window_class_file_list
_window_file_list_t::count
int count
Definition: window_file_list.h:69
AM_HID
#define AM_HID
Definition: ff.h:352
WF_SORT_BY_NAME
Definition: window_file_list.h:82
FILINFO::fattrib
BYTE fattrib
Definition: ff.h:201
file_item_cmp_by_time
int file_item_cmp_by_time(const void *a, const void *b)
Definition: window_file_list.c:46
FILINFO::fdate
WORD fdate
Definition: ff.h:199
_window_file_list_t::altpath
char altpath[F_MAXPATHNAMELENGTH - 12]
Definition: window_file_list.h:73
i
uint8_t i
Definition: screen_test_graph.c:72
WF_SORT_BY_TIME
Definition: window_file_list.h:81
_window_file_list_t::index
int index
Definition: window_file_list.h:70
file_item_cmp_by_name
int file_item_cmp_by_name(const void *a, const void *b)
Definition: window_file_list.c:34
_window_t
Definition: window.h:76
FILINFO::ftime
WORD ftime
Definition: ff.h:200
SDSORT_LIMIT
#define SDSORT_LIMIT
Definition: window_file_list.h:27
_window_file_list_t::file_items
FILINFO file_items[SDSORT_LIMIT]
Definition: window_file_list.h:74
_dbg
#define _dbg(...)
Definition: dbg.h:50
FILINFO::fname
TCHAR fname[13]
Definition: ff.h:206
AM_SYS
#define AM_SYS
Definition: ff.h:353
WF_Sort_t
WF_Sort_t
Definition: window_file_list.h:80
FRESULT
FRESULT
Definition: ff.h:214
AM_DIR
#define AM_DIR
Definition: ff.h:354
f_findnext
FRESULT f_findnext(DIR *dp, FILINFO *fno)
FR_OK
Definition: ff.h:215
DIR
Definition: ff.h:178
pattern_matching
int pattern_matching(const TCHAR *pat, const TCHAR *nam, int skip, int inf)
_window_file_list_t::top_index
int top_index
Definition: window_file_list.h:71
filters
static const char * filters[]
Definition: screen_filebrowser.cpp:44
f_closedir
FRESULT f_closedir(DIR *dp)
Definition: ff.c:4291
f_findfirst
FRESULT f_findfirst(DIR *dp, FILINFO *fno, const TCHAR *path, const TCHAR *pattern)
FILINFO
Definition: ff.h:197
_window_invalidate
static void _window_invalidate(window_t *window)
Definition: window.h:257
info
uint8_t info[12]
Definition: masstorage.h:54