From 981747fc50c427b6f3437198895e5253b28058a1 Mon Sep 17 00:00:00 2001 From: lambda Date: Tue, 27 Oct 2026 13:55:03 +0300 Subject: [PATCH] feat: FTP in state with set_ftp/get_ftp (phase 3) --- src-tauri/src/lib.rs | 21 ++++++++++++++++++++- src-tauri/src/state.rs | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8b5b47c..51f67e7 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -229,6 +229,22 @@ fn get_workout(path: String) -> Result { workout::read_workout(&path).map_err(|e| e.to_string()) } +/// Задать FTP гонщика (Вт). Используется для перевода %FTP → ватты. +#[tauri::command] +fn set_ftp(app: AppHandle, ftp: u16) -> Result<(), String> { + if ftp == 0 { + return Err("FTP должен быть больше нуля".to_string()); + } + *app.state::().ftp.lock().unwrap() = ftp; + Ok(()) +} + +/// Текущий FTP гонщика (Вт). +#[tauri::command] +fn get_ftp(app: AppHandle) -> u16 { + *app.state::().ftp.lock().unwrap() +} + /// Why the watchdog loop stopped consuming a stream. enum StreamOutcome { /// The stream ended (peripheral disconnected / notifications closed). @@ -386,6 +402,7 @@ pub fn run() { trainer: Mutex::new(None), streams: Mutex::new(std::collections::HashMap::new()), trainer_state: Mutex::new(TrainerState::default()), + ftp: Mutex::new(state::DEFAULT_FTP), }); Ok::<(), Box>(()) }) @@ -398,7 +415,9 @@ pub fn run() { trainer_start, trainer_stop, list_workouts, - get_workout + get_workout, + set_ftp, + get_ftp ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index 7871228..02f098c 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -6,6 +6,9 @@ use tauri::async_runtime::JoinHandle; use crate::ble::SensorSource; use crate::device::Device; +/// FTP по умолчанию (Вт) — для перевода %FTP воркаутов в ватты. +pub const DEFAULT_FTP: u16 = 250; + /// Trainer control state, restored after a reconnect. #[derive(Default)] pub struct TrainerState { @@ -24,4 +27,6 @@ pub struct State { pub streams: Mutex>>, /// Trainer control state, restored after a reconnect. pub trainer_state: Mutex, + /// FTP гонщика (Вт), для перевода %FTP воркаутов в ватты. + pub ftp: Mutex, }