Prusa MINI Firmware overview
gui_timer.c File Reference
#include "gui_timer.h"
#include <string.h>
#include "stm32f4xx_hal.h"
#include "screen.h"

Classes

struct  _gui_timer_t
 

Macros

#define GUI_MAX_TIMERS   5
 
#define GUI_TIMER_NONE   0
 
#define GUI_TIMER_1SHT   1
 
#define GUI_TIMER_PERI   2
 
#define GUI_MENU_TIMEOUT   3
 

Typedefs

typedef struct _gui_timer_t gui_timer_t
 

Functions

int8_t gui_timer_new (uint8_t timer, uint32_t ms, int16_t win_id)
 
int8_t gui_timer_create_oneshot (uint32_t ms, int16_t win_id)
 
int8_t gui_timer_create_periodical (uint32_t ms, int16_t win_id)
 
int8_t gui_timer_create_timeout (uint32_t ms, int16_t win_id)
 
void gui_timer_delete (int8_t id)
 
void gui_timers_delete_by_window_id (int16_t win_id)
 
uint32_t gui_timers_cycle (void)
 
void gui_timer_reset (int8_t id)
 
int8_t gui_timer_expired (int8_t id)
 
int8_t gui_get_menu_timeout_id (void)
 

Variables

gui_timer_t gui_timers [GUI_MAX_TIMERS]
 
int8_t gui_timer_count = -1
 
int8_t gui_menu_timeout_id = -1
 

Macro Definition Documentation

◆ GUI_MAX_TIMERS

#define GUI_MAX_TIMERS   5

◆ GUI_TIMER_NONE

#define GUI_TIMER_NONE   0

◆ GUI_TIMER_1SHT

#define GUI_TIMER_1SHT   1

◆ GUI_TIMER_PERI

#define GUI_TIMER_PERI   2

◆ GUI_MENU_TIMEOUT

#define GUI_MENU_TIMEOUT   3

Typedef Documentation

◆ gui_timer_t

typedef struct _gui_timer_t gui_timer_t

Function Documentation

◆ gui_timer_new()

int8_t gui_timer_new ( uint8_t  timer,
uint32_t  ms,
int16_t  win_id 
)
38  {
39  window_t *window;
40  uint32_t tick = HAL_GetTick();
41  int8_t id = -1;
43  id = 0;
44  if (gui_timer_count == -1) //not initialized
45  {
46  gui_timer_count = 0;
47  memset(gui_timers, 0, GUI_MAX_TIMERS * sizeof(gui_timer_t));
48  } else //find free id
49  while ((id < GUI_MAX_TIMERS) && (gui_timers[id].f_timer != GUI_TIMER_NONE))
50  id++;
51  if (id < GUI_MAX_TIMERS) //id is valid
52  {
53  gui_timers[id].start = tick;
54  gui_timers[id].delay = ms;
55  gui_timers[id].f_timer = timer;
56  gui_timers[id].win_id = win_id;
57  gui_timer_count++; //increment count
58  if ((window = window_ptr(win_id)) != 0)
59  window->f_timer = 1; //set timer flag
60  } else
61  id = -1;
62  }
63  return id;
64 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_timer_create_oneshot()

int8_t gui_timer_create_oneshot ( uint32_t  ms,
int16_t  win_id 
)
66  {
67  return gui_timer_new(GUI_TIMER_1SHT, ms, win_id);
68 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_timer_create_periodical()

int8_t gui_timer_create_periodical ( uint32_t  ms,
int16_t  win_id 
)
70  {
71  return gui_timer_new(GUI_TIMER_PERI, ms, win_id);
72 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_timer_create_timeout()

int8_t gui_timer_create_timeout ( uint32_t  ms,
int16_t  win_id 
)
74  {
76  return gui_menu_timeout_id;
77 }
Here is the call graph for this function:

◆ gui_timer_delete()

void gui_timer_delete ( int8_t  id)
79  {
80  if ((id >= 0) && (id < GUI_MAX_TIMERS) && (gui_timers[id].f_timer != GUI_TIMER_NONE)) {
81  gui_timers[id].start = 0;
82  gui_timers[id].delay = 0;
83  if (gui_timers[id].f_timer == GUI_MENU_TIMEOUT)
86  gui_timers[id].win_id = 0;
87  gui_timer_count--; //decrement count
88  }
89 }
Here is the caller graph for this function:

◆ gui_timers_delete_by_window_id()

void gui_timers_delete_by_window_id ( int16_t  win_id)
91  {
92  int8_t id;
93  for (id = 0; id < GUI_MAX_TIMERS; id++)
94  if (gui_timers[id].win_id == win_id)
95  gui_timer_delete(id);
96 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_timers_cycle()

uint32_t gui_timers_cycle ( void  )
98  {
99  uint32_t tick = HAL_GetTick();
100  uint32_t delay;
101  uint32_t diff;
102  uint32_t diff_min = 0xffffffff;
103  uint8_t f_timer;
104  uint8_t count = 0;
105  int8_t id;
106  for (id = 0; (id < GUI_MAX_TIMERS); id++)
107  if ((f_timer = gui_timers[id].f_timer) != GUI_TIMER_NONE) {
108  if ((delay = gui_timers[id].delay) > 0) {
109  diff = tick - gui_timers[id].start;
110  if (delay <= diff) {
111  switch (gui_timers[id].f_timer) {
112  case GUI_TIMER_1SHT:
113  screen_dispatch_event(window_ptr(gui_timers[id].win_id), WINDOW_EVENT_TIMER, (void *)(int)id);
114  gui_timers[id].delay = 0;
115  break;
116  case GUI_TIMER_PERI:
117  screen_dispatch_event(window_ptr(gui_timers[id].win_id), WINDOW_EVENT_TIMER, (void *)(int)id);
118  gui_timers[id].start += delay;
119  break;
120  case GUI_MENU_TIMEOUT:
121  gui_timers[id].delay = 0;
122  break;
123  }
124  } else if (diff_min < diff)
125  diff_min = diff;
126  }
127  if (++count >= gui_timer_count)
128  break;
129  }
130  return diff_min;
131 }
Here is the call graph for this function:

◆ gui_timer_reset()

void gui_timer_reset ( int8_t  id)
133  {
134 
135  if ((id >= 0) && (id < GUI_MAX_TIMERS) && (gui_timers[id].f_timer != GUI_TIMER_NONE))
136  gui_timers[id].start = HAL_GetTick();
137 }
Here is the call graph for this function:

◆ gui_timer_expired()

int8_t gui_timer_expired ( int8_t  id)
139  {
140 
141  if ((id >= 0) && (id < GUI_MAX_TIMERS) && (gui_timers[id].f_timer != GUI_TIMER_NONE))
142  return gui_timers[id].delay == 0 ? 1 : 0;
143 
144  return -1;
145 }
Here is the caller graph for this function:

◆ gui_get_menu_timeout_id()

int8_t gui_get_menu_timeout_id ( void  )
147  {
148  return gui_menu_timeout_id;
149 }
Here is the caller graph for this function:

Variable Documentation

◆ gui_timers

◆ gui_timer_count

int8_t gui_timer_count = -1

◆ gui_menu_timeout_id

int8_t gui_menu_timeout_id = -1
_gui_timer_t::delay
uint32_t delay
Definition: gui_timer.c:20
_gui_timer_t::f_timer
uint32_t f_timer
Definition: gui_timer.c:26
gui_menu_timeout_id
int8_t gui_menu_timeout_id
Definition: gui_timer.c:36
_window_t::f_timer
uint32_t f_timer
Definition: window.h:94
GUI_MAX_TIMERS
#define GUI_MAX_TIMERS
Definition: gui_timer.c:8
gui_timer_delete
void gui_timer_delete(int8_t id)
Definition: gui_timer.c:79
GUI_TIMER_NONE
#define GUI_TIMER_NONE
Definition: gui_timer.c:10
gui_timer_count
int8_t gui_timer_count
Definition: gui_timer.c:35
HAL_GetTick
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
Definition: stm32f4xx_hal.c:339
GUI_TIMER_1SHT
#define GUI_TIMER_1SHT
Definition: gui_timer.c:11
window_ptr
window_t * window_ptr(int16_t id)
Definition: window.c:82
_window_t
Definition: window.h:76
_gui_timer_t
Definition: gui_timer.c:18
uint8_t
const uint8_t[]
Definition: 404_html.c:3
delay
void delay(uint32_t ms)
Definition: wiring_time.c:42
_gui_timer_t::win_id
int16_t win_id
Definition: gui_timer.c:29
GUI_MENU_TIMEOUT
#define GUI_MENU_TIMEOUT
Definition: gui_timer.c:13
GUI_TIMER_PERI
#define GUI_TIMER_PERI
Definition: gui_timer.c:12
gui_timer_new
int8_t gui_timer_new(uint8_t timer, uint32_t ms, int16_t win_id)
Definition: gui_timer.c:38
WINDOW_EVENT_TIMER
#define WINDOW_EVENT_TIMER
Definition: window.h:50
gui_timers
gui_timer_t gui_timers[GUI_MAX_TIMERS]
Definition: gui_timer.c:34
screen_dispatch_event
void screen_dispatch_event(window_t *window, uint8_t event, void *param)
Definition: screen.c:103
_gui_timer_t::start
uint32_t start
Definition: gui_timer.c:19