Prusa MINI Firmware overview
marlin_vars.h
Go to the documentation of this file.
1 // marlin_vars.h
2 #ifndef _MARLIN_VARS_H
3 #define _MARLIN_VARS_H
4 
5 #include "variant8.h"
6 
7 // Marlin variables
8 #define MARLIN_VAR_MOTION 0x00 // R: uint8, method stepper.axis_is_moving
9 #define MARLIN_VAR_GQUEUE 0x01 // R: uint8, method queue.length
10 #define MARLIN_VAR_PQUEUE 0x02 // R: uint8, variables planner.block_buffer_head/tail
11 #define MARLIN_VAR_IPOS_X 0x03 // RW: int32, variable stepper.count_position
12 #define MARLIN_VAR_IPOS_Y 0x04 // RW: ==||==
13 #define MARLIN_VAR_IPOS_Z 0x05 // RW: ==||==
14 #define MARLIN_VAR_IPOS_E 0x06 // RW: ==||==
15 #define MARLIN_VAR_POS_X 0x07 // RW: float, planner.getAxisPosition_mm(), setAxisPosition_mm()
16 #define MARLIN_VAR_POS_Y 0x08 // RW: ==||==
17 #define MARLIN_VAR_POS_Z 0x09 // RW: ==||==
18 #define MARLIN_VAR_POS_E 0x0a // RW: ==||==
19 #define MARLIN_VAR_TEMP_NOZ 0x0b // R: float, thermalManager.temp_hotend[0].current
20 #define MARLIN_VAR_TEMP_BED 0x0c // R: float, thermalManager.temp_bed.current
21 #define MARLIN_VAR_TTEM_NOZ 0x0d // RW: float, thermalManager.temp_hotend[0].target, thermalManager.setTargetHotend()
22 #define MARLIN_VAR_TTEM_BED 0x0e // RW: float, thermalManager.temp_bed.target, thermalManager.setTargetBed()
23 #define MARLIN_VAR_Z_OFFSET 0x0f // R: float, zprobe_zoffset
24 #define MARLIN_VAR_FANSPEED 0x10 // RW: uint8, thermalManager.fan_speed[0], thermalManager.set_fan_speed()
25 #define MARLIN_VAR_PRNSPEED 0x11 // RW: uint16, feedrate_percentage
26 #define MARLIN_VAR_FLOWFACT 0x12 // RW: uint16, planner.flow_percentage
27 #define MARLIN_VAR_WAITHEAT 0x13 // RW: uint8, Marlin, wait_for_heatup
28 #define MARLIN_VAR_WAITUSER 0x14 // RW: uint8, Marlin, wait_for_user
29 #define MARLIN_VAR_SD_PRINT 0x15 // R: uint8, card.flag.sdprinting
30 #define MARLIN_VAR_SD_PDONE 0x16 // R: uint8, card.percentDone()
31 #define MARLIN_VAR_DURATION 0x17 // R: uint32, print_job_timer.duration()
32 #define MARLIN_VAR_MAX MARLIN_VAR_DURATION
33 
34 // variable masks
35 #define MARLIN_VAR_MSK(v_id) ((uint64_t)1 << (v_id))
36 
37 #define MARLIN_VAR_MSK_IPOS_XYZE ( \
38  MARLIN_VAR_MSK(MARLIN_VAR_IPOS_X) | MARLIN_VAR_MSK(MARLIN_VAR_IPOS_Y) | MARLIN_VAR_MSK(MARLIN_VAR_IPOS_Z) | MARLIN_VAR_MSK(MARLIN_VAR_IPOS_E))
39 
40 #define MARLIN_VAR_MSK_POS_XYZE ( \
41  MARLIN_VAR_MSK(MARLIN_VAR_POS_X) | MARLIN_VAR_MSK(MARLIN_VAR_POS_Y) | MARLIN_VAR_MSK(MARLIN_VAR_POS_Z) | MARLIN_VAR_MSK(MARLIN_VAR_POS_E))
42 
43 #define MARLIN_VAR_MSK_TEMP_CURR ( \
44  MARLIN_VAR_MSK(MARLIN_VAR_TEMP_NOZ) | MARLIN_VAR_MSK(MARLIN_VAR_TEMP_BED))
45 
46 #define MARLIN_VAR_MSK_TEMP_TARG ( \
47  MARLIN_VAR_MSK(MARLIN_VAR_TTEM_NOZ) | MARLIN_VAR_MSK(MARLIN_VAR_TTEM_BED))
48 
49 #define MARLIN_VAR_MSK_TEMP_ALL ( \
50  MARLIN_VAR_MSK(MARLIN_VAR_TEMP_NOZ) | MARLIN_VAR_MSK(MARLIN_VAR_TEMP_BED) | MARLIN_VAR_MSK(MARLIN_VAR_TTEM_NOZ) | MARLIN_VAR_MSK(MARLIN_VAR_TTEM_BED))
51 
52 #define MARLIN_VAR_MSK_DEF ( \
53  MARLIN_VAR_MSK(MARLIN_VAR_MOTION) | MARLIN_VAR_MSK(MARLIN_VAR_GQUEUE) | MARLIN_VAR_MSK_POS_XYZE | MARLIN_VAR_MSK_TEMP_ALL | MARLIN_VAR_MSK(MARLIN_VAR_SD_PRINT) | MARLIN_VAR_MSK(MARLIN_VAR_SD_PDONE) | MARLIN_VAR_MSK(MARLIN_VAR_DURATION))
54 
55 #define MARLIN_VAR_MSK_ALL ( \
56  MARLIN_VAR_MSK(MARLIN_VAR_MOTION) | MARLIN_VAR_MSK(MARLIN_VAR_GQUEUE) | MARLIN_VAR_MSK(MARLIN_VAR_PQUEUE) | MARLIN_VAR_MSK_IPOS_XYZE | MARLIN_VAR_MSK_POS_XYZE | MARLIN_VAR_MSK_TEMP_ALL | MARLIN_VAR_MSK(MARLIN_VAR_Z_OFFSET) | MARLIN_VAR_MSK(MARLIN_VAR_FANSPEED) | MARLIN_VAR_MSK(MARLIN_VAR_PRNSPEED) | MARLIN_VAR_MSK(MARLIN_VAR_FLOWFACT) | MARLIN_VAR_MSK(MARLIN_VAR_WAITHEAT) | MARLIN_VAR_MSK(MARLIN_VAR_WAITUSER) | MARLIN_VAR_MSK(MARLIN_VAR_SD_PRINT) | MARLIN_VAR_MSK(MARLIN_VAR_SD_PDONE) | MARLIN_VAR_MSK(MARLIN_VAR_DURATION))
57 
58 // usr8 in variant8_t message contains id (bit0..6) and variable/event flag (bit7)
59 #define MARLIN_USR8_VAR_FLG 0x80 // usr8 - variable flag (bit7 set)
60 #define MARLIN_USR8_MSK_ID 0x7f // usr8 - event/variable id mask
61 
62 #define MARLINE_VAR_NAME_MAX 16 //var_name max length
63 
64 #define MARLIN_VAR_INDEX_X 0
65 #define MARLIN_VAR_INDEX_Y 1
66 #define MARLIN_VAR_INDEX_Z 2
67 #define MARLIN_VAR_INDEX_E 3
68 #define MARLIN_VAR_MOTION_MSK_X (1 << MARLIN_VAR_INDEX_X)
69 #define MARLIN_VAR_MOTION_MSK_Y (1 << MARLIN_VAR_INDEX_Y)
70 #define MARLIN_VAR_MOTION_MSK_Z (1 << MARLIN_VAR_INDEX_Z)
71 #define MARLIN_VAR_MOTION_MSK_E (1 << MARLIN_VAR_INDEX_E)
72 
73 #pragma pack(push)
74 #pragma pack(1)
75 
76 // variables structure - used in server and client
77 typedef struct _marlin_vars_t {
78  uint8_t motion; // motion (bit0-X, bit1-Y, bit2-Z, bit3-E)
79  uint8_t gqueue; // number of commands in gcode queue
80  uint8_t pqueue; // number of commands in planner queue
81  int32_t ipos[4]; // integer position XYZE [steps]
82  float pos[4]; // position XYZE [mm]
83  float temp_nozzle; // nozzle temperature [C]
84  float temp_bed; // bed temperature [C]
85  float target_nozzle; // nozzle target temperature [C]
86  float target_bed; // bed target temperature [C]
87  float z_offset; // probe z-offset [mm]
88  uint8_t fan_speed; // print fan0 speed [0..255]
89  uint16_t print_speed; // printing speed factor [%]
90  uint16_t flow_factor; // flow factor [%]
91  uint8_t wait_heat; // wait_for_heatup
92  uint8_t wait_user; // wait_for_user
93  uint8_t sd_printing; // card.flag.sdprinting
94  uint8_t sd_percent_done; // card.percentDone()
95  uint32_t print_duration; // print_job_timer.duration()
97 
98 typedef union _marlin_changes_t {
99  uint64_t var;
100  struct
101  {
126  uint64_t var_reserved : 42;
127  };
129 
130 #pragma pack(pop)
131 
132 #ifdef __cplusplus
133 extern "C" {
134 #endif //__cplusplus
135 
136 // returns variable name
137 extern const char *marlin_vars_get_name(uint8_t var_id);
138 
139 // returns variable id by name or -1 if not match
140 extern int marlin_vars_get_id_by_name(const char *var_name);
141 
142 // get variable value as variant8 directly from vars structure
144 
145 // set variable value as variant8 directly in vars structure
146 extern void marlin_vars_set_var(marlin_vars_t *vars, uint8_t var_id, variant8_t var);
147 
148 // format variable to string
149 extern void marlin_vars_value_to_str(marlin_vars_t *vars, uint8_t var_id, char *str);
150 
151 // parse variable from string, returns sscanf result (1 = ok)
152 extern int marlin_vars_str_to_value(marlin_vars_t *vars, uint8_t var_id, const char *str);
153 
154 #ifdef __cplusplus
155 }
156 #endif //__cplusplus
157 
158 #endif //_MARLIN_VARS_H
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_vars_get_name
const char * marlin_vars_get_name(uint8_t var_id)
Definition: marlin_vars.c:36
MARLIN_VAR_TEMP_BED
#define MARLIN_VAR_TEMP_BED
Definition: marlin_vars.h:20
_marlin_changes_t::var_sd_printing
uint8_t var_sd_printing
Definition: marlin_vars.h:123
_marlin_changes_t::var_wait_heat
uint8_t var_wait_heat
Definition: marlin_vars.h:121
marlin_vars_get_var
variant8_t marlin_vars_get_var(marlin_vars_t *vars, uint8_t var_id)
Definition: marlin_vars.c:50
_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
_marlin_changes_t::var_motion
uint8_t var_motion
Definition: marlin_vars.h:102
_variant8_t::ui8
uint8_t ui8
Definition: variant8.h:36
MARLIN_VAR_FANSPEED
#define MARLIN_VAR_FANSPEED
Definition: marlin_vars.h:24
_marlin_changes_t::var_ipos_x
uint8_t var_ipos_x
Definition: marlin_vars.h:105
_marlin_changes_t::var_z_offset
uint8_t var_z_offset
Definition: marlin_vars.h:117
marlin_vars_value_to_str
void marlin_vars_value_to_str(marlin_vars_t *vars, uint8_t var_id, char *str)
Definition: marlin_vars.c:183
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
_marlin_changes_t::var_temp_bed
uint8_t var_temp_bed
Definition: marlin_vars.h:114
_marlin_changes_t::var_pos_x
uint8_t var_pos_x
Definition: marlin_vars.h:109
_marlin_changes_t::var_wait_user
uint8_t var_wait_user
Definition: marlin_vars.h:122
variant8_ui16
variant8_t variant8_ui16(uint16_t ui16)
Definition: variant8.c:30
marlin_vars_get_id_by_name
int marlin_vars_get_id_by_name(const char *var_name)
Definition: marlin_vars.c:42
MARLIN_VAR_WAITUSER
#define MARLIN_VAR_WAITUSER
Definition: marlin_vars.h:28
marlin_vars_set_var
void marlin_vars_set_var(marlin_vars_t *vars, uint8_t var_id, variant8_t var)
Definition: marlin_vars.c:105
_marlin_vars_t::temp_nozzle
float temp_nozzle
Definition: marlin_vars.h:83
_marlin_changes_t::var_flow_factor
uint8_t var_flow_factor
Definition: marlin_vars.h:120
_variant8_t
Definition: variant8.h:24
MARLIN_VAR_IPOS_Y
#define MARLIN_VAR_IPOS_Y
Definition: marlin_vars.h:12
_variant8_t::flt
float flt
Definition: variant8.h:31
marlin_vars_str_to_value
int marlin_vars_str_to_value(marlin_vars_t *vars, uint8_t var_id, const char *str)
Definition: marlin_vars.c:251
marlin_vars_value_to_str
void marlin_vars_value_to_str(marlin_vars_t *vars, uint8_t var_id, char *str)
Definition: marlin_vars.c:183
MARLIN_VAR_TEMP_NOZ
#define MARLIN_VAR_TEMP_NOZ
Definition: marlin_vars.h:19
variant8.h
_marlin_changes_t::var_gqueue
uint8_t var_gqueue
Definition: marlin_vars.h:103
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_changes_t::var_print_speed
uint8_t var_print_speed
Definition: marlin_vars.h:119
MARLIN_VAR_WAITHEAT
#define MARLIN_VAR_WAITHEAT
Definition: marlin_vars.h:27
marlin_vars_set_var
void marlin_vars_set_var(marlin_vars_t *vars, uint8_t var_id, variant8_t var)
Definition: marlin_vars.c:105
_marlin_changes_t::var_target_bed
uint8_t var_target_bed
Definition: marlin_vars.h:116
_marlin_changes_t::var_fan_speed
uint8_t var_fan_speed
Definition: marlin_vars.h:118
marlin_changes_t
union _marlin_changes_t marlin_changes_t
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_changes_t::var_pos_e
uint8_t var_pos_e
Definition: marlin_vars.h:112
_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
marlin_vars.h
variant8_empty
variant8_t variant8_empty(void)
Definition: variant8.c:10
uint8_t
const uint8_t[]
Definition: 404_html.c:3
_marlin_changes_t::var_reserved
uint64_t var_reserved
Definition: marlin_vars.h:126
_marlin_changes_t::var_temp_nozzle
uint8_t var_temp_nozzle
Definition: marlin_vars.h:113
marlin_vars_get_name
const char * marlin_vars_get_name(uint8_t var_id)
Definition: marlin_vars.c:36
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_get_var
variant8_t marlin_vars_get_var(marlin_vars_t *vars, uint8_t var_id)
Definition: marlin_vars.c:50
_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_changes_t::var_pqueue
uint8_t var_pqueue
Definition: marlin_vars.h:104
_marlin_vars_t
Definition: marlin_vars.h:77
_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
struct _marlin_vars_t marlin_vars_t
_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
_marlin_changes_t::var_target_nozzle
uint8_t var_target_nozzle
Definition: marlin_vars.h:115
_marlin_changes_t::var_pos_z
uint8_t var_pos_z
Definition: marlin_vars.h:111
_marlin_changes_t
Definition: marlin_vars.h:98
_variant8_t::ui32
uint32_t ui32
Definition: variant8.h:32
_marlin_changes_t::var_ipos_e
uint8_t var_ipos_e
Definition: marlin_vars.h:108
_marlin_changes_t::var_ipos_y
uint8_t var_ipos_y
Definition: marlin_vars.h:106
marlin_vars_str_to_value
int marlin_vars_str_to_value(marlin_vars_t *vars, uint8_t var_id, const char *str)
Definition: marlin_vars.c:251
_marlin_changes_t::var_sd_percent_done
uint8_t var_sd_percent_done
Definition: marlin_vars.h:124
variant8_flt
variant8_t variant8_flt(float flt)
Definition: variant8.c:48
_marlin_changes_t::var_pos_y
uint8_t var_pos_y
Definition: marlin_vars.h:110
_marlin_changes_t::var_ipos_z
uint8_t var_ipos_z
Definition: marlin_vars.h:107
_marlin_changes_t::var_print_duration
uint8_t var_print_duration
Definition: marlin_vars.h:125
_marlin_vars_t::sd_printing
uint8_t sd_printing
Definition: marlin_vars.h:93
_marlin_changes_t::var
uint64_t var
Definition: marlin_vars.h:99
_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
marlin_vars_get_id_by_name
int marlin_vars_get_id_by_name(const char *var_name)
Definition: marlin_vars.c:42
_variant8_t::i32
int32_t i32
Definition: variant8.h:33