From 75230a5cc70b672618e315763da593e107b92ed3 Mon Sep 17 00:00:00 2001 From: RavenX8 <7156279+RavenX8@users.noreply.github.com> Date: Sun, 30 Mar 2025 13:21:05 -0400 Subject: [PATCH] cleaned up unused functions --- src/device.rs | 14 -------------- src/hid_worker.rs | 8 ++++---- src/main.rs | 6 +++--- src/ui.rs | 30 +----------------------------- src/util.rs | 19 ------------------- 5 files changed, 8 insertions(+), 69 deletions(-) diff --git a/src/device.rs b/src/device.rs index 93d584b..20bf52e 100644 --- a/src/device.rs +++ b/src/device.rs @@ -166,20 +166,6 @@ impl crate::ShiftTool { } } - /// Finds the index in the `device_list` corresponding to the saved receiver config. - pub(crate) fn find_receiver_device_index(&self, receiver_config_index: usize) -> usize { - self.find_device_index_for_saved( - &self.config.data.receivers[receiver_config_index] - ) - } - - /// Finds the index in the `device_list` corresponding to the saved source config. - pub(crate) fn find_source_device_index(&self, source_config_index: usize) -> usize { - self.find_device_index_for_saved( - &self.config.data.sources[source_config_index] - ) - } - /// Generic helper to find a device index based on SavedDevice data. fn find_device_index_for_saved(&self, saved_device: &SavedDevice) -> usize { if saved_device.vendor_id == 0 && saved_device.product_id == 0 { diff --git a/src/hid_worker.rs b/src/hid_worker.rs index d743b54..5f71419 100644 --- a/src/hid_worker.rs +++ b/src/hid_worker.rs @@ -1,7 +1,7 @@ use crate::config::{ModifiersArray}; use crate::device::SavedDevice; use crate::{SharedDeviceState, SharedStateFlag}; // Import shared types -use crate::util::{self, merge_u8_into_u16, read_bit, set_bit, ReportFormat, MAX_REPORT_SIZE}; +use crate::util::{self, read_bit, ReportFormat, MAX_REPORT_SIZE}; use log::{debug, error, info, trace, warn}; use hidapi::{HidApi, HidDevice, HidError}; use std::{ @@ -259,14 +259,14 @@ fn run_hid_worker_loop(hidapi: HidApi, data: WorkerData) { let mut read_buffer = [0u8; MAX_REPORT_SIZE]; let mut write_buffer = [0u8; MAX_REPORT_SIZE]; // Buffer for calculated output - let &(ref run_lock, ref run_cvar) = &*data.run_state; + let &(ref run_lock, ref _run_cvar) = &*data.run_state; loop { // --- Check Run State --- let should_run = { // Scope for mutex guard match run_lock.lock() { Ok(guard) => *guard, - Err(poisoned) => { + Err(_poisoned) => { error!("Run state mutex poisoned in worker loop!"); false } @@ -523,7 +523,7 @@ fn run_hid_worker_loop(hidapi: HidApi, data: WorkerData) { if let Ok(mut guard) = shared_state.lock() { *guard = 0; } } } - Err(e_actual) => { + Err(_e_actual) => { if let Some(shared_state) = data.receiver_states_shared.get(i) { if let Ok(mut guard) = shared_state.lock() { *guard = 0; } } diff --git a/src/main.rs b/src/main.rs index 4552212..64592e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,7 +82,7 @@ impl Default for ShiftTool { device_list: vec![], source_states: vec![], receiver_states: vec![], - shift_state: Arc::new((Mutex::new(0))), // Keep Condvar if needed for shift_state? + shift_state: Arc::new(Mutex::new(0)), // Keep Condvar if needed for shift_state? thread_state: Arc::new((Mutex::new(false), Condvar::new())), config, } @@ -115,13 +115,13 @@ impl ShiftTool { // Helper to add state tracking for a new source fn add_source_state(&mut self) { self.source_states - .push(Arc::new((Mutex::new(0)))); + .push(Arc::new(Mutex::new(0))); } // Helper to add state tracking for a new receiver fn add_receiver_state(&mut self) { self.receiver_states - .push(Arc::new((Mutex::new(0)))); + .push(Arc::new(Mutex::new(0))); } // Helper to get thread status (could be in ui.rs or main.rs) diff --git a/src/ui.rs b/src/ui.rs index c0bd360..10f31a6 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -350,7 +350,7 @@ fn device_selector_combo( }; ui.add_enabled_ui(!disabled, |ui| { - egui::ComboBox::from_id_source(id_source) + egui::ComboBox::from_id_salt(id_source) .width(300.0) // Adjust width as needed .selected_text(selected_text) .show_ui(ui, |ui| { @@ -464,34 +464,6 @@ fn draw_status_bits( }); } -/// Draws the ONLINE/OFFLINE status indicator. -fn draw_online_status( - ui: &mut Ui, - saved_device_config: &crate::device::SavedDevice, // Pass the config for this slot - thread_running: bool, -) { - // Infer status: Online if thread is running AND device is configured (VID/PID != 0) - let is_configured = saved_device_config.vendor_id != 0 && saved_device_config.product_id != 0; - - // Determine status text and color - let (text, color) = if thread_running && is_configured { - // We assume the worker *tries* to talk to configured devices. - // A more advanced check could involve reading another shared state - // updated by the worker indicating recent success/failure for this device. - ("ONLINE", Color32::GREEN) - } else if !is_configured { - ("UNCONFIGURED", Color32::YELLOW) // Show if slot is empty - } else { // Thread not running or device not configured - ("OFFLINE", Color32::GRAY) - }; - - // Use selectable_label for consistent look, but make it non-interactive - // Set 'selected' argument to false as it's just a status display - ui.selectable_label(false, egui::RichText::new(text).color(color)); -} - - - /// Draws the control buttons in the right column. fn draw_control_buttons( app: &mut ShiftTool, diff --git a/src/util.rs b/src/util.rs index b09b143..1456225 100644 --- a/src/util.rs +++ b/src/util.rs @@ -203,25 +203,6 @@ pub(crate) fn read_bit(value: u16, position: u8) -> bool { (value & (1 << position)) != 0 } -/// Sets or clears a specific bit in a u8 value. -/// `bit_position` is 0-indexed (0-7). -/// Returns the modified u8 value. -pub(crate) fn set_bit(value: u8, bit_position: u8, bit_value: bool) -> u8 { - if bit_position > 7 { - warn!("set_bit called with invalid position: {}", bit_position); - return value; // Return original value on error - } - if bit_value { - value | (1 << bit_position) // Set the bit to 1 - } else { - value & !(1 << bit_position) // Set the bit to 0 - } -} - -/// Combines high and low bytes into a u16 value. -pub(crate) fn merge_u8_into_u16(high_byte: u8, low_byte: u8) -> u16 { - (high_byte as u16) << 8 | (low_byte as u16) -} /// Checks if a device firmware string is supported. /// TODO: Implement actual firmware checking logic if needed.