@@ -8,7 +8,7 @@ use std::time::Duration;
8
8
9
9
use crate :: color_picker:: { color_picker_widget, color_picker_window, COLORS } ;
10
10
use crate :: custom_highlighter:: highlight_impl;
11
- use crate :: data:: { DataContainer , SerialDirection } ;
11
+ use crate :: data:: GuiOutputDataContainer ;
12
12
use crate :: serial:: { clear_serial_settings, save_serial_settings, Device , SerialDevices } ;
13
13
use crate :: settings_window:: settings_window;
14
14
use crate :: toggle:: toggle;
@@ -24,7 +24,7 @@ use eframe::{egui, Storage};
24
24
use egui:: ThemePreference ;
25
25
use egui_file_dialog:: information_panel:: InformationPanel ;
26
26
use egui_file_dialog:: FileDialog ;
27
- use egui_plot:: { log_grid_spacer, GridMark , Legend , Line , Plot , PlotPoint , PlotPoints } ;
27
+ use egui_plot:: { log_grid_spacer, GridMark , Legend , Line , Plot , PlotPoints } ;
28
28
use preferences:: Preferences ;
29
29
#[ cfg( feature = "self_update" ) ]
30
30
use self_update:: update:: Release ;
@@ -118,7 +118,7 @@ pub struct MyApp {
118
118
plot_serial_display_ratio : f32 ,
119
119
picked_path : PathBuf ,
120
120
plot_location : Option < egui:: Rect > ,
121
- data : DataContainer ,
121
+ data : GuiOutputDataContainer ,
122
122
file_dialog_state : FileDialogState ,
123
123
file_dialog : FileDialog ,
124
124
information_panel : InformationPanel ,
@@ -129,7 +129,7 @@ pub struct MyApp {
129
129
device_lock : Arc < RwLock < Device > > ,
130
130
devices_lock : Arc < RwLock < Vec < String > > > ,
131
131
connected_lock : Arc < RwLock < bool > > ,
132
- data_lock : Arc < RwLock < DataContainer > > ,
132
+ data_lock : Arc < RwLock < GuiOutputDataContainer > > ,
133
133
save_tx : Sender < FileOptions > ,
134
134
load_tx : Sender < PathBuf > ,
135
135
load_names_rx : Receiver < Vec < String > > ,
@@ -156,7 +156,7 @@ pub struct MyApp {
156
156
impl MyApp {
157
157
pub fn new (
158
158
cc : & eframe:: CreationContext ,
159
- data_lock : Arc < RwLock < DataContainer > > ,
159
+ data_lock : Arc < RwLock < GuiOutputDataContainer > > ,
160
160
device_lock : Arc < RwLock < Device > > ,
161
161
devices_lock : Arc < RwLock < Vec < String > > > ,
162
162
devices : SerialDevices ,
@@ -203,7 +203,7 @@ impl MyApp {
203
203
picked_path : PathBuf :: new ( ) ,
204
204
device : "" . to_string ( ) ,
205
205
old_device : "" . to_string ( ) ,
206
- data : DataContainer :: default ( ) ,
206
+ data : GuiOutputDataContainer :: default ( ) ,
207
207
file_dialog_state : FileDialogState :: None ,
208
208
file_dialog,
209
209
information_panel : InformationPanel :: default ( ) . add_file_preview ( "csv" , |ui, item| {
@@ -283,25 +283,6 @@ impl MyApp {
283
283
window_feedback
284
284
}
285
285
286
- fn console_text ( & self , packet : & crate :: data:: Packet ) -> Option < String > {
287
- match ( self . show_sent_cmds , self . show_timestamps , & packet. direction ) {
288
- ( true , true , _) => Some ( format ! (
289
- "[{}] t + {:.3}s: {}\n " ,
290
- packet. direction,
291
- packet. relative_time as f32 / 1000.0 ,
292
- packet. payload
293
- ) ) ,
294
- ( true , false , _) => Some ( format ! ( "[{}]: {}\n " , packet. direction, packet. payload) ) ,
295
- ( false , true , SerialDirection :: Receive ) => Some ( format ! (
296
- "t + {:.3}s: {}\n " ,
297
- packet. relative_time as f32 / 1000.0 ,
298
- packet. payload
299
- ) ) ,
300
- ( false , false , SerialDirection :: Receive ) => Some ( packet. payload . clone ( ) + "\n " ) ,
301
- ( _, _, _) => None ,
302
- }
303
- }
304
-
305
286
fn draw_central_panel ( & mut self , ctx : & egui:: Context ) {
306
287
egui:: CentralPanel :: default ( ) . show ( ctx, |ui| {
307
288
let left_border = 10.0 ;
@@ -327,11 +308,17 @@ impl MyApp {
327
308
ui. horizontal ( |ui| {
328
309
ui. add_space ( left_border) ;
329
310
ui. vertical ( |ui| {
330
- if let Ok ( read_guard) = self . data_lock . read ( ) {
331
- self . data = read_guard. clone ( ) ;
311
+ if let Ok ( gui_data) = self . data_lock . read ( ) {
312
+ self . data = gui_data. clone ( ) ;
313
+ self . labels = gui_data. plots . iter ( ) . map ( |d| d. 0 . clone ( ) ) . collect ( ) ;
314
+ self . colors = ( 0 ..max ( self . labels . len ( ) , 1 ) )
315
+ . map ( |i| COLORS [ i % COLORS . len ( ) ] )
316
+ . collect ( ) ;
317
+ self . color_vals = ( 0 ..max ( self . data . plots . len ( ) , 1 ) ) . map ( |_| 0.0 ) . collect ( ) ;
332
318
}
333
319
334
- if self . data . loaded_from_file && self . file_opened {
320
+ // TODO what about self.data.loaded_from_file
321
+ if self . file_opened {
335
322
if let Ok ( labels) = self . load_names_rx . try_recv ( ) {
336
323
self . labels = labels;
337
324
self . colors = ( 0 ..max ( self . labels . len ( ) , 1 ) )
@@ -341,32 +328,40 @@ impl MyApp {
341
328
}
342
329
}
343
330
if self . serial_devices . number_of_plots [ self . device_idx ] > 0 {
344
- if self . data . dataset . len ( ) != self . labels . len ( ) && !self . file_opened {
345
- self . labels = ( 0 ..max ( self . data . dataset . len ( ) , 1 ) )
346
- . map ( |i| format ! ( "Column {i}" ) )
347
- . collect ( ) ;
348
- self . colors = ( 0 ..max ( self . data . dataset . len ( ) , 1 ) )
331
+ if self . data . plots . len ( ) != self . labels . len ( ) && !self . file_opened {
332
+ // self.labels = (0..max(self.data.dataset.len(), 1))
333
+ // .map(|i| format!("Column {i}"))
334
+ // .collect();
335
+ self . colors = ( 0 ..max ( self . data . plots . len ( ) , 1 ) )
349
336
. map ( |i| COLORS [ i % COLORS . len ( ) ] )
350
337
. collect ( ) ;
351
338
self . color_vals =
352
- ( 0 ..max ( self . data . dataset . len ( ) , 1 ) ) . map ( |_| 0.0 ) . collect ( ) ;
339
+ ( 0 ..max ( self . data . plots . len ( ) , 1 ) ) . map ( |_| 0.0 ) . collect ( ) ;
353
340
}
354
341
355
- let mut graphs: Vec < Vec < PlotPoint > > = vec ! [ vec![ ] ; self . data. dataset. len( ) ] ;
356
- let window = self . data . dataset [ 0 ]
357
- . len ( )
358
- . saturating_sub ( self . plotting_range ) ;
359
-
360
- for ( i, time) in self . data . time [ window..] . iter ( ) . enumerate ( ) {
361
- let x = * time / 1000.0 ;
362
- for ( graph, data) in graphs. iter_mut ( ) . zip ( & self . data . dataset ) {
363
- if self . data . time . len ( ) == data. len ( ) {
364
- if let Some ( y) = data. get ( i + window) {
365
- graph. push ( PlotPoint { x, y : * y as f64 } ) ;
366
- }
367
- }
368
- }
369
- }
342
+ // offloaded to main thread
343
+
344
+ // let mut graphs: Vec<Vec<PlotPoint>> = vec![vec![]; self.data.dataset.len()];
345
+ // let window = self.data.dataset[0]
346
+ // .len()
347
+ // .saturating_sub(self.plotting_range);
348
+ //
349
+ // for (i, time) in self.data.time[window..].iter().enumerate() {
350
+ // let x = *time / 1000.0;
351
+ // for (graph, data) in graphs.iter_mut().zip(&self.data.dataset) {
352
+ // if self.data.time.len() == data.len() {
353
+ // if let Some(y) = data.get(i + window) {
354
+ // graph.push(PlotPoint { x, y: *y as f64 });
355
+ // }
356
+ // }
357
+ // }
358
+ // }
359
+
360
+ let window = if let Some ( first_entry) = self . data . plots . first ( ) {
361
+ first_entry. 1 . len ( ) . saturating_sub ( self . plotting_range )
362
+ } else {
363
+ 0
364
+ } ;
370
365
371
366
let t_fmt = |x : GridMark , _range : & RangeInclusive < f64 > | {
372
367
format ! ( "{:4.2} s" , x. value)
@@ -388,13 +383,15 @@ impl MyApp {
388
383
. x_axis_formatter ( t_fmt) ;
389
384
390
385
let plot_inner = signal_plot. show ( ui, |signal_plot_ui| {
391
- for ( i, graph) in graphs . iter ( ) . enumerate ( ) {
386
+ for ( i, ( _label , graph) ) in self . data . plots . iter ( ) . enumerate ( ) {
392
387
// this check needs to be here for when we change devices (not very elegant)
393
388
if i < self . labels . len ( ) {
394
389
signal_plot_ui. line (
395
- Line :: new ( PlotPoints :: Owned ( graph. to_vec ( ) ) )
396
- . name ( & self . labels [ i] )
397
- . color ( self . colors [ i] ) ,
390
+ Line :: new ( PlotPoints :: Owned (
391
+ graph[ window..] . to_vec ( ) ,
392
+ ) )
393
+ . name ( & self . labels [ i] )
394
+ . color ( self . colors [ i] ) ,
398
395
) ;
399
396
}
400
397
}
@@ -430,7 +427,7 @@ impl MyApp {
430
427
let serial_height =
431
428
panel_height - plot_ui_heigh - left_border * 2.0 - top_spacing;
432
429
433
- let num_rows = self . data . raw_traffic . len ( ) ;
430
+ let num_rows = self . data . prints . len ( ) ;
434
431
let row_height = ui. text_style_height ( & egui:: TextStyle :: Body ) ;
435
432
436
433
let color = if self . gui_conf . dark_mode {
@@ -453,10 +450,10 @@ impl MyApp {
453
450
let content: String = row_range
454
451
. into_iter ( )
455
452
. flat_map ( |i| {
456
- if self . data . raw_traffic . is_empty ( ) {
453
+ if self . data . prints . is_empty ( ) {
457
454
None
458
455
} else {
459
- self . console_text ( & self . data . raw_traffic [ i] )
456
+ Some ( self . data . prints [ i] . clone ( ) )
460
457
}
461
458
} )
462
459
. collect ( ) ;
@@ -578,7 +575,7 @@ impl MyApp {
578
575
// let selected_new_device = response.changed(); //somehow this does not work
579
576
// if selected_new_device {
580
577
if old_name != self . device {
581
- if !self . data . time . is_empty ( ) {
578
+ if !self . data . prints . is_empty ( ) {
582
579
self . show_warning_window = WindowFeedback :: Waiting ;
583
580
self . old_device = old_name;
584
581
} else {
@@ -623,7 +620,7 @@ impl MyApp {
623
620
. send ( true )
624
621
. expect ( "failed to send clear after choosing new device" ) ;
625
622
// need to clear the data here such that we don't get errors in the gui (plot)
626
- self . data = DataContainer :: default ( ) ;
623
+ self . data = GuiOutputDataContainer :: default ( ) ;
627
624
self . show_warning_window = WindowFeedback :: None ;
628
625
}
629
626
WindowFeedback :: Cancel => {
@@ -920,7 +917,7 @@ impl MyApp {
920
917
log:: error!( "clear_tx thread send failed: {:?}" , err) ;
921
918
}
922
919
// need to clear the data here in order to prevent errors in the gui (plot)
923
- self . data = DataContainer :: default ( ) ;
920
+ self . data = GuiOutputDataContainer :: default ( ) ;
924
921
// self.names_tx.send(self.serial_devices.labels[self.device_idx].clone()).expect("Failed to send names");
925
922
}
926
923
ui. add_space ( 5.0 ) ;
0 commit comments