Skip to content

Commit 2e6f9f4

Browse files
committed
zephyrSerial: Add int and double prints
Add more variants of prints like double and integer support. Also, include zephyrSerial in Arduino.h so that it can be used with just including Arduino.h Signed-off-by: Dhruva Gole <[email protected]>
1 parent ea7d49b commit 2e6f9f4

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

Diff for: cores/arduino/Arduino.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
#include <zephyr/drivers/gpio.h>
1010
#include <zephyr/zephyr.h>
1111

12-
#include <variants.h>
12+
#include <variants.h>
13+
#include <zephyrSerial.h>

Diff for: cores/arduino/zephyrSerial.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ size_t arduino::ZephyrSerial::print(char ch){
2424
return print_char(ch, false);
2525
}
2626

27+
size_t arduino::ZephyrSerial::print(const int val) {
28+
printk("%d",val);
29+
return sizeof(int);
30+
}
31+
32+
size_t arduino::ZephyrSerial::print(double d) {
33+
printk("%0.4f",d);
34+
return sizeof(double);
35+
}
36+
2737
size_t arduino::ZephyrSerial::print(const int val, const int base) {
2838
if (base == 2) { /* Todo: print Binary */
2939
printk("%d", val);

Diff for: cores/arduino/zephyrSerial.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class ZephyrSerial {
2121
size_t begin(unsigned long int baudrate); //TODO
2222

2323
size_t print(const char c);
24+
size_t print(const int val);
25+
size_t print(double d);
2426
size_t print(const char * ptr);
2527
size_t print(const int val, const int base);
2628

Diff for: module.conf

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ CONFIG_ARDUINO_API=y
44
CONFIG_I2C=y
55
CONFIG_NEWLIB_LIBC=y
66
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
7+
CONFIG_CBPRINTF_FP_SUPPORT=y
78
CONFIG_RING_BUFFER=y

0 commit comments

Comments
 (0)