mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Added log and automatic reconnect.
This commit is contained in:
@@ -26,36 +26,17 @@ impl<E> From<HostErr<WireError>> for WorkbookError<E> {
|
||||
}
|
||||
}
|
||||
|
||||
trait FlattenErr {
|
||||
type Good;
|
||||
type Bad;
|
||||
fn flatten(self) -> Result<Self::Good, WorkbookError<Self::Bad>>;
|
||||
}
|
||||
|
||||
impl<T, E> FlattenErr for Result<T, E> {
|
||||
type Good = T;
|
||||
type Bad = E;
|
||||
fn flatten(self) -> Result<Self::Good, WorkbookError<Self::Bad>> {
|
||||
self.map_err(WorkbookError::Endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
impl WorkbookClient {
|
||||
pub fn new() -> Self {
|
||||
let client = HostClient::new_raw_nusb(
|
||||
pub fn new() -> Result<Self, String> {
|
||||
let client = HostClient::try_new_raw_nusb(
|
||||
|d| d.product_string() == Some("Bioz Amplifier"),
|
||||
ERROR_PATH,
|
||||
8,
|
||||
VarSeqKind::Seq2,
|
||||
);
|
||||
Self { client }
|
||||
}
|
||||
|
||||
pub fn new_serial(port: &str) -> Self {
|
||||
let client = HostClient::new_serial_cobs(port, ERROR_PATH, 8, 9600, VarSeqKind::Seq2);
|
||||
Self { client }
|
||||
)?;
|
||||
Ok(Self { client })
|
||||
}
|
||||
|
||||
pub async fn wait_closed(&self) {
|
||||
@@ -87,7 +68,6 @@ impl WorkbookClient {
|
||||
self.client
|
||||
.send_resp::<StartImpedanceEndpoint>(&StartImpedance { update_frequency: 60, sinus_frequency: frequency })
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -96,13 +76,6 @@ impl WorkbookClient {
|
||||
.client
|
||||
.send_resp::<StopImpedanceEndpoint>(&())
|
||||
.await?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WorkbookClient {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user