Implemented setting and getting pll settings
This commit is contained in:
parent
e059e712a8
commit
6a29ab91da
|
@ -89,6 +89,9 @@ impl eframe::App for CheapsdoControl {
|
|||
status_msg.pwm as f64
|
||||
]);
|
||||
},
|
||||
Ok(serial::Data::PLLSettings(settings)) => {
|
||||
self.pll_settings = settings;
|
||||
}
|
||||
Err(_) => break,
|
||||
};
|
||||
},
|
||||
|
@ -143,7 +146,10 @@ impl eframe::App for CheapsdoControl {
|
|||
if let Some(cmd_tx) = &self.cmd_tx {
|
||||
cmd_tx.send(serial::Cmd::Disconnect).unwrap();
|
||||
}
|
||||
|
||||
self.serial_connected = false;
|
||||
self.cmd_tx = None;
|
||||
self.data_rx = None;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -217,6 +223,36 @@ impl eframe::App for CheapsdoControl {
|
|||
ui.end_row();
|
||||
});
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
if ui
|
||||
.add_enabled(
|
||||
self.cmd_tx.is_some(),
|
||||
egui::Button::new("Apply").fill(egui::Color32::DARK_GREEN),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
if let Some(cmd_tx) = &self.cmd_tx {
|
||||
cmd_tx
|
||||
.send(serial::Cmd::SetPLLSetting(self.pll_settings.clone()))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
ui.add_space(40.0);
|
||||
if ui
|
||||
.add_enabled(
|
||||
self.cmd_tx.is_some(),
|
||||
egui::Button::new("Reset").fill(egui::Color32::DARK_RED),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
if let Some(cmd_tx) = &self.cmd_tx {
|
||||
cmd_tx.send(serial::Cmd::GetPLLSettings).unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,11 +10,14 @@ use cheapsdo_protocol::*;
|
|||
#[derive(PartialEq, Debug)]
|
||||
pub enum Cmd {
|
||||
Disconnect,
|
||||
GetPLLSettings,
|
||||
SetPLLSetting(PLLSettings),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Data {
|
||||
DeviceState(StatusMessage),
|
||||
PLLSettings(PLLSettings),
|
||||
}
|
||||
|
||||
pub fn poll_device(port: String, cmd_rx: Receiver<Cmd>, data_tx: Sender<Data>, ctx: egui::Context) {
|
||||
|
@ -23,9 +26,13 @@ pub fn poll_device(port: String, cmd_rx: Receiver<Cmd>, data_tx: Sender<Data>, c
|
|||
.open()
|
||||
.expect("Failed to open port");
|
||||
|
||||
let host_msg = HostMessage::RequestStatus;
|
||||
let msg_bytes = to_stdvec_cobs(&host_msg).unwrap();
|
||||
port.write_all(&msg_bytes).unwrap();
|
||||
let get_pll_settings = HostMessage::GetPllSettings;
|
||||
let get_pll_settings_bytes = to_stdvec_cobs(&get_pll_settings).unwrap();
|
||||
port.write_all(&get_pll_settings_bytes).unwrap();
|
||||
|
||||
let request_status = HostMessage::RequestStatus;
|
||||
let request_status_bytes = to_stdvec_cobs(&request_status).unwrap();
|
||||
port.write_all(&request_status_bytes).unwrap();
|
||||
|
||||
loop {
|
||||
let mut serial_buf: Vec<u8> = vec![0; 128];
|
||||
|
@ -41,7 +48,10 @@ pub fn poll_device(port: String, cmd_rx: Receiver<Cmd>, data_tx: Sender<Data>, c
|
|||
data_tx.send(Data::DeviceState(status_msg)).unwrap();
|
||||
ctx.request_repaint();
|
||||
}
|
||||
DeviceMessage::PLLSettings(_) => {}
|
||||
DeviceMessage::PLLSettings(settings) => {
|
||||
data_tx.send(Data::PLLSettings(settings)).unwrap();
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
|
||||
|
@ -51,12 +61,18 @@ pub fn poll_device(port: String, cmd_rx: Receiver<Cmd>, data_tx: Sender<Data>, c
|
|||
select! {
|
||||
recv(cmd_rx) -> cmd => match cmd {
|
||||
Ok(Cmd::Disconnect) => return,
|
||||
Ok(Cmd::GetPLLSettings) => {
|
||||
port.write_all(&get_pll_settings_bytes).unwrap();
|
||||
}
|
||||
Ok(Cmd::SetPLLSetting(settings)) => {
|
||||
let set_settings = HostMessage::SetPLLSettings(settings);
|
||||
let set_settings_bytes = to_stdvec_cobs(&set_settings).unwrap();
|
||||
port.write_all(&set_settings_bytes).unwrap();
|
||||
}
|
||||
Err(_) => {},
|
||||
},
|
||||
default(Duration::from_secs(1)) => {
|
||||
let host_msg = HostMessage::RequestStatus;
|
||||
let msg_bytes = to_stdvec_cobs(&host_msg).unwrap();
|
||||
port.write_all(&msg_bytes).unwrap();
|
||||
port.write_all(&request_status_bytes).unwrap();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue