From 4f8d9115deb1b54f06c979f5567e6633dbf5aa1c Mon Sep 17 00:00:00 2001 From: Cooper Quintin Date: Mon, 25 Nov 2024 10:55:45 -0800 Subject: [PATCH 1/3] add colorblind mode. Fixes #77 --- bin/src/config.rs | 4 ++++ bin/src/daemon.rs | 8 +++++++- dist/config.toml.example | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/src/config.rs b/bin/src/config.rs index ee119ef..354cf66 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -9,6 +9,7 @@ struct ConfigFile { debug_mode: Option, ui_level: Option, enable_dummy_analyzer: Option, + colorblind_mode: Option, } #[derive(Debug)] @@ -18,6 +19,7 @@ pub struct Config { pub debug_mode: bool, pub ui_level: u8, pub enable_dummy_analyzer: bool, + pub colorblind_mode: bool, } impl Default for Config { @@ -28,6 +30,7 @@ impl Default for Config { debug_mode: false, ui_level: 1, enable_dummy_analyzer: false, + colorblind_mode: false, } } } @@ -42,6 +45,7 @@ pub fn parse_config

(path: P) -> Result where P: AsRef parsed_config.debug_mode.map(|v| config.debug_mode = v); parsed_config.ui_level.map(|v| config.ui_level = v); parsed_config.enable_dummy_analyzer.map(|v| config.enable_dummy_analyzer = v); + parsed_config.colorblind_mode.map(|v| config.colorblind_mode = v); } Ok(config) } diff --git a/bin/src/daemon.rs b/bin/src/daemon.rs index 14f8932..1ec4d6c 100644 --- a/bin/src/daemon.rs +++ b/bin/src/daemon.rs @@ -21,6 +21,7 @@ use crate::framebuffer::Framebuffer; use analysis::{get_analysis_status, run_analysis_thread, start_analysis, AnalysisCtrlMessage, AnalysisStatus}; use axum::response::Redirect; use diag::{get_analysis_report, start_recording, stop_recording, DiagDeviceCtrlMessage}; +use framebuffer::Color565; use log::{info, error}; use rayhunter::diag_device::DiagDevice; use axum::routing::{get, post}; @@ -142,12 +143,17 @@ fn run_ctrl_c_thread( fn update_ui(task_tracker: &TaskTracker, config: &config::Config, mut ui_shutdown_rx: oneshot::Receiver<()>, mut ui_update_rx: Receiver) -> JoinHandle<()> { static IMAGE_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/static/images/"); + let mut display_color: Color565; let display_level = config.ui_level; if display_level == 0 { info!("Invisible mode, not spawning UI."); } - let mut display_color = framebuffer::Color565::Green; + if config.colorblind_mode { + display_color = framebuffer::Color565::Blue; + } else { + display_color = framebuffer::Color565::Green; + } task_tracker.spawn_blocking(move || { let mut fb: Framebuffer = Framebuffer::new(); diff --git a/dist/config.toml.example b/dist/config.toml.example index edfdaed..6cd2c7f 100644 --- a/dist/config.toml.example +++ b/dist/config.toml.example @@ -1,6 +1,9 @@ # cat config.toml qmdl_store_path = "/data/rayhunter/qmdl" port = 8080 +debug_mode = false +enable_dummy_analyzer = false +colorblind_mode = false # UI Levels: # 0 = invisible mode, no indicator that rayhunter is running # 1 = Subtle mode, display a green line at the top of the screen when rayhunter is running From c30746403e780940441fb0f0793feaa6ad5ce960 Mon Sep 17 00:00:00 2001 From: Cooper Quintin Date: Mon, 25 Nov 2024 11:34:12 -0800 Subject: [PATCH 2/3] remove unneeded import --- bin/src/daemon.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/src/daemon.rs b/bin/src/daemon.rs index 1ec4d6c..3ec26e3 100644 --- a/bin/src/daemon.rs +++ b/bin/src/daemon.rs @@ -21,7 +21,6 @@ use crate::framebuffer::Framebuffer; use analysis::{get_analysis_status, run_analysis_thread, start_analysis, AnalysisCtrlMessage, AnalysisStatus}; use axum::response::Redirect; use diag::{get_analysis_report, start_recording, stop_recording, DiagDeviceCtrlMessage}; -use framebuffer::Color565; use log::{info, error}; use rayhunter::diag_device::DiagDevice; use axum::routing::{get, post}; @@ -143,7 +142,7 @@ fn run_ctrl_c_thread( fn update_ui(task_tracker: &TaskTracker, config: &config::Config, mut ui_shutdown_rx: oneshot::Receiver<()>, mut ui_update_rx: Receiver) -> JoinHandle<()> { static IMAGE_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/static/images/"); - let mut display_color: Color565; + let mut display_color: framebuffer::Color565; let display_level = config.ui_level; if display_level == 0 { info!("Invisible mode, not spawning UI."); From 0e7ba51507659dbd83ae44367a636a7aef304dbd Mon Sep 17 00:00:00 2001 From: Cooper Quintin Date: Mon, 25 Nov 2024 15:49:21 -0800 Subject: [PATCH 3/3] propegate colorblind mode beyond start/stop --- bin/src/daemon.rs | 1 + bin/src/diag.rs | 10 +++++++++- bin/src/framebuffer.rs | 2 ++ bin/src/server.rs | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bin/src/daemon.rs b/bin/src/daemon.rs index 3ec26e3..26edbc1 100644 --- a/bin/src/daemon.rs +++ b/bin/src/daemon.rs @@ -59,6 +59,7 @@ async fn run_server( debug_mode: config.debug_mode, analysis_status_lock, analysis_sender, + colorblind_mode: config.colorblind_mode, }); let app = Router::new() diff --git a/bin/src/diag.rs b/bin/src/diag.rs index 68e2f90..2827b1d 100644 --- a/bin/src/diag.rs +++ b/bin/src/diag.rs @@ -129,8 +129,16 @@ pub async fn start_recording(State(state): State>) -> Result<(S let qmdl_writer = QmdlWriter::new(qmdl_file); state.diag_device_ctrl_sender.send(DiagDeviceCtrlMessage::StartRecording((qmdl_writer, analysis_file))).await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("couldn't send stop recording message: {}", e)))?; - state.ui_update_sender.send(framebuffer::DisplayState::Recording).await + + let display_state: framebuffer::DisplayState; + if state.colorblind_mode { + display_state = framebuffer::DisplayState::RecordingCBM; + } else { + display_state = framebuffer::DisplayState::Recording; + } + state.ui_update_sender.send(display_state).await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("couldn't send ui update message: {}", e)))?; + Ok((StatusCode::ACCEPTED, "ok".to_string())) } diff --git a/bin/src/framebuffer.rs b/bin/src/framebuffer.rs index 2477613..6e1ecd1 100644 --- a/bin/src/framebuffer.rs +++ b/bin/src/framebuffer.rs @@ -27,6 +27,7 @@ pub enum DisplayState { Recording, Paused, WarningDetected, + RecordingCBM, } impl From for Color565 { @@ -34,6 +35,7 @@ impl From for Color565 { match state { DisplayState::Paused => Color565::White, DisplayState::Recording => Color565::Green, + DisplayState::RecordingCBM => Color565::Blue, DisplayState::WarningDetected => Color565::Red, } } diff --git a/bin/src/server.rs b/bin/src/server.rs index 3f9f481..c90a6a1 100644 --- a/bin/src/server.rs +++ b/bin/src/server.rs @@ -22,7 +22,8 @@ pub struct ServerState { pub ui_update_sender: Sender, pub analysis_status_lock: Arc>, pub analysis_sender: Sender, - pub debug_mode: bool + pub debug_mode: bool, + pub colorblind_mode: bool, } pub async fn get_qmdl(State(state): State>, Path(qmdl_name): Path) -> Result {