Prusa MINI Firmware overview
marlin_vars.c File Reference
#include "marlin_vars.h"
#include <stdio.h>
#include <string.h>

Functions

const char * marlin_vars_get_name (uint8_t var_id)
 
int marlin_vars_get_id_by_name (const char *var_name)
 
variant8_t marlin_vars_get_var (marlin_vars_t *vars, uint8_t var_id)
 
void marlin_vars_set_var (marlin_vars_t *vars, uint8_t var_id, variant8_t var)
 
void marlin_vars_value_to_str (marlin_vars_t *vars, uint8_t var_id, char *str)
 
int marlin_vars_str_to_value (marlin_vars_t *vars, uint8_t var_id, const char *str)
 

Variables

const char * __var_name []
 

Function Documentation

◆ marlin_vars_get_name()

const char* marlin_vars_get_name ( uint8_t  var_id)
36  {
37  if (var_id <= MARLIN_VAR_MAX)
38  return __var_name[var_id];
39  return "";
40 }
Here is the caller graph for this function:

◆ marlin_vars_get_id_by_name()

int marlin_vars_get_id_by_name ( const char *  var_name)
42  {
43  int i;
44  for (i = 0; i <= MARLIN_VAR_MAX; i++)
45  if (strcmp(var_name, __var_name[i]) == 0)
46  return i;
47  return -1;
48 }
Here is the caller graph for this function:

◆ marlin_vars_get_var()

variant8_t marlin_vars_get_var ( marlin_vars_t vars,
uint8_t  var_id 
)
50  {
51  if (vars)
52  switch (var_id) {
53  case MARLIN_VAR_MOTION:
54  return variant8_ui8(vars->motion);
55  case MARLIN_VAR_GQUEUE:
56  return variant8_ui8(vars->gqueue);
57  case MARLIN_VAR_PQUEUE:
58  return variant8_ui8(vars->pqueue);
59  case MARLIN_VAR_IPOS_X:
60  return variant8_i32(vars->ipos[0]);
61  case MARLIN_VAR_IPOS_Y:
62  return variant8_i32(vars->ipos[1]);
63  case MARLIN_VAR_IPOS_Z:
64  return variant8_i32(vars->ipos[2]);
65  case MARLIN_VAR_IPOS_E:
66  return variant8_i32(vars->ipos[3]);
67  case MARLIN_VAR_POS_X:
68  return variant8_flt(vars->pos[0]);
69  case MARLIN_VAR_POS_Y:
70  return variant8_flt(vars->pos[1]);
71  case MARLIN_VAR_POS_Z:
72  return variant8_flt(vars->pos[2]);
73  case MARLIN_VAR_POS_E:
74  return variant8_flt(vars->pos[3]);
76  return variant8_flt(vars->temp_nozzle);
78  return variant8_flt(vars->temp_bed);
80  return variant8_flt(vars->target_nozzle);
82  return variant8_flt(vars->target_bed);
84  return variant8_flt(vars->z_offset);
86  return variant8_ui8(vars->fan_speed);
88  return variant8_ui16(vars->print_speed);
90  return variant8_ui16(vars->flow_factor);
92  return variant8_ui8(vars->wait_heat);
94  return variant8_ui8(vars->wait_user);
96  return variant8_ui8(vars->sd_printing);
98  return variant8_ui8(vars->sd_percent_done);
100  return variant8_ui32(vars->print_duration);
101  }
102  return variant8_empty();
103 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_vars_set_var()

void marlin_vars_set_var ( marlin_vars_t vars,
uint8_t  var_id,
variant8_t  var 
)
105  {
106  if (vars)
107  switch (var_id) {
108  case MARLIN_VAR_MOTION:
109  vars->motion = var.ui8;
110  break;
111  case MARLIN_VAR_GQUEUE:
112  vars->gqueue = var.ui8;
113  break;
114  case MARLIN_VAR_PQUEUE:
115  vars->pqueue = var.ui8;
116  break;
117  case MARLIN_VAR_IPOS_X:
118  vars->ipos[0] = var.i32;
119  break;
120  case MARLIN_VAR_IPOS_Y:
121  vars->ipos[1] = var.i32;
122  break;
123  case MARLIN_VAR_IPOS_Z:
124  vars->ipos[2] = var.i32;
125  break;
126  case MARLIN_VAR_IPOS_E:
127  vars->ipos[3] = var.i32;
128  break;
129  case MARLIN_VAR_POS_X:
130  vars->pos[0] = var.flt;
131  break;
132  case MARLIN_VAR_POS_Y:
133  vars->pos[1] = var.flt;
134  break;
135  case MARLIN_VAR_POS_Z:
136  vars->pos[2] = var.flt;
137  break;
138  case MARLIN_VAR_POS_E:
139  vars->pos[3] = var.flt;
140  break;
141  case MARLIN_VAR_TEMP_NOZ:
142  vars->temp_nozzle = var.flt;
143  break;
144  case MARLIN_VAR_TEMP_BED:
145  vars->temp_bed = var.flt;
146  break;
147  case MARLIN_VAR_TTEM_NOZ:
148  vars->target_nozzle = var.flt;
149  break;
150  case MARLIN_VAR_TTEM_BED:
151  vars->target_bed = var.flt;
152  break;
153  case MARLIN_VAR_Z_OFFSET:
154  vars->z_offset = var.flt;
155  break;
156  case MARLIN_VAR_FANSPEED:
157  vars->fan_speed = var.ui8;
158  break;
159  case MARLIN_VAR_PRNSPEED:
160  vars->print_speed = var.ui16;
161  break;
162  case MARLIN_VAR_FLOWFACT:
163  vars->flow_factor = var.ui16;
164  break;
165  case MARLIN_VAR_WAITHEAT:
166  vars->wait_heat = var.ui8;
167  break;
168  case MARLIN_VAR_WAITUSER:
169  vars->wait_user = var.ui8;
170  break;
171  case MARLIN_VAR_SD_PRINT:
172  vars->sd_printing = var.ui8;
173  break;
174  case MARLIN_VAR_SD_PDONE:
175  vars->sd_percent_done = var.ui8;
176  break;
177  case MARLIN_VAR_DURATION:
178  vars->print_duration = var.ui32;
179  break;
180  }
181 }
Here is the caller graph for this function:

◆ marlin_vars_value_to_str()

void marlin_vars_value_to_str ( marlin_vars_t vars,
uint8_t  var_id,
char *  str 
)
183  {
184  if (vars)
185  switch (var_id) {
186  case MARLIN_VAR_MOTION:
187  sprintf(str, "%u", (unsigned int)(vars->motion));
188  break;
189  case MARLIN_VAR_GQUEUE:
190  sprintf(str, "%u", (unsigned int)(vars->gqueue));
191  break;
192  case MARLIN_VAR_PQUEUE:
193  sprintf(str, "%u", (unsigned int)(vars->pqueue));
194  break;
195  case MARLIN_VAR_IPOS_X:
196  case MARLIN_VAR_IPOS_Y:
197  case MARLIN_VAR_IPOS_Z:
198  case MARLIN_VAR_IPOS_E:
199  sprintf(str, "%li", (long int)vars->ipos[var_id - MARLIN_VAR_IPOS_X]);
200  break;
201  case MARLIN_VAR_POS_X:
202  case MARLIN_VAR_POS_Y:
203  case MARLIN_VAR_POS_Z:
204  case MARLIN_VAR_POS_E:
205  sprintf(str, "%.3f", (double)(vars->pos[var_id - MARLIN_VAR_POS_X]));
206  break;
207  case MARLIN_VAR_TEMP_NOZ:
208  sprintf(str, "%.1f", (double)(vars->temp_nozzle));
209  break;
210  case MARLIN_VAR_TEMP_BED:
211  sprintf(str, "%.1f", (double)(vars->temp_bed));
212  break;
213  case MARLIN_VAR_TTEM_NOZ:
214  sprintf(str, "%.1f", (double)(vars->target_nozzle));
215  break;
216  case MARLIN_VAR_TTEM_BED:
217  sprintf(str, "%.1f", (double)(vars->target_bed));
218  break;
219  case MARLIN_VAR_Z_OFFSET:
220  sprintf(str, "%.4f", (double)(vars->z_offset));
221  break;
222  case MARLIN_VAR_FANSPEED:
223  sprintf(str, "%u", (unsigned int)(vars->fan_speed));
224  break;
225  case MARLIN_VAR_PRNSPEED:
226  sprintf(str, "%u", (unsigned int)(vars->print_speed));
227  break;
228  case MARLIN_VAR_FLOWFACT:
229  sprintf(str, "%u", (unsigned int)(vars->flow_factor));
230  break;
231  case MARLIN_VAR_WAITHEAT:
232  sprintf(str, "%u", (unsigned int)(vars->wait_heat));
233  break;
234  case MARLIN_VAR_WAITUSER:
235  sprintf(str, "%u", (unsigned int)(vars->wait_user));
236  break;
237  case MARLIN_VAR_SD_PRINT:
238  sprintf(str, "%u", (unsigned int)(vars->sd_printing));
239  break;
240  case MARLIN_VAR_SD_PDONE:
241  sprintf(str, "%u", (unsigned int)(vars->sd_percent_done));
242  break;
243  case MARLIN_VAR_DURATION:
244  sprintf(str, "%lu", (long unsigned int)(vars->print_duration));
245  break;
246  default:
247  sprintf(str, "???");
248  }
249 }
Here is the caller graph for this function:

◆ marlin_vars_str_to_value()

int marlin_vars_str_to_value ( marlin_vars_t vars,
uint8_t  var_id,
const char *  str 
)
251  {
252  int ret = 0;
253  if (vars)
254  switch (var_id) {
255  case MARLIN_VAR_MOTION:
256  ret = sscanf(str, "%hhu", &(vars->motion));
257  break;
258  case MARLIN_VAR_GQUEUE:
259  ret = sscanf(str, "%hhu", &(vars->gqueue));
260  break;
261  case MARLIN_VAR_PQUEUE:
262  ret = sscanf(str, "%hhu", &(vars->pqueue));
263  break;
264  case MARLIN_VAR_IPOS_X:
265  case MARLIN_VAR_IPOS_Y:
266  case MARLIN_VAR_IPOS_Z:
267  case MARLIN_VAR_IPOS_E:
268  ret = sscanf(str, "%li", &(vars->ipos[var_id - MARLIN_VAR_IPOS_X]));
269  break;
270  case MARLIN_VAR_POS_X:
271  case MARLIN_VAR_POS_Y:
272  case MARLIN_VAR_POS_Z:
273  case MARLIN_VAR_POS_E:
274  ret = sscanf(str, "%f", &(vars->pos[var_id - MARLIN_VAR_POS_X]));
275  break;
276  case MARLIN_VAR_TEMP_NOZ:
277  ret = sscanf(str, "%f", &(vars->temp_nozzle));
278  break;
279  case MARLIN_VAR_TEMP_BED:
280  ret = sscanf(str, "%f", &(vars->temp_bed));
281  break;
282  case MARLIN_VAR_TTEM_NOZ:
283  ret = sscanf(str, "%f", &(vars->target_nozzle));
284  break;
285  case MARLIN_VAR_TTEM_BED:
286  ret = sscanf(str, "%f", &(vars->target_bed));
287  break;
288  case MARLIN_VAR_Z_OFFSET:
289  ret = sscanf(str, "%f", &(vars->z_offset));
290  break;
291  case MARLIN_VAR_FANSPEED:
292  ret = sscanf(str, "%hhu", &(vars->fan_speed));
293  break;
294  case MARLIN_VAR_PRNSPEED:
295  ret = sscanf(str, "%hu", (unsigned short *)&(vars->print_speed));
296  break;
297  case MARLIN_VAR_FLOWFACT:
298  ret = sscanf(str, "%hu", (unsigned short *)&(vars->flow_factor));
299  break;
300  case MARLIN_VAR_WAITHEAT:
301  ret = sscanf(str, "%hhu", &(vars->wait_heat));
302  break;
303  case MARLIN_VAR_WAITUSER:
304  ret = sscanf(str, "%hhu", &(vars->wait_user));
305  break;
306  case MARLIN_VAR_SD_PRINT:
307  ret = sscanf(str, "%hhu", &(vars->sd_printing));
308  break;
309  case MARLIN_VAR_SD_PDONE:
310  ret = sscanf(str, "%hhu", &(vars->sd_percent_done));
311  break;
312  case MARLIN_VAR_DURATION:
313  ret = sscanf(str, "%lu", &(vars->print_duration));
314  break;
315  }
316  return ret;
317 }
Here is the caller graph for this function:

Variable Documentation

◆ __var_name

const char* __var_name[]
Initial value:
= {
"MOTION",
"GQUEUE",
"PQUEUE",
"IPOS_X",
"IPOS_Y",
"IPOS_Z",
"IPOS_E",
"POS_X",
"POS_Y",
"POS_Z",
"POS_E",
"TEMP_NOZ",
"TEMP_BED",
"TTEM_NOZ",
"TTEM_BED",
"Z_OFFSET",
"FANSPEED",
"PRNSPEED",
"FLOWFACT",
"WAITHEAT",
"WAITUSER",
"SD_PRINT",
"SD_PDONE",
"DURATION",
"FSENSOR",
}
MARLIN_VAR_IPOS_E
#define MARLIN_VAR_IPOS_E
Definition: marlin_vars.h:14
variant8_ui8
variant8_t variant8_ui8(uint8_t ui8)
Definition: variant8.c:18
MARLIN_VAR_TEMP_BED
#define MARLIN_VAR_TEMP_BED
Definition: marlin_vars.h:20
_variant8_t::ui16
uint16_t ui16
Definition: variant8.h:34
MARLIN_VAR_FLOWFACT
#define MARLIN_VAR_FLOWFACT
Definition: marlin_vars.h:26
MARLIN_VAR_POS_X
#define MARLIN_VAR_POS_X
Definition: marlin_vars.h:15
MARLIN_VAR_MOTION
#define MARLIN_VAR_MOTION
Definition: marlin_vars.h:8
_marlin_vars_t::z_offset
float z_offset
Definition: marlin_vars.h:87
MARLIN_VAR_IPOS_X
#define MARLIN_VAR_IPOS_X
Definition: marlin_vars.h:11
MARLIN_VAR_SD_PDONE
#define MARLIN_VAR_SD_PDONE
Definition: marlin_vars.h:30
_variant8_t::ui8
uint8_t ui8
Definition: variant8.h:36
MARLIN_VAR_FANSPEED
#define MARLIN_VAR_FANSPEED
Definition: marlin_vars.h:24
i
uint8_t i
Definition: screen_test_graph.c:72
_marlin_vars_t::pqueue
uint8_t pqueue
Definition: marlin_vars.h:80
MARLIN_VAR_TTEM_BED
#define MARLIN_VAR_TTEM_BED
Definition: marlin_vars.h:22
variant8_ui16
variant8_t variant8_ui16(uint16_t ui16)
Definition: variant8.c:30
MARLIN_VAR_WAITUSER
#define MARLIN_VAR_WAITUSER
Definition: marlin_vars.h:28
_marlin_vars_t::temp_nozzle
float temp_nozzle
Definition: marlin_vars.h:83
MARLIN_VAR_IPOS_Y
#define MARLIN_VAR_IPOS_Y
Definition: marlin_vars.h:12
_variant8_t::flt
float flt
Definition: variant8.h:31
MARLIN_VAR_TEMP_NOZ
#define MARLIN_VAR_TEMP_NOZ
Definition: marlin_vars.h:19
MARLIN_VAR_PQUEUE
#define MARLIN_VAR_PQUEUE
Definition: marlin_vars.h:10
MARLIN_VAR_GQUEUE
#define MARLIN_VAR_GQUEUE
Definition: marlin_vars.h:9
__var_name
const char * __var_name[]
Definition: marlin_vars.c:8
_marlin_vars_t::wait_heat
uint8_t wait_heat
Definition: marlin_vars.h:91
_marlin_vars_t::target_nozzle
float target_nozzle
Definition: marlin_vars.h:85
MARLIN_VAR_WAITHEAT
#define MARLIN_VAR_WAITHEAT
Definition: marlin_vars.h:27
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_vars_t::wait_user
uint8_t wait_user
Definition: marlin_vars.h:92
_marlin_vars_t::temp_bed
float temp_bed
Definition: marlin_vars.h:84
variant8_empty
variant8_t variant8_empty(void)
Definition: variant8.c:10
MARLIN_VAR_PRNSPEED
#define MARLIN_VAR_PRNSPEED
Definition: marlin_vars.h:25
MARLIN_VAR_SD_PRINT
#define MARLIN_VAR_SD_PRINT
Definition: marlin_vars.h:29
_marlin_vars_t::print_speed
uint16_t print_speed
Definition: marlin_vars.h:89
MARLIN_VAR_DURATION
#define MARLIN_VAR_DURATION
Definition: marlin_vars.h:31
variant8_ui32
variant8_t variant8_ui32(uint32_t ui32)
Definition: variant8.c:42
_marlin_vars_t::print_duration
uint32_t print_duration
Definition: marlin_vars.h:95
_marlin_vars_t::sd_percent_done
uint8_t sd_percent_done
Definition: marlin_vars.h:94
_marlin_vars_t::flow_factor
uint16_t flow_factor
Definition: marlin_vars.h:90
_marlin_vars_t::gqueue
uint8_t gqueue
Definition: marlin_vars.h:79
variant8_i32
variant8_t variant8_i32(int32_t i32)
Definition: variant8.c:36
MARLIN_VAR_IPOS_Z
#define MARLIN_VAR_IPOS_Z
Definition: marlin_vars.h:13
MARLIN_VAR_POS_Y
#define MARLIN_VAR_POS_Y
Definition: marlin_vars.h:16
_marlin_vars_t::pos
float pos[4]
Definition: marlin_vars.h:82
MARLIN_VAR_TTEM_NOZ
#define MARLIN_VAR_TTEM_NOZ
Definition: marlin_vars.h:21
_variant8_t::ui32
uint32_t ui32
Definition: variant8.h:32
variant8_flt
variant8_t variant8_flt(float flt)
Definition: variant8.c:48
_marlin_vars_t::sd_printing
uint8_t sd_printing
Definition: marlin_vars.h:93
_marlin_vars_t::target_bed
float target_bed
Definition: marlin_vars.h:86
_marlin_vars_t::ipos
int32_t ipos[4]
Definition: marlin_vars.h:81
MARLIN_VAR_MAX
#define MARLIN_VAR_MAX
Definition: marlin_vars.h:32
MARLIN_VAR_Z_OFFSET
#define MARLIN_VAR_Z_OFFSET
Definition: marlin_vars.h:23
_marlin_vars_t::motion
uint8_t motion
Definition: marlin_vars.h:78
_marlin_vars_t::fan_speed
uint8_t fan_speed
Definition: marlin_vars.h:88
_variant8_t::i32
int32_t i32
Definition: variant8.h:33