Rename LCD menus according to variable types (#12892)

This commit is contained in:
Scott Lahteine
2019-01-12 16:01:04 -06:00
committed by GitHub
parent ed3ab5e212
commit eb78aed863
13 changed files with 109 additions and 65 deletions

View File

@@ -57,24 +57,51 @@ void safe_delay(millis_t ms) {
#define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ')
#define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
// Convert unsigned int to string 123 format
char* i8tostr3(const uint8_t i) {
// Convert unsigned 8bit int to string 123 format
char* ui8tostr3(const uint8_t i) {
conv[4] = RJDIGIT(i, 100);
conv[5] = RJDIGIT(i, 10);
conv[6] = DIGIMOD(i, 1);
return &conv[4];
}
// Convert signed int to rj string with 123 or -12 format
char* itostr3(int i) {
conv[4] = MINUSOR(i, RJDIGIT(i, 100));
conv[5] = RJDIGIT(i, 10);
conv[6] = DIGIMOD(i, 1);
// Convert signed 8bit int to rj string with 123 or -12 format
char* i8tostr3(const int8_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];
}
// Convert unsigned int to lj string with 123 format
char* itostr3left(const int i) {
// 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];
}
// Convert unsigned 16bit int to lj string with 123 format
char* i16tostr3left(const int16_t i) {
char *str = &conv[6];
*str = DIGIMOD(i, 1);
if (i >= 10) {
@@ -85,8 +112,8 @@ void safe_delay(millis_t ms) {
return str;
}
// Convert signed int to rj string with 1234, _123, -123, _-12, or __-1 format
char* itostr4sign(const int i) {
// Convert signed 16bit int to rj string with 1234, _123, -123, _-12, or __-1 format
char* i16tostr4sign(const int16_t i) {
const bool neg = i < 0;
const int ii = neg ? -i : i;
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
char* ftostr4sign(const float &f) {
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 int ii = neg ? -i : i;
conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' ');

View File

@@ -56,16 +56,25 @@ inline void serial_delay(const millis_t ms) {
#if ENABLED(ULTRA_LCD) || ENABLED(DEBUG_LEVELING_FEATURE) || ENABLED(EXTENSIBLE_UI)
// Convert uint8_t to string with 123 format
char* i8tostr3(const uint8_t x);
char* ui8tostr3(const uint8_t x);
// Convert signed int to rj string with 123 or -12 format
char* itostr3(const int x);
// Convert int8_t to string with 123 format
char* i8tostr3(const int8_t x);
// Convert uint16_t to string with 123 format
char* ui16tostr3(const uint16_t x);
// Convert uint16_t to string with 1234 format
char* ui16tostr4(const uint16_t x);
// Convert int16_t to string with 123 format
char* i16tostr3(const int16_t x);
// Convert unsigned int to lj string with 123 format
char* itostr3left(const int xx);
char* i16tostr3left(const int16_t xx);
// Convert signed int to rj string with _123, -123, _-12, or __-1 format
char* itostr4sign(const int x);
char* i16tostr4sign(const int16_t x);
// Convert unsigned float to string with 1.23 format
char* ftostr12ns(const float &x);
@@ -95,14 +104,14 @@ inline void serial_delay(const millis_t ms) {
char* ftostr62rj(const float &x);
// Convert float to rj string with 123 or -12 format
FORCE_INLINE char* ftostr3(const float &x) { return itostr3(int(x + (x < 0 ? -0.5f : 0.5f))); }
FORCE_INLINE char* ftostr3(const float &x) { return i16tostr3(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }
#if ENABLED(LCD_DECIMAL_SMALL_XY)
// Convert float to rj string with 1234, _123, 12.3, _1.2, -123, _-12, or -1.2 format
char* ftostr4sign(const float &fx);
#else
// Convert float to rj string with 1234, _123, -123, __12, _-12, ___1, or __-1 format
FORCE_INLINE char* ftostr4sign(const float &x) { return itostr4sign(int(x + (x < 0 ? -0.5f : 0.5f))); }
FORCE_INLINE char* ftostr4sign(const float &x) { return i16tostr4sign(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }
#endif
#endif // ULTRA_LCD