Skip to content

Commit b7b1050

Browse files
feat: add listing of boards
Signed-off-by: NicoletaBumbacea <aleniko.bum@yahoo.com>
1 parent d55dea8 commit b7b1050

6 files changed

Lines changed: 438 additions & 115 deletions

File tree

.github/workflows/rust.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ jobs:
2121
- uses: actions/checkout@v3
2222
- name: Install libudev
2323
run: sudo apt-get install -y libudev-dev
24+
- name: Tauri dependencies
25+
run: |
26+
sudo apt update && sudo apt install -y \
27+
libwebkit2gtk-4.1-dev \
28+
build-essential \
29+
curl \
30+
wget \
31+
file \
32+
libxdo-dev \
33+
libssl-dev \
34+
libayatana-appindicator3-dev \
35+
librsvg2-dev \
36+
webkit2gtk-driver \
37+
xvfb
2438
- name: Build
2539
run: cargo build --verbose
2640
- name: Run tests
@@ -49,5 +63,19 @@ jobs:
4963
components: clippy
5064
- name: Install libudev
5165
run: sudo apt-get install -y libudev-dev
66+
- name: Tauri dependencies
67+
run: |
68+
sudo apt update && sudo apt install -y \
69+
libwebkit2gtk-4.1-dev \
70+
build-essential \
71+
curl \
72+
wget \
73+
file \
74+
libxdo-dev \
75+
libssl-dev \
76+
libayatana-appindicator3-dev \
77+
librsvg2-dev \
78+
webkit2gtk-driver \
79+
xvfb
5280
- name: ci-job-clippy
5381
run: make ci-job-clippy

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[workspace]
66

7-
resolver= "2"
7+
resolver= "3"
88

99
members = [
1010
"tockloader-cli",

tock-ui/src-tauri/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ tauri = { version = "2", features = [] }
2222
tauri-plugin-opener = "2"
2323
serde = { version = "1", features = ["derive"] }
2424
serde_json = "1"
25-
25+
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
26+
tockloader-lib = { path = "../../tockloader-lib" }
27+
tokio-serial = {version = "5.4.4", features = ["libudev"] }
28+
probe-rs = { version = "0.24.0" }

tock-ui/src-tauri/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
22
#[tauri::command]
33
fn greet(name: &str) -> String {
4-
format!("Hello, {}! You've been greeted from Rust!", name)
4+
format!("Hello, {name}! You've been greeted from Rust!")
55
}
66

77
#[cfg_attr(mobile, tauri::mobile_entry_point)]

tock-ui/src-tauri/src/main.rs

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,98 @@
1-
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
21
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
32

3+
use probe_rs::probe::list::Lister;
4+
use serde::{Deserialize, Serialize};
5+
use tokio_serial::available_ports;
6+
use tokio_serial::SerialPortType;
7+
#[derive(Debug, Serialize, Deserialize)]
8+
pub struct DebugProbeSummary {
9+
pub identifier: String,
10+
pub vendor_id: u16,
11+
pub product_id: u16,
12+
pub serial_number: Option<String>,
13+
}
14+
15+
#[derive(Debug, Serialize, Deserialize)]
16+
pub struct SerialPortSummary {
17+
pub port_name: String,
18+
pub usb_vid: Option<u16>,
19+
pub usb_pid: Option<u16>,
20+
pub manufacturer: Option<String>,
21+
pub product: Option<String>,
22+
pub serial_number: Option<String>,
23+
}
24+
25+
#[derive(Debug, Serialize, Deserialize)]
26+
pub struct ConnectedDevices {
27+
pub debug_probes: Vec<DebugProbeSummary>,
28+
29+
pub serial_ports: Vec<SerialPortSummary>,
30+
}
31+
32+
#[tauri::command]
33+
async fn list_all_devices() -> Result<ConnectedDevices, String> {
34+
// 1. List Debug Probes
35+
let probes = Lister::new().list_all();
36+
let debug_probe_summaries: Vec<DebugProbeSummary> = probes
37+
.into_iter()
38+
.map(|p| DebugProbeSummary {
39+
identifier: p.identifier,
40+
vendor_id: p.vendor_id,
41+
product_id: p.product_id,
42+
serial_number: p.serial_number,
43+
})
44+
.collect();
45+
46+
// 2. List Serial Ports
47+
let serial_ports = match available_ports() {
48+
Ok(ports) => ports,
49+
Err(e) => {
50+
eprintln!("Error listing serial ports: {e:?}");
51+
return Err(format!("Failed to list serial ports: {e}"));
52+
}
53+
};
54+
55+
let serial_port_summaries: Vec<SerialPortSummary> = serial_ports
56+
.into_iter()
57+
.map(|p| {
58+
let mut usb_vid = None;
59+
let mut usb_pid = None;
60+
let mut manufacturer = None;
61+
let mut product = None;
62+
let mut serial_number = None;
63+
64+
// Extract USB-specific fields if the port is a USB port
65+
if let SerialPortType::UsbPort(usb_info) = p.port_type {
66+
usb_vid = Some(usb_info.vid);
67+
usb_pid = Some(usb_info.pid);
68+
manufacturer = usb_info.manufacturer;
69+
product = usb_info.product;
70+
serial_number = usb_info.serial_number;
71+
}
72+
73+
SerialPortSummary {
74+
port_name: p.port_name,
75+
usb_vid,
76+
usb_pid,
77+
manufacturer,
78+
product,
79+
serial_number,
80+
}
81+
})
82+
.collect();
83+
84+
// Combine results into the ConnectedDevices struct
85+
Ok(ConnectedDevices {
86+
debug_probes: debug_probe_summaries,
87+
serial_ports: serial_port_summaries,
88+
})
89+
}
90+
91+
// The main function for your Tauri application
492
fn main() {
5-
tock_ui_lib::run()
93+
tauri::Builder::default()
94+
// Register the new command so it can be called from the frontend
95+
.invoke_handler(tauri::generate_handler![list_all_devices])
96+
.run(tauri::generate_context!())
97+
.expect("error while running tauri application");
698
}

0 commit comments

Comments
 (0)