Prusa MINI Firmware overview
window_dlg_change.c File Reference
#include "gui.h"
#include "window_dlg_statemachine.h"
#include "marlin_client.h"
#include "menu_vars.h"
#include "stm32f4xx_hal.h"
#include <limits.h>
#include "window_msgbox.h"
#include "window_dlg_preheat.h"
#include "window_dlg_loadunload_shared.h"
#include "button_draw.h"
#include "filament_sensor.h"

Functions

static dlg_result_t _gui_dlg_change (void)
 
dlg_result_t gui_dlg_change (void)
 
static int f_CH_WAIT_E_POS__RAM_RETRACTING (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_WAIT_E_POS__RAMMING (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_WAIT_E_POS__UNLOADING (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_INIT (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
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)
 
static int f_CH_INSERT_FILAMENT (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_WAIT_E_POS__INSERTING (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_WAIT_E_POS__LOADING_TO_NOZ (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_WAIT_E_POS__PURGING (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_CHECK_MARLIN_EVENT (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_PURGE_USER_INTERACTION (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 
static int f_CH_PURGE_SHOW_PROGRESS (_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
 

Variables

static const _cl_dlg cl_unload
 
const _dlg_button_t bt_yesno_ena
 
const _dlg_button_t bt_yesno_dis
 
static const _dlg_state unload_states []
 

Function Documentation

◆ _gui_dlg_change()

static dlg_result_t _gui_dlg_change ( void  )
static
17  {
18  _dlg_ld_vars ld_vars;
19  memset(&ld_vars, '\0', sizeof(ld_vars));
20  ld_vars.z_min_extr_pos = 10;
21  dlg_result_t res = _gui_dlg(&cl_unload, &ld_vars, -1); //-1 == 49710 days
22  if (res == DLG_OK) {
23  if (fs_get_state() == FS_NO_FILAMENT) {
24  if (gui_msgbox("The filament sensor failed to detect inserted filament. Disable the sensor?",
26  == MSGBOX_RES_YES)
27  fs_disable();
28  else
29  fs_enable();
30  }
31  }
32  return res;
33 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_dlg_change()

dlg_result_t gui_dlg_change ( void  )
35  {
36  //todo must be called inside _gui_dlg, but nested dialogs are not supported now
37  //if (gui_dlg_preheat_autoselect_if_able(NULL) < 1) return DLG_ABORTED;//user can choose "RETURN"
38  return _gui_dlg_change();
39 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ f_CH_WAIT_E_POS__RAM_RETRACTING()

static int f_CH_WAIT_E_POS__RAM_RETRACTING ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
46  {
47  // 0 ... -8
48  float pos = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] - additional_vars->e_start;
49  if ( //todo unprecise
50  (pos < -7.9F) || (pos > 0.0F) //this part should not happen, just to be safe
51  )
52  p_vars->phase++;
53 
54  float ret = 100.0F * (-pos) / 8;
55  if (ret >= 100)
56  return 100;
57  if (ret <= 0)
58  return 0;
59  return ret;
60 }

◆ f_CH_WAIT_E_POS__RAMMING()

static int f_CH_WAIT_E_POS__RAMMING ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
62  {
63  // -8 ... 8
64  float pos = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] - additional_vars->e_start;
65  if ( //todo unprecise
66  (pos > 4.0F) || (pos < -20) // skip this phase - this can maybe happend when we miss previous condition
67  //(p_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] > 7.9F) ||
68  //(p_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] < -8.1F) //this part should not happen, just to be safe
69  )
70  p_vars->phase++;
71 
72  float ret = 100.0F * (8.0F + pos) / (8 + 8);
73 
74  if (ret >= 100)
75  return 100;
76  if (ret <= 0)
77  return 0;
78  return ret;
79 }

◆ f_CH_WAIT_E_POS__UNLOADING()

static int f_CH_WAIT_E_POS__UNLOADING ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
81  {
82  // 8 ... -392
83  float pos = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] - additional_vars->e_start;
84  if (pos < (filament_unload_mini_length - 1.0F))
85  p_vars->phase++;
86  return 100 * (8.0F - pos) / (filament_unload_mini_length + 8);
87 }

◆ f_CH_INIT()

static int f_CH_INIT ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
89  {
91  p_vars->flags |= DLG_CH_CMD; //kill screen after M600 ends
92 
93  //marlin_gcode("G92 E0");//saves calculation
95  if ((marlin_vars()->motion & 0x08) == 0) {
97  p_vars->phase++;
98  }
99  return 0;
100 }
Here is the call 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 }

◆ f_CH_INSERT_FILAMENT()

static int f_CH_INSERT_FILAMENT ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
112  {
113  if (p_vars->flags & DLG_BT_FLG) {
114  p_vars->flags &= ~DLG_BT_FLG;
115  p_vars->phase++;
117  }
118  return 0;
119 }
Here is the call graph for this function:

◆ f_CH_WAIT_E_POS__INSERTING()

static int f_CH_WAIT_E_POS__INSERTING ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
121  {
122  //todo i should not need this
123  if (marlin_event_clr(MARLIN_EVT_UserConfirmRequired)) //clear wait for user
124  {
126  }
127  float pos = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] - additional_vars->e_start;
128  //wait E pos >= 40
130  p_vars->phase++;
131  return 100 * (pos) / filament_change_slow_load_length;
132 }
Here is the call graph for this function:

◆ f_CH_WAIT_E_POS__LOADING_TO_NOZ()

static int f_CH_WAIT_E_POS__LOADING_TO_NOZ ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
134  {
135  //wait E pos >= 360
136  float pos = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] - additional_vars->e_start;
138  p_vars->phase++;
140  return ret;
141 }

◆ f_CH_WAIT_E_POS__PURGING()

static int f_CH_WAIT_E_POS__PURGING ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
143  {
144  //wait E pos >= 400
145  float pos = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E] - additional_vars->e_start;
146  if ((pos >= filament_change_full_purge_load_length) && (marlin_motion() == 0))
147  p_vars->phase++;
149 }
Here is the call graph for this function:

◆ f_CH_CHECK_MARLIN_EVENT()

static int f_CH_CHECK_MARLIN_EVENT ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
151  {
153  p_vars->phase++;
154  return 0;
155 }
Here is the call graph for this function:

◆ f_CH_PURGE_USER_INTERACTION()

static int f_CH_PURGE_USER_INTERACTION ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
157  {
158  switch (p_vars->flags & (LD_BT_PURG | LD_BT_DONE)) {
159  case LD_BT_PURG:
161  additional_vars->e_last = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E]; //needed in next phase
162  p_vars->phase++; //f_LD_PURGE_SHOW_PROGRESS
163  break;
164  case LD_BT_DONE:
165  case (LD_BT_DONE | LD_BT_PURG): //if both buttons are clicked DONE has priority, but should not happen
167  p_vars->phase += 2; //DONE
168  break;
169  }
170  return 100; //progressbar MUST be 100
171 }
Here is the call graph for this function:

◆ f_CH_PURGE_SHOW_PROGRESS()

static int f_CH_PURGE_SHOW_PROGRESS ( _dlg_vars p_vars,
_dlg_ld_vars additional_vars 
)
static
173  {
174 
176  p_vars->phase--; //jump back to f_LD_PURGE_USER_INTERACTION
177  p_vars->flags &= (~(LD_BT_PURG | LD_BT_DONE)); //clr buttons
178  p_vars->flags |= LD_BT_PURG_SEL; //select done
179  return 0;
180  }
181  float pos = additional_vars->p_marlin_vars->pos[MARLIN_VAR_INDEX_E];
182  float ret = 100.0F * (pos - additional_vars->e_last)
183  / ld_purge_amount;
184  if (ret > 99.0F)
185  return 99;
186  return (int)ret;
187 }
Here is the call graph for this function:

Variable Documentation

◆ cl_unload

static const _cl_dlg cl_unload
static
Initial value:

◆ bt_yesno_ena

const _dlg_button_t bt_yesno_ena

◆ bt_yesno_dis

const _dlg_button_t bt_yesno_dis

◆ unload_states

const _dlg_state unload_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_CH_INSERT_FILAMENT },
}
fs_enable
void fs_enable()
Definition: filament_sensor.c:90
bt_yesno_dis
const _dlg_button_t bt_yesno_dis
Definition: window_dlg_load.c:220
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
f_CH_WAIT_E_POS__UNLOADING
static int f_CH_WAIT_E_POS__UNLOADING(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:81
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
f_CH_PURGE_USER_INTERACTION
static int f_CH_PURGE_USER_INTERACTION(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:157
_gui_dlg_change
static dlg_result_t _gui_dlg_change(void)
Definition: window_dlg_change.c:17
set_repaint_btn_flg
void set_repaint_btn_flg(window_dlg_statemachine_t *window)
Definition: window_dlg_statemachine.c:49
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
filament_unload_mini_length
constexpr const float filament_unload_mini_length
Definition: menu_vars.cpp:110
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
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
f_CH_WAIT_E_POS__LOADING_TO_NOZ
static int f_CH_WAIT_E_POS__LOADING_TO_NOZ(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:134
_dlg_ld_vars::z_start
float z_start
Definition: window_dlg_loadunload_shared.h:18
MSGBOX_ICO_QUESTION
#define MSGBOX_ICO_QUESTION
Definition: window_msgbox.h:34
_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
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
_dlg_ld_vars::e_start
float e_start
Definition: window_dlg_loadunload_shared.h:19
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
_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
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
f_SH_WAIT_E_STOPPED
int f_SH_WAIT_E_STOPPED(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_loadunload_shared.c:119
marlin_motion
int marlin_motion(void)
Definition: marlin_client.c:182
ld_purge_amount
const float ld_purge_amount
Definition: window_dlg_loadunload_shared.c:14
MARLIN_EVT_CommandEnd
#define MARLIN_EVT_CommandEnd
Definition: marlin_events.h:34
f_CH_WAIT_E_POS__PURGING
static int f_CH_WAIT_E_POS__PURGING(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:143
marlin_vars
marlin_vars_t * marlin_vars(void)
Definition: marlin_client.c:361
MSGBOX_RES_YES
#define MSGBOX_RES_YES
Definition: window_msgbox.h:44
f_CH_WAIT_E_POS__INSERTING
static int f_CH_WAIT_E_POS__INSERTING(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:121
bt_stop_dis
const _dlg_button_t bt_stop_dis
Definition: window_dlg_loadunload_shared.c:25
marlin_host_button_click
void marlin_host_button_click(host_prompt_button_t button)
Definition: marlin_client.c:542
FS_NO_FILAMENT
Definition: filament_sensor.h:20
fs_get_state
fsensor_t fs_get_state()
Definition: filament_sensor.c:67
cl_unload
static const _cl_dlg cl_unload
Definition: window_dlg_change.c:15
f_CH_CHECK_MARLIN_EVENT
static int f_CH_CHECK_MARLIN_EVENT(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:151
_dlg_ld_vars
Definition: window_dlg_loadunload_shared.h:13
MARLIN_VAR_POS_Z
#define MARLIN_VAR_POS_Z
Definition: marlin_vars.h:17
MARLIN_VAR_POS_E
#define MARLIN_VAR_POS_E
Definition: marlin_vars.h:18
marlin_update_vars
marlin_vars_t * marlin_update_vars(uint64_t msk)
Definition: marlin_client.c:368
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
MARLIN_VAR_MSK
#define MARLIN_VAR_MSK(v_id)
Definition: marlin_vars.h:35
MARLIN_EVT_HostPrompt
#define MARLIN_EVT_HostPrompt
Definition: marlin_events.h:26
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
MSGBOX_BTN_YESNO
#define MSGBOX_BTN_YESNO
Definition: window_msgbox.h:24
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
filament_change_full_purge_load_length
constexpr const int32_t filament_change_full_purge_load_length
Definition: menu_vars.cpp:113
bt_stop_ena
const _dlg_button_t bt_stop_ena
Definition: window_dlg_loadunload_shared.c:20
bt_yesno_ena
const _dlg_button_t bt_yesno_ena
Definition: window_dlg_load.c:216
f_CH_WAIT_E_POS__RAMMING
static int f_CH_WAIT_E_POS__RAMMING(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:62
_marlin_vars_t::pos
float pos[4]
Definition: marlin_vars.h:82
f_CH_PURGE_SHOW_PROGRESS
static int f_CH_PURGE_SHOW_PROGRESS(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:173
WINDOW_EVENT_BTN_DN
#define WINDOW_EVENT_BTN_DN
Definition: window.h:38
fs_disable
void fs_disable()
Definition: filament_sensor.c:97
HOST_PROMPT_BTN_Continue
Definition: marlin_host.h:27
_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
f_CH_WAIT_E_POS__RAM_RETRACTING
static int f_CH_WAIT_E_POS__RAM_RETRACTING(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:46
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
unload_states
static const _dlg_state unload_states[]
Definition: window_dlg_change.c:192
f_CH_INSERT_FILAMENT
static int f_CH_INSERT_FILAMENT(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:112
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
f_CH_INIT
static int f_CH_INIT(_dlg_vars *p_vars, _dlg_ld_vars *additional_vars)
Definition: window_dlg_change.c:89