diff --git a/rust/serial_reader/Cargo.toml b/rust/serial_reader/Cargo.toml index 478b70a..619d1ca 100644 --- a/rust/serial_reader/Cargo.toml +++ b/rust/serial_reader/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" [dependencies] serialport = "*" gtk = { version = "*", features = ["v3_24"] } -anyhow = { version = "1.0", features = ["backtrace"] } +anyhow = { version = "1.0.65", features = ["backtrace"] } glib = "*" diff --git a/rust/serial_reader/src/main.rs b/rust/serial_reader/src/main.rs index 729e16c..0e2de99 100644 --- a/rust/serial_reader/src/main.rs +++ b/rust/serial_reader/src/main.rs @@ -1,10 +1,10 @@ use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::SeqCst; -use gtk::{prelude::*, TextView}; +use gtk::{prelude::*, PolicyType, TextView}; use gtk::{Application, ApplicationWindow}; -use gtk::{Button, Entry, Orientation}; +use gtk::{Button, Entry, Orientation, ScrolledWindow}; use glib; @@ -34,12 +34,16 @@ fn main() { let vid = Entry::builder().text("0x16c0").editable(true).build(); let connect_button = Button::with_label("Connect"); let serial_info = TextView::new(); + let scrolled_window = ScrolledWindow::builder() + .vscrollbar_policy(PolicyType::Automatic) + .child(&serial_info) + .build(); top_bar_box.pack_end(&connect_button, true, true, 3); top_bar_box.pack_end(&vid, true, true, 3); top_bar_box.pack_end(&pid, true, true, 3); - master_box.pack_end(&serial_info, true, true, 3); + master_box.pack_end(&scrolled_window, true, true, 3); master_box.pack_end(&top_bar_box, false, true, 3); let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); @@ -90,6 +94,7 @@ fn main() { if let Ok(port) = Port::open(usb_id, serialport_settings) { CONNECTED.store(true, SeqCst); + unsafe { PORT = Some(port); } @@ -102,6 +107,7 @@ fn main() { rx.attach(None, move |message| { if !message.is_empty() { buffer.insert(&mut buffer.end_iter(), &format!("{}\n", message)); + serial_info.scroll_to_iter(&mut buffer.end_iter(), 0.0, true, 0.0, 0.0); } glib::Continue(true)