Prusa MINI Firmware overview
screen_home.cpp File Reference
#include "ff.h"
#include "dbg.h"
#include "gui.h"
#include "config.h"
#include "window_header.h"
#include "status_footer.h"
#include "marlin_client.h"
#include "screen_print_preview.h"
#include "screen_printing.h"
#include "print_utils.h"
#include "../Marlin/src/sd/cardreader.h"

Classes

struct  screen_home_data_t
 

Macros

#define BUTTON_PRINT   0
 
#define BUTTON_PREHEAT   1
 
#define BUTTON_FILAMENT   2
 
#define BUTTON_CALIBRATION   3
 
#define BUTTON_SETTINGS   4
 
#define BUTTON_INFO   5
 
#define pw   ((screen_home_data_t *)screen->pdata)
 

Functions

static bool find_latest_gcode (char *fpath, int fpath_len, char *fname, int fname_len)
 
void screen_home_disable_print_button (screen_t *screen)
 
void screen_home_init (screen_t *screen)
 
void screen_home_done (screen_t *screen)
 
void screen_home_draw (screen_t *screen)
 
static void on_print_preview_action (print_preview_action_t action)
 
int screen_home_event (screen_t *screen, window_t *window, uint8_t event, void *param)
 

Variables

screen_tpscreen_filebrowser
 
screen_tpscreen_menu_preheat
 
uint8_t menu_preheat_type
 
screen_tpscreen_menu_filament
 
screen_tpscreen_menu_calibration
 
screen_tpscreen_menu_settings
 
screen_tpscreen_menu_info
 
const uint16_t icons [6]
 
const char * labels [7]
 
screen_t screen_home
 
const screen_tpscreen_home = &screen_home
 

Macro Definition Documentation

◆ BUTTON_PRINT

#define BUTTON_PRINT   0

◆ BUTTON_PREHEAT

#define BUTTON_PREHEAT   1

◆ BUTTON_FILAMENT

#define BUTTON_FILAMENT   2

◆ BUTTON_CALIBRATION

#define BUTTON_CALIBRATION   3

◆ BUTTON_SETTINGS

#define BUTTON_SETTINGS   4

◆ BUTTON_INFO

#define BUTTON_INFO   5

◆ pw

#define pw   ((screen_home_data_t *)screen->pdata)

Function Documentation

◆ find_latest_gcode()

static bool find_latest_gcode ( char *  fpath,
int  fpath_len,
char *  fname,
int  fname_len 
)
static
220  {
221  DIR dir = { 0 };
222 
223  FRESULT result = f_opendir(&dir, "/");
224  if (result != FR_OK) {
225  return false;
226  }
227 
228  fname[0] = 0;
229  WORD latest_fdate = 0;
230  WORD latest_ftime = 0;
231  FILINFO current_finfo = { 0 };
232 
233  result = f_findfirst(&dir, &current_finfo, "", "*.gcode");
234  while (result == FR_OK && current_finfo.fname[0]) {
235  bool skip = current_finfo.fattrib & AM_SYS
236  || current_finfo.fattrib & AM_HID;
237  bool is_newer = latest_fdate != current_finfo.fdate
238  ? latest_fdate < current_finfo.fdate
239  : latest_ftime < current_finfo.ftime;
240 
241  if ((fname[0] == 0 || is_newer) && !skip) {
242  const char *short_name = current_finfo.altname[0] ? current_finfo.altname : current_finfo.fname;
243  snprintf(fpath, fpath_len, "/%s", short_name);
244  snprintf(fname, fname_len, "%s", current_finfo.fname);
245  latest_fdate = current_finfo.fdate;
246  latest_ftime = current_finfo.ftime;
247  }
248 
249  result = f_findnext(&dir, &current_finfo);
250  }
251 
252  f_closedir(&dir);
253  return result == FR_OK && fname[0] != 0 ? true : false;
254 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ screen_home_disable_print_button()

void screen_home_disable_print_button ( screen_t screen)
256  {
257  pw->w_buttons[0].win.f_disabled = 1;
258  pw->w_buttons[0].win.f_enabled = 0; // cant't be focused
259  window_set_text(pw->w_labels[0].win.id, labels[6]);
260 
261  // move to preheat when Print is focused
262  if (window_is_focused(pw->w_buttons[0].win.id)) {
263  window_set_focus(pw->w_buttons[1].win.id);
264  }
265 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ screen_home_init()

void screen_home_init ( screen_t screen)
81  {
82  // Every 49days and some time in 5 seconds window, auto filebrowser open did not work.
83  // Seconds (timestamp) from UNIX epocho will fix this
84  pw->time = HAL_GetTick();
85  pw->is_starting = (pw->time < 5000) ? 1 : 0;
86 
87  int16_t id;
88 
89  int16_t root = window_create_ptr(WINDOW_CLS_FRAME, -1,
90  rect_ui16(0, 0, 0, 0), &(pw->root));
91 
93  rect_ui16(0, 0, 240, 31), &(pw->header));
95  p_window_header_set_text(&(pw->header), "HOME");
96 
98  rect_ui16(41, 31, 158, 40), &(pw->logo));
100 
101  for (uint8_t row = 0; row < 2; row++) {
102  for (uint8_t col = 0; col < 3; col++) {
103  id = window_create_ptr(
104  WINDOW_CLS_ICON, root,
105  rect_ui16(8 + (15 + 64) * col, 88 + (14 + 64) * row, 64, 64),
106  &(pw->w_buttons[row * 3 + col]));
108  window_set_icon_id(id, icons[row * 3 + col]);
109  window_set_tag(id, row * 3 + col + 1);
110  window_enable(id);
111 
112  /*
113  w_buttons[row*3+col] = window_icon_create(
114  win,
115  rect_ui16(8+(16+64)*col, 98+(14+64)*row, 64, 64),
116  IDR_PNG_menu_icon_square,
117  COLOR_BLACK);
118  */
119  id = window_create_ptr(
120  WINDOW_CLS_TEXT, root,
121  rect_ui16(80 * col, 152 + (15 + 64) * row, 80, 14),
122  &(pw->w_labels[row * 3 + col]));
123  pw->w_labels[row * 3 + col].font = resource_font(IDR_FNT_SMALL);
125  window_set_padding(id, padding_ui8(0, 0, 0, 0));
126  window_set_text(id, labels[row * 3 + col]);
127  }
128  }
129 
130  if (!IS_SD_INSERTED())
132 
133  status_footer_init(&(pw->footer), root);
134 }
Here is the call graph for this function:

◆ screen_home_done()

void screen_home_done ( screen_t screen)
136  {
137  window_destroy(pw->root.win.id);
138 }
Here is the call graph for this function:

◆ screen_home_draw()

void screen_home_draw ( screen_t screen)
140  {
141 }

◆ on_print_preview_action()

static void on_print_preview_action ( print_preview_action_t  action)
static
143  {
144  if (action == PRINT_PREVIEW_ACTION_BACK) {
145  screen_close(); // close the print preview
146  } else if (action == PRINT_PREVIEW_ACTION_PRINT) {
147  screen_close(); // close the print preview
150  }
151 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ screen_home_event()

int screen_home_event ( screen_t screen,
window_t window,
uint8_t  event,
void param 
)
153  {
154  if (status_footer_event(&(pw->footer), window, event, param)) {
155  return 1;
156  }
157 
158  if (pw->is_starting) // first 1000ms (cca 50ms is event period) skip MediaInserted
159  {
160  uint32_t now = HAL_GetTick();
161  if ((now - pw->time) > 950) {
162  pw->is_starting = 0;
163  }
167  }
168 
170 
171  (HAL_GetTick() > 5000)) {
172  // FIXME: currently, we are using the screen_printing_file_{name,path} buffers
173  // ... and we should not be
174  if (find_latest_gcode(
178  sizeof(screen_printing_file_name))) {
183  }
184  return 1;
185  }
186 
189  }
190 
191  if (event != WINDOW_EVENT_CLICK) {
192  return 0;
193  }
194 
195  switch ((int)param) {
196  case BUTTON_PRINT + 1:
198  return 1;
199  break;
200  case BUTTON_PREHEAT + 1:
201  menu_preheat_type = 0;
203  return 1;
204  case BUTTON_FILAMENT + 1:
206  return 1;
207  case BUTTON_CALIBRATION + 1:
209  return 1;
210  case BUTTON_SETTINGS + 1:
212  return 1;
213  case BUTTON_INFO + 1:
215  return 1;
216  }
217  return 0;
218 }
Here is the call graph for this function:

Variable Documentation

◆ pscreen_filebrowser

screen_t* pscreen_filebrowser

◆ pscreen_menu_preheat

screen_t* pscreen_menu_preheat

◆ menu_preheat_type

uint8_t menu_preheat_type

◆ pscreen_menu_filament

screen_t* pscreen_menu_filament

◆ pscreen_menu_calibration

screen_t* pscreen_menu_calibration

◆ pscreen_menu_settings

screen_t* pscreen_menu_settings

◆ pscreen_menu_info

screen_t* pscreen_menu_info

◆ icons

◆ labels

const char* labels[7]
Initial value:
= {
"Print",
"Preheat",
"Filament",
"Calibration",
"Settings",
"Info",
"No USB"
}

◆ screen_home

screen_t screen_home

◆ pscreen_home

const screen_t* pscreen_home = &screen_home
window_set_alignment
void window_set_alignment(int16_t id, uint8_t alignment)
Definition: window.c:561
IDR_PNG_status_logo_prusa_prn
#define IDR_PNG_status_logo_prusa_prn
Definition: resource.h:18
PRINT_PREVIEW_ACTION_PRINT
Definition: screen_print_preview.h:10
IDR_PNG_menu_icon_settings
#define IDR_PNG_menu_icon_settings
Definition: resource.h:33
labels
const char * labels[7]
Definition: screen_home.cpp:45
window_set_padding
void window_set_padding(int16_t id, padding_ui8_t padding)
Definition: window.c:549
IDR_PNG_menu_icon_spool
#define IDR_PNG_menu_icon_spool
Definition: resource.h:30
AM_HID
#define AM_HID
Definition: ff.h:352
print_begin
void print_begin(const char *filename)
Definition: print_utils.cpp:6
IDR_PNG_status_icon_home
#define IDR_PNG_status_icon_home
Definition: resource.h:25
MARLIN_EVT_MediaError
#define MARLIN_EVT_MediaError
Definition: marlin_events.h:12
window_set_color_back
void window_set_color_back(int16_t id, color_t clr)
Definition: window.c:431
FILINFO::fattrib
BYTE fattrib
Definition: ff.h:201
screen_printing_file_path
char screen_printing_file_path[_MAX_LFN+2]
Definition: screen_printing.cpp:165
ALIGN_CENTER
#define ALIGN_CENTER
Definition: guitypes.h:19
rect_ui16
static rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition: guitypes.h:159
on_print_preview_action
static void on_print_preview_action(print_preview_action_t action)
Definition: screen_home.cpp:143
WORD
unsigned short WORD
Definition: onboard_sd.h:14
FILINFO::fdate
WORD fdate
Definition: ff.h:199
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
padding_ui8
static padding_ui8_t padding_ui8(uint8_t l, uint8_t t, uint8_t r, uint8_t b)
Definition: guitypes.h:164
screen_printing_file_name
char screen_printing_file_name[_MAX_LFN+1]
Definition: screen_printing.cpp:164
screen_home_data_t
Definition: screen_home.cpp:58
window_set_icon_id
void window_set_icon_id(int16_t id, uint16_t id_res)
Definition: window.c:659
screen_print_preview_set_gcode_filename
void screen_print_preview_set_gcode_filename(const char *fname)
Definition: screen_print_preview.c:89
IDR_PNG_menu_icon_preheat
#define IDR_PNG_menu_icon_preheat
Definition: resource.h:29
BUTTON_SETTINGS
#define BUTTON_SETTINGS
Definition: screen_home.cpp:33
screen_open
void screen_open(int16_t screen_id)
Definition: screen.c:62
screen_home_event
int screen_home_event(screen_t *screen, window_t *window, uint8_t event, void *param)
Definition: screen_home.cpp:153
MARLIN_EVT_MediaInserted
#define MARLIN_EVT_MediaInserted
Definition: marlin_events.h:11
IDR_PNG_menu_icon_calibration
#define IDR_PNG_menu_icon_calibration
Definition: resource.h:32
screen_home_disable_print_button
void screen_home_disable_print_button(screen_t *screen)
Definition: screen_home.cpp:256
HAL_GetTick
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
Definition: stm32f4xx_hal.c:339
screen_close
void screen_close(void)
Definition: screen.c:80
pw
#define pw
Definition: screen_home.cpp:76
BUTTON_INFO
#define BUTTON_INFO
Definition: screen_home.cpp:34
find_latest_gcode
static bool find_latest_gcode(char *fpath, int fpath_len, char *fname, int fname_len)
Definition: screen_home.cpp:220
PRINT_PREVIEW_ACTION_BACK
Definition: screen_print_preview.h:9
COLOR_GRAY
#define COLOR_GRAY
Definition: guitypes.h:50
pscreen_menu_calibration
screen_t * pscreen_menu_calibration
Definition: screen_menu_calibration.c:101
window_set_text
void window_set_text(int16_t id, const char *text)
Definition: window.c:340
pscreen_printing
screen_t * pscreen_printing
Definition: screen_printing.cpp:161
IDR_PNG_menu_icon_info
#define IDR_PNG_menu_icon_info
Definition: resource.h:34
BUTTON_CALIBRATION
#define BUTTON_CALIBRATION
Definition: screen_home.cpp:32
WINDOW_CLS_FRAME
#define WINDOW_CLS_FRAME
Definition: window.h:9
FILINFO::ftime
WORD ftime
Definition: ff.h:200
f_opendir
FRESULT f_opendir(DIR *dp, const TCHAR *path)
Definition: ff.c:4221
BUTTON_FILAMENT
#define BUTTON_FILAMENT
Definition: screen_home.cpp:31
window_set_focus
void window_set_focus(int16_t id)
Definition: window.c:480
BUTTON_PREHEAT
#define BUTTON_PREHEAT
Definition: screen_home.cpp:30
screen_print_preview_set_gcode_filepath
void screen_print_preview_set_gcode_filepath(const char *fpath)
Definition: screen_print_preview.c:81
window_is_focused
int window_is_focused(int16_t id)
Definition: window.c:267
window_set_tag
void window_set_tag(int16_t id, uint8_t tag)
Definition: window.c:329
BUTTON_PRINT
#define BUTTON_PRINT
Definition: screen_home.cpp:29
uint8_t
const uint8_t[]
Definition: 404_html.c:3
pscreen_menu_preheat
screen_t * pscreen_menu_preheat
Definition: screen_menu_preheat.cpp:93
FILINFO::fname
TCHAR fname[13]
Definition: ff.h:206
AM_SYS
#define AM_SYS
Definition: ff.h:353
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
WINDOW_CLS_ICON
#define WINDOW_CLS_ICON
Definition: window.h:12
WINDOW_CLS_TEXT
#define WINDOW_CLS_TEXT
Definition: window.h:10
pscreen_menu_settings
screen_t * pscreen_menu_settings
Definition: screen_menu_settings.c:133
FRESULT
FRESULT
Definition: ff.h:214
f_findnext
FRESULT f_findnext(DIR *dp, FILINFO *fno)
resource_font
font_t * resource_font(uint16_t id)
Definition: guitypes.c:186
pscreen_menu_filament
screen_t * pscreen_menu_filament
Definition: screen_menu_filament.c:124
WINDOW_EVENT_CLICK
#define WINDOW_EVENT_CLICK
Definition: window.h:46
pscreen_menu_info
screen_t * pscreen_menu_info
Definition: screen_menu_info.c:66
screen_home_done
void screen_home_done(screen_t *screen)
Definition: screen_home.cpp:136
FR_OK
Definition: ff.h:215
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
window_enable
void window_enable(int16_t id)
Definition: window.c:517
IDR_FNT_SMALL
#define IDR_FNT_SMALL
Definition: resource.h:9
_screen_t::id
int16_t id
Definition: screen.h:19
DIR
Definition: ff.h:178
pscreen_filebrowser
screen_t * pscreen_filebrowser
Definition: screen_filebrowser.cpp:177
screen_home_init
void screen_home_init(screen_t *screen)
Definition: screen_home.cpp:81
IDR_PNG_menu_icon_print
#define IDR_PNG_menu_icon_print
Definition: resource.h:28
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
f_closedir
FRESULT f_closedir(DIR *dp)
Definition: ff.c:4291
p_window_header_event_clr
int p_window_header_event_clr(window_header_t *window, uint8_t evt_id)
Definition: window_header.c:157
icons
const uint16_t icons[6]
Definition: screen_home.cpp:36
f_findfirst
FRESULT f_findfirst(DIR *dp, FILINFO *fno, const TCHAR *path, const TCHAR *pattern)
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
screen_home_draw
void screen_home_draw(screen_t *screen)
Definition: screen_home.cpp:140
menu_preheat_type
uint8_t menu_preheat_type
Definition: screen_menu_preheat.cpp:14
p_window_header_set_text
void p_window_header_set_text(window_header_t *window, const char *text)
Definition: window_header.c:152