File tree 1 file changed +11
-8
lines changed
1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ use esp_idf_hal::{
7
7
} ;
8
8
use esp_idf_sys as _;
9
9
10
+ const CR : u8 = 13 ;
11
+
10
12
fn main ( ) {
11
13
esp_idf_sys:: link_patches ( ) ;
12
14
@@ -25,20 +27,21 @@ fn main() {
25
27
)
26
28
. unwrap ( ) ;
27
29
28
- let mut uart_buf : Vec < u8 > = Vec :: new ( ) ;
30
+ let mut cli_buf : Vec < u8 > = Vec :: new ( ) ;
29
31
30
32
loop {
31
33
let mut buf: [ u8 ; 10 ] = [ 0 ; 10 ] ;
32
34
match uart. read ( & mut buf, NON_BLOCK ) {
33
- Ok ( x) => {
34
- if x > 0 {
35
- uart_buf. push ( buf[ 0 ] ) ;
36
- if uart_buf[ uart_buf. len ( ) - 1 ] == 13 {
37
- match uart. write ( & uart_buf) {
38
- Ok ( _) => println ! ( "{:?} written" , buf) ,
35
+ Ok ( bytes_read) => {
36
+ if bytes_read > 0 {
37
+ let b = buf[ 0 ] ;
38
+ cli_buf. push ( b) ;
39
+ if b == CR {
40
+ match uart. write ( & cli_buf) {
41
+ Ok ( _) => println ! ( "{:?} written" , cli_buf) ,
39
42
Err ( _) => { }
40
43
}
41
- uart_buf . clear ( ) ;
44
+ cli_buf . clear ( ) ;
42
45
}
43
46
}
44
47
}
You can’t perform that action at this time.
0 commit comments