@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88use serialport:: { DataBits , FlowControl , Parity , SerialPort , StopBits } ;
99
1010use 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 } ;
1212
1313#[ derive( Debug , Clone , Serialize , Deserialize ) ]
1414pub struct SerialDevices {
@@ -112,32 +112,41 @@ pub fn serial_thread(
112112
113113 let device = get_device ( & devices_lock, & device_lock) ;
114114
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 ;
131118 }
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 ;
135149 }
136- print_to_console (
137- & print_lock,
138- Print :: Error ( format ! ( "Error connecting: {}" , err) ) ,
139- ) ;
140- continue ;
141150 }
142151 } ;
143152
@@ -176,6 +185,7 @@ fn available_devices() -> Vec<String> {
176185 . unwrap ( )
177186 . iter ( )
178187 . map ( |p| p. port_name . clone ( ) )
188+ . chain ( std:: iter:: once ( "stdio" . into ( ) ) )
179189 . collect ( )
180190}
181191
0 commit comments