Prusa MINI Firmware overview
firstlay.h File Reference
#include <inttypes.h>
#include "gui.h"
#include "wizard_types.h"
#include "wizard_load_unload.h"

Go to the source code of this file.

Classes

struct  firstlay_screen_t
 
struct  firstlay_data_t
 

Macros

#define DEBUG_TERM   0
 
#define FIRSTLAY_SCREEN_TERM_X   25
 
#define FIRSTLAY_SCREEN_TERM_Y   10
 

Enumerations

enum  _FL_STATE { _FL_INIT, _FL_GCODE_HEAD, _FL_GCODE_BODY, _FL_GCODE_DONE }
 

Functions

void wizard_firstlay_event_dn (firstlay_screen_t *p_screen)
 
void wizard_firstlay_event_up (firstlay_screen_t *p_screen)
 
void wizard_init_screen_firstlay (int16_t id_body, firstlay_screen_t *p_screen, firstlay_data_t *p_data)
 
int wizard_firstlay_print (int16_t id_body, firstlay_screen_t *p_screen, firstlay_data_t *p_data, float z_offset)
 

Macro Definition Documentation

◆ DEBUG_TERM

#define DEBUG_TERM   0

◆ FIRSTLAY_SCREEN_TERM_X

#define FIRSTLAY_SCREEN_TERM_X   25

◆ FIRSTLAY_SCREEN_TERM_Y

#define FIRSTLAY_SCREEN_TERM_Y   10

Enumeration Type Documentation

◆ _FL_STATE

enum _FL_STATE
Enumerator
_FL_INIT 
_FL_GCODE_HEAD 
_FL_GCODE_BODY 
_FL_GCODE_DONE 
21  {
22  _FL_INIT,
26 } _FL_STATE;

Function Documentation

◆ wizard_firstlay_event_dn()

void wizard_firstlay_event_dn ( firstlay_screen_t p_screen)
241  {
242 #if DEBUG_TERM == 1
243  //todo term is bugged spinner can make it not showing
244  window_invalidate(p_screen->term.win.id);
245 #endif
246  p_screen->Z_offset_request -= z_offset_step;
247 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wizard_firstlay_event_up()

void wizard_firstlay_event_up ( firstlay_screen_t p_screen)
249  {
250 #if DEBUG_TERM == 1
251  //todo term is bugged spinner can make it not showing
252  window_invalidate(p_screen->term.win.id);
253 #endif
254  p_screen->Z_offset_request += z_offset_step;
255 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wizard_init_screen_firstlay()

void wizard_init_screen_firstlay ( int16_t  id_body,
firstlay_screen_t p_screen,
firstlay_data_t p_data 
)
67  {
68  //marlin_vars_t* vars = marlin_update_vars( MARLIN_VAR_MSK(MARLIN_VAR_Z_OFFSET) );
69  //p_screen->Z_offset = vars->z_offset;
70  p_screen->Z_offset_request = 0;
71 
72  int16_t id;
73  window_destroy_children(id_body);
74  window_show(id_body);
75  window_invalidate(id_body);
76 
77  uint16_t y = 40;
78  uint16_t x = WIZARD_MARGIN_LEFT;
79 #if DEBUG_TERM == 0
80  point_ui16_t pt;
82  pt.x += 5;
83  pt.y += 5;
84  id = window_create_ptr(WINDOW_CLS_TEXT, id_body, rect_ui16(x, y, pt.x, pt.y), &(p_screen->text_state));
87 
88  y += pt.y + 5;
89 #else
90  id = window_create_ptr(WINDOW_CLS_TERM, id_body,
91  rect_ui16(10, y,
94  &(p_screen->term));
95  p_screen->term.font = resource_font(IDR_FNT_SMALL);
96  term_init(&(p_screen->terminal), FIRSTLAY_SCREEN_TERM_X, FIRSTLAY_SCREEN_TERM_Y, p_screen->term_buff);
97  p_screen->term.term = &(p_screen->terminal);
98 
99  y += 18 * FIRSTLAY_SCREEN_TERM_Y + 3;
100 #endif
101  id = window_create_ptr(WINDOW_CLS_TEXT, id_body, rect_ui16(x, y, 110, 22), &(p_screen->text_Z_pos));
102  window_set_text(id, "Z height:");
103 
104  id = window_create_ptr(WINDOW_CLS_NUMB, id_body, rect_ui16(x + 110, y, 70, 22), &(p_screen->spin_baby_step));
105  window_set_format(id, "%.3f");
106  window_set_value(id, p_screen->Z_offset);
108 
109  id = window_create_ptr(WINDOW_CLS_TEXT, id_body, rect_ui16(x + 110 + 70, y, WIZARD_X_SPACE - x - 110 - 70, 22),
110  &(p_screen->text_direction_arrow));
111  window_set_text(id, "-|+");
112 
113  y += 22 + 10;
114 
115  id = window_create_ptr(WINDOW_CLS_PROGRESS, id_body, rect_ui16(x, y, WIZARD_X_SPACE, 8), &(p_screen->progress));
116 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wizard_firstlay_print()

int wizard_firstlay_print ( int16_t  id_body,
firstlay_screen_t p_screen,
firstlay_data_t p_data,
float  z_offset 
)
118  {
119  if (p_data->state_print == _TEST_START) {
120  p_screen->state = _FL_INIT;
121  p_data->state_print = _TEST_RUN;
122 
125  switch (get_filament()) {
126  case FILAMENT_PETG:
129  break;
130  case FILAMENT_ASA:
133  break;
134  case FILAMENT_FLEX:
137  break;
138  case FILAMENT_PLA:
139  default:
142  break;
143  }
144 
146 
147  //G28 must be before G29, both must be present or head is invalid
148  //find "G29" == MBL
149  for (G29_pos = 0; (G29_pos < head_gcode_sz) && strcmp(head_gcode[G29_pos], "G29"); ++G29_pos)
150  ; //no body
151  //find "G28" == autohome needed for retry
152  for (G28_pos = 0; (G28_pos < G29_pos) && strcmp(head_gcode[G28_pos], "G28"); ++G28_pos)
153  ; //no body
154  if (G28_pos >= G29_pos || G29_pos >= head_gcode_sz) {
155  //error no G29
156  p_data->state_print = _TEST_FAILED;
157  return 100;
158  }
159  }
160 
161  int remaining_lines;
162  switch (p_screen->state) {
163  case _FL_INIT:
164  p_screen->Z_offset = z_offset;
165  wizard_init_screen_firstlay(id_body, p_screen, p_data);
166 #if DEBUG_TERM == 1
167  term_printf(&p_screen->terminal, "INITIALIZED\n");
168  window_invalidate(p_screen->term.win.id);
169 #endif
171  p_screen->state = _FL_GCODE_HEAD;
173 #if DEBUG_TERM == 1
174  term_printf(&p_screen->terminal, "HEAD\n");
175  window_invalidate(p_screen->term.win.id);
176 #endif
177  break;
178  case _FL_GCODE_HEAD:
179  //have to wait to next state after MBL to check error
182  marlin_gcode("G0 Z30"); //Z 30mm
183  marlin_gcode("M84"); //Disable steppers
184  if (wizard_msgbox("Mesh bed leveling failed?", MSGBOX_BTN_RETRYCANCEL, 0) == MSGBOX_RES_RETRY) {
185  //RETRY
186  line_head = G28_pos;
187  } else {
188  //CANCEL
189  p_data->state_print = _TEST_FAILED;
190  return 100;
191  }
192  }
193 #if DEBUG_TERM == 0
194  remaining_lines = _run_gcode_line(&line_head, head_gcode,
195  head_gcode_sz);
196 #else
197  remaining_lines = _run_gcode_line(&line_head, head_gcode,
198  head_gcode_sz, &p_screen->term);
199 #endif
200  if (remaining_lines < 1) {
201  p_screen->state = _FL_GCODE_BODY;
202 #if DEBUG_TERM == 1
203  term_printf(&p_screen->terminal, "BODY\n");
204  window_invalidate(p_screen->term.win.id);
205 #endif
206  p_screen->Z_offset_request = 0; //ignore Z_offset_request variable changes until now
209  }
210  break;
211  case _FL_GCODE_BODY:
212  _wizard_firstlay_Z_step(p_screen);
213 #if DEBUG_TERM == 0
214  remaining_lines = _run_gcode_line(&line_body, body_gcode,
215  body_gcode_sz);
216 #else
217  remaining_lines = _run_gcode_line(&line_body, body_gcode,
218  body_gcode_sz, &p_screen->term);
219 #endif
220  if (remaining_lines < 1) {
221  p_screen->state = _FL_GCODE_DONE;
222  }
223  break;
224  case _FL_GCODE_DONE:
225 #if DEBUG_TERM == 1
226  term_printf(&p_screen->terminal, "PASSED\n");
227  window_invalidate(p_screen->term.win.id);
228 #endif
229  p_data->state_print = _TEST_PASSED;
230  //marlin_settings_save();
231  p_screen->Z_offset_request = 0;
232  return 100;
233  }
234 
235  int progress = _get_progress(); //max 99
236 
237  window_set_value(p_screen->progress.win.id, (float)progress);
238  return progress;
239 }
Here is the call graph for this function:
Here is the caller graph for this function:
firstlay_screen_t::state
_FL_STATE state
Definition: firstlay.h:32
firstlay_screen_t::text_Z_pos
window_text_t text_Z_pos
Definition: firstlay.h:45
line_head
static uint32_t line_head
Definition: firstlay.c:35
_FL_GCODE_DONE
Definition: firstlay.h:25
V2_gcodes_head_PETG_sz
const size_t V2_gcodes_head_PETG_sz
Definition: firstlay.c:25
firstlay_screen_t::spin_baby_step
window_numb_t spin_baby_step
Definition: firstlay.h:47
z_offset_step
const float z_offset_step
Definition: menu_vars.cpp:26
FIRSTLAY_SCREEN_TERM_Y
#define FIRSTLAY_SCREEN_TERM_Y
Definition: firstlay.h:29
_set_gcode_first_lines
void _set_gcode_first_lines()
Definition: firstlay.c:444
WINDOW_CLS_TERM
#define WINDOW_CLS_TERM
Definition: window.h:17
head_gcode_sz
static size_t head_gcode_sz
Definition: firstlay.c:40
WINDOW_CLS_NUMB
#define WINDOW_CLS_NUMB
Definition: window.h:11
V2_gcodes_head_FLEX
const char * V2_gcodes_head_FLEX[]
Definition: firstlay.c:21
_TEST_FAILED
Definition: wizard_types.h:88
_FL_GCODE_BODY
Definition: firstlay.h:24
V2_gcodes_head_ASA
const char * V2_gcodes_head_ASA[]
Definition: firstlay.c:20
window_destroy_children
void window_destroy_children(int16_t id)
Definition: window.c:157
_FL_INIT
Definition: firstlay.h:22
window_set_format
void window_set_format(int16_t id, const char *format)
Definition: window.c:403
_window_numb_t::color_text
color_t color_text
Definition: window_numb.h:20
window_invalidate
void window_invalidate(int16_t id)
Definition: window.c:304
rect_ui16
static rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition: guitypes.h:159
_point_ui16_t::x
uint16_t x
Definition: guitypes.h:65
WIZARD_MARGIN_LEFT
#define WIZARD_MARGIN_LEFT
Definition: wizard_ui.h:8
_FL_STATE
_FL_STATE
Definition: firstlay.h:21
IDR_FNT_NORMAL
#define IDR_FNT_NORMAL
Definition: resource.h:10
head_gcode
static const char ** head_gcode
Definition: firstlay.c:38
FILAMENT_PETG
Definition: filament.h:28
firstlay_data_t::state_print
_TEST_STATE_t state_print
Definition: firstlay.h:67
_wizard_firstlay_Z_step
void _wizard_firstlay_Z_step(firstlay_screen_t *p_screen)
Definition: firstlay.c:257
FIRSTLAY_SCREEN_TERM_X
#define FIRSTLAY_SCREEN_TERM_X
Definition: firstlay.h:28
firstlay_screen_t::progress
window_progress_t progress
Definition: firstlay.h:33
window_show
void window_show(int16_t id)
Definition: window.c:529
_wizard_firstlay_text
static const char * _wizard_firstlay_text
Definition: firstlay.c:52
FILAMENT_PLA
Definition: filament.h:27
marlin_error_clr
int marlin_error_clr(uint8_t err_id)
Definition: marlin_client.c:324
_point_ui16_t
Definition: guitypes.h:64
_window_t::id
int16_t id
Definition: window.h:79
V2_gcodes_head_FLEX_sz
const size_t V2_gcodes_head_FLEX_sz
Definition: firstlay.c:27
COLOR_GRAY
#define COLOR_GRAY
Definition: guitypes.h:50
MARLIN_ERR_ProbingFailed
#define MARLIN_ERR_ProbingFailed
Definition: marlin_errors.h:9
body_gcode
static const char ** body_gcode
Definition: firstlay.c:39
WIZARD_X_SPACE
#define WIZARD_X_SPACE
Definition: wizard_ui.h:10
window_set_text
void window_set_text(int16_t id, const char *text)
Definition: window.c:340
COLOR_ORANGE
#define COLOR_ORANGE
Definition: guitypes.h:57
firstlay_screen_t::Z_offset_request
float Z_offset_request
Definition: firstlay.h:50
WINDOW_CLS_PROGRESS
#define WINDOW_CLS_PROGRESS
Definition: window.h:20
_point_ui16_t::y
uint16_t y
Definition: guitypes.h:66
V2_gcodes_head_PETG
const char * V2_gcodes_head_PETG[]
Definition: firstlay.c:19
MSGBOX_BTN_RETRYCANCEL
#define MSGBOX_BTN_RETRYCANCEL
Definition: window_msgbox.h:25
_TEST_RUN
Definition: wizard_types.h:86
gcode_sz
static size_t gcode_sz
Definition: firstlay.c:42
G28_pos
static size_t G28_pos
Definition: firstlay.c:43
window_set_value
void window_set_value(int16_t id, float value)
Definition: window.c:363
get_filament
FILAMENT_t get_filament()
Definition: filament.cpp:41
V2_gcodes_body
const char * V2_gcodes_body[]
Definition: firstlay.c:22
body_gcode_sz
static size_t body_gcode_sz
Definition: firstlay.c:41
FILAMENT_FLEX
Definition: filament.h:30
G29_pos
static size_t G29_pos
Definition: firstlay.c:44
marlin_gcode
void marlin_gcode(const char *gcode)
Definition: marlin_client.c:195
_run_gcode_line
int _run_gcode_line(uint32_t *p_line, const char *gcodes[], size_t gcodes_count)
Definition: firstlay.c:450
firstlay_screen_t::Z_offset
float Z_offset
Definition: firstlay.h:49
WINDOW_CLS_TEXT
#define WINDOW_CLS_TEXT
Definition: window.h:10
firstlay_screen_t::text_state
window_text_t text_state
Definition: firstlay.h:35
_TEST_START
Definition: wizard_types.h:85
resource_font
font_t * resource_font(uint16_t id)
Definition: guitypes.c:186
MSGBOX_RES_RETRY
#define MSGBOX_RES_RETRY
Definition: window_msgbox.h:42
term_init
void term_init(term_t *pt, uint8_t cols, uint8_t rows, uint8_t *buff)
Definition: term.c:6
firstlay_screen_t::text_direction_arrow
window_text_t text_direction_arrow
Definition: firstlay.h:46
V2_gcodes_body_sz
const size_t V2_gcodes_body_sz
Definition: firstlay.c:28
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
IDR_FNT_SMALL
#define IDR_FNT_SMALL
Definition: resource.h:9
line_body
static uint32_t line_body
Definition: firstlay.c:36
V2_gcodes_head_PLA
const char * V2_gcodes_head_PLA[]
Definition: firstlay.c:18
_window_text_t::font
font_t * font
Definition: window_text.h:19
wizard_msgbox
int wizard_msgbox(const char *text, uint16_t flags, uint16_t id_icon)
Definition: wizard_ui.c:42
marlin_error
int marlin_error(uint8_t err_id)
Definition: marlin_client.c:304
V2_gcodes_head_PLA_sz
const size_t V2_gcodes_head_PLA_sz
Definition: firstlay.c:24
V2_gcodes_head_ASA_sz
const size_t V2_gcodes_head_ASA_sz
Definition: firstlay.c:26
_get_progress
int _get_progress()
Definition: firstlay.c:435
_FL_GCODE_HEAD
Definition: firstlay.h:23
font_meas_text
point_ui16_t font_meas_text(font_t *pf, const char *str)
Definition: guitypes.c:97
wizard_init_screen_firstlay
void wizard_init_screen_firstlay(int16_t id_body, firstlay_screen_t *p_screen, firstlay_data_t *p_data)
Definition: firstlay.c:67
_window_progress_t::win
window_t win
Definition: window_progress.h:16
_window_numb_t::win
window_t win
Definition: window_numb.h:18
_TEST_PASSED
Definition: wizard_types.h:87
term_printf
int term_printf(term_t *pt, const char *fmt,...)
Definition: term.c:178
FILAMENT_ASA
Definition: filament.h:29