1
1
use core:: f32;
2
+ use crossbeam_channel:: { Receiver , Sender } ;
2
3
use std:: cmp:: max;
3
4
use std:: ops:: RangeInclusive ;
4
5
use std:: path:: PathBuf ;
5
- use std:: sync:: mpsc:: { Receiver , Sender } ;
6
6
use std:: sync:: { Arc , RwLock } ;
7
7
use std:: time:: Duration ;
8
8
@@ -64,6 +64,13 @@ pub enum WindowFeedback {
64
64
Cancel ,
65
65
}
66
66
67
+ #[ derive( Clone ) ]
68
+ pub enum GuiCommand {
69
+ Clear ,
70
+ ShowTimestamps ( bool ) ,
71
+ ShowSentTraffic ( bool ) ,
72
+ }
73
+
67
74
#[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
68
75
pub struct GuiSettingsContainer {
69
76
pub device : String ,
@@ -134,7 +141,7 @@ pub struct MyApp {
134
141
load_tx : Sender < PathBuf > ,
135
142
load_names_rx : Receiver < Vec < String > > ,
136
143
send_tx : Sender < String > ,
137
- clear_tx : Sender < bool > ,
144
+ gui_cmd_tx : Sender < GuiCommand > ,
138
145
history : Vec < String > ,
139
146
index : usize ,
140
147
eol : String ,
@@ -166,7 +173,7 @@ impl MyApp {
166
173
load_tx : Sender < PathBuf > ,
167
174
load_names_rx : Receiver < Vec < String > > ,
168
175
send_tx : Sender < String > ,
169
- clear_tx : Sender < bool > ,
176
+ gui_cmd_tx : Sender < GuiCommand > ,
170
177
) -> Self {
171
178
let mut file_dialog = FileDialog :: default ( )
172
179
//.initial_directory(PathBuf::from("/path/to/app"))
@@ -227,7 +234,7 @@ impl MyApp {
227
234
load_tx,
228
235
load_names_rx,
229
236
send_tx,
230
- clear_tx ,
237
+ gui_cmd_tx ,
231
238
plotting_range : usize:: MAX ,
232
239
plot_serial_display_ratio : 0.45 ,
233
240
command : "" . to_string ( ) ,
@@ -616,8 +623,8 @@ impl MyApp {
616
623
self . device_idx = self . serial_devices . devices . len ( ) - 1 ;
617
624
save_serial_settings ( & self . serial_devices ) ;
618
625
}
619
- self . clear_tx
620
- . send ( true )
626
+ self . gui_cmd_tx
627
+ . send ( GuiCommand :: Clear )
621
628
. expect ( "failed to send clear after choosing new device" ) ;
622
629
// need to clear the data here such that we don't get errors in the gui (plot)
623
630
self . data = GuiOutputDataContainer :: default ( ) ;
@@ -913,7 +920,7 @@ impl MyApp {
913
920
|| ui. input_mut ( |i| i. consume_shortcut ( & CLEAR_PLOT_SHORTCUT ) )
914
921
{
915
922
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 ) {
917
924
log:: error!( "clear_tx thread send failed: {:?}" , err) ;
918
925
}
919
926
// need to clear the data here in order to prevent errors in the gui (plot)
@@ -934,14 +941,34 @@ impl MyApp {
934
941
} ) ;
935
942
ui. add_space ( 5.0 ) ;
936
943
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
+ }
939
956
ui. label ( "Show Sent Commands" ) ;
940
957
} ) ;
941
958
ui. add_space ( 5.0 ) ;
942
959
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
+ }
945
972
ui. label ( "Show Timestamp" ) ;
946
973
} ) ;
947
974
ui. add_space ( 5.0 ) ;
0 commit comments