cleaned up unused functions
This commit is contained in:
@@ -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.
|
/// Generic helper to find a device index based on SavedDevice data.
|
||||||
fn find_device_index_for_saved(&self, saved_device: &SavedDevice) -> usize {
|
fn find_device_index_for_saved(&self, saved_device: &SavedDevice) -> usize {
|
||||||
if saved_device.vendor_id == 0 && saved_device.product_id == 0 {
|
if saved_device.vendor_id == 0 && saved_device.product_id == 0 {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::config::{ModifiersArray};
|
use crate::config::{ModifiersArray};
|
||||||
use crate::device::SavedDevice;
|
use crate::device::SavedDevice;
|
||||||
use crate::{SharedDeviceState, SharedStateFlag}; // Import shared types
|
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 log::{debug, error, info, trace, warn};
|
||||||
use hidapi::{HidApi, HidDevice, HidError};
|
use hidapi::{HidApi, HidDevice, HidError};
|
||||||
use std::{
|
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 read_buffer = [0u8; MAX_REPORT_SIZE];
|
||||||
let mut write_buffer = [0u8; MAX_REPORT_SIZE]; // Buffer for calculated output
|
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 {
|
loop {
|
||||||
// --- Check Run State ---
|
// --- Check Run State ---
|
||||||
let should_run = { // Scope for mutex guard
|
let should_run = { // Scope for mutex guard
|
||||||
match run_lock.lock() {
|
match run_lock.lock() {
|
||||||
Ok(guard) => *guard,
|
Ok(guard) => *guard,
|
||||||
Err(poisoned) => {
|
Err(_poisoned) => {
|
||||||
error!("Run state mutex poisoned in worker loop!");
|
error!("Run state mutex poisoned in worker loop!");
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@@ -523,7 +523,7 @@ fn run_hid_worker_loop(hidapi: HidApi, data: WorkerData) {
|
|||||||
if let Ok(mut guard) = shared_state.lock() { *guard = 0; }
|
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 Some(shared_state) = data.receiver_states_shared.get(i) {
|
||||||
if let Ok(mut guard) = shared_state.lock() { *guard = 0; }
|
if let Ok(mut guard) = shared_state.lock() { *guard = 0; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ impl Default for ShiftTool {
|
|||||||
device_list: vec![],
|
device_list: vec![],
|
||||||
source_states: vec![],
|
source_states: vec![],
|
||||||
receiver_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())),
|
thread_state: Arc::new((Mutex::new(false), Condvar::new())),
|
||||||
config,
|
config,
|
||||||
}
|
}
|
||||||
@@ -115,13 +115,13 @@ impl ShiftTool {
|
|||||||
// Helper to add state tracking for a new source
|
// Helper to add state tracking for a new source
|
||||||
fn add_source_state(&mut self) {
|
fn add_source_state(&mut self) {
|
||||||
self.source_states
|
self.source_states
|
||||||
.push(Arc::new((Mutex::new(0))));
|
.push(Arc::new(Mutex::new(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to add state tracking for a new receiver
|
// Helper to add state tracking for a new receiver
|
||||||
fn add_receiver_state(&mut self) {
|
fn add_receiver_state(&mut self) {
|
||||||
self.receiver_states
|
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)
|
// Helper to get thread status (could be in ui.rs or main.rs)
|
||||||
|
|||||||
30
src/ui.rs
30
src/ui.rs
@@ -350,7 +350,7 @@ fn device_selector_combo(
|
|||||||
};
|
};
|
||||||
|
|
||||||
ui.add_enabled_ui(!disabled, |ui| {
|
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
|
.width(300.0) // Adjust width as needed
|
||||||
.selected_text(selected_text)
|
.selected_text(selected_text)
|
||||||
.show_ui(ui, |ui| {
|
.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.
|
/// Draws the control buttons in the right column.
|
||||||
fn draw_control_buttons(
|
fn draw_control_buttons(
|
||||||
app: &mut ShiftTool,
|
app: &mut ShiftTool,
|
||||||
|
|||||||
19
src/util.rs
19
src/util.rs
@@ -203,25 +203,6 @@ pub(crate) fn read_bit(value: u16, position: u8) -> bool {
|
|||||||
(value & (1 << position)) != 0
|
(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.
|
/// Checks if a device firmware string is supported.
|
||||||
/// TODO: Implement actual firmware checking logic if needed.
|
/// TODO: Implement actual firmware checking logic if needed.
|
||||||
|
|||||||
Reference in New Issue
Block a user