Prusa MINI Firmware overview
window_file_list.c File Reference
#include "window_file_list.h"
#include "gui.h"
#include "config.h"
#include "fatfs.h"
#include "dbg.h"

Functions

int pattern_matching (const TCHAR *pat, const TCHAR *nam, int skip, int inf)
 
void window_file_list_inc (window_file_list_t *window, int dif)
 
void window_file_list_dec (window_file_list_t *window, int dif)
 
int file_item_cmp_by_is_dir (const FILINFO *ia, const FILINFO *ib)
 
int file_item_cmp_by_name (const void *a, const void *b)
 
int file_item_cmp_by_time (const void *a, const void *b)
 
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)
 
void window_file_list_init (window_file_list_t *window)
 
void window_file_list_done (window_file_list_t *window)
 
void window_file_list_draw (window_file_list_t *window)
 
void window_file_list_event (window_file_list_t *window, uint8_t event, void *param)
 

Variables

int16_t WINDOW_CLS_FILE_LIST = 0
 
const window_class_file_list_t window_class_file_list
 

Function Documentation

◆ pattern_matching()

int pattern_matching ( const TCHAR pat,
const TCHAR nam,
int  skip,
int  inf 
)
Here is the caller graph for this function:

◆ window_file_list_inc()

void window_file_list_inc ( window_file_list_t window,
int  dif 
)
224  {
225  int item_height = window->font->h + window->padding.top + window->padding.bottom;
226  int visible_count = window->win.rect.h / item_height;
227  int old = window->index;
228  window->index += dif;
229  if (window->index >= window->count)
230  window->index = window->count - 1;
231  if (window->index >= (window->top_index + visible_count))
232  window->top_index = window->index - visible_count + 1;
233 
234  if (window->index != old)
235  _window_invalidate((window_t *)window);
236 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_file_list_dec()

void window_file_list_dec ( window_file_list_t window,
int  dif 
)
238  {
239  int old = window->index;
240  window->index -= dif;
241  if (window->index < 0)
242  window->index = 0;
243  if (window->index < window->top_index)
244  window->top_index = window->index;
245 
246  if (window->index != old)
247  _window_invalidate((window_t *)window);
248 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_item_cmp_by_is_dir()

int file_item_cmp_by_is_dir ( const FILINFO ia,
const FILINFO ib 
)
30  {
31  return (ib->fattrib & AM_DIR) - (ia->fattrib & AM_DIR); // directory (1) first
32 }
Here is the caller graph for this function:

◆ file_item_cmp_by_name()

int file_item_cmp_by_name ( const void a,
const void b 
)
34  {
35  const FILINFO *ia = (FILINFO *)a;
36  const FILINFO *ib = (FILINFO *)b;
37 
38  int rv = file_item_cmp_by_is_dir(ia, ib);
39  if (rv)
40  return rv;
41 
42  rv = strcmp(ia->fname, ib->fname);
43  return rv;
44 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_item_cmp_by_time()

int file_item_cmp_by_time ( const void a,
const void b 
)
46  {
47  FILINFO *ia = (FILINFO *)a;
48  FILINFO *ib = (FILINFO *)b;
49 
50  int rv = file_item_cmp_by_is_dir(ia, ib);
51  if (rv)
52  return rv;
53 
54  if (ia->fdate != ib->fdate) {
55  return ib->fdate - ia->fdate;
56  }
57  if (ia->ftime != ib->ftime) {
58  return ib->ftime - ia->ftime;
59  }
60  return file_item_cmp_by_name(a, b);
61 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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:

◆ window_file_list_init()

void window_file_list_init ( window_file_list_t window)
125  {
128  window->font = gui_defaults.font;
129  window->padding = padding_ui8(2, 6, 2, 6);
130  window->alignment = ALIGN_LEFT_CENTER;
131  window->win.flg |= WINDOW_FLG_ENABLED;
132 
133  strcpy(window->altpath, "/");
134 }
Here is the call graph for this function:

◆ window_file_list_done()

void window_file_list_done ( window_file_list_t window)
136 {}

◆ window_file_list_draw()

void window_file_list_draw ( window_file_list_t window)
138  {
139  int item_height = window->font->h + window->padding.top + window->padding.bottom;
140  rect_ui16_t rc_win = window->win.rect;
141 
142  int visible_count = rc_win.h / item_height;
143  int i;
144  for (i = 0; i < visible_count && i < window->count; i++) {
145  int idx = i + window->top_index;
146  uint16_t id_icon = IDR_NULL;
147  if (idx == 0) {
148  id_icon = (!strcmp(window->altpath, "/")) ? IDR_PNG_filescreen_icon_home : IDR_PNG_filescreen_icon_up_folder;
149  } else if (window->file_items[idx].fattrib & AM_DIR) {
151  }
152 
153  color_t color_text = window->color_text;
154  color_t color_back = window->color_back;
155  uint8_t swap = 0;
156 
157  rect_ui16_t rc = { rc_win.x, rc_win.y + i * item_height,
158  rc_win.w, item_height };
159  padding_ui8_t padding = window->padding;
160 
161  if (rect_in_rect_ui16(rc, rc_win)) {
162  /* TODO: disabled file types
163  if (window->file_items[idx].flg & WF_DISABLED)
164  {
165  color_text = window->color_disabled;
166  }
167  */
168 
169  if ((window->win.flg & WINDOW_FLG_FOCUSED) && (window->index == idx)) {
170  color_t swp = color_text;
171  color_text = color_back;
172  color_back = swp;
173  swap = ROPFN_SWAPBW;
174  }
175 
176  if (id_icon) {
177  rect_ui16_t irc = { rc.x, rc.y, 16, 30 };
178  rc.x += irc.w;
179  rc.w -= irc.w;
180  render_icon_align(irc, id_icon,
181  window->color_back, RENDER_FLG(ALIGN_CENTER, swap));
182  } else {
183  padding.left += 16;
184  }
185 
186  render_text_align(rc, window->file_items[idx].fname, window->font,
187  color_back, color_text,
188  padding, window->alignment);
189 
190  /* too slow
191  display->draw_line(
192  point_ui16(rc_win.x, rc_win.y + (i+1) * item_height-1),
193  point_ui16(rc_win.x+rc_win.w, rc_win.y + (i+1) * item_height-1),
194  COLOR_GRAY);
195  */
196  }
197  }
198 
199  rc_win.h = rc_win.h - (i * item_height);
200 
201  if (rc_win.h) {
202  rc_win.y += i * item_height;
203  display->fill_rect(rc_win, window->color_back);
204  }
205 }
Here is the call graph for this function:

◆ window_file_list_event()

void window_file_list_event ( window_file_list_t window,
uint8_t  event,
void param 
)
207  {
208  switch (event) {
209  case WINDOW_EVENT_BTN_DN:
211  break;
212  case WINDOW_EVENT_ENC_DN:
213  window_file_list_dec(window, (int)param);
214  break;
215  case WINDOW_EVENT_ENC_UP:
216  window_file_list_inc(window, (int)param);
217  break;
218  case WINDOW_EVENT_CAPT_1:
219  //TODO: change flag to checked
220  break;
221  }
222 }
Here is the call graph for this function:

Variable Documentation

◆ WINDOW_CLS_FILE_LIST

int16_t WINDOW_CLS_FILE_LIST = 0

◆ window_class_file_list

RENDER_FLG
#define RENDER_FLG(a, r)
Definition: display_helper.h:10
window_draw_t
void() window_draw_t(void *window)
Definition: window.h:57
WINDOW_EVENT_CAPT_1
#define WINDOW_EVENT_CAPT_1
Definition: window.h:45
_rect_ui16_t::y
uint16_t y
Definition: guitypes.h:71
_font_t::h
uint8_t h
Definition: guitypes.h:78
_rect_ui16_t::w
uint16_t w
Definition: guitypes.h:72
window_file_list_t
struct _window_file_list_t window_file_list_t
Definition: window_file_list.h:46
_padding_ui8_t::bottom
uint8_t bottom
Definition: guitypes.h:90
_window_file_list_t::count
int count
Definition: window_file_list.h:69
AM_HID
#define AM_HID
Definition: ff.h:352
_gui_defaults_t::color_text
color_t color_text
Definition: guitypes.h:108
_padding_ui8_t::top
uint8_t top
Definition: guitypes.h:88
IDR_PNG_filescreen_icon_folder
#define IDR_PNG_filescreen_icon_folder
Definition: resource.h:41
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
window_file_list_dec
void window_file_list_dec(window_file_list_t *window, int dif)
Definition: window_file_list.c:238
WINDOW_EVENT_ENC_UP
#define WINDOW_EVENT_ENC_UP
Definition: window.h:41
ALIGN_CENTER
#define ALIGN_CENTER
Definition: guitypes.h:19
_gui_defaults_t::font
font_t * font
Definition: guitypes.h:110
_window_file_list_t::font
font_t * font
Definition: window_file_list.h:66
FILINFO::fdate
WORD fdate
Definition: ff.h:199
_window_file_list_t::altpath
char altpath[F_MAXPATHNAMELENGTH - 12]
Definition: window_file_list.h:73
padding_ui8
static padding_ui8_t padding_ui8(uint8_t l, uint8_t t, uint8_t r, uint8_t b)
Definition: guitypes.h:164
i
uint8_t i
Definition: screen_test_graph.c:72
WINDOW_CLS_USER
#define WINDOW_CLS_USER
Definition: window.h:21
IDR_NULL
#define IDR_NULL
Definition: resource.h:6
rect_in_rect_ui16
static int rect_in_rect_ui16(rect_ui16_t rc, rect_ui16_t rc1)
Definition: guitypes.h:173
IDR_PNG_filescreen_icon_home
#define IDR_PNG_filescreen_icon_home
Definition: resource.h:40
NULL
#define NULL
Definition: usbd_def.h:53
window_file_list_draw
void window_file_list_draw(window_file_list_t *window)
Definition: window_file_list.c:138
_window_file_list_t::alignment
uint8_t alignment
Definition: window_file_list.h:68
_window_file_list_t::index
int index
Definition: window_file_list.h:70
file_item_cmp_by_is_dir
int file_item_cmp_by_is_dir(const FILINFO *ia, const FILINFO *ib)
Definition: window_file_list.c:30
_display_t::fill_rect
display_fill_rect_t * fill_rect
Definition: display.h:33
_padding_ui8_t::left
uint8_t left
Definition: guitypes.h:87
window_done_t
void() window_done_t(void *window)
Definition: window.h:56
window_file_list_done
void window_file_list_done(window_file_list_t *window)
Definition: window_file_list.c:136
file_item_cmp_by_name
int file_item_cmp_by_name(const void *a, const void *b)
Definition: window_file_list.c:34
_window_file_list_t::color_text
color_t color_text
Definition: window_file_list.h:65
_window_t
Definition: window.h:76
_window_file_list_t::padding
padding_ui8_t padding
Definition: window_file_list.h:67
FILINFO::ftime
WORD ftime
Definition: ff.h:200
_gui_defaults_t::color_back
color_t color_back
Definition: guitypes.h:107
SDSORT_LIMIT
#define SDSORT_LIMIT
Definition: window_file_list.h:27
IDR_PNG_filescreen_icon_up_folder
#define IDR_PNG_filescreen_icon_up_folder
Definition: resource.h:42
_padding_ui8_t
Definition: guitypes.h:86
ROPFN_SWAPBW
#define ROPFN_SWAPBW
Definition: guitypes.h:32
createSpeedLookupTable.a
list a
Definition: createSpeedLookupTable.py:29
_window_file_list_t::file_items
FILINFO file_items[SDSORT_LIMIT]
Definition: window_file_list.h:74
window_file_list_inc
void window_file_list_inc(window_file_list_t *window, int dif)
Definition: window_file_list.c:224
_window_file_list_t::color_back
color_t color_back
Definition: window_file_list.h:64
window_event_t
void() window_event_t(void *window, uint8_t event, void *param)
Definition: window.h:58
_rect_ui16_t
Definition: guitypes.h:69
render_text_align
void render_text_align(rect_ui16_t rc, const char *text, font_t *font, color_t clr0, color_t clr1, padding_ui8_t padding, uint16_t flags)
Definition: display_helper.c:6
uint8_t
const uint8_t[]
Definition: 404_html.c:3
_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
display
display_t * display
Definition: display.c:6
_rect_ui16_t::h
uint16_t h
Definition: guitypes.h:73
window_file_list_event
void window_file_list_event(window_file_list_t *window, uint8_t event, void *param)
Definition: window_file_list.c:207
_window_t::rect
rect_ui16_t rect
Definition: window.h:101
FRESULT
FRESULT
Definition: ff.h:214
AM_DIR
#define AM_DIR
Definition: ff.h:354
f_findnext
FRESULT f_findnext(DIR *dp, FILINFO *fno)
WINDOW_EVENT_CLICK
#define WINDOW_EVENT_CLICK
Definition: window.h:46
WINDOW_FLG_FOCUSED
#define WINDOW_FLG_FOCUSED
Definition: window.h:27
FR_OK
Definition: ff.h:215
DIR
Definition: ff.h:178
_rect_ui16_t::x
uint16_t x
Definition: guitypes.h:70
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
color_t
uint32_t color_t
Definition: guitypes.h:62
window_init_t
void() window_init_t(void *window)
Definition: window.h:55
filters
static const char * filters[]
Definition: screen_filebrowser.cpp:44
gui_defaults
gui_defaults_t gui_defaults
Definition: gui.c:20
render_icon_align
void render_icon_align(rect_ui16_t rc, uint16_t id_res, color_t clr0, uint16_t flags)
Definition: display_helper.c:55
WINDOW_EVENT_BTN_DN
#define WINDOW_EVENT_BTN_DN
Definition: window.h:38
window_file_list_init
void window_file_list_init(window_file_list_t *window)
Definition: window_file_list.c:125
f_closedir
FRESULT f_closedir(DIR *dp)
Definition: ff.c:4291
_window_t::flg
uint32_t flg
Definition: window.h:81
f_findfirst
FRESULT f_findfirst(DIR *dp, FILINFO *fno, const TCHAR *path, const TCHAR *pattern)
createSpeedLookupTable.b
list b
Definition: createSpeedLookupTable.py:30
screen_dispatch_event
void screen_dispatch_event(window_t *window, uint8_t event, void *param)
Definition: screen.c:103
FILINFO
Definition: ff.h:197
WINDOW_FLG_ENABLED
#define WINDOW_FLG_ENABLED
Definition: window.h:25
_window_invalidate
static void _window_invalidate(window_t *window)
Definition: window.h:257
WINDOW_EVENT_ENC_DN
#define WINDOW_EVENT_ENC_DN
Definition: window.h:40
_window_file_list_t::win
window_t win
Definition: window_file_list.h:63
ALIGN_LEFT_CENTER
#define ALIGN_LEFT_CENTER
Definition: guitypes.h:21
info
uint8_t info[12]
Definition: masstorage.h:54