11use core:: f32;
2+ use crossbeam_channel:: { Receiver , Sender } ;
23use std:: cmp:: max;
34use std:: ops:: RangeInclusive ;
45use std:: path:: PathBuf ;
5- use std:: sync:: mpsc:: { Receiver , Sender } ;
66use std:: sync:: { Arc , RwLock } ;
77use std:: time:: Duration ;
88
@@ -64,6 +64,13 @@ pub enum WindowFeedback {
6464 Cancel ,
6565}
6666
67+ #[ derive( Clone ) ]
68+ pub enum GuiCommand {
69+ Clear ,
70+ ShowTimestamps ( bool ) ,
71+ ShowSentTraffic ( bool ) ,
72+ }
73+
6774#[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
6875pub struct GuiSettingsContainer {
6976 pub device : String ,
@@ -134,7 +141,7 @@ pub struct MyApp {
134141 load_tx : Sender < PathBuf > ,
135142 load_names_rx : Receiver < Vec < String > > ,
136143 send_tx : Sender < String > ,
137- clear_tx : Sender < bool > ,
144+ gui_cmd_tx : Sender < GuiCommand > ,
138145 history : Vec < String > ,
139146 index : usize ,
140147 eol : String ,
@@ -166,7 +173,7 @@ impl MyApp {
166173 load_tx : Sender < PathBuf > ,
167174 load_names_rx : Receiver < Vec < String > > ,
168175 send_tx : Sender < String > ,
169- clear_tx : Sender < bool > ,
176+ gui_cmd_tx : Sender < GuiCommand > ,
170177 ) -> Self {
171178 let mut file_dialog = FileDialog :: default ( )
172179 //.initial_directory(PathBuf::from("/path/to/app"))
@@ -227,7 +234,7 @@ impl MyApp {
227234 load_tx,
228235 load_names_rx,
229236 send_tx,
230- clear_tx ,
237+ gui_cmd_tx ,
231238 plotting_range : usize:: MAX ,
232239 plot_serial_display_ratio : 0.45 ,
233240 command : "" . to_string ( ) ,
@@ -616,8 +623,8 @@ impl MyApp {
616623 self . device_idx = self . serial_devices . devices . len ( ) - 1 ;
617624 save_serial_settings ( & self . serial_devices ) ;
618625 }
619- self . clear_tx
620- . send ( true )
626+ self . gui_cmd_tx
627+ . send ( GuiCommand :: Clear )
621628 . expect ( "failed to send clear after choosing new device" ) ;
622629 // need to clear the data here such that we don't get errors in the gui (plot)
623630 self . data = GuiOutputDataContainer :: default ( ) ;
@@ -913,7 +920,7 @@ impl MyApp {
913920 || ui. input_mut ( |i| i. consume_shortcut ( & CLEAR_PLOT_SHORTCUT ) )
914921 {
915922 log:: info!( "Cleared recorded Data" ) ;
916- if let Err ( err) = self . clear_tx . send ( true ) {
923+ if let Err ( err) = self . gui_cmd_tx . send ( GuiCommand :: Clear ) {
917924 log:: error!( "clear_tx thread send failed: {:?}" , err) ;
918925 }
919926 // need to clear the data here in order to prevent errors in the gui (plot)
@@ -934,14 +941,34 @@ impl MyApp {
934941 } ) ;
935942 ui. add_space ( 5.0 ) ;
936943 ui. horizontal ( |ui| {
937- ui. add ( toggle ( & mut self . show_sent_cmds ) )
938- . on_hover_text ( "Show sent commands in console." ) ;
944+ if ui
945+ . add ( toggle ( & mut self . show_sent_cmds ) )
946+ . on_hover_text ( "Show sent commands in console." )
947+ . changed ( )
948+ {
949+ if let Err ( err) = self
950+ . gui_cmd_tx
951+ . send ( GuiCommand :: ShowSentTraffic ( self . show_sent_cmds ) )
952+ {
953+ log:: error!( "clear_tx thread send failed: {:?}" , err) ;
954+ }
955+ }
939956 ui. label ( "Show Sent Commands" ) ;
940957 } ) ;
941958 ui. add_space ( 5.0 ) ;
942959 ui. horizontal ( |ui| {
943- ui. add ( toggle ( & mut self . show_timestamps ) )
944- . on_hover_text ( "Show timestamp in console." ) ;
960+ if ui
961+ . add ( toggle ( & mut self . show_timestamps ) )
962+ . on_hover_text ( "Show timestamp in console." )
963+ . changed ( )
964+ {
965+ if let Err ( err) = self
966+ . gui_cmd_tx
967+ . send ( GuiCommand :: ShowTimestamps ( self . show_sent_cmds ) )
968+ {
969+ log:: error!( "clear_tx thread send failed: {:?}" , err) ;
970+ }
971+ }
945972 ui. label ( "Show Timestamp" ) ;
946973 } ) ;
947974 ui. add_space ( 5.0 ) ;
0 commit comments