Prusa MINI Firmware overview
screen_filebrowser.cpp File Reference
#include "gui.h"
#include "dbg.h"
#include "window_file_list.h"
#include "window_header.h"
#include "config.h"
#include "stdlib.h"
#include "usb_host.h"
#include "cmsis_os.h"
#include "marlin_client.h"
#include "screen_print_preview.h"
#include "screen_printing.h"
#include "print_utils.h"
#include "../Marlin/src/sd/cardreader.h"
#include "../Marlin/src/gcode/queue.h"
#include "../Marlin/src/gcode/lcd/M73_PE.h"

Classes

struct  screen_filebrowser_data_t
 

Macros

#define MAXPATHNAMELENGTH   F_MAXPATHNAMELENGTH
 
#define LOG_ERROR(...)   _dbg3("FILEBROWSER ERROR: " __VA_ARGS__)
 
#define pd   ((screen_filebrowser_data_t *)screen->pdata)
 

Functions

static void screen_filebrowser_init (screen_t *screen)
 
static void screen_filebrowser_done (_screen_t *screen)
 
static void screen_filebrowser_draw (screen_t *screen)
 
static void on_print_preview_action (print_preview_action_t action)
 
static int screen_filebrowser_event (screen_t *screen, window_t *window, uint8_t event, void *param)
 

Variables

static WF_Sort_t screen_filebrowser_sort = WF_SORT_BY_TIME
 
static const char * filters [] = { "*.gcode", "*.gco", "*.g" }
 
static const size_t filt_cnt = sizeof(filters) / sizeof(const char *)
 
static screen_t screen_filebrowser
 
const screen_tpscreen_filebrowser = &screen_filebrowser
 

Macro Definition Documentation

◆ MAXPATHNAMELENGTH

#define MAXPATHNAMELENGTH   F_MAXPATHNAMELENGTH

◆ LOG_ERROR

#define LOG_ERROR (   ...)    _dbg3("FILEBROWSER ERROR: " __VA_ARGS__)

◆ pd

#define pd   ((screen_filebrowser_data_t *)screen->pdata)

Function Documentation

◆ screen_filebrowser_init()

static void screen_filebrowser_init ( screen_t screen)
static
47  {
48  // TODO: load screen_filebrowser_sort from eeprom
49  // FIXME: this could crash with very fast insert and eject, status_header will fix this
50  marlin_event_clr(MARLIN_EVT_MediaRemoved); // when screen is open, USB must be inserted
51 
52  int16_t id;
53  int16_t root = window_create_ptr(WINDOW_CLS_FRAME, -1,
54  rect_ui16(0, 0, 0, 0),
55  &(pd->root));
56  window_disable(root); // hack for do not change capture
57 
59  rect_ui16(0, 0, 240, 31), &(pd->header));
61  p_window_header_set_text(&(pd->header), "SELECT FILE");
62 
64  rect_ui16(10, 32, 220, 278),
65  &(pd->w_filelist));
67  window_file_set_item_index(&(pd->w_filelist), 1);
68  window_set_capture(id); // hack for do not change capture
69  window_set_focus(id); // hack for do not change capture
70 }
Here is the call graph for this function:

◆ screen_filebrowser_done()

static void screen_filebrowser_done ( _screen_t screen)
static
72  {
73  window_destroy(pd->root.win.id);
74 }
Here is the call graph for this function:

◆ screen_filebrowser_draw()

static void screen_filebrowser_draw ( screen_t screen)
static
76 {}

◆ on_print_preview_action()

static void on_print_preview_action ( print_preview_action_t  action)
static
78  {
79  if (action == PRINT_PREVIEW_ACTION_BACK) {
80  screen_close(); // close the print preview
81  } else if (action == PRINT_PREVIEW_ACTION_PRINT) {
82  screen_close(); // close the print preview
83  screen_close(); // close the file browser
86  }
87 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ screen_filebrowser_event()

static int screen_filebrowser_event ( screen_t screen,
window_t window,
uint8_t  event,
void param 
)
static
90  {
91  if (marlin_event_clr(MARLIN_EVT_MediaRemoved)) { // close screen when media removed
92  screen_close();
93  return 1;
94  }
95 
96  window_header_events(&(pd->header));
97 
98  window_file_list_t *filelist = &(pd->w_filelist);
99 
100  if (event != WINDOW_EVENT_CLICK) {
101  return 0;
102  }
103 
104  const FILINFO *file_item = &(filelist->file_items[(intptr_t)param]);
105  //there must be fname, not altname
106  if (!strcmp(file_item->fname, "..") && !strcmp(filelist->altpath, "/")) {
107  screen_close();
108  return 1;
109  }
110 
111  if (file_item->fattrib & AM_DIR) { // directory selected
112  if (strcmp(file_item->fname, "..")) { // not same -> not ..
113  if ((strlen(filelist->altpath) + strlen(file_item->altname) + 1) >= MAXPATHNAMELENGTH) {
114  LOG_ERROR("path too long");
115  return 0;
116  }
117 
118  size_t len = strlen(filelist->altpath);
119  if (filelist->altpath[len - 1] != '/') {
120  filelist->altpath[len++] = '/';
121  }
122  strcpy(filelist->altpath + len, file_item->altname[0] == 0 ? file_item->fname : file_item->altname);
124  window_set_text(pd->header.win.id, strrchr(filelist->altpath, '/'));
125  } else {
126  char *last = strrchr(filelist->altpath, '/');
127  if (last == filelist->altpath) {
128  strcpy(last, "/");
129  } else {
130  last[0] = '\0'; // stop the string :D
131  }
133  window_set_text(pd->header.win.id, strrchr(filelist->altpath, '/'));
134  }
135  } else { // print the file
136  if ((strlen(filelist->altpath) + strlen(file_item->altname) + 1) >= MAXPATHNAMELENGTH) {
137  LOG_ERROR("path too long");
138  return 0;
139  }
140 
141  int written;
142  if (!strcmp(filelist->altpath, "/"))
143  written = snprintf(screen_printing_file_path, sizeof(screen_printing_file_path),
144  "/%s", file_item->altname);
145  else
146  written = snprintf(screen_printing_file_path, sizeof(screen_printing_file_path),
147  "%s/%s", filelist->altpath, file_item->altname);
148 
149  if (written < 0 || written >= (int)sizeof(screen_printing_file_path)) {
150  LOG_ERROR("failed to prepare file path for print");
151  return 0;
152  }
153 
154  strcpy(screen_printing_file_name, file_item->fname);
155 
160  return 1;
161  }
162 
163  return 0;
164 }
Here is the call graph for this function:

Variable Documentation

◆ screen_filebrowser_sort

WF_Sort_t screen_filebrowser_sort = WF_SORT_BY_TIME
static

◆ filters

const char* filters[] = { "*.gcode", "*.gco", "*.g" }
static

◆ filt_cnt

const size_t filt_cnt = sizeof(filters) / sizeof(const char *)
static

◆ screen_filebrowser

◆ pscreen_filebrowser

const screen_t* pscreen_filebrowser = &screen_filebrowser
PRINT_PREVIEW_ACTION_PRINT
Definition: screen_print_preview.h:10
print_begin
void print_begin(const char *filename)
Definition: print_utils.cpp:6
IDR_PNG_filescreen_icon_folder
#define IDR_PNG_filescreen_icon_folder
Definition: resource.h:41
window_header_events
#define window_header_events(window)
Definition: window_header.h:72
FILINFO::fattrib
BYTE fattrib
Definition: ff.h:201
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)
Definition: window_file_list.c:63
screen_filebrowser_data_t
Definition: screen_filebrowser.cpp:31
pd
#define pd
Definition: screen_filebrowser.cpp:39
screen_filebrowser_init
static void screen_filebrowser_init(screen_t *screen)
Definition: screen_filebrowser.cpp:47
screen_printing_file_path
char screen_printing_file_path[_MAX_LFN+2]
Definition: screen_printing.cpp:165
rect_ui16
static rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition: guitypes.h:159
screen_print_preview_get_gcode_filepath
const char * screen_print_preview_get_gcode_filepath()
Definition: screen_print_preview.c:85
window_destroy
void window_destroy(int16_t id)
Definition: window.c:132
_window_file_list_t::altpath
char altpath[F_MAXPATHNAMELENGTH - 12]
Definition: window_file_list.h:73
screen_filebrowser_draw
static void screen_filebrowser_draw(screen_t *screen)
Definition: screen_filebrowser.cpp:76
screen_printing_file_name
char screen_printing_file_name[_MAX_LFN+1]
Definition: screen_printing.cpp:164
screen_print_preview_set_gcode_filename
void screen_print_preview_set_gcode_filename(const char *fname)
Definition: screen_print_preview.c:89
screen_open
void screen_open(int16_t screen_id)
Definition: screen.c:62
on_print_preview_action
static void on_print_preview_action(print_preview_action_t action)
Definition: screen_filebrowser.cpp:78
screen_close
void screen_close(void)
Definition: screen.c:80
PRINT_PREVIEW_ACTION_BACK
Definition: screen_print_preview.h:9
window_disable
void window_disable(int16_t id)
Definition: window.c:523
window_set_text
void window_set_text(int16_t id, const char *text)
Definition: window.c:340
screen_filebrowser_done
static void screen_filebrowser_done(_screen_t *screen)
Definition: screen_filebrowser.cpp:72
pscreen_printing
screen_t * pscreen_printing
Definition: screen_printing.cpp:161
WINDOW_CLS_FRAME
#define WINDOW_CLS_FRAME
Definition: window.h:9
screen_filebrowser_event
static int screen_filebrowser_event(screen_t *screen, window_t *window, uint8_t event, void *param)
Definition: screen_filebrowser.cpp:89
window_set_focus
void window_set_focus(int16_t id)
Definition: window.c:480
filt_cnt
static const size_t filt_cnt
Definition: screen_filebrowser.cpp:45
window_set_capture
void window_set_capture(int16_t id)
Definition: window.c:500
screen_print_preview_set_gcode_filepath
void screen_print_preview_set_gcode_filepath(const char *fpath)
Definition: screen_print_preview.c:81
_window_file_list_t::file_items
FILINFO file_items[SDSORT_LIMIT]
Definition: window_file_list.h:74
FILINFO::fname
TCHAR fname[13]
Definition: ff.h:206
screen_print_preview_set_on_action
void screen_print_preview_set_on_action(print_preview_action_handler_t handler)
Definition: screen_print_preview.c:93
AM_DIR
#define AM_DIR
Definition: ff.h:354
screen_filebrowser_sort
static WF_Sort_t screen_filebrowser_sort
Definition: screen_filebrowser.cpp:42
WINDOW_EVENT_CLICK
#define WINDOW_EVENT_CLICK
Definition: window.h:46
WINDOW_CLS_FILE_LIST
int16_t WINDOW_CLS_FILE_LIST
Definition: window_file_list.c:24
MAXPATHNAMELENGTH
#define MAXPATHNAMELENGTH
Definition: screen_filebrowser.cpp:26
window_create_ptr
int16_t window_create_ptr(int16_t cls_id, int16_t id_parent, rect_ui16_t rect, void *ptr)
Definition: window.c:102
_screen_t::id
int16_t id
Definition: screen.h:19
window_file_set_item_index
void window_file_set_item_index(window_file_list_t *window, int index)
Definition: window_file_list.c:118
WINDOW_CLS_HEADER
int16_t WINDOW_CLS_HEADER
Definition: window_header.c:24
MARLIN_EVT_MediaRemoved
#define MARLIN_EVT_MediaRemoved
Definition: marlin_events.h:13
filters
static const char * filters[]
Definition: screen_filebrowser.cpp:44
LOG_ERROR
#define LOG_ERROR(...)
Definition: screen_filebrowser.cpp:29
_window_file_list_t
Definition: window_file_list.h:62
p_window_header_set_icon
void p_window_header_set_icon(window_header_t *window, uint16_t id_res)
Definition: window_header.c:121
pscreen_print_preview
screen_t *const pscreen_print_preview
Definition: screen_print_preview.c:77
FILINFO
Definition: ff.h:197
p_window_header_set_text
void p_window_header_set_text(window_header_t *window, const char *text)
Definition: window_header.c:152
marlin_event_clr
int marlin_event_clr(uint8_t evt_id)
Definition: marlin_client.c:252