Prusa MINI Firmware overview
numtostr.cpp File Reference
#include "numtostr.h"
#include "../inc/MarlinConfigPre.h"
#include "../core/utility.h"

Macros

#define DIGIT(n)   ('0' + (n))
 
#define DIGIMOD(n, f)   DIGIT((n)/(f) % 10)
 
#define RJDIGIT(n, f)   ((n) >= (f) ? DIGIMOD(n, f) : ' ')
 
#define MINUSOR(n, alt)   (n >= 0 ? (alt) : (n = -n, '-'))
 

Functions

const char * ui8tostr4pct (const uint8_t i)
 
const char * ui8tostr3 (const uint8_t i)
 
const char * i8tostr3 (const int8_t x)
 
const char * permyriadtostr4 (const uint16_t xx)
 
const char * ui16tostr5 (const uint16_t xx)
 
const char * ui16tostr4 (const uint16_t xx)
 
const char * ui16tostr3 (const uint16_t xx)
 
const char * i16tostr3 (const int16_t x)
 
const char * i16tostr3left (const int16_t i)
 
const char * i16tostr4sign (const int16_t i)
 
const char * ftostr12ns (const float &f)
 
const char * ftostr42_52 (const float &f)
 
const char * ftostr52 (const float &f)
 
const char * ftostr41sign (const float &f)
 
const char * ftostr43sign (const float &f, char plus)
 
const char * ftostr54sign (const float &f, char plus)
 
const char * ftostr5rj (const float &f)
 
const char * ftostr51sign (const float &f)
 
const char * ftostr52sign (const float &f)
 
const char * ftostr51rj (const float &f)
 
const char * ftostr52sp (const float &f)
 

Variables

char conv [8] = { 0 }
 

Macro Definition Documentation

◆ DIGIT

#define DIGIT (   n)    ('0' + (n))

◆ DIGIMOD

#define DIGIMOD (   n,
 
)    DIGIT((n)/(f) % 10)

◆ RJDIGIT

#define RJDIGIT (   n,
 
)    ((n) >= (f) ? DIGIMOD(n, f) : ' ')

◆ MINUSOR

#define MINUSOR (   n,
  alt 
)    (n >= 0 ? (alt) : (n = -n, '-'))

Function Documentation

◆ ui8tostr4pct()

const char* ui8tostr4pct ( const uint8_t  i)

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

36  {
37  const uint8_t n = ui8_to_percent(i);
38  conv[3] = RJDIGIT(n, 100);
39  conv[4] = RJDIGIT(n, 10);
40  conv[5] = DIGIMOD(n, 1);
41  conv[6] = '%';
42  return &conv[3];
43 }
Here is the call graph for this function:

◆ ui8tostr3()

const char* ui8tostr3 ( const uint8_t  i)
46  {
47  conv[4] = RJDIGIT(i, 100);
48  conv[5] = RJDIGIT(i, 10);
49  conv[6] = DIGIMOD(i, 1);
50  return &conv[4];
51 }

◆ i8tostr3()

const char* i8tostr3 ( const int8_t  x)
54  {
55  int xx = x;
56  conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
57  conv[5] = RJDIGIT(xx, 10);
58  conv[6] = DIGIMOD(xx, 1);
59  return &conv[4];
60 }

◆ permyriadtostr4()

const char* permyriadtostr4 ( const uint16_t  xx)
64  {
65  if (xx >= 10000)
66  return "100";
67  else if (xx >= 1000) {
68  conv[3] = DIGIMOD(xx, 1000);
69  conv[4] = DIGIMOD(xx, 100);
70  conv[5] = '.';
71  conv[6] = DIGIMOD(xx, 10);
72  return &conv[3];
73  }
74  else if (xx % 100 == 0) {
75  conv[4] = ' ';
76  conv[5] = RJDIGIT(xx, 1000);
77  conv[6] = DIGIMOD(xx, 100);
78  return &conv[4];
79  }
80  else {
81  conv[3] = DIGIMOD(xx, 100);
82  conv[4] = '.';
83  conv[5] = DIGIMOD(xx, 10);
84  conv[6] = RJDIGIT(xx, 1);
85  return &conv[3];
86  }
87  }

◆ ui16tostr5()

const char* ui16tostr5 ( const uint16_t  xx)
91  {
92  conv[2] = RJDIGIT(xx, 10000);
93  conv[3] = RJDIGIT(xx, 1000);
94  conv[4] = RJDIGIT(xx, 100);
95  conv[5] = RJDIGIT(xx, 10);
96  conv[6] = DIGIMOD(xx, 1);
97  return &conv[2];
98 }
Here is the caller graph for this function:

◆ ui16tostr4()

const char* ui16tostr4 ( const uint16_t  xx)
101  {
102  conv[3] = RJDIGIT(xx, 1000);
103  conv[4] = RJDIGIT(xx, 100);
104  conv[5] = RJDIGIT(xx, 10);
105  conv[6] = DIGIMOD(xx, 1);
106  return &conv[3];
107 }

◆ ui16tostr3()

const char* ui16tostr3 ( const uint16_t  xx)
110  {
111  conv[4] = RJDIGIT(xx, 100);
112  conv[5] = RJDIGIT(xx, 10);
113  conv[6] = DIGIMOD(xx, 1);
114  return &conv[4];
115 }

◆ i16tostr3()

const char* i16tostr3 ( const int16_t  x)
118  {
119  int xx = x;
120  conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
121  conv[5] = RJDIGIT(xx, 10);
122  conv[6] = DIGIMOD(xx, 1);
123  return &conv[4];
124 }
Here is the caller graph for this function:

◆ i16tostr3left()

const char* i16tostr3left ( const int16_t  i)
127  {
128  char *str = &conv[6];
129  *str = DIGIMOD(i, 1);
130  if (i >= 10) {
131  *(--str) = DIGIMOD(i, 10);
132  if (i >= 100)
133  *(--str) = DIGIMOD(i, 100);
134  }
135  return str;
136 }

◆ i16tostr4sign()

const char* i16tostr4sign ( const int16_t  i)
139  {
140  const bool neg = i < 0;
141  const int ii = neg ? -i : i;
142  if (i >= 1000) {
143  conv[3] = DIGIMOD(ii, 1000);
144  conv[4] = DIGIMOD(ii, 100);
145  conv[5] = DIGIMOD(ii, 10);
146  }
147  else if (ii >= 100) {
148  conv[3] = neg ? '-' : ' ';
149  conv[4] = DIGIMOD(ii, 100);
150  conv[5] = DIGIMOD(ii, 10);
151  }
152  else {
153  conv[3] = ' ';
154  conv[4] = ' ';
155  if (ii >= 10) {
156  conv[4] = neg ? '-' : ' ';
157  conv[5] = DIGIMOD(ii, 10);
158  }
159  else {
160  conv[5] = neg ? '-' : ' ';
161  }
162  }
163  conv[6] = DIGIMOD(ii, 1);
164  return &conv[3];
165 }
Here is the caller graph for this function:

◆ ftostr12ns()

const char* ftostr12ns ( const float &  f)
168  {
169  const long i = ((f < 0 ? -f : f) * 1000 + 5) / 10;
170  conv[3] = DIGIMOD(i, 100);
171  conv[4] = '.';
172  conv[5] = DIGIMOD(i, 10);
173  conv[6] = DIGIMOD(i, 1);
174  return &conv[3];
175 }

◆ ftostr42_52()

const char* ftostr42_52 ( const float &  f)
178  {
179  if (f <= -10 || f >= 100) return ftostr52(f); // need more digits
180  long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
181  conv[2] = (f >= 0 && f < 10) ? ' ' : MINUSOR(i, DIGIMOD(i, 1000));
182  conv[3] = DIGIMOD(i, 100);
183  conv[4] = '.';
184  conv[5] = DIGIMOD(i, 10);
185  conv[6] = DIGIMOD(i, 1);
186  return &conv[2];
187 }
Here is the call graph for this function:

◆ ftostr52()

const char* ftostr52 ( const float &  f)
190  {
191  long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
192  conv[1] = MINUSOR(i, DIGIMOD(i, 10000));
193  conv[2] = DIGIMOD(i, 1000);
194  conv[3] = DIGIMOD(i, 100);
195  conv[4] = '.';
196  conv[5] = DIGIMOD(i, 10);
197  conv[6] = DIGIMOD(i, 1);
198  return &conv[1];
199 }
Here is the caller graph for this function:

◆ ftostr41sign()

const char* ftostr41sign ( const float &  f)
219  {
220  int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
221  conv[1] = MINUSOR(i, '+');
222  conv[2] = DIGIMOD(i, 1000);
223  conv[3] = DIGIMOD(i, 100);
224  conv[4] = DIGIMOD(i, 10);
225  conv[5] = '.';
226  conv[6] = DIGIMOD(i, 1);
227  return &conv[1];
228 }

◆ ftostr43sign()

const char* ftostr43sign ( const float &  f,
char  plus 
)
231  {
232  long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
233  conv[1] = i ? MINUSOR(i, plus) : ' ';
234  conv[2] = DIGIMOD(i, 1000);
235  conv[3] = '.';
236  conv[4] = DIGIMOD(i, 100);
237  conv[5] = DIGIMOD(i, 10);
238  conv[6] = DIGIMOD(i, 1);
239  return &conv[1];
240 }

◆ ftostr54sign()

const char* ftostr54sign ( const float &  f,
char  plus 
)
243  {
244  long i = (f * 100000 + (f < 0 ? -5: 5)) / 10;
245  conv[0] = i ? MINUSOR(i, plus) : ' ';
246  conv[1] = DIGIMOD(i, 10000);
247  conv[2] = '.';
248  conv[3] = DIGIMOD(i, 1000);
249  conv[4] = DIGIMOD(i, 100);
250  conv[5] = DIGIMOD(i, 10);
251  conv[6] = DIGIMOD(i, 1);
252  return &conv[0];
253 }

◆ ftostr5rj()

const char* ftostr5rj ( const float &  f)
256  {
257  const long i = ((f < 0 ? -f : f) * 10 + 5) / 10;
258  return ui16tostr5(i);
259 }
Here is the call graph for this function:

◆ ftostr51sign()

const char* ftostr51sign ( const float &  f)
262  {
263  long i = (f * 100 + (f < 0 ? -5: 5)) / 10;
264  conv[0] = MINUSOR(i, '+');
265  conv[1] = DIGIMOD(i, 10000);
266  conv[2] = DIGIMOD(i, 1000);
267  conv[3] = DIGIMOD(i, 100);
268  conv[4] = DIGIMOD(i, 10);
269  conv[5] = '.';
270  conv[6] = DIGIMOD(i, 1);
271  return conv;
272 }

◆ ftostr52sign()

const char* ftostr52sign ( const float &  f)
275  {
276  long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
277  conv[0] = MINUSOR(i, '+');
278  conv[1] = DIGIMOD(i, 10000);
279  conv[2] = DIGIMOD(i, 1000);
280  conv[3] = DIGIMOD(i, 100);
281  conv[4] = '.';
282  conv[5] = DIGIMOD(i, 10);
283  conv[6] = DIGIMOD(i, 1);
284  return conv;
285 }

◆ ftostr51rj()

const char* ftostr51rj ( const float &  f)
288  {
289  const long i = ((f < 0 ? -f : f) * 100 + 5) / 10;
290  conv[0] = ' ';
291  conv[1] = RJDIGIT(i, 10000);
292  conv[2] = RJDIGIT(i, 1000);
293  conv[3] = RJDIGIT(i, 100);
294  conv[4] = DIGIMOD(i, 10);
295  conv[5] = '.';
296  conv[6] = DIGIMOD(i, 1);
297  return conv;
298 }

◆ ftostr52sp()

const char* ftostr52sp ( const float &  f)
301  {
302  long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
303  uint8_t dig;
304  conv[0] = MINUSOR(i, ' ');
305  conv[1] = RJDIGIT(i, 10000);
306  conv[2] = RJDIGIT(i, 1000);
307  conv[3] = DIGIMOD(i, 100);
308 
309  if ((dig = i % 10)) { // second digit after decimal point?
310  conv[4] = '.';
311  conv[5] = DIGIMOD(i, 10);
312  conv[6] = DIGIT(dig);
313  }
314  else {
315  if ((dig = (i / 10) % 10)) { // first digit after decimal point?
316  conv[4] = '.';
317  conv[5] = DIGIT(dig);
318  }
319  else // nothing after decimal point
320  conv[4] = conv[5] = ' ';
321  conv[6] = ' ';
322  }
323  return conv;
324 }

Variable Documentation

◆ conv

char conv[8] = { 0 }

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

RJDIGIT
#define RJDIGIT(n, f)
Definition: numtostr.cpp:32
DIGIT
#define DIGIT(n)
Definition: numtostr.cpp:30
MINUSOR
#define MINUSOR(n, alt)
Definition: numtostr.cpp:33
i
uint8_t i
Definition: screen_test_graph.c:72
ftostr52
const char * ftostr52(const float &f)
Definition: numtostr.cpp:190
conv
char conv[8]
Definition: numtostr.cpp:28
uint8_t
const uint8_t[]
Definition: 404_html.c:3
DIGIMOD
#define DIGIMOD(n, f)
Definition: numtostr.cpp:31
ui8_to_percent
constexpr uint8_t ui8_to_percent(const uint8_t i)
Definition: utility.h:81
ui16tostr5
const char * ui16tostr5(const uint16_t xx)
Definition: numtostr.cpp:91