feat: FTP in state with set_ftp/get_ftp (phase 3)

pull/4/head
lambda 6 days ago
parent 46e6510f05
commit 981747fc50
No known key found for this signature in database
GPG Key ID: CF45A8EE158BBCB6

@ -229,6 +229,22 @@ fn get_workout(path: String) -> Result<workout::Workout, String> {
workout::read_workout(&path).map_err(|e| e.to_string()) 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::<State>().ftp.lock().unwrap() = ftp;
Ok(())
}
/// Текущий FTP гонщика (Вт).
#[tauri::command]
fn get_ftp(app: AppHandle) -> u16 {
*app.state::<State>().ftp.lock().unwrap()
}
/// Why the watchdog loop stopped consuming a stream. /// Why the watchdog loop stopped consuming a stream.
enum StreamOutcome { enum StreamOutcome {
/// The stream ended (peripheral disconnected / notifications closed). /// The stream ended (peripheral disconnected / notifications closed).
@ -386,6 +402,7 @@ pub fn run() {
trainer: Mutex::new(None), trainer: Mutex::new(None),
streams: Mutex::new(std::collections::HashMap::new()), streams: Mutex::new(std::collections::HashMap::new()),
trainer_state: Mutex::new(TrainerState::default()), trainer_state: Mutex::new(TrainerState::default()),
ftp: Mutex::new(state::DEFAULT_FTP),
}); });
Ok::<(), Box<dyn std::error::Error>>(()) Ok::<(), Box<dyn std::error::Error>>(())
}) })
@ -398,7 +415,9 @@ pub fn run() {
trainer_start, trainer_start,
trainer_stop, trainer_stop,
list_workouts, list_workouts,
get_workout get_workout,
set_ftp,
get_ftp
]) ])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");

@ -6,6 +6,9 @@ use tauri::async_runtime::JoinHandle;
use crate::ble::SensorSource; use crate::ble::SensorSource;
use crate::device::Device; use crate::device::Device;
/// FTP по умолчанию (Вт) — для перевода %FTP воркаутов в ватты.
pub const DEFAULT_FTP: u16 = 250;
/// Trainer control state, restored after a reconnect. /// Trainer control state, restored after a reconnect.
#[derive(Default)] #[derive(Default)]
pub struct TrainerState { pub struct TrainerState {
@ -24,4 +27,6 @@ pub struct State {
pub streams: Mutex<HashMap<String, JoinHandle<()>>>, pub streams: Mutex<HashMap<String, JoinHandle<()>>>,
/// Trainer control state, restored after a reconnect. /// Trainer control state, restored after a reconnect.
pub trainer_state: Mutex<TrainerState>, pub trainer_state: Mutex<TrainerState>,
/// FTP гонщика (Вт), для перевода %FTP воркаутов в ватты.
pub ftp: Mutex<u16>,
} }

Loading…
Cancel
Save