-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
56 lines (44 loc) · 1.57 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
mod communication;
mod data;
mod gui;
mod signal_process;
use anyhow::{Context, Result};
use communication::usb_comm::{connection, receive_data};
use gui::gui_config::GuiConfig;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use tokio::{self, sync::mpsc, task};
/// Handles USB communication and data streaming
async fn usb_task(tx: mpsc::Sender<f32>) -> Result<()> {
let mut usb_device_interface = connection().context("Failed to establish USB connection")?;
// Start data receiving task
let tx_clone = tx.clone();
let _handle = tokio::spawn(async move {
receive_data(&mut usb_device_interface, tx_clone.clone()).await;
});
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create channel for data communication
let (tx, rx) = mpsc::channel(100); // Buffer size of 100
// Create shutdown signal
let shutdown = Arc::new(AtomicBool::new(false));
let _shutdown_clone = shutdown.clone();
// Spawn USB connection task
let _usb_handle = task::spawn(usb_task(tx));
// let _debug_comm_handle = task::spawn(debug_data(tx.clone()));
// Configure application window
let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size(GuiConfig::default().get_window_size()),
..Default::default()
};
// Run the GUI application
eframe::run_native(
"Biosensor Virtualization Panel",
native_options,
Box::new(|_cc| Ok(Box::new(gui::ui::VirtualizationApp::new(rx)))),
)?;
Ok(())
}