@@ -22,6 +22,7 @@ struct Behaviour {
2222 motor_state : MotorState ,
2323 probes : Vec < DebugProbeInfo > ,
2424 last_probe_check_time : Option < Instant > ,
25+ last_poll_time : Option < Instant > ,
2526 device : Option < Device > ,
2627 status_label : Option < String > ,
2728 value_to_write : u32 ,
@@ -35,9 +36,26 @@ impl Behaviour {
3536 . last_probe_check_time
3637 . is_none_or ( |last| last. elapsed ( ) >= Duration :: from_secs ( 1 ) )
3738 {
39+ self . last_probe_check_time = Some ( Instant :: now ( ) ) ;
40+
3841 self . probes = connection:: list_all ( ) ;
3942 }
4043 }
44+
45+ fn pull_values_from_device ( & mut self ) {
46+ if self
47+ . last_poll_time
48+ . is_none_or ( |last| last. elapsed ( ) >= Duration :: from_millis ( 10 ) )
49+ {
50+ self . last_poll_time = Some ( Instant :: now ( ) ) ;
51+ let Some ( device) = self . device . as_mut ( ) else {
52+ return ;
53+ } ;
54+
55+ self . motor_state . electrical_angle_rad =
56+ device. encoder_angle ( ) . unwrap ( ) as f32 / 2f32 . powi ( 14 ) ;
57+ }
58+ }
4159}
4260
4361#[ derive( Debug , PartialEq , Eq ) ]
@@ -335,6 +353,7 @@ fn main() -> Result<(), eframe::Error> {
335353 } ,
336354 probes : Vec :: new ( ) ,
337355 last_probe_check_time : None ,
356+ last_poll_time : None ,
338357 device : None ,
339358 status_label : None ,
340359 value_to_write : 0 ,
@@ -349,6 +368,7 @@ fn main() -> Result<(), eframe::Error> {
349368 ctx. options_mut ( |options| options. theme_preference = egui:: ThemePreference :: Dark ) ;
350369
351370 behavior. update_probe_list ( ) ;
371+ behavior. pull_values_from_device ( ) ;
352372 behavior. motor_state . update ( ) ;
353373
354374 egui:: CentralPanel :: default ( ) . show ( ctx, |ui| {
0 commit comments