Fix for aligment at displayfloat command (#18601)

* Fix for wrong aligment at displayfloat command

* Added alignment parameter to prevent regression

---------

Co-authored-by: JeroenSt <nospam@nospam.org>
This commit is contained in:
Jeroen 2023-05-08 09:58:26 +02:00 committed by GitHub
parent cdc6ba7c96
commit 6cb92ffe49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,14 +83,14 @@
DisplayFloat num [,position {0-(Settings->display_width-1)} [,precision {0-Settings->display_width} [,length {1 to Settings->display_width}]]] DisplayFloat num [,position {0-(Settings->display_width-1)} [,precision {0-Settings->display_width} [,length {1 to Settings->display_width} [,alignment {0=left 1=right}]]]]
Clears and then displays float (with decimal point) command e.g., "DisplayFloat 12.34" Clears and then displays float (with decimal point) command e.g., "DisplayFloat 12.34"
See function description below for more details. See function description below for more details.
DisplayFloatNC num [,position {0-(Settings->display_width-1)} [,precision {0-Settings->display_width} [,length {1 to Settings->display_width}]]] DisplayFloatNC num [,position {0-(Settings->display_width-1)} [,precision {0-Settings->display_width} [,length {1 to Settings->display_width} [,alignment {0=left 1=right}]]]]
Displays float (with decimal point) as above, but without clearing first. command e.g., "DisplayFloatNC 12.34" Displays float (with decimal point) as above, but without clearing first. command e.g., "DisplayFloatNC 12.34"
See function description below for more details. See function description below for more details.
@ -431,14 +431,18 @@ bool CmndTM1637Float(bool clear)
char sPrecision[CMD_MAX_LEN]; char sPrecision[CMD_MAX_LEN];
char sPosition[CMD_MAX_LEN]; char sPosition[CMD_MAX_LEN];
char sLength[CMD_MAX_LEN]; char sLength[CMD_MAX_LEN];
char sAlignment[CMD_MAX_LEN];
uint8_t length = 0; uint8_t length = 0;
uint8_t precision = Settings->display_width; uint8_t precision = Settings->display_width;
uint8_t position = 0; uint8_t position = 0;
uint8_t alignment = 0;
float fnum = 0.0f; float fnum = 0.0f;
switch (ArgC()) switch (ArgC())
{ {
case 5:
subStr(sAlignment, XdrvMailbox.data, ",", 5);
alignment = atoi(sAlignment);
case 4: case 4:
subStr(sLength, XdrvMailbox.data, ",", 4); subStr(sLength, XdrvMailbox.data, ",", 4);
length = atoi(sLength); length = atoi(sLength);
@ -469,6 +473,14 @@ bool CmndTM1637Float(bool clear)
if ((length <= 0) || (length > Settings->display_width)) if ((length <= 0) || (length > Settings->display_width))
length = Settings->display_width; length = Settings->display_width;
// Add leading spaces before value if txt is shorter than length
if ((alignment == 1) && (strlen(txt) < length + 1))
{
char tmptxt[30];
ext_snprintf_P(tmptxt, sizeof(tmptxt), "%*s%s", strlen(txt)-(length+1), "", txt);
strcpy (txt, tmptxt);
}
AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: num %4_f, prec %d, len %d"), &fnum, precision, length); AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: num %4_f, prec %d, len %d"), &fnum, precision, length);
if (TM1637 == TM1637Data.display_type) if (TM1637 == TM1637Data.display_type)