Prusa MINI Firmware overview
gcode_file.cpp File Reference
#include "gcode_file.h"
#include "dbg.h"
#include "gcode_thumb_decoder.h"

Macros

#define DBG   _dbg0
 

Functions

static int read (struct _reent *_r, void *pv, char *pc, int n)
 
static int write (struct _reent *_r, void *pv, const char *pc, int n)
 
static int close (struct _reent *_r, void *pv)
 
static _fpos_t seek (struct _reent *_r, void *pv, _fpos_t fpos, int ipos)
 
int f_gcode_thumb_open (FILE *fp, FIL *gcode_fp)
 
int f_gcode_thumb_close (FILE *fp)
 
static bool read_line (FIL *fp, SLine &line)
 
static char * str_trim (char *str)
 
bool f_gcode_get_next_comment_assignment (FIL *fp, char *name_buffer, int name_buffer_len, char *value_buffer, int value_buffer_len)
 

Variables

static FILgcode_thumb_fp = nullptr
 

Macro Definition Documentation

◆ DBG

#define DBG   _dbg0

Function Documentation

◆ read()

static int read ( struct _reent *  _r,
void pv,
char *  pc,
int  n 
)
static
9  {
10  int count = GCodeThumbDecoder::Instance().Read(gcode_thumb_fp, pc, n);
11  if (count < 0) {
12  return 0;
13  }
14  return count;
15 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

static int write ( struct _reent *  _r,
void pv,
const char *  pc,
int  n 
)
static
17  {
18  return 0;
19 }
Here is the caller graph for this function:

◆ close()

static int close ( struct _reent *  _r,
void pv 
)
static
21  {
22  return 0;
23 }
Here is the caller graph for this function:

◆ seek()

static _fpos_t seek ( struct _reent *  _r,
void pv,
_fpos_t  fpos,
int  ipos 
)
static
25  {
26  return 0;
27 }
Here is the caller graph for this function:

◆ f_gcode_thumb_open()

int f_gcode_thumb_open ( FILE *  fp,
FIL gcode_fp 
)
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:

◆ read_line()

static bool read_line ( FIL fp,
SLine line 
)
static
60  {
61  uint8_t byte;
62  UINT bytes_read;
63  line.Reset();
64  for (;;) {
65  if (f_eof(fp))
66  return line.size > 0;
67  if (f_read(fp, &byte, 1, &bytes_read) != FR_OK || bytes_read != 1)
68  return false;
69  if (byte == '\n')
70  break;
71  line.AppendByte(byte);
72  }
73  return true;
74 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_trim()

static char* str_trim ( char *  str)
static
76  {
77 
78  // trim leading space
79  while (*str == ' ')
80  str++;
81 
82  if (*str == 0)
83  return str;
84 
85  // trim trailing space
86  char *end = str + strlen(str) - 1;
87  while (end > str && *end == ' ')
88  end--;
89  end[1] = '\0';
90 
91  return str;
92 }
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:

Variable Documentation

◆ gcode_thumb_fp

FIL* gcode_thumb_fp = nullptr
static
SLine::AppendByte
void AppendByte(uint8_t b)
Definition: gcode_thumb_decoder.h:36
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
SLine::size
uint8_t size
Definition: gcode_thumb_decoder.h:28
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
createSpeedLookupTable.end
end
Definition: createSpeedLookupTable.py:33
GCodeThumbDecoder::Read
int Read(FIL *f, char *pc, int n)
Definition: gcode_thumb_decoder.cpp:71
close
static int close(struct _reent *_r, void *pv)
Definition: gcode_file.cpp:21
SLine::Reset
void Reset()
Definition: gcode_thumb_decoder.h:43
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
f_eof
#define f_eof(fp)
Definition: ff.h:277
read
static int read(struct _reent *_r, void *pv, char *pc, int n)
Definition: gcode_file.cpp:9
FR_OK
Definition: ff.h:215
str_trim
static char * str_trim(char *str)
Definition: gcode_file.cpp:76
createSpeedLookupTable.int
int
Definition: createSpeedLookupTable.py:15
byte
uint8_t byte
Definition: wiring_constants.h:112
UINT
unsigned int UINT
Definition: onboard_sd.h:16
f_read
FRESULT f_read(FIL *fp, void *buff, UINT btr, UINT *br)
Definition: ff.c:3499
write
static int write(struct _reent *_r, void *pv, const char *pc, int n)
Definition: gcode_file.cpp:17