mirror of
https://github.com/NevermindZZT/letter-shell.git
synced 2025-01-21 10:02:54 +08:00
修复浮点参数自动转换
This commit is contained in:
parent
86896167aa
commit
e5a0166072
14
shell.c
14
shell.c
@ -196,7 +196,7 @@ static void shellDisplayReturn(SHELL_TypeDef *shell, int value)
|
||||
{
|
||||
char str[11] = "0000000000";
|
||||
unsigned int v = value;
|
||||
char i = 9;
|
||||
char i = 10;
|
||||
char tmp;
|
||||
|
||||
shellDisplay(shell, "Return: ");
|
||||
@ -207,22 +207,22 @@ static void shellDisplayReturn(SHELL_TypeDef *shell, int value)
|
||||
}
|
||||
while (v)
|
||||
{
|
||||
str[i--] = v % 10 + 48;
|
||||
str[--i] = v % 10 + 48;
|
||||
v /= 10;
|
||||
}
|
||||
shellDisplay(shell, str);
|
||||
shellDisplay(shell, str + i - (value == 0));
|
||||
v = value;
|
||||
if (value < 0)
|
||||
{
|
||||
v = (unsigned int)value;
|
||||
}
|
||||
i = 7;
|
||||
i = 8;
|
||||
str[8] = 0;
|
||||
while (v)
|
||||
{
|
||||
tmp = v %16;
|
||||
str[i--] = (tmp > 9) ? (tmp + 87) : (tmp + 48);
|
||||
v /= 16;
|
||||
tmp = v & 0x0000000F;
|
||||
str[--i] = (tmp > 9) ? (tmp + 87) : (tmp + 48);
|
||||
v >>= 4;
|
||||
}
|
||||
shellDisplay(shell, ", 0x");
|
||||
shellDisplay(shell, str);
|
||||
|
34
shell_ext.c
34
shell_ext.c
@ -36,15 +36,13 @@ static NUM_Type shellExtNumType(char *string)
|
||||
{
|
||||
type = NUM_TYPE_OCT;
|
||||
}
|
||||
else
|
||||
|
||||
while (*p++)
|
||||
{
|
||||
while (*p++)
|
||||
if (*p == '.' && *(p + 1) != 0)
|
||||
{
|
||||
if (*p == '.' && *(p + 1) != 0)
|
||||
{
|
||||
type = NUM_TYPE_FLOAT;
|
||||
break;
|
||||
}
|
||||
type = NUM_TYPE_FLOAT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,6 +173,8 @@ static unsigned int shellExtParseNumber(char *string)
|
||||
char offset = 0;
|
||||
signed char sign = 1;
|
||||
unsigned int valueInt = 0;
|
||||
float valueFloat = 0.0;
|
||||
unsigned int devide = 0;
|
||||
|
||||
if (*string == '-')
|
||||
{
|
||||
@ -206,17 +206,27 @@ static unsigned int shellExtParseNumber(char *string)
|
||||
|
||||
p = string + offset + ((sign == -1) ? 1 : 0);
|
||||
|
||||
if (type != NUM_TYPE_FLOAT)
|
||||
while (*p)
|
||||
{
|
||||
while (*p)
|
||||
if (*p == '.')
|
||||
{
|
||||
valueInt = valueInt * radix + shellExtToNum(*p);
|
||||
devide = 1;
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
valueInt = valueInt * radix + shellExtToNum(*p);
|
||||
devide *= 10;
|
||||
p++;
|
||||
}
|
||||
if (type == NUM_TYPE_FLOAT && devide != 0)
|
||||
{
|
||||
valueFloat = (float)valueInt / devide * sign;
|
||||
return *(unsigned int *)(&valueFloat);
|
||||
}
|
||||
else
|
||||
{
|
||||
return valueInt * sign;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user