File tree Expand file tree Collapse file tree 3 files changed +42
-14
lines changed
samples/hello_arduino/src Expand file tree Collapse file tree 3 files changed +42
-14
lines changed Original file line number Diff line number Diff line change @@ -6,23 +6,35 @@ size_t arduino::ZephyrSerial::begin(unsigned long int baudrate){
6
6
return 0 ;
7
7
}
8
8
9
+ size_t arduino::ZephyrSerial::print_char (char ch, bool lf){
10
+ printk (lf ? " %c\n " : " %c" , ch);
11
+ return lf ? 2 : 1 ;
12
+ }
13
+
14
+ size_t arduino::ZephyrSerial::print_str (const char * ptr, bool lf) {
15
+ printf (lf ? " %s\n " : " %s" , ptr);
16
+ return lf ? strlen (ptr)+1 : strlen (ptr);
17
+ }
18
+
9
19
size_t arduino::ZephyrSerial::print (char ch){
10
- printk (" %c" ,ch);
11
- return 0 ;
20
+ return print_char (ch, false );
12
21
}
13
- size_t arduino::ZephyrSerial::println ( const char * ptr) {
14
- printf ( " \n %s \n " , ptr);
15
- return 0 ;
22
+
23
+ size_t arduino::ZephyrSerial::println ( char ch){
24
+ return print_char (ch, true ) ;
16
25
}
17
- size_t arduino::ZephyrSerial::println (char c){
18
- // pvt_c = c;
19
- printf (" \n %c\n " ,c);
20
- return 0 ;
26
+
27
+ size_t arduino::ZephyrSerial::print (const char * ptr) {
28
+ return print_str (ptr, false );
29
+ }
30
+
31
+ size_t arduino::ZephyrSerial::println (const char * ptr){
32
+ return print_str (ptr, true );
21
33
}
22
34
23
35
size_t arduino::ZephyrSerial::println (void ){
24
36
printf (" \n " );
25
37
return 0 ;
26
38
}
27
39
28
- arduino::ZephyrSerial Serial;
40
+ arduino::ZephyrSerial Serial;
Original file line number Diff line number Diff line change @@ -7,11 +7,16 @@ namespace arduino {
7
7
8
8
class ZephyrSerial {
9
9
char pvt_c;
10
+
11
+ private:
12
+ size_t print_char (const char c, bool lf);
13
+ size_t print_str (const char * ptr, bool lf);
14
+
10
15
public:
11
16
size_t begin (unsigned long int baudrate); // TODO
12
17
13
18
size_t print (const char c);
14
-
19
+ size_t print ( const char * ptr);
15
20
size_t println (const char c);
16
21
size_t println (const char * ptr);
17
22
size_t println (void );
@@ -20,4 +25,4 @@ class ZephyrSerial {
20
25
21
26
} // namespace arduino
22
27
23
- extern arduino::ZephyrSerial Serial;
28
+ extern arduino::ZephyrSerial Serial;
Original file line number Diff line number Diff line change @@ -12,7 +12,18 @@ void setup() {
12
12
}
13
13
void loop () {
14
14
char c = ' D' ;
15
- Serial.print (c);
16
- Serial.println (" Hello, World!" );
15
+ size_t ret1;
16
+ size_t ret2;
17
+ ret1 = Serial.print (c);
18
+ ret2 = Serial.println (" Hello, World!" );
19
+ printk (" Sizes: %d %d\n " , ret1, ret2);
20
+ Serial.println ();
21
+ ret1 = Serial.print (" My letter is: " );
22
+ ret2 = Serial.println (c);
23
+ printk (" Sizes: %d %d\n " , ret1, ret2);
24
+ Serial.println ();
25
+ char myString[] = " Will it print?" ;
26
+ ret1 = Serial.println (myString);
27
+ printk (" Size: %d \n\n\n " , ret1);
17
28
delay (1000 ); // 1 second delay
18
29
}
You can’t perform that action at this time.
0 commit comments