Prusa MINI Firmware overview
window_dlg_statemachine.h File Reference
#include "window.h"
#include "dlg_result.h"

Go to the source code of this file.

Classes

struct  _dlg_vars
 
struct  _dlg_button_t
 
struct  _dlg_state
 
struct  _cl_dlg
 
struct  _window_dlg_statemachine_t
 
struct  _window_class_dlg_statemachine_t
 

Macros

#define BT_ENABLED   ((uint8_t)(1 << 0))
 
#define BT_AUTOEXIT   ((uint8_t)(1 << 2))
 
#define DLG_BT_FLG   ((uint8_t)(1 << 0))
 
#define DLG_CH_CMD   ((uint8_t)(1 << 1))
 
#define DLG_DI_US0   ((uint8_t)(1 << 4))
 
#define DLG_DI_US1   ((uint8_t)(1 << 5))
 
#define DLG_DI_US2   ((uint8_t)(1 << 6))
 
#define DLG_DI_US3   ((uint8_t)(1 << 7))
 

Typedefs

typedef struct _window_dlg_statemachine_t window_dlg_statemachine_t
 
typedef void() window_draw_dlg_cb_t(window_dlg_statemachine_t *window)
 
typedef void() window_event_dlg_cb_t(window_dlg_statemachine_t *window, uint8_t event, void *param)
 
typedef int(* dlg_state_func) (_dlg_vars *p_vars, void *p_additional_vars)
 
typedef void(* dlg_cb_t) (void)
 
typedef loop_result_t(* dlg_loop_cb_t) (_dlg_vars *p_vars, void *p_additional_vars)
 
typedef struct _window_class_dlg_statemachine_t window_class_dlg_statemachine_t
 

Enumerations

enum  loop_result_t { LOOP_RESULT_CONTINUE, LOOP_RESULT_BREAK }
 

Functions

void set_repaint_btn_flg (window_dlg_statemachine_t *window)
 
int is_repaint_btn_flg (window_dlg_statemachine_t *window)
 
void window_dlg_statemachine_draw_progress_tot (window_dlg_statemachine_t *window)
 
void window_dlg_statemachine_draw_progress_part (window_dlg_statemachine_t *window)
 
void window_dlg_statemachine_draw_progress_none (window_dlg_statemachine_t *window)
 
rect_ui16_t _get_dlg_statemachine_button_size (window_dlg_statemachine_t *window)
 
dlg_result_t _gui_dlg (const _cl_dlg *_ths, void *p_additional_vars, int32_t ttl)
 
void window_dlg_statemachine_draw_0bt (window_dlg_statemachine_t *window)
 
void window_dlg_statemachine_draw_1bt (window_dlg_statemachine_t *window)
 
void window_dlg_statemachine_event_1bt (window_dlg_statemachine_t *window, uint8_t event, void *param)
 

Variables

int16_t WINDOW_CLS_DLG_LOADUNLOAD
 
const window_class_dlg_statemachine_t window_class_dlg_statemachine
 

Macro Definition Documentation

◆ BT_ENABLED

#define BT_ENABLED   ((uint8_t)(1 << 0))

◆ BT_AUTOEXIT

#define BT_AUTOEXIT   ((uint8_t)(1 << 2))

◆ DLG_BT_FLG

#define DLG_BT_FLG   ((uint8_t)(1 << 0))

◆ DLG_CH_CMD

#define DLG_CH_CMD   ((uint8_t)(1 << 1))

◆ DLG_DI_US0

#define DLG_DI_US0   ((uint8_t)(1 << 4))

◆ DLG_DI_US1

#define DLG_DI_US1   ((uint8_t)(1 << 5))

◆ DLG_DI_US2

#define DLG_DI_US2   ((uint8_t)(1 << 6))

◆ DLG_DI_US3

#define DLG_DI_US3   ((uint8_t)(1 << 7))

Typedef Documentation

◆ window_dlg_statemachine_t

◆ window_draw_dlg_cb_t

typedef void() window_draw_dlg_cb_t(window_dlg_statemachine_t *window)

◆ window_event_dlg_cb_t

typedef void() window_event_dlg_cb_t(window_dlg_statemachine_t *window, uint8_t event, void *param)

◆ dlg_state_func

typedef int(* dlg_state_func) (_dlg_vars *p_vars, void *p_additional_vars)

◆ dlg_cb_t

typedef void(* dlg_cb_t) (void)

◆ dlg_loop_cb_t

typedef loop_result_t(* dlg_loop_cb_t) (_dlg_vars *p_vars, void *p_additional_vars)

◆ window_class_dlg_statemachine_t

Enumeration Type Documentation

◆ loop_result_t

Enumerator
LOOP_RESULT_CONTINUE 
LOOP_RESULT_BREAK 

Function Documentation

◆ set_repaint_btn_flg()

void set_repaint_btn_flg ( window_dlg_statemachine_t window)
49  {
50  window->flags |= DLG_BTN_CH;
51 }
Here is the caller graph for this function:

◆ is_repaint_btn_flg()

int is_repaint_btn_flg ( window_dlg_statemachine_t window)
53  {
54  return window->flags | DLG_BTN_CH;
55 }

◆ window_dlg_statemachine_draw_progress_tot()

void window_dlg_statemachine_draw_progress_tot ( window_dlg_statemachine_t window)
144  {
145  if (window->flags & DLG_PRO_CH)
146  progress_draw(window->win.rect, window->font_title, window->color_back,
147  window->color_text, window->padding, window->vars.progress);
148 }
Here is the call graph for this function:

◆ window_dlg_statemachine_draw_progress_part()

void window_dlg_statemachine_draw_progress_part ( window_dlg_statemachine_t window)
150  {
151  if (window->flags & DLG_PPR_CH)
152  progress_draw(window->win.rect, window->font_title, window->color_back,
153  window->color_text, window->padding, window->vars.part_progress);
154 }
Here is the call graph for this function:

◆ window_dlg_statemachine_draw_progress_none()

void window_dlg_statemachine_draw_progress_none ( window_dlg_statemachine_t window)
156  {
157  progress_clr(window->win.rect, window->font_title, window->color_back);
158 }
Here is the call graph for this function:

◆ _get_dlg_statemachine_button_size()

rect_ui16_t _get_dlg_statemachine_button_size ( window_dlg_statemachine_t window)
78  {
79  rect_ui16_t rc_btn = window->win.rect;
80  rc_btn.y += (rc_btn.h - 40); // 30pixels for button (+ 10 space for grey frame)
81  rc_btn.h = 30;
82  rc_btn.x += 6;
83  rc_btn.w -= 12;
84  return rc_btn;
85 }
Here is the caller graph for this function:

◆ _gui_dlg()

dlg_result_t _gui_dlg ( const _cl_dlg _ths,
void p_additional_vars,
int32_t  ttl 
)
257  {
258  clr_logs();
259 
261  memset(&dlg, 0, sizeof(dlg));
262  dlg._ths = _ths;
263  int16_t id_capture = window_capture();
265  window_1 = (window_t *)&dlg;
266  gui_reset_jogwheel();
267  gui_invalidate();
268  window_set_capture(id);
269 
270  _dlg_vars *const p_vars = &(dlg.vars);
271 
272  uint32_t start_tick = HAL_GetTick();
273 
274  //inicialization cb given in parameter
275  if (_ths->on_load != NULL)
276  _ths->on_load();
277 
278  while ((size_t)(p_vars->phase) < _ths->count) //negative number will force exit
279  {
280  //loop cb given in parameter
281  if (_ths->on_loop != NULL) {
282  if (_ths->on_loop(p_vars, p_additional_vars) == LOOP_RESULT_BREAK)
283  break;
284  }
285 
286  //time to live reached?
287  if ((uint32_t)(HAL_GetTick() - start_tick) >= (uint32_t)ttl) {
288  if (_ths->on_timeout != NULL)
289  _ths->on_timeout();
290  break;
291  }
292 
293  //button auto exit flag must be handled here
294  //state could change phase
295  if (
296  (p_vars->flags & DLG_BT_FLG) && //button clicked
297  (_ths->p_states[p_vars->phase].p_button->flags & BT_AUTOEXIT) //autoexit flag on current button
298  ) {
299  break;
300  }
301 
302  int part_progress = _ths->p_states[p_vars->phase].state_fnc(p_vars, p_additional_vars); //state machine
303 
304  //forced exit
305  //intended to be used as handling user clicked exit button
306  //any state change phase to -1 and force exit
307  if ((size_t)(p_vars->phase) >= _ths->count)
308  break;
309 
310  p_vars->flags &= ~DLG_BT_FLG; //disable button clicked
311 
312  is_part_log(part_progress); //log raw value obtained from state
313 
314  //calculate partial progress (progress of current phase)
315  if (part_progress > p_vars->part_progress)
316  p_vars->part_progress = (uint8_t)part_progress; //progress can only rise
317  if (part_progress > 100)
318  p_vars->part_progress = 100;
319  if (part_progress < 0)
320  p_vars->part_progress = 0;
321 
322  if (p_vars->prev_part_progress != p_vars->part_progress) {
323  dlg.flags |= (p_vars->prev_part_progress != p_vars->part_progress) ? DLG_PPR_CH : 0;
324  }
325 
326  //phase changed
327  if (p_vars->prev_phase != p_vars->phase) {
328  p_vars->part_progress = 0;
329  dlg.flags |= DLG_PHA_CH;
330  gui_invalidate();
331  p_vars->base_progress = 100 * _phase_time_total(p_vars->prev_phase, _ths) / p_vars->time_total;
332  p_vars->prev_phase = p_vars->phase;
333  p_vars->tick_part_start = HAL_GetTick();
334 
335  phase_changed_log(p_vars->phase, p_vars->base_progress);
336  }
337 
338  //calculate "total" progress
339  //p_vars->part_progress MUST remain unscaled
340  //p_vars->base_progress is scaled
341  part_progress = (int)(p_vars->part_progress) * (_ths->p_states[p_vars->phase].time) / p_vars->time_total;
342  p_vars->progress = p_vars->base_progress + part_progress;
343 
344  //in last phase maximum progress is 100
345  //in all other phases maximum progress is 99
346  if ((size_t)(p_vars->phase) == _ths->count - 1) {
347  if (p_vars->progress > 100)
348  p_vars->progress = 100;
349  } else {
350  if (p_vars->progress > 99)
351  p_vars->progress = 99;
352  }
353 
354  //progress changed
355  dlg.flags |= (p_vars->prev_progress != p_vars->progress) ? DLG_PRO_CH : 0;
356 
357  if (dlg.flags & (DLG_PRX_CH)) //any progress changed
358  {
359  gui_invalidate();
361  p_vars->prev_progress = p_vars->progress;
362  }
363 
364  print_log();
365  gui_loop();
366  }
367  if (_ths->on_done != NULL)
368  _ths->on_done();
369  window_destroy(id);
370  window_set_capture(id_capture);
372  return DLG_OK;
373 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_dlg_statemachine_draw_0bt()

void window_dlg_statemachine_draw_0bt ( window_dlg_statemachine_t window)
94  {
96 
97  display->fill_rect(rc_btn, window->color_back);
98 }
Here is the call graph for this function:

◆ window_dlg_statemachine_draw_1bt()

void window_dlg_statemachine_draw_1bt ( window_dlg_statemachine_t window)
87  {
89  const char *label = window->_ths->p_states[window->vars.phase].p_button->labels[0];
90  int enabled = window->_ths->p_states[window->vars.phase].p_button->flags & BT_ENABLED ? 1 : 0;
91  button_draw(rc_btn, label, window->font_title, enabled);
92 }
Here is the call graph for this function:

◆ window_dlg_statemachine_event_1bt()

void window_dlg_statemachine_event_1bt ( window_dlg_statemachine_t window,
uint8_t  event,
void param 
)
236  {
237  switch (event) {
238  case WINDOW_EVENT_BTN_DN:
239  //case WINDOW_EVENT_BTN_UP:
240  case WINDOW_EVENT_CLICK:
241  window->vars.flags |= DLG_BT_FLG;
242  return;
243  }
244 }

Variable Documentation

◆ WINDOW_CLS_DLG_LOADUNLOAD

int16_t WINDOW_CLS_DLG_LOADUNLOAD

◆ window_class_dlg_statemachine

const window_class_dlg_statemachine_t window_class_dlg_statemachine
_cl_dlg::on_timeout
const dlg_cb_t on_timeout
Definition: window_dlg_statemachine.h:83
phase_changed_log
static void phase_changed_log(int phase, int base_progress)
Definition: window_dlg_statemachine.c:461
_window_dlg_statemachine_t::_ths
const _cl_dlg * _ths
Definition: window_dlg_statemachine.h:97
_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
WINDOW_CLS_DLG_LOADUNLOAD
int16_t WINDOW_CLS_DLG_LOADUNLOAD
Definition: window_dlg_statemachine.c:37
progress_draw
void progress_draw(rect_ui16_t win_rect, font_t *font, color_t color_back, color_t color_text, padding_ui8_t padding, uint8_t progress)
Definition: window_dlg_statemachine.c:108
window_capture
int16_t window_capture(void)
Definition: window.c:169
_rect_ui16_t::y
uint16_t y
Definition: guitypes.h:71
_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
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
DLG_PRX_CH
#define DLG_PRX_CH
Definition: window_dlg_statemachine.c:31
BT_AUTOEXIT
#define BT_AUTOEXIT
Definition: window_dlg_statemachine.h:17
_cl_dlg::on_loop
const dlg_loop_cb_t on_loop
Definition: window_dlg_statemachine.h:82
DLG_PPR_CH
#define DLG_PPR_CH
Definition: window_dlg_statemachine.c:30
window_invalidate
void window_invalidate(int16_t id)
Definition: window.c:304
progress_clr
void progress_clr(rect_ui16_t win_rect, font_t *font, color_t color_back)
Definition: window_dlg_statemachine.c:130
_dlg_state::state_fnc
dlg_state_func state_fnc
Definition: window_dlg_statemachine.h:73
window_destroy
void window_destroy(int16_t id)
Definition: window.c:132
DLG_BTN_CH
#define DLG_BTN_CH
Definition: window_dlg_statemachine.c:27
_gui_defaults_t::msg_box_sz
rect_ui16_t msg_box_sz
Definition: guitypes.h:114
print_log
static void print_log()
Definition: window_dlg_statemachine.c:463
_dlg_vars::phase
int8_t phase
Definition: window_dlg_statemachine.h:39
NULL
#define NULL
Definition: usbd_def.h:53
_window_dlg_statemachine_t::color_text
color_t color_text
Definition: window_dlg_statemachine.h:90
_window_dlg_statemachine_t
Definition: window_dlg_statemachine.h:87
_display_t::fill_rect
display_fill_rect_t * fill_rect
Definition: display.h:33
HAL_GetTick
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
Definition: stm32f4xx_hal.c:339
_window_dlg_statemachine_t::vars
_dlg_vars vars
Definition: window_dlg_statemachine.h:98
is_part_log
static void is_part_log(int part_progress)
Definition: window_dlg_statemachine.c:457
_dlg_vars::time_total
uint32_t time_total
Definition: window_dlg_statemachine.h:47
button_draw
void button_draw(rect_ui16_t rc_btn, const char *text, font_t *pf, int is_selected)
Definition: button_draw.c:5
gui_invalidate
void gui_invalidate(void)
Definition: gui.c:66
LOOP_RESULT_BREAK
Definition: window_dlg_statemachine.h:52
_window_dlg_statemachine_t::font_title
font_t * font_title
Definition: window_dlg_statemachine.h:92
_window_dlg_statemachine_t::win
window_t win
Definition: window_dlg_statemachine.h:88
LOOP_RESULT_CONTINUE
Definition: window_dlg_statemachine.h:51
_window_t
Definition: window.h:76
_cl_dlg::on_done
const dlg_cb_t on_done
Definition: window_dlg_statemachine.h:84
_dlg_vars::base_progress
uint8_t base_progress
Definition: window_dlg_statemachine.h:44
_dlg_button_t::flags
uint8_t flags
Definition: window_dlg_statemachine.h:62
window_set_capture
void window_set_capture(int16_t id)
Definition: window.c:500
if
if(size<=((png_alloc_size_t) -1) - ob)
Definition: pngwrite.c:2176
_phase_time_total
static uint32_t _phase_time_total(int phase, const _cl_dlg *_ths)
Definition: window_dlg_statemachine.c:375
_rect_ui16_t
Definition: guitypes.h:69
_dlg_vars::prev_phase
int8_t prev_phase
Definition: window_dlg_statemachine.h:40
_dlg_state::time
uint32_t time
Definition: window_dlg_statemachine.h:69
uint8_t
const uint8_t[]
Definition: 404_html.c:3
progress_changed_log
static void progress_changed_log(int progress)
Definition: window_dlg_statemachine.c:459
DLG_OK
Definition: dlg_result.h:10
_dlg_vars
Definition: window_dlg_statemachine.h:36
display
display_t * display
Definition: display.c:6
_rect_ui16_t::h
uint16_t h
Definition: guitypes.h:73
_dlg_vars::part_progress
uint8_t part_progress
Definition: window_dlg_statemachine.h:43
_window_t::rect
rect_ui16_t rect
Definition: window.h:101
_dlg_state::p_button
const _dlg_button_t * p_button
Definition: window_dlg_statemachine.h:72
WINDOW_EVENT_CLICK
#define WINDOW_EVENT_CLICK
Definition: window.h:46
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
DLG_PRO_CH
#define DLG_PRO_CH
Definition: window_dlg_statemachine.c:29
_rect_ui16_t::x
uint16_t x
Definition: guitypes.h:70
_window_dlg_statemachine_t::padding
padding_ui8_t padding
Definition: window_dlg_statemachine.h:93
createSpeedLookupTable.int
int
Definition: createSpeedLookupTable.py:15
_dlg_vars::prev_part_progress
uint8_t prev_part_progress
Definition: window_dlg_statemachine.h:45
gui_defaults
gui_defaults_t gui_defaults
Definition: gui.c:20
WINDOW_EVENT_BTN_DN
#define WINDOW_EVENT_BTN_DN
Definition: window.h:38
_cl_dlg::count
const size_t count
Definition: window_dlg_statemachine.h:80
_dlg_vars::progress
uint8_t progress
Definition: window_dlg_statemachine.h:41
window_1
window_t * window_1
Definition: window.c:14
_get_dlg_statemachine_button_size
rect_ui16_t _get_dlg_statemachine_button_size(window_dlg_statemachine_t *window)
Definition: window_dlg_statemachine.c:78
DLG_PHA_CH
#define DLG_PHA_CH
Definition: window_dlg_statemachine.c:32
_dlg_vars::tick_part_start
uint32_t tick_part_start
Definition: window_dlg_statemachine.h:46
_dlg_button_t::labels
const char ** labels
Definition: window_dlg_statemachine.h:61
clr_logs
static void clr_logs()
Definition: window_dlg_statemachine.c:455
loop_result_t
loop_result_t
Definition: window_dlg_statemachine.h:50
_cl_dlg::on_load
const dlg_cb_t on_load
Definition: window_dlg_statemachine.h:81
_window_dlg_statemachine_t::flags
uint16_t flags
Definition: window_dlg_statemachine.h:94
_dlg_vars::prev_progress
uint8_t prev_progress
Definition: window_dlg_statemachine.h:42