|
@ -57,24 +57,51 @@ void safe_delay(millis_t ms) { |
|
|
#define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ') |
|
|
#define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ') |
|
|
#define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-')) |
|
|
#define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-')) |
|
|
|
|
|
|
|
|
// Convert unsigned int to string 123 format
|
|
|
// Convert unsigned 8bit int to string 123 format
|
|
|
char* i8tostr3(const uint8_t i) { |
|
|
char* ui8tostr3(const uint8_t i) { |
|
|
conv[4] = RJDIGIT(i, 100); |
|
|
conv[4] = RJDIGIT(i, 100); |
|
|
conv[5] = RJDIGIT(i, 10); |
|
|
conv[5] = RJDIGIT(i, 10); |
|
|
conv[6] = DIGIMOD(i, 1); |
|
|
conv[6] = DIGIMOD(i, 1); |
|
|
return &conv[4]; |
|
|
return &conv[4]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Convert signed int to rj string with 123 or -12 format
|
|
|
// Convert signed 8bit int to rj string with 123 or -12 format
|
|
|
char* itostr3(int i) { |
|
|
char* i8tostr3(const int8_t x) { |
|
|
conv[4] = MINUSOR(i, RJDIGIT(i, 100)); |
|
|
int xx = x; |
|
|
conv[5] = RJDIGIT(i, 10); |
|
|
conv[4] = MINUSOR(xx, RJDIGIT(xx, 100)); |
|
|
conv[6] = DIGIMOD(i, 1); |
|
|
conv[5] = RJDIGIT(xx, 10); |
|
|
|
|
|
conv[6] = DIGIMOD(xx, 1); |
|
|
|
|
|
return &conv[4]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Convert unsigned 16bit int to string 123 format
|
|
|
|
|
|
char* ui16tostr3(const uint16_t xx) { |
|
|
|
|
|
conv[4] = RJDIGIT(xx, 100); |
|
|
|
|
|
conv[5] = RJDIGIT(xx, 10); |
|
|
|
|
|
conv[6] = DIGIMOD(xx, 1); |
|
|
|
|
|
return &conv[4]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Convert unsigned 16bit int to string 1234 format
|
|
|
|
|
|
char* ui16tostr4(const uint16_t xx) { |
|
|
|
|
|
conv[3] = RJDIGIT(xx, 1000); |
|
|
|
|
|
conv[4] = RJDIGIT(xx, 100); |
|
|
|
|
|
conv[5] = RJDIGIT(xx, 10); |
|
|
|
|
|
conv[6] = DIGIMOD(xx, 1); |
|
|
|
|
|
return &conv[3]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Convert signed 16bit int to rj string with 123 or -12 format
|
|
|
|
|
|
char* i16tostr3(const int16_t x) { |
|
|
|
|
|
int xx = x; |
|
|
|
|
|
conv[4] = MINUSOR(xx, RJDIGIT(xx, 100)); |
|
|
|
|
|
conv[5] = RJDIGIT(xx, 10); |
|
|
|
|
|
conv[6] = DIGIMOD(xx, 1); |
|
|
return &conv[4]; |
|
|
return &conv[4]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Convert unsigned int to lj string with 123 format
|
|
|
// Convert unsigned 16bit int to lj string with 123 format
|
|
|
char* itostr3left(const int i) { |
|
|
char* i16tostr3left(const int16_t i) { |
|
|
char *str = &conv[6]; |
|
|
char *str = &conv[6]; |
|
|
*str = DIGIMOD(i, 1); |
|
|
*str = DIGIMOD(i, 1); |
|
|
if (i >= 10) { |
|
|
if (i >= 10) { |
|
@ -85,8 +112,8 @@ void safe_delay(millis_t ms) { |
|
|
return str; |
|
|
return str; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Convert signed int to rj string with 1234, _123, -123, _-12, or __-1 format
|
|
|
// Convert signed 16bit int to rj string with 1234, _123, -123, _-12, or __-1 format
|
|
|
char* itostr4sign(const int i) { |
|
|
char* i16tostr4sign(const int16_t i) { |
|
|
const bool neg = i < 0; |
|
|
const bool neg = i < 0; |
|
|
const int ii = neg ? -i : i; |
|
|
const int ii = neg ? -i : i; |
|
|
if (i >= 1000) { |
|
|
if (i >= 1000) { |
|
@ -141,7 +168,7 @@ void safe_delay(millis_t ms) { |
|
|
// Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
|
|
|
// Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
|
|
|
char* ftostr4sign(const float &f) { |
|
|
char* ftostr4sign(const float &f) { |
|
|
const int i = (f * 100 + (f < 0 ? -5: 5)) / 10; |
|
|
const int i = (f * 100 + (f < 0 ? -5: 5)) / 10; |
|
|
if (!WITHIN(i, -99, 999)) return itostr4sign((int)f); |
|
|
if (!WITHIN(i, -99, 999)) return i16tostr4sign((int)f); |
|
|
const bool neg = i < 0; |
|
|
const bool neg = i < 0; |
|
|
const int ii = neg ? -i : i; |
|
|
const int ii = neg ? -i : i; |
|
|
conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' '); |
|
|
conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' '); |
|
|