gui conf persistence
This commit is contained in:
parent
b567bf7528
commit
2fb5a5709f
3 changed files with 85 additions and 13 deletions
46
interface/Cargo.lock
generated
46
interface/Cargo.lock
generated
|
@ -23,6 +23,10 @@ name = "accesskit"
|
|||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3d3b8f9bae46a948369bc4a03e815d4ed6d616bd00de4051133a5019dc31c5a"
|
||||
dependencies = [
|
||||
"enumn",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "accesskit_atspi_common"
|
||||
|
@ -134,6 +138,7 @@ dependencies = [
|
|||
"cfg-if",
|
||||
"getrandom 0.2.15",
|
||||
"once_cell",
|
||||
"serde",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
]
|
||||
|
@ -512,6 +517,12 @@ dependencies = [
|
|||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.70.1"
|
||||
|
@ -556,6 +567,9 @@ name = "bitflags"
|
|||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block"
|
||||
|
@ -1006,6 +1020,7 @@ checksum = "7d72e9c39f6e11a2e922d04a34ec5e7ef522ea3f5a1acfca7a19d16ad5fe50f5"
|
|||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1024,6 +1039,7 @@ dependencies = [
|
|||
"glow 0.16.0",
|
||||
"glutin",
|
||||
"glutin-winit",
|
||||
"home",
|
||||
"image",
|
||||
"js-sys",
|
||||
"log",
|
||||
|
@ -1034,6 +1050,8 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
"profiling",
|
||||
"raw-window-handle",
|
||||
"ron",
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
|
@ -1057,6 +1075,8 @@ dependencies = [
|
|||
"log",
|
||||
"nohash-hasher",
|
||||
"profiling",
|
||||
"ron",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1101,6 +1121,7 @@ dependencies = [
|
|||
"log",
|
||||
"profiling",
|
||||
"raw-window-handle",
|
||||
"serde",
|
||||
"smithay-clipboard",
|
||||
"web-time",
|
||||
"webbrowser",
|
||||
|
@ -1153,6 +1174,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c4fe73c1207b864ee40aa0b0c038d6092af1030744678c60188a05c28553515d"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1203,6 +1225,17 @@ dependencies = [
|
|||
"syn 2.0.96",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enumn"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.96",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.30.0"
|
||||
|
@ -1219,6 +1252,7 @@ dependencies = [
|
|||
"nohash-hasher",
|
||||
"parking_lot",
|
||||
"profiling",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2860,6 +2894,18 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
|
||||
|
||||
[[package]]
|
||||
name = "ron"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bitflags 2.8.0",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-music-theory"
|
||||
version = "0.2.0"
|
||||
|
|
|
@ -14,7 +14,7 @@ tokio = { version = "1.43.0", features = ["full"] }
|
|||
common = {path = "../common"}
|
||||
heapless = "0.7.0"
|
||||
|
||||
eframe = "0.30"
|
||||
eframe = { version = "0.30", features = ["persistence"] }
|
||||
egui_extras = { version = "0.30", features = ["default", "image"] }
|
||||
egui-toast = "0.16.0"
|
||||
home = "0.5.11"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
use std::{cell::OnceCell, path::PathBuf, time::Duration};
|
||||
|
||||
use common::{ControlPacket, TelemetryPacket};
|
||||
use eframe::egui::{self, containers, Align2, Checkbox, Context, Id, Label};
|
||||
use eframe::{egui::{self, containers, Align2, Checkbox, Context, Id, Label}, Storage};
|
||||
use tokio::{runtime::Runtime, sync::{mpsc, watch::Receiver}};
|
||||
use egui_toast::{Toast, Toasts};
|
||||
|
||||
|
@ -24,7 +24,7 @@ pub fn gui(data: Receiver<GUIData>, toasts: mpsc::Receiver<Toast>, executor: Run
|
|||
// This gives us image support:
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
|
||||
Ok(Box::new(GUI::with_receivers(data, toasts, executor)))
|
||||
Ok(Box::new(GUI::with_receivers(data, toasts, executor, cc.storage.unwrap())))
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
@ -35,18 +35,43 @@ pub struct GUIData {
|
|||
pub last_command: Option<ControlPacket>,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
const DEFAULT_VOLUME_THRESHOLD: f32 = 5.0;
|
||||
#[cfg(target_os = "windows")]
|
||||
const DEFAULT_VOLUME_THRESHOLD: f32 = 1.0;
|
||||
const DEFAULT_TURN_GAIN: f32 = 0.3;
|
||||
const DEFAULT_FIRE_DISTANCE: f32 = 55.0;
|
||||
|
||||
struct GUI {
|
||||
data: Receiver<GUIData>,
|
||||
toasts: mpsc::Receiver<Toast>,
|
||||
executor: Option<Runtime>,
|
||||
volume_threshold: f32,
|
||||
auto_turn_gain: f32,
|
||||
/// mm
|
||||
auto_fire_distance: f32,
|
||||
selected_auto: usize,
|
||||
}
|
||||
|
||||
impl GUI {
|
||||
fn with_receivers(data: Receiver<GUIData>, toasts: mpsc::Receiver<Toast>, executor: Runtime) -> Self {
|
||||
fn with_receivers(data: Receiver<GUIData>, toasts: mpsc::Receiver<Toast>, executor: Runtime, storage: &dyn Storage) -> Self {
|
||||
let volume_threshold: f32 = storage.get_string("volume_threshold").map(|s| s.parse().ok()).flatten().unwrap_or(DEFAULT_VOLUME_THRESHOLD);
|
||||
|
||||
let auto_turn_gain: f32 = storage.get_string("auto_turn_gain").map(|s| s.parse().ok()).flatten().unwrap_or(DEFAULT_TURN_GAIN);
|
||||
|
||||
let auto_fire_distance: f32 = storage.get_string("auto_fire_distance").map(|s| s.parse().ok()).flatten().unwrap_or(DEFAULT_FIRE_DISTANCE);
|
||||
|
||||
let selected_auto: usize = storage.get_string("selected_auto").map(|s| s.parse().ok()).flatten().unwrap_or(0);
|
||||
|
||||
|
||||
Self {
|
||||
data,
|
||||
toasts,
|
||||
executor: Some(executor),
|
||||
volume_threshold,
|
||||
auto_turn_gain,
|
||||
auto_fire_distance,
|
||||
selected_auto,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,22 +79,23 @@ impl GUI {
|
|||
impl eframe::App for GUI {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
let _ = GUI.set(ctx.clone());
|
||||
let mut num = 0.0;
|
||||
let mut num2 = 0.0;
|
||||
let mut num3 = 0.0;
|
||||
let mut auto_idx = 0;
|
||||
egui::SidePanel::right(Id::new("config")).resizable(false).show(ctx, |ui| {
|
||||
ui.heading("configuration");
|
||||
ui.add(egui::Slider::new(&mut num, 0.0..=10.0).text("volume threshold"));
|
||||
ui.add(egui::Slider::new(&mut self.volume_threshold, 0.0..=10.0).text("volume threshold"));
|
||||
ui.label("higher accepts less noise (better)");
|
||||
ui.add(egui::Slider::new(&mut num2, 0.0..=1.0).text("auto turn kP"));
|
||||
ui.add(egui::Slider::new(&mut num3, 30.0..=100.0).text("auto fire distance (mm)"));
|
||||
ui.add(egui::Slider::new(&mut self.auto_turn_gain, 0.0..=1.0).text("auto turn kP"));
|
||||
ui.add(egui::Slider::new(&mut self.auto_fire_distance, 30.0..=100.0).text("auto fire distance (mm)"));
|
||||
ui.horizontal(|ui| {
|
||||
egui::ComboBox::new("auto selector", "select auto")
|
||||
.show_index(ui, &mut auto_idx, 3, |n| ["a","b","c"][n]);
|
||||
.show_index(ui, &mut self.selected_auto, 3, |n| ["a","b","c"][n]);
|
||||
ui.button("refresh").clicked();
|
||||
});
|
||||
println!("data {:?}", storage_dir("cruisecontrol"));
|
||||
|
||||
let storage = _frame.storage_mut().unwrap();
|
||||
storage.set_string("volume_threshold", format!("{}",self.volume_threshold));
|
||||
storage.set_string("auto_turn_gain", format!("{}",self.auto_turn_gain));
|
||||
storage.set_string("auto_fire_distance", format!("{}",self.auto_fire_distance));
|
||||
storage.set_string("selected_auto", format!("{}",self.selected_auto));
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
|
|
Loading…
Reference in a new issue