update code base to Marlin 2.0.9.2

This commit is contained in:
Stefan Kalscheuer
2021-10-03 18:57:12 +02:00
parent b9d7ba838e
commit 7077da3591
2617 changed files with 332093 additions and 103438 deletions

128
Marlin/src/libs/numtostr.cpp Executable file → Normal file
View File

@@ -16,7 +16,7 @@
* 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/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
@@ -31,17 +31,23 @@ char conv[8] = { 0 };
#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, '-'))
#define INTFLOAT(V,N) (((V) * 10 * pow(10, N) + ((V) < 0 ? -5: 5)) / 10) // pow10?
#define UINTFLOAT(V,N) INTFLOAT((V) < 0 ? -(V) : (V), N)
// Convert a full-range unsigned 8bit int to a percentage
const char* ui8tostr4pctrj(const uint8_t i) {
const uint8_t n = ui8_to_percent(i);
conv[3] = RJDIGIT(n, 100);
conv[4] = RJDIGIT(n, 10);
conv[5] = DIGIMOD(n, 1);
// Format uint8_t (0-100) as rj string with 123% / _12% / __1% format
const char* pcttostrpctrj(const uint8_t i) {
conv[3] = RJDIGIT(i, 100);
conv[4] = RJDIGIT(i, 10);
conv[5] = DIGIMOD(i, 1);
conv[6] = '%';
return &conv[3];
}
// Convert uint8_t (0-255) to a percentage, format as above
const char* ui8tostr4pctrj(const uint8_t i) {
return pcttostrpctrj(ui8_to_percent(i));
}
// Convert unsigned 8bit int to string 123 format
const char* ui8tostr3rj(const uint8_t i) {
conv[4] = RJDIGIT(i, 100);
@@ -50,6 +56,13 @@ const char* ui8tostr3rj(const uint8_t i) {
return &conv[4];
}
// Convert uint8_t to string with 12 format
const char* ui8tostr2(const uint8_t i) {
conv[5] = DIGIMOD(i, 10);
conv[6] = DIGIMOD(i, 1);
return &conv[5];
}
// Convert signed 8bit int to rj string with 123 or -12 format
const char* i8tostr3rj(const int8_t x) {
int xx = x;
@@ -164,9 +177,18 @@ const char* i16tostr4signrj(const int16_t i) {
return &conv[3];
}
// Convert unsigned float to string with 1.1 format
const char* ftostr11ns(const_float_t f) {
const long i = UINTFLOAT(f, 1);
conv[4] = DIGIMOD(i, 10);
conv[5] = '.';
conv[6] = DIGIMOD(i, 1);
return &conv[4];
}
// Convert unsigned float to string with 1.23 format
const char* ftostr12ns(const float &f) {
const long i = ((f < 0 ? -f : f) * 1000 + 5) / 10;
const char* ftostr12ns(const_float_t f) {
const long i = UINTFLOAT(f, 2);
conv[3] = DIGIMOD(i, 100);
conv[4] = '.';
conv[5] = DIGIMOD(i, 10);
@@ -174,10 +196,31 @@ const char* ftostr12ns(const float &f) {
return &conv[3];
}
// Convert unsigned float to string with 12.3 format
const char* ftostr31ns(const_float_t f) {
const long i = UINTFLOAT(f, 1);
conv[3] = DIGIMOD(i, 100);
conv[4] = DIGIMOD(i, 10);
conv[5] = '.';
conv[6] = DIGIMOD(i, 1);
return &conv[3];
}
// Convert unsigned float to string with 123.4 format
const char* ftostr41ns(const_float_t f) {
const long i = UINTFLOAT(f, 1);
conv[2] = DIGIMOD(i, 1000);
conv[3] = DIGIMOD(i, 100);
conv[4] = DIGIMOD(i, 10);
conv[5] = '.';
conv[6] = DIGIMOD(i, 1);
return &conv[2];
}
// Convert signed float to fixed-length string with 12.34 / _2.34 / -2.34 or -23.45 / 123.45 format
const char* ftostr42_52(const float &f) {
const char* ftostr42_52(const_float_t f) {
if (f <= -10 || f >= 100) return ftostr52(f); // -23.45 / 123.45
long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
long i = INTFLOAT(f, 2);
conv[2] = (f >= 0 && f < 10) ? ' ' : MINUSOR(i, DIGIMOD(i, 1000));
conv[3] = DIGIMOD(i, 100);
conv[4] = '.';
@@ -187,8 +230,8 @@ const char* ftostr42_52(const float &f) {
}
// Convert signed float to fixed-length string with 023.45 / -23.45 format
const char* ftostr52(const float &f) {
long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
const char* ftostr52(const_float_t f) {
long i = INTFLOAT(f, 2);
conv[1] = MINUSOR(i, DIGIMOD(i, 10000));
conv[2] = DIGIMOD(i, 1000);
conv[3] = DIGIMOD(i, 100);
@@ -199,9 +242,9 @@ const char* ftostr52(const float &f) {
}
// Convert signed float to fixed-length string with 12.345 / _2.345 / -2.345 or -23.45 / 123.45 format
const char* ftostr53_63(const float &f) {
const char* ftostr53_63(const_float_t f) {
if (f <= -10 || f >= 100) return ftostr63(f); // -23.456 / 123.456
long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
long i = INTFLOAT(f, 3);
conv[1] = (f >= 0 && f < 10) ? ' ' : MINUSOR(i, DIGIMOD(i, 10000));
conv[2] = DIGIMOD(i, 1000);
conv[3] = '.';
@@ -212,8 +255,8 @@ const char* ftostr53_63(const float &f) {
}
// Convert signed float to fixed-length string with 023.456 / -23.456 format
const char* ftostr63(const float &f) {
long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
const char* ftostr63(const_float_t f) {
long i = INTFLOAT(f, 3);
conv[0] = MINUSOR(i, DIGIMOD(i, 100000));
conv[1] = DIGIMOD(i, 10000);
conv[2] = DIGIMOD(i, 1000);
@@ -227,8 +270,8 @@ const char* ftostr63(const float &f) {
#if ENABLED(LCD_DECIMAL_SMALL_XY)
// Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
const char* ftostr4sign(const float &f) {
const int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
const char* ftostr4sign(const_float_t f) {
const int i = INTFLOAT(f, 1);
if (!WITHIN(i, -99, 999)) return i16tostr4signrj((int)f);
const bool neg = i < 0;
const int ii = neg ? -i : i;
@@ -241,9 +284,20 @@ const char* ftostr63(const float &f) {
#endif
// Convert float to fixed-length string with +12.3 / -12.3 format
const char* ftostr31sign(const_float_t f) {
int i = INTFLOAT(f, 1);
conv[2] = MINUSOR(i, '+');
conv[3] = DIGIMOD(i, 100);
conv[4] = DIGIMOD(i, 10);
conv[5] = '.';
conv[6] = DIGIMOD(i, 1);
return &conv[2];
}
// Convert float to fixed-length string with +123.4 / -123.4 format
const char* ftostr41sign(const float &f) {
int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
const char* ftostr41sign(const_float_t f) {
int i = INTFLOAT(f, 1);
conv[1] = MINUSOR(i, '+');
conv[2] = DIGIMOD(i, 1000);
conv[3] = DIGIMOD(i, 100);
@@ -254,8 +308,8 @@ const char* ftostr41sign(const float &f) {
}
// Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
const char* ftostr43sign(const float &f, char plus/*=' '*/) {
long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
const char* ftostr43sign(const_float_t f, char plus/*=' '*/) {
long i = INTFLOAT(f, 3);
conv[1] = i ? MINUSOR(i, plus) : ' ';
conv[2] = DIGIMOD(i, 1000);
conv[3] = '.';
@@ -266,8 +320,8 @@ const char* ftostr43sign(const float &f, char plus/*=' '*/) {
}
// Convert signed float to string (5 digit) with -1.2345 / _0.0000 / +1.2345 format
const char* ftostr54sign(const float &f, char plus/*=' '*/) {
long i = (f * 100000 + (f < 0 ? -5: 5)) / 10;
const char* ftostr54sign(const_float_t f, char plus/*=' '*/) {
long i = INTFLOAT(f, 4);
conv[0] = i ? MINUSOR(i, plus) : ' ';
conv[1] = DIGIMOD(i, 10000);
conv[2] = '.';
@@ -279,14 +333,14 @@ const char* ftostr54sign(const float &f, char plus/*=' '*/) {
}
// Convert unsigned float to rj string with 12345 format
const char* ftostr5rj(const float &f) {
const long i = ((f < 0 ? -f : f) * 10 + 5) / 10;
const char* ftostr5rj(const_float_t f) {
const long i = UINTFLOAT(f, 0);
return ui16tostr5rj(i);
}
// Convert signed float to string with +1234.5 format
const char* ftostr51sign(const float &f) {
long i = (f * 100 + (f < 0 ? -5: 5)) / 10;
const char* ftostr51sign(const_float_t f) {
long i = INTFLOAT(f, 1);
conv[0] = MINUSOR(i, '+');
conv[1] = DIGIMOD(i, 10000);
conv[2] = DIGIMOD(i, 1000);
@@ -298,8 +352,8 @@ const char* ftostr51sign(const float &f) {
}
// Convert signed float to string with +123.45 format
const char* ftostr52sign(const float &f) {
long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
const char* ftostr52sign(const_float_t f) {
long i = INTFLOAT(f, 2);
conv[0] = MINUSOR(i, '+');
conv[1] = DIGIMOD(i, 10000);
conv[2] = DIGIMOD(i, 1000);
@@ -311,8 +365,8 @@ const char* ftostr52sign(const float &f) {
}
// Convert signed float to string with +12.345 format
const char* ftostr53sign(const float &f) {
long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
const char* ftostr53sign(const_float_t f) {
long i = INTFLOAT(f, 3);
conv[0] = MINUSOR(i, '+');
conv[1] = DIGIMOD(i, 10000);
conv[2] = DIGIMOD(i, 1000);
@@ -324,8 +378,8 @@ const char* ftostr53sign(const float &f) {
}
// Convert unsigned float to string with ____4.5, __34.5, _234.5, 1234.5 format
const char* ftostr51rj(const float &f) {
const long i = ((f < 0 ? -f : f) * 100 + 5) / 10;
const char* ftostr51rj(const_float_t f) {
const long i = UINTFLOAT(f, 1);
conv[0] = ' ';
conv[1] = RJDIGIT(i, 10000);
conv[2] = RJDIGIT(i, 1000);
@@ -337,8 +391,8 @@ const char* ftostr51rj(const float &f) {
}
// Convert signed float to space-padded string with -_23.4_ format
const char* ftostr52sp(const float &f) {
long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
const char* ftostr52sp(const_float_t f) {
long i = INTFLOAT(f, 2);
uint8_t dig;
conv[0] = MINUSOR(i, ' ');
conv[1] = RJDIGIT(i, 10000);