Merge pull request #15314 from aabadie/pr/sys/arduino_print_float
sys/arduino: fix print float
This commit is contained in:
commit
45b8902659
@ -13,6 +13,7 @@ ifneq (,$(filter arduino,$(USEMODULE)))
|
||||
FEATURES_OPTIONAL += arduino_pwm
|
||||
FEATURES_OPTIONAL += periph_adc
|
||||
FEATURES_REQUIRED += periph_gpio
|
||||
USEMODULE += fmt
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ extern "C" {
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fmt.h"
|
||||
#include "irq.h"
|
||||
}
|
||||
|
||||
@ -148,7 +149,7 @@ size_t SerialPort::print(float val)
|
||||
size_t SerialPort::print(float val, int format)
|
||||
{
|
||||
char buf[64];
|
||||
size_t len = sprintf(buf, "%.*f", format, (double)val);
|
||||
size_t len = fmt_float(buf, val, format);
|
||||
write(buf, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -105,6 +105,15 @@ static void print_test(void)
|
||||
Serial.print("): ");
|
||||
Serial.println(ul, f);
|
||||
}
|
||||
|
||||
Serial.print("print(float): ");
|
||||
Serial.print((float)3.1415);
|
||||
Serial.println();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Serial.print("print(float): ");
|
||||
Serial.print((float)3.1415, i);
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
|
||||
@ -64,6 +64,11 @@ def testfunc(child):
|
||||
child.expect_exact("println(unsigned long, DEC): 1234567890")
|
||||
child.expect_exact("print(unsigned long, HEX): 499602d2")
|
||||
child.expect_exact("println(unsigned long, HEX): 499602d2")
|
||||
child.expect_exact("print(float): 3.14")
|
||||
child.expect_exact("print(float): 3")
|
||||
child.expect_exact("print(float): 3.1")
|
||||
child.expect_exact("print(float): 3.14")
|
||||
child.expect_exact("print(float): 3.141")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user