Skip to content

Commit ace45d6

Browse files
committed
feat(gui): pull encoder angle to gui
1 parent 34439bd commit ace45d6

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

gui/gui/src/connection.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ impl Device {
5656
pub fn sin_cos(&mut self, value: f32) -> Result<(f32, f32), anyhow::Error> {
5757
self.rpc_channel.call::<icd::SinCosEndpoint>(value)
5858
}
59+
60+
pub fn encoder_angle(&mut self) -> Result<u16, anyhow::Error> {
61+
self.rpc_channel.call::<icd::EncoderAngle>(())
62+
}
5963
}
6064

6165
struct RpcChannel {

gui/gui/src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)