Prusa MINI Firmware overview
numtostr.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4  *
5  * Based on Sprinter and grbl.
6  * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 #pragma once
23 
24 #include <stdint.h>
25 
26 // Convert a full-range unsigned 8bit int to a percentage
27 const char* ui8tostr4pct(const uint8_t i);
28 
29 // Convert uint8_t to string with 123 format
30 const char* ui8tostr3(const uint8_t i);
31 
32 // Convert int8_t to string with 123 format
33 const char* i8tostr3(const int8_t x);
34 
35 #if HAS_PRINT_PROGRESS_PERMYRIAD
36  // Convert 16-bit unsigned permyriad value to percent: 100 / 23 / 23.4 / 3.45
37  const char* permyriadtostr4(const uint16_t xx);
38 #endif
39 
40 // Convert uint16_t to string with 12345 format
41 const char* ui16tostr5(const uint16_t x);
42 
43 // Convert uint16_t to string with 1234 format
44 const char* ui16tostr4(const uint16_t x);
45 
46 // Convert uint16_t to string with 123 format
47 const char* ui16tostr3(const uint16_t x);
48 
49 // Convert int16_t to string with 123 format
50 const char* i16tostr3(const int16_t x);
51 
52 // Convert unsigned int to lj string with 123 format
53 const char* i16tostr3left(const int16_t xx);
54 
55 // Convert signed int to rj string with _123, -123, _-12, or __-1 format
56 const char* i16tostr4sign(const int16_t x);
57 
58 // Convert unsigned float to string with 1.23 format
59 const char* ftostr12ns(const float &x);
60 
61 // Convert signed float to fixed-length string with 12.34 / -2.34 or 023.45 / -23.45 format
62 const char* ftostr42_52(const float &x);
63 
64 // Convert signed float to fixed-length string with 023.45 / -23.45 format
65 const char* ftostr52(const float &x);
66 
67 // Convert float to fixed-length string with +123.4 / -123.4 format
68 const char* ftostr41sign(const float &x);
69 
70 // Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
71 const char* ftostr43sign(const float &x, char plus=' ');
72 
73 // Convert signed float to string (5 digit) with -1.2345 / _0.0000 / +1.2345 format
74 const char* ftostr54sign(const float &x, char plus=' ');
75 
76 // Convert unsigned float to rj string with 12345 format
77 const char* ftostr5rj(const float &x);
78 
79 // Convert signed float to string with +1234.5 format
80 const char* ftostr51sign(const float &x);
81 
82 // Convert signed float to space-padded string with -_23.4_ format
83 const char* ftostr52sp(const float &x);
84 
85 // Convert signed float to string with +123.45 format
86 const char* ftostr52sign(const float &x);
87 
88 // Convert unsigned float to string with 1234.5 format omitting trailing zeros
89 const char* ftostr51rj(const float &x);
90 
91 #include "../core/macros.h"
92 
93 // Convert float to rj string with 123 or -12 format
94 FORCE_INLINE const char* ftostr3(const float &x) { return i16tostr3(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }
95 
96 #include "../inc/MarlinConfigPre.h"
97 
98 #if ENABLED(LCD_DECIMAL_SMALL_XY)
99  // Convert float to rj string with 1234, _123, 12.3, _1.2, -123, _-12, or -1.2 format
100  const char* ftostr4sign(const float &fx);
101 #else
102  // Convert float to rj string with 1234, _123, -123, __12, _-12, ___1, or __-1 format
103  FORCE_INLINE const char* ftostr4sign(const float &x) { return i16tostr4sign(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }
104 #endif
WITHIN
#define WITHIN(N, L, H)
Definition: macros.h:195
ui16tostr4
const char * ui16tostr4(const uint16_t x)
Definition: numtostr.cpp:101
ftostr42_52
const char * ftostr42_52(const float &f)
Definition: numtostr.cpp:178
ftostr41sign
const char * ftostr41sign(const float &x)
Definition: numtostr.cpp:219
ftostr12ns
const char * ftostr12ns(const float &f)
Definition: numtostr.cpp:168
ftostr5rj
const char * ftostr5rj(const float &x)
Definition: numtostr.cpp:256
RJDIGIT
#define RJDIGIT(n, f)
Definition: numtostr.cpp:32
ui16tostr4
const char * ui16tostr4(const uint16_t xx)
Definition: numtostr.cpp:101
ui16tostr3
const char * ui16tostr3(const uint16_t x)
Definition: numtostr.cpp:110
ftostr12ns
const char * ftostr12ns(const float &x)
Definition: numtostr.cpp:168
ftostr42_52
const char * ftostr42_52(const float &x)
Definition: numtostr.cpp:178
i8tostr3
const char * i8tostr3(const int8_t x)
Definition: numtostr.cpp:54
ftostr4sign
const FORCE_INLINE char * ftostr4sign(const float &x)
Definition: numtostr.h:103
ftostr43sign
const char * ftostr43sign(const float &f, char plus)
Definition: numtostr.cpp:231
numtostr.h
i16tostr4sign
const char * i16tostr4sign(const int16_t x)
Definition: numtostr.cpp:139
DIGIT
#define DIGIT(n)
Definition: numtostr.cpp:30
MINUSOR
#define MINUSOR(n, alt)
Definition: numtostr.cpp:33
ftostr52sp
const char * ftostr52sp(const float &f)
Definition: numtostr.cpp:301
ui8tostr4pct
const char * ui8tostr4pct(const uint8_t i)
Definition: numtostr.cpp:36
ui8tostr4pct
const char * ui8tostr4pct(const uint8_t i)
Definition: numtostr.cpp:36
ui16tostr5
const char * ui16tostr5(const uint16_t x)
Definition: numtostr.cpp:91
i
uint8_t i
Definition: screen_test_graph.c:72
ftostr3
const FORCE_INLINE char * ftostr3(const float &x)
Definition: numtostr.h:94
ftostr52
const char * ftostr52(const float &f)
Definition: numtostr.cpp:190
ftostr51rj
const char * ftostr51rj(const float &x)
Definition: numtostr.cpp:288
ui8tostr3
const char * ui8tostr3(const uint8_t i)
Definition: numtostr.cpp:46
ftostr54sign
const char * ftostr54sign(const float &x, char plus=' ')
Definition: numtostr.cpp:243
ftostr52sp
const char * ftostr52sp(const float &x)
Definition: numtostr.cpp:301
FORCE_INLINE
#define FORCE_INLINE
Definition: macros.h:40
ftostr5rj
const char * ftostr5rj(const float &f)
Definition: numtostr.cpp:256
conv
char conv[8]
Definition: numtostr.cpp:28
i16tostr3left
const char * i16tostr3left(const int16_t xx)
Definition: numtostr.cpp:127
ui16tostr3
const char * ui16tostr3(const uint16_t xx)
Definition: numtostr.cpp:110
ftostr43sign
const char * ftostr43sign(const float &x, char plus=' ')
Definition: numtostr.cpp:231
i16tostr3left
const char * i16tostr3left(const int16_t i)
Definition: numtostr.cpp:127
ftostr52sign
const char * ftostr52sign(const float &x)
Definition: numtostr.cpp:275
permyriadtostr4
const char * permyriadtostr4(const uint16_t xx)
Definition: numtostr.cpp:64
i16tostr3
const char * i16tostr3(const int16_t x)
Definition: numtostr.cpp:118
uint8_t
const uint8_t[]
Definition: 404_html.c:3
ftostr51sign
const char * ftostr51sign(const float &x)
Definition: numtostr.cpp:262
i8tostr3
const char * i8tostr3(const int8_t x)
Definition: numtostr.cpp:54
ftostr54sign
const char * ftostr54sign(const float &f, char plus)
Definition: numtostr.cpp:243
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
ui8tostr3
const char * ui8tostr3(const uint8_t i)
Definition: numtostr.cpp:46
i16tostr4sign
const char * i16tostr4sign(const int16_t i)
Definition: numtostr.cpp:139
ftostr51rj
const char * ftostr51rj(const float &f)
Definition: numtostr.cpp:288
i16tostr3
const char * i16tostr3(const int16_t x)
Definition: numtostr.cpp:118
ftostr41sign
const char * ftostr41sign(const float &f)
Definition: numtostr.cpp:219
ftostr51sign
const char * ftostr51sign(const float &f)
Definition: numtostr.cpp:262
ftostr52sign
const char * ftostr52sign(const float &f)
Definition: numtostr.cpp:275
ftostr52
const char * ftostr52(const float &x)
Definition: numtostr.cpp:190