Integrate hand gateway and spatial force rendering
This commit is contained in:
@@ -4,7 +4,9 @@ use std::time::Duration;
|
||||
|
||||
use crossbeam_channel::{self, Receiver, Sender, TryRecvError};
|
||||
|
||||
use crate::serial_core::serial::{SerialIoStats, SerialPortReadWrite, run_serial_loop};
|
||||
use crate::serial_core::serial::{
|
||||
SerialIoStats, SerialPortReadWrite, SerialProtocol, run_serial_loop,
|
||||
};
|
||||
|
||||
/// Connection state visible to the UI.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -28,6 +30,8 @@ struct Session {
|
||||
handle: JoinHandle<()>,
|
||||
sample_rx: Receiver<Vec<i32>>,
|
||||
stats_rx: Receiver<SerialIoStats>,
|
||||
rows: u32,
|
||||
cols: u32,
|
||||
}
|
||||
|
||||
/// Thread-safe connection manager that the UI and renderer can share.
|
||||
@@ -72,7 +76,14 @@ impl ConnectionManager {
|
||||
}
|
||||
|
||||
/// Connect to the given serial port and start streaming in a background thread.
|
||||
pub fn connect(&self, port_name: &str, rows: u32, cols: u32) {
|
||||
pub fn connect(
|
||||
&self,
|
||||
port_name: &str,
|
||||
rows: u32,
|
||||
cols: u32,
|
||||
baud_rate: u32,
|
||||
protocol: SerialProtocol,
|
||||
) {
|
||||
self.disconnect();
|
||||
self.set_state(ConnectionState::Connecting);
|
||||
|
||||
@@ -90,6 +101,8 @@ impl ConnectionManager {
|
||||
&port,
|
||||
rows,
|
||||
cols,
|
||||
baud_rate,
|
||||
protocol,
|
||||
&state,
|
||||
&cancel_rx,
|
||||
&sample_tx,
|
||||
@@ -107,6 +120,8 @@ impl ConnectionManager {
|
||||
handle,
|
||||
sample_rx,
|
||||
stats_rx,
|
||||
rows,
|
||||
cols,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -135,10 +150,12 @@ impl ConnectionManager {
|
||||
loop {
|
||||
match session.sample_rx.try_recv() {
|
||||
Ok(vals) => {
|
||||
let rows = 12u32;
|
||||
let cols = 7u32;
|
||||
let matrix = vals.iter().map(|v| (*v).max(0) as u32).collect();
|
||||
last = Some(PressureSample { matrix, rows, cols });
|
||||
last = Some(PressureSample {
|
||||
matrix,
|
||||
rows: session.rows,
|
||||
cols: session.cols,
|
||||
});
|
||||
}
|
||||
Err(TryRecvError::Empty) => break,
|
||||
Err(TryRecvError::Disconnected) => break,
|
||||
@@ -163,13 +180,15 @@ fn run_device_loop(
|
||||
port_name: &str,
|
||||
rows: u32,
|
||||
cols: u32,
|
||||
baud_rate: u32,
|
||||
protocol: SerialProtocol,
|
||||
state: &Arc<Mutex<ConnectionState>>,
|
||||
cancel_rx: &Receiver<()>,
|
||||
sample_tx: &Sender<Vec<i32>>,
|
||||
stats_tx: &Sender<SerialIoStats>,
|
||||
latest_sample: &Arc<Mutex<Option<PressureSample>>>,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let port = serialport::new(port_name, 921_600)
|
||||
let port = serialport::new(port_name, baud_rate)
|
||||
.timeout(Duration::from_millis(100))
|
||||
.open()?;
|
||||
|
||||
@@ -182,6 +201,7 @@ fn run_device_loop(
|
||||
&mut rw,
|
||||
rows as usize,
|
||||
cols as usize,
|
||||
protocol,
|
||||
cancel_rx,
|
||||
sample_tx,
|
||||
Some(stats_tx),
|
||||
|
||||
Reference in New Issue
Block a user