Improve hand mode panels and recording
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::recording::Recorder;
|
||||
use crate::serial_core::codec::Codec;
|
||||
use crate::serial_core::codecs::hand_gateway::{HandGatewayCodec, HandGatewayFrame};
|
||||
use crate::serial_core::codecs::tactile_a::TactileACodec;
|
||||
@@ -6,7 +7,7 @@ use crossbeam_channel::{Receiver, Sender};
|
||||
use std::io::{Read, Write};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
const POLL_INTERVAL_MS: u64 = 10;
|
||||
const POLL_INTERVAL_MS: u64 = 5;
|
||||
const DEFAULT_HAND_GATEWAY_NODE_SAMPLE_COUNTS: &[u16] = &[84, 84, 84, 84, 84, 70, 44];
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -31,12 +32,15 @@ pub fn run_serial_loop(
|
||||
cancel_rx: &Receiver<()>,
|
||||
sample_tx: &Sender<Vec<i32>>,
|
||||
stats_tx: Option<&Sender<SerialIoStats>>,
|
||||
recorder: Option<&Recorder>,
|
||||
) {
|
||||
match protocol {
|
||||
SerialProtocol::TactileA => {
|
||||
run_tactile_a_loop(port, rows, cols, cancel_rx, sample_tx, stats_tx)
|
||||
run_tactile_a_loop(port, rows, cols, cancel_rx, sample_tx, stats_tx, recorder)
|
||||
}
|
||||
SerialProtocol::HandGateway => {
|
||||
run_hand_gateway_loop(port, cancel_rx, sample_tx, stats_tx, recorder)
|
||||
}
|
||||
SerialProtocol::HandGateway => run_hand_gateway_loop(port, cancel_rx, sample_tx, stats_tx),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +51,7 @@ fn run_tactile_a_loop(
|
||||
cancel_rx: &Receiver<()>,
|
||||
sample_tx: &Sender<Vec<i32>>,
|
||||
stats_tx: Option<&Sender<SerialIoStats>>,
|
||||
recorder: Option<&Recorder>,
|
||||
) {
|
||||
let session_started_at = Instant::now();
|
||||
let mut codec = TactileACodec::new(cols, rows);
|
||||
@@ -90,6 +95,11 @@ fn run_tactile_a_loop(
|
||||
for frame in frames {
|
||||
if let TactileAFrame::Rep(rep) = frame {
|
||||
if let Ok(vals) = TactileACodec::parse_data_frame(&rep.payload) {
|
||||
if let Some(recorder) = recorder {
|
||||
let pressures: Vec<u32> =
|
||||
vals.iter().map(|v| (*v).max(0) as u32).collect();
|
||||
recorder.add_frame(&pressures);
|
||||
}
|
||||
let _ = sample_tx.try_send(vals);
|
||||
}
|
||||
}
|
||||
@@ -116,6 +126,7 @@ fn run_hand_gateway_loop(
|
||||
cancel_rx: &Receiver<()>,
|
||||
sample_tx: &Sender<Vec<i32>>,
|
||||
stats_tx: Option<&Sender<SerialIoStats>>,
|
||||
recorder: Option<&Recorder>,
|
||||
) {
|
||||
let session_started_at = Instant::now();
|
||||
let mut codec = HandGatewayCodec::new(DEFAULT_HAND_GATEWAY_NODE_SAMPLE_COUNTS);
|
||||
@@ -174,6 +185,11 @@ fn run_hand_gateway_loop(
|
||||
|
||||
if parse_ok {
|
||||
// println!("[hand-packet-values] samples={}", vals.len());
|
||||
if let Some(recorder) = recorder {
|
||||
let pressures: Vec<u32> =
|
||||
vals.iter().map(|v| (*v).max(0) as u32).collect();
|
||||
recorder.add_frame(&pressures);
|
||||
}
|
||||
let _ = sample_tx.try_send(vals);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user