рефакторинг библиотеки.

This commit is contained in:
Кобелев Андрей Андреевич
2026-08-15 23:53:45 +05:00
parent 896670b62f
commit efc53e6ef5
13 changed files with 584 additions and 371 deletions
+12 -23
View File
@@ -1,7 +1,9 @@
//! Имитирует компактный дашборд и обновляет только изменяемые поля через `print_at`.
mod common;
use anyhow::Result;
use std::time::Duration;
use m::vfd::VfdConfig;
use m::worker::VfdWorker;
fn pad_left(s: &str, width: usize) -> String {
@@ -18,26 +20,13 @@ fn main() -> Result<()> {
// 1) port (default: /dev/cu.usbmodem101)
// 2) width (default: 20)
// 3) delay_ms (default: 200)
let port_name = std::env::args()
.nth(1)
.unwrap_or("/dev/cu.usbmodem101".into());
let width: usize = std::env::args()
.nth(2)
.as_deref()
.unwrap_or("20")
.parse()
.unwrap_or(20);
let delay_ms: u64 = std::env::args()
.nth(3)
.as_deref()
.unwrap_or("200")
.parse()
.unwrap_or(200);
let cfg = VfdConfig::new(port_name).with_width(width);
let worker = VfdWorker::start(cfg)?;
let mut args = common::ExampleArgs::from_env();
let delay_ms: u64 = args.parse_or(200);
let width = args.width;
if width < 20 {
anyhow::bail!("update_at requires a display width of at least 20 columns");
}
let worker = VfdWorker::start(args.config)?;
let vfd = worker.handle();
vfd.clear();
@@ -103,6 +92,6 @@ fn main() -> Result<()> {
si = (si + 1) % spinner.len();
}
std::thread::sleep(Duration::from_millis(delay_ms));
common::sleep_ms(delay_ms);
}
}