@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
8
8
use serialport:: { DataBits , FlowControl , Parity , SerialPort , StopBits } ;
9
9
10
10
use crate :: data:: { get_epoch_ms, SerialDirection } ;
11
- use crate :: { print_to_console, Packet , Print , APP_INFO , PREFS_KEY_SERIAL } ;
11
+ use crate :: { print_to_console, stdio , Packet , Print , APP_INFO , PREFS_KEY_SERIAL } ;
12
12
13
13
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
14
14
pub struct SerialDevices {
@@ -112,32 +112,41 @@ pub fn serial_thread(
112
112
113
113
let device = get_device ( & devices_lock, & device_lock) ;
114
114
115
- let mut port = match serialport:: new ( & device. name , device. baud_rate )
116
- . timeout ( Duration :: from_millis ( 100 ) )
117
- . open ( )
118
- {
119
- Ok ( p) => {
120
- if let Ok ( mut connected) = connected_lock. write ( ) {
121
- * connected = true ;
122
- }
123
- print_to_console (
124
- & print_lock,
125
- Print :: Ok ( format ! (
126
- "Connected to serial port: {} @ baud = {}" ,
127
- device. name, device. baud_rate
128
- ) ) ,
129
- ) ;
130
- BufReader :: new ( p)
115
+ let mut port = if device. name == "stdio" {
116
+ if let Ok ( mut connected) = connected_lock. write ( ) {
117
+ * connected = true ;
131
118
}
132
- Err ( err) => {
133
- if let Ok ( mut write_guard) = device_lock. write ( ) {
134
- write_guard. name . clear ( ) ;
119
+ print_to_console ( & print_lock, Print :: Ok ( format ! ( "Connected to stdio" ) ) ) ;
120
+
121
+ BufReader :: new ( Box :: new ( stdio:: Stdio ) as _ )
122
+ } else {
123
+ match serialport:: new ( & device. name , device. baud_rate )
124
+ . timeout ( Duration :: from_millis ( 100 ) )
125
+ . open ( )
126
+ {
127
+ Ok ( p) => {
128
+ if let Ok ( mut connected) = connected_lock. write ( ) {
129
+ * connected = true ;
130
+ }
131
+ print_to_console (
132
+ & print_lock,
133
+ Print :: Ok ( format ! (
134
+ "Connected to serial port: {} @ baud = {}" ,
135
+ device. name, device. baud_rate
136
+ ) ) ,
137
+ ) ;
138
+ BufReader :: new ( p)
139
+ }
140
+ Err ( err) => {
141
+ if let Ok ( mut write_guard) = device_lock. write ( ) {
142
+ write_guard. name . clear ( ) ;
143
+ }
144
+ print_to_console (
145
+ & print_lock,
146
+ Print :: Error ( format ! ( "Error connecting: {}" , err) ) ,
147
+ ) ;
148
+ continue ;
135
149
}
136
- print_to_console (
137
- & print_lock,
138
- Print :: Error ( format ! ( "Error connecting: {}" , err) ) ,
139
- ) ;
140
- continue ;
141
150
}
142
151
} ;
143
152
@@ -176,6 +185,7 @@ fn available_devices() -> Vec<String> {
176
185
. unwrap ( )
177
186
. iter ( )
178
187
. map ( |p| p. port_name . clone ( ) )
188
+ . chain ( std:: iter:: once ( "stdio" . into ( ) ) )
179
189
. collect ( )
180
190
}
181
191
0 commit comments