Prusa MINI Firmware overview
gcode_file.h File Reference
#include "ff.h"
#include <stdbool.h>
#include <stdio.h>

Go to the source code of this file.

Functions

int f_gcode_thumb_open (FILE *fp, FIL *real_file)
 
int f_gcode_thumb_close (FILE *fp)
 
bool f_gcode_get_next_comment_assignment (FIL *fp, char *name_buffer, int name_buffer_len, char *value_buffer, int value_buffer_len)
 

Function Documentation

◆ f_gcode_thumb_open()

int f_gcode_thumb_open ( FILE *  fp,
FIL real_file 
)
29  {
30  if (gcode_thumb_fp) {
31  DBG("a gcode png file is already open");
32  return 1;
33  }
34  gcode_thumb_fp = gcode_fp;
35 
37 
38  memset(fp, 0, sizeof(FILE));
39  fp->_read = read;
40  fp->_write = write;
41  fp->_close = close;
42  fp->_seek = seek;
43  fp->_file = -1;
44  fp->_flags = __SRD;
45  fp->_lbfsize = 512;
46  fp->_bf._base = (uint8_t *)malloc(fp->_lbfsize);
47  fp->_bf._size = fp->_lbfsize;
48 
49  return 0;
50 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ f_gcode_thumb_close()

int f_gcode_thumb_close ( FILE *  fp)
52  {
53  if (fp && fp->_bf._base) {
54  free(fp->_bf._base);
55  }
56  gcode_thumb_fp = nullptr;
57  return 0;
58 }
Here is the caller graph for this function:

◆ f_gcode_get_next_comment_assignment()

bool f_gcode_get_next_comment_assignment ( FIL fp,
char *  name_buffer,
int  name_buffer_len,
char *  value_buffer,
int  value_buffer_len 
)

Parse comment line in given file

Reads from the file current line and parses it. Example: Read line: ; infill extrusion width = 0.40mm\n Ouptut: name = "infill extrusion width", value = "0.40mm"

97  {
98  SLine line;
99  while (true) {
100  if (!read_line(fp, line))
101  return false;
102 
103  // is it a comment line?
104  if (strncmp(line, ";", 1) != 0)
105  continue;
106 
107  // find equal sign or discard this line
108  int equal_sign_pos = -1;
109  for (int i = 1; i < (int)strlen(line); i++) {
110  if (line[i] == '=') {
111  equal_sign_pos = i;
112  break;
113  }
114  }
115  if (equal_sign_pos == -1)
116  continue;
117 
118  // trim leading spaces
119  int name_start = 1;
120  while (name_start < equal_sign_pos && line[name_start] == ' ')
121  name_start++;
122  int value_start = equal_sign_pos + 1;
123  while (line[value_start] == ' ')
124  value_start++;
125 
126  // copy name and value to given buffers
127  snprintf(name_buffer, name_buffer_len, "%.*s",
128  equal_sign_pos - name_start,
129  (const char *)line.l + name_start);
130  snprintf(value_buffer, value_buffer_len, "%s",
131  (const char *)line.l + value_start);
132 
133  // trim trailing spaces
134  str_trim(name_buffer);
135  str_trim(value_buffer);
136 
137  return true;
138  }
139 }
Here is the call graph for this function:
Here is the caller graph for this function:
GCodeThumbDecoder::Instance
static GCodeThumbDecoder & Instance()
Definition: gcode_thumb_decoder.h:145
DBG
#define DBG
Definition: gcode_file.cpp:5
gcode_thumb_fp
static FIL * gcode_thumb_fp
Definition: gcode_file.cpp:7
GCodeThumbDecoder::Reset
void Reset()
Definition: gcode_thumb_decoder.h:156
i
uint8_t i
Definition: screen_test_graph.c:72
SLine
Definition: gcode_thumb_decoder.h:26
SLine::l
uint8_t l[MAX+1]
Definition: gcode_thumb_decoder.h:32
read_line
static bool read_line(FIL *fp, SLine &line)
Definition: gcode_file.cpp:60
close
static int close(struct _reent *_r, void *pv)
Definition: gcode_file.cpp:21
seek
static _fpos_t seek(struct _reent *_r, void *pv, _fpos_t fpos, int ipos)
Definition: gcode_file.cpp:25
uint8_t
const uint8_t[]
Definition: 404_html.c:3
read
static int read(struct _reent *_r, void *pv, char *pc, int n)
Definition: gcode_file.cpp:9
str_trim
static char * str_trim(char *str)
Definition: gcode_file.cpp:76
createSpeedLookupTable.int
int
Definition: createSpeedLookupTable.py:15
write
static int write(struct _reent *_r, void *pv, const char *pc, int n)
Definition: gcode_file.cpp:17