|
1 | 1 | use chrono::DateTime; |
2 | 2 | use serde::{Deserialize, Serialize}; |
3 | 3 | use std::{ |
4 | | - collections::{BTreeMap, VecDeque}, |
| 4 | + collections::{BTreeMap, HashMap, VecDeque}, |
5 | 5 | sync::{Arc, Mutex}, |
6 | | - time::Duration, |
7 | 6 | }; |
8 | 7 |
|
9 | | -use egui::{Color32, Context, FontData, FontDefinitions, FontFamily}; |
| 8 | +use egui::{Color32, FontData, FontDefinitions, FontFamily}; |
10 | 9 | use egui_dock::DockState; |
11 | 10 | use mio::{Events, Poll}; |
12 | 11 | use mio_serial::{SerialPortInfo, SerialStream}; |
@@ -56,6 +55,11 @@ pub struct Record { |
56 | 55 | pub value: f64, |
57 | 56 | } |
58 | 57 |
|
| 58 | +#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)] |
| 59 | +struct ModeDisplaySettings { |
| 60 | + pub auto_scale_units: bool, // true = use mV / mΩ / kΩ etc. (current default behavior) |
| 61 | +} |
| 62 | + |
59 | 63 | /// We derive Deserialize/Serialize so we can persist app state on shutdown. |
60 | 64 | #[derive(Serialize, Deserialize)] |
61 | 65 | #[serde(default)] // if we add new fields, give them default values when deserializing old state |
@@ -94,7 +98,7 @@ pub struct MyApp { |
94 | 98 | recording_interval_ms: u64, // Persistent, fixed interval duration |
95 | 99 | recording_active: bool, // Persistent, whether recording is active |
96 | 100 | recording_timestamp_format: TimestampFormat, // Persistent, timestamp format |
97 | | - cont_disable_unit_scaling: bool, |
| 101 | + mode_display_settings: HashMap<MeterMode, ModeDisplaySettings>, |
98 | 102 | #[serde(skip)] |
99 | 103 | recording_data: Vec<Record>, // Do not persist recording data |
100 | 104 | #[serde(skip)] |
@@ -254,7 +258,7 @@ impl Default for MyApp { |
254 | 258 | last_record_time: 0.0, // Initialize last recording time |
255 | 259 | graph_config: graph::GraphConfig::default(), // Default graph config |
256 | 260 | plot_dock_state: DockState::new(vec![]), // Initialize empty, populated in update |
257 | | - cont_disable_unit_scaling: false, |
| 261 | + mode_display_settings: HashMap::default(), |
258 | 262 | } |
259 | 263 | } |
260 | 264 | } |
@@ -384,4 +388,18 @@ impl MyApp { |
384 | 388 | self.hist_values.clear(); // Clear histogram data |
385 | 389 | self.meas_count = 0; // Reset measurement counter |
386 | 390 | } |
| 391 | + |
| 392 | + pub fn auto_scale_units(&self, mode: &MeterMode) -> bool { |
| 393 | + self.mode_display_settings |
| 394 | + .get(mode) |
| 395 | + .map_or(true, |s| s.auto_scale_units) // default = enabled (matches current behavior for all modes) |
| 396 | + } |
| 397 | + |
| 398 | + pub fn set_auto_scale_units(&mut self, mode: MeterMode, enabled: bool) { |
| 399 | + self.mode_display_settings |
| 400 | + .entry(mode) |
| 401 | + .or_default() |
| 402 | + .auto_scale_units = enabled; |
| 403 | + // Optional: self.save_settings() if you have an immediate-save helper |
| 404 | + } |
387 | 405 | } |
0 commit comments