Prusa MINI Firmware overview
window_dlg_load.c File Reference
#include "window_dlg_load.h"
#include "marlin_client.h"
#include "menu_vars.h"
#include "stm32f4xx_hal.h"
#include <limits.h>
#include "window_dlg_preheat.h"
#include "window_dlg_loadunload_shared.h"
#include "gui.h"
#include "button_draw.h"
#include "filament.h"

Functions

void window_dlg_load_draw_buttons (window_dlg_statemachine_t *window, int is_donelhs_purgerhs)
 
void window_dlg_load_draw_buttons_cb (window_dlg_statemachine_t *window)
 
void window_dlg_load_event_cb (window_dlg_statemachine_t *window, uint8_t event, void *param)
 
void window_dlg_load_event_inverted_cb (window_dlg_statemachine_t *window, uint8_t event, void *param)
 
static dlg_result_t _gui_dlg_load (void)
 
dlg_result_t gui_dlg_load (void)
 
dlg_result_t gui_dlg_load_forced (void)
 
static int f_LD_GCODE (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_LD_INSERT_FILAMENT (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_LD_WAIT_E_POS__INSERTING (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_LD_WAIT_E_POS__LOADING_TO_NOZ (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_LD_WAIT_E_POS__PURGING (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_LD_CHECK_MARLIN_EVENT (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_LD_PURGE_USER_INTERACTION (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_LD_PURGE_SHOW_PROGRESS (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 

Variables

static const _cl_dlg cl_load
 
static const char * txt_yesno [] = { "YES", "NO" }
 
const _dlg_button_t bt_yesno_ena
 
const _dlg_button_t bt_yesno_dis
 
static const _dlg_state load_states []
 

Function Documentation

◆ window_dlg_load_draw_buttons()

void window_dlg_load_draw_buttons ( window_dlg_statemachine_t window,
int  is_donelhs_purgerhs 
)
23  {
25  int is_enabled = window->_ths->p_states[window->vars.phase].p_button->flags & BT_ENABLED;
26 
27  const char *bt_caption = window->_ths->p_states[window->vars.phase].p_button->labels[0];
28  int is_active = ((window->vars.flags & LD_BT_PURG_SEL) != 0) != (is_donelhs_purgerhs != 0);
29  int16_t btn_width = rc_btn.w / 2 - gui_defaults.btn_spacing;
30 
31  rc_btn.w = btn_width;
32  //lhs button
33  button_draw(rc_btn, bt_caption, window->font_title, is_active && is_enabled);
34 
35  //more difficult calculations of coords to avoid round errors
36 
37  //space between buttons
38  rc_btn.x += btn_width;
39  rc_btn.w = _get_dlg_statemachine_button_size(window).w - rc_btn.w * 2;
40  display->fill_rect(rc_btn, window->color_back);
41 
42  //distance of both buttons from screen sides is same
43  rc_btn.x += rc_btn.w;
44  rc_btn.w = btn_width;
45  is_active = !is_active;
46  bt_caption = window->_ths->p_states[window->vars.phase].p_button->labels[1];
47  //rhs button
48  button_draw(rc_btn, bt_caption, window->font_title, is_active && is_enabled);
49 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_dlg_load_draw_buttons_cb()

void window_dlg_load_draw_buttons_cb ( window_dlg_statemachine_t window)
51  {
53 }
Here is the call graph for this function:

◆ window_dlg_load_event_cb()

void window_dlg_load_event_cb ( window_dlg_statemachine_t window,
uint8_t  event,
void param 
)
56  {
57  uint8_t *p_flags = &window->vars.flags;
58  switch (event) {
60  case WINDOW_EVENT_CLICK:
61  if ((*p_flags) & LD_BT_PURG_SEL)
62  window->vars.flags |= LD_BT_PURG; //set purge button
63  else
64  window->vars.flags |= LD_BT_DONE; //set done button
65  return;
67  if ((*p_flags) & LD_BT_PURG_SEL) {
68  (*p_flags) &= ~LD_BT_PURG_SEL;
69  set_repaint_btn_flg(window); //set window flag - wil repaint buttons
70  }
71  return;
73  if (!((*p_flags) & LD_BT_PURG_SEL)) {
74  (*p_flags) |= LD_BT_PURG_SEL;
75  set_repaint_btn_flg(window); //set window flag - wil repaint buttons
76  }
77  return;
78  }
79 }
Here is the call graph for this function:

◆ window_dlg_load_event_inverted_cb()

void window_dlg_load_event_inverted_cb ( window_dlg_statemachine_t window,
uint8_t  event,
void param 
)
83  {
84  uint8_t *p_flags = &window->vars.flags;
85  switch (event) {
87  case WINDOW_EVENT_CLICK:
88  if ((*p_flags) & LD_BT_PURG_SEL)
89  window->vars.flags |= LD_BT_PURG; //set purge button
90  else
91  window->vars.flags |= LD_BT_DONE; //set done button
92  return;
94  if ((*p_flags) & LD_BT_PURG_SEL) {
95  (*p_flags) &= ~LD_BT_PURG_SEL;
96  set_repaint_btn_flg(window); //set window flag - wil repaint buttons
97  }
98  return;
100  if (!((*p_flags) & LD_BT_PURG_SEL)) {
101  (*p_flags) |= LD_BT_PURG_SEL;
102  set_repaint_btn_flg(window); //set window flag - wil repaint buttons
103  }
104  return;
105  }
106 }
Here is the call graph for this function:

◆ _gui_dlg_load()

static dlg_result_t _gui_dlg_load ( void  )
static
108  {
109  _dlg_ld_vars ld_vars;
110  memset(&ld_vars, '\0', sizeof(ld_vars));
111  ld_vars.z_min_extr_pos = 30;
112  dlg_result_t ret = _gui_dlg(&cl_load, &ld_vars, 600000); //10min
113  if (ret != DLG_OK)set_filament(FILAMENT_NONE);
114  return ret;
115 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_dlg_load()

dlg_result_t gui_dlg_load ( void  )
117  {
118  //todo must be called inside _gui_dlg, but nested dialogs are not supported now
119  if (gui_dlg_preheat(NULL) < 1)
120  return DLG_ABORTED; //0 is return
121  return _gui_dlg_load();
122 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_dlg_load_forced()

dlg_result_t gui_dlg_load_forced ( void  )
124  {
125  //todo must be called inside _gui_dlg, but nested dialogs are not supported now
126  if (gui_dlg_preheat_forced("PREHEAT for LOAD") < 0)
127  return DLG_ABORTED; //DLG_ABORTED should not happen
128  return _gui_dlg_load();
129 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ f_LD_GCODE()

static int f_LD_GCODE ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
133  {
134  marlin_gcode("M701 Z0");
135  p_vars->phase++;
136  p_vars->flags |= DLG_CH_CMD; //kill screen after M701 ends
137  return 0;
138 }
Here is the call graph for this function:

◆ f_LD_INSERT_FILAMENT()

static int f_LD_INSERT_FILAMENT ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
140  {
141  if (p_vars->flags & DLG_BT_FLG) {
142  p_vars->flags &= ~DLG_BT_FLG;
143  p_vars->phase++;
144  }
145  return 0;
146 }

◆ f_LD_WAIT_E_POS__INSERTING()

static int f_LD_WAIT_E_POS__INSERTING ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
148  {
149  //todo i should not need this
150  if (marlin_event_clr(MARLIN_EVT_UserConfirmRequired)) //clear wait for user
151  {
153  }
154  //wait E pos >= 40
156  p_vars->phase++;
157  return 100 * (additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E]) / filament_change_slow_load_length;
158 }
Here is the call graph for this function:

◆ f_LD_WAIT_E_POS__LOADING_TO_NOZ()

static int f_LD_WAIT_E_POS__LOADING_TO_NOZ ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
160  {
161  //wait E pos >= 360
163  p_vars->phase++;
165  return ret;
166 }

◆ f_LD_WAIT_E_POS__PURGING()

static int f_LD_WAIT_E_POS__PURGING ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
168  {
169  //wait E pos >= 400
171  p_vars->phase++;
173 }
Here is the call graph for this function:

◆ f_LD_CHECK_MARLIN_EVENT()

static int f_LD_CHECK_MARLIN_EVENT ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
175  {
177  p_vars->phase++;
178  return 0;
179 }
Here is the call graph for this function:

◆ f_LD_PURGE_USER_INTERACTION()

static int f_LD_PURGE_USER_INTERACTION ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
181  {
182  switch (p_vars->flags & (LD_BT_PURG | LD_BT_DONE)) {
183  case LD_BT_PURG:
185  additional_vars->e_last = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E]; //needed in next phase
186  p_vars->phase++; //f_LD_PURGE_SHOW_PROGRESS
187  break;
188  case LD_BT_DONE:
189  case (LD_BT_DONE | LD_BT_PURG): //if both buttons are clicked DONE has priority, but should not happen
191  p_vars->phase += 2; //DONE
192  break;
193  }
194  return 100; //progressbar MUST be 100
195 }
Here is the call graph for this function:

◆ f_LD_PURGE_SHOW_PROGRESS()

static int f_LD_PURGE_SHOW_PROGRESS ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
197  {
198 
200  p_vars->phase--; //jump back to f_LD_PURGE_USER_INTERACTION
201  p_vars->flags &= (~(LD_BT_PURG | LD_BT_DONE)); //clr buttons
202  p_vars->flags |= LD_BT_PURG_SEL; //select done
203  return 0;
204  }
205 
206  float ret = 100.0F * (additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] - additional_vars->e_last)
207  / ld_purge_amount;
208  if (ret > 99.0F)
209  return 99;
210  return (int)ret;
211 }
Here is the call graph for this function:

Variable Documentation

◆ cl_load

static const _cl_dlg cl_load
static
Initial value:
= {
"Loading filament",
sizeof(load_states) / sizeof(load_states[0]),
NULL,
}

◆ txt_yesno

const char* txt_yesno[] = { "YES", "NO" }
static

◆ bt_yesno_ena

◆ bt_yesno_dis

const _dlg_button_t bt_yesno_dis

◆ load_states

const _dlg_state load_states[]
static
Initial value:
= {
{ 0, window_dlg_statemachine_draw_progress_tot, "Press CONTINUE and\npush filament into\nthe extruder.", &bt_cont_ena, (dlg_state_func)f_LD_INSERT_FILAMENT },
}
_window_dlg_statemachine_t::_ths
const _cl_dlg * _ths
Definition: window_dlg_statemachine.h:97
f_LD_WAIT_E_POS__INSERTING
static int f_LD_WAIT_E_POS__INSERTING(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_load.c:148
_cl_dlg::p_states
const _dlg_state * p_states
Definition: window_dlg_statemachine.h:79
BT_ENABLED
#define BT_ENABLED
Definition: window_dlg_statemachine.h:15
f_SH_on_loop
loop_result_t f_SH_on_loop(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_loadunload_shared.c:47
_window_dlg_statemachine_t::color_back
color_t color_back
Definition: window_dlg_statemachine.h:89
_rect_ui16_t::w
uint16_t w
Definition: guitypes.h:72
f_SH_WAIT_INITIAL_Z_STOPPED
int f_SH_WAIT_INITIAL_Z_STOPPED(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_loadunload_shared.c:98
DLG_BT_FLG
#define DLG_BT_FLG
Definition: window_dlg_statemachine.h:19
_dlg_vars::flags
uint8_t flags
Definition: window_dlg_statemachine.h:38
MARLIN_VAR_INDEX_E
#define MARLIN_VAR_INDEX_E
Definition: marlin_vars.h:67
bt_none
const _dlg_button_t bt_none
Definition: window_dlg_loadunload_shared.c:38
_gui_dlg
dlg_result_t _gui_dlg(const _cl_dlg *_ths, void *p_additional_vars, int32_t ttl)
Definition: window_dlg_statemachine.c:257
cl_load
static const _cl_dlg cl_load
Definition: window_dlg_load.c:16
set_repaint_btn_flg
void set_repaint_btn_flg(window_dlg_statemachine_t *window)
Definition: window_dlg_statemachine.c:49
set_filament
void set_filament(FILAMENT_t filament)
Definition: filament.cpp:32
_gui_dlg_load
static dlg_result_t _gui_dlg_load(void)
Definition: window_dlg_load.c:108
FILAMENT_NONE
Definition: filament.h:26
window_dlg_load_event_cb
void window_dlg_load_event_cb(window_dlg_statemachine_t *window, uint8_t event, void *param)
Definition: window_dlg_load.c:56
f_SH_WAIT_TEMP
int f_SH_WAIT_TEMP(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_loadunload_shared.c:126
f_LD_CHECK_MARLIN_EVENT
static int f_LD_CHECK_MARLIN_EVENT(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_load.c:175
gui_dlg_preheat
int gui_dlg_preheat(const char *caption)
Definition: window_dlg_preheat.c:126
LD_BT_PURG_SEL
#define LD_BT_PURG_SEL
Definition: window_dlg_loadunload_shared.h:30
WINDOW_EVENT_ENC_UP
#define WINDOW_EVENT_ENC_UP
Definition: window.h:41
f_SH_INIT
int f_SH_INIT(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_loadunload_shared.c:67
window_dlg_load_draw_buttons
void window_dlg_load_draw_buttons(window_dlg_statemachine_t *window, int is_donelhs_purgerhs)
Definition: window_dlg_load.c:22
_dlg_ld_vars::e_last
float e_last
Definition: window_dlg_loadunload_shared.h:20
filament_change_full_load_length
constexpr const int32_t filament_change_full_load_length
Definition: menu_vars.cpp:112
_dlg_vars::phase
int8_t phase
Definition: window_dlg_statemachine.h:39
bt_yesno_dis
const _dlg_button_t bt_yesno_dis
Definition: window_dlg_load.c:220
window_dlg_load_draw_buttons_cb
void window_dlg_load_draw_buttons_cb(window_dlg_statemachine_t *window)
Definition: window_dlg_load.c:51
HOST_PROMPT_BTN_PurgeMore
Definition: marlin_host.h:28
window_dlg_statemachine_draw_progress_tot
void window_dlg_statemachine_draw_progress_tot(window_dlg_statemachine_t *window)
Definition: window_dlg_statemachine.c:144
window_dlg_statemachine_draw_progress_part
void window_dlg_statemachine_draw_progress_part(window_dlg_statemachine_t *window)
Definition: window_dlg_statemachine.c:150
NULL
#define NULL
Definition: usbd_def.h:53
F
#define F(str)
Definition: UHS_macros.h:164
f_SH_MOVE_INITIAL_Z
int f_SH_MOVE_INITIAL_Z(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_loadunload_shared.c:74
dlg_loop_cb_t
loop_result_t(* dlg_loop_cb_t)(_dlg_vars *p_vars, void *p_additional_vars)
Definition: window_dlg_statemachine.h:57
LD_BT_PURG
#define LD_BT_PURG
Definition: window_dlg_loadunload_shared.h:29
_display_t::fill_rect
display_fill_rect_t * fill_rect
Definition: display.h:33
_window_dlg_statemachine_t::vars
_dlg_vars vars
Definition: window_dlg_statemachine.h:98
filament_change_slow_load_length
constexpr const int32_t filament_change_slow_load_length
Definition: menu_vars.cpp:107
f_LD_PURGE_SHOW_PROGRESS
static int f_LD_PURGE_SHOW_PROGRESS(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_load.c:197
dlg_state_func
int(* dlg_state_func)(_dlg_vars *p_vars, void *p_additional_vars)
Definition: window_dlg_statemachine.h:55
_dlg_ld_vars::z_min_extr_pos
float z_min_extr_pos
Definition: window_dlg_loadunload_shared.h:16
button_draw
void button_draw(rect_ui16_t rc_btn, const char *text, font_t *pf, int is_selected)
Definition: button_draw.c:5
marlin_motion
int marlin_motion(void)
Definition: marlin_client.c:182
_window_dlg_statemachine_t::font_title
font_t * font_title
Definition: window_dlg_statemachine.h:92
ld_purge_amount
const float ld_purge_amount
Definition: window_dlg_loadunload_shared.c:14
DLG_ABORTED
Definition: dlg_result.h:11
f_LD_PURGE_USER_INTERACTION
static int f_LD_PURGE_USER_INTERACTION(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_load.c:181
_dlg_button_t::flags
uint8_t flags
Definition: window_dlg_statemachine.h:62
bt_stop_dis
const _dlg_button_t bt_stop_dis
Definition: window_dlg_loadunload_shared.c:25
gui_dlg_preheat_forced
int gui_dlg_preheat_forced(const char *caption)
Definition: window_dlg_preheat.c:152
marlin_host_button_click
void marlin_host_button_click(host_prompt_button_t button)
Definition: marlin_client.c:542
_gui_defaults_t::btn_spacing
uint8_t btn_spacing
Definition: guitypes.h:115
f_LD_WAIT_E_POS__PURGING
static int f_LD_WAIT_E_POS__PURGING(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_load.c:168
_dlg_ld_vars
Definition: window_dlg_loadunload_shared.h:13
marlin_gcode
void marlin_gcode(const char *gcode)
Definition: marlin_client.c:195
_rect_ui16_t
Definition: guitypes.h:69
load_states
static const _dlg_state load_states[]
Definition: window_dlg_load.c:227
marlin_set_wait_user
uint8_t marlin_set_wait_user(uint8_t val)
Definition: marlin_client.c:429
dlg_result_t
dlg_result_t
Definition: dlg_result.h:9
uint8_t
const uint8_t[]
Definition: 404_html.c:3
DLG_OK
Definition: dlg_result.h:10
display
display_t * display
Definition: display.c:6
MARLIN_EVT_HostPrompt
#define MARLIN_EVT_HostPrompt
Definition: marlin_events.h:26
_dlg_state::p_button
const _dlg_button_t * p_button
Definition: window_dlg_statemachine.h:72
f_SH_on_load
void f_SH_on_load(void)
Definition: window_dlg_loadunload_shared.c:42
WINDOW_EVENT_CLICK
#define WINDOW_EVENT_CLICK
Definition: window.h:46
DLG_CH_CMD
#define DLG_CH_CMD
Definition: window_dlg_statemachine.h:20
window_dlg_statemachine_draw_progress_none
void window_dlg_statemachine_draw_progress_none(window_dlg_statemachine_t *window)
Definition: window_dlg_statemachine.c:156
txt_yesno
static const char * txt_yesno[]
Definition: window_dlg_load.c:215
filament_change_full_purge_load_length
constexpr const int32_t filament_change_full_purge_load_length
Definition: menu_vars.cpp:113
f_LD_INSERT_FILAMENT
static int f_LD_INSERT_FILAMENT(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_load.c:140
bt_stop_ena
const _dlg_button_t bt_stop_ena
Definition: window_dlg_loadunload_shared.c:20
f_LD_WAIT_E_POS__LOADING_TO_NOZ
static int f_LD_WAIT_E_POS__LOADING_TO_NOZ(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_load.c:160
_rect_ui16_t::x
uint16_t x
Definition: guitypes.h:70
f_LD_GCODE
static int f_LD_GCODE(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_load.c:133
_marlin_vars_t::pos
float pos[4]
Definition: marlin_vars.h:82
gui_defaults
gui_defaults_t gui_defaults
Definition: gui.c:20
WINDOW_EVENT_BTN_DN
#define WINDOW_EVENT_BTN_DN
Definition: window.h:38
_get_dlg_statemachine_button_size
rect_ui16_t _get_dlg_statemachine_button_size(window_dlg_statemachine_t *window)
Definition: window_dlg_statemachine.c:78
HOST_PROMPT_BTN_Continue
Definition: marlin_host.h:27
_dlg_button_t::labels
const char ** labels
Definition: window_dlg_statemachine.h:61
f_SH_WAIT_INITIAL_Z_MOTION
int f_SH_WAIT_INITIAL_Z_MOTION(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_loadunload_shared.c:85
_dlg_ld_vars::p_marlin_vars
marlin_vars_t * p_marlin_vars
Definition: window_dlg_loadunload_shared.h:15
f_SH_on_timeout
void f_SH_on_timeout(void)
Definition: window_dlg_loadunload_shared.c:59
bt_yesno_ena
const _dlg_button_t bt_yesno_ena
Definition: window_dlg_load.c:216
WINDOW_EVENT_ENC_DN
#define WINDOW_EVENT_ENC_DN
Definition: window.h:40
LD_BT_DONE
#define LD_BT_DONE
Definition: window_dlg_loadunload_shared.h:28
marlin_event_clr
int marlin_event_clr(uint8_t evt_id)
Definition: marlin_client.c:252
MARLIN_EVT_UserConfirmRequired
#define MARLIN_EVT_UserConfirmRequired
Definition: marlin_events.h:19
bt_cont_ena
const _dlg_button_t bt_cont_ena
Definition: window_dlg_loadunload_shared.c:29