Removed duplicated code in worker thread
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use hidapi::{DeviceInfo, HidApi, HidError};
|
||||
use log::{error, info, warn, debug, trace}; // Use log crate
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::rc::Rc; // Keep Rc for potential sharing within UI if needed
|
||||
use std::rc::Rc;
|
||||
|
||||
// Represents a discovered VPC device
|
||||
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Hash, Clone)]
|
||||
@@ -73,7 +73,6 @@ impl Default for SavedDevice {
|
||||
|
||||
/// Finds the index in the `device_list` corresponding to the saved device data.
|
||||
/// Returns 0 (default "No Connection") if not found or if saved_device is invalid.
|
||||
// Make this function standalone or static, not requiring &self
|
||||
pub(crate) fn find_device_index_for_saved(
|
||||
device_list: &[VpcDevice], // Pass device list explicitly
|
||||
saved_device: &SavedDevice,
|
||||
@@ -94,7 +93,6 @@ pub(crate) fn find_device_index_for_saved(
|
||||
|
||||
// --- Device Management Functions ---
|
||||
|
||||
// Now part of ShiftTool impl block
|
||||
impl crate::ShiftTool {
|
||||
/// Refreshes the internal list of available HID devices.
|
||||
pub(crate) fn refresh_devices(&mut self) {
|
||||
|
||||
@@ -404,21 +404,6 @@ fn run_hid_worker_loop(hidapi: HidApi, data: WorkerData) {
|
||||
// If send fails later, reopen will be attempted then.
|
||||
}
|
||||
}
|
||||
|
||||
// --- Read current state (Optional Merge) ---
|
||||
read_buffer[0] = receiver_format.report_id; // Use receiver format ID
|
||||
let mut receiver_current_state: u16 = 0;
|
||||
log::trace!("Worker: Reading current state from receiver[{}] before merge using format '{}'.", i, receiver_format.name);
|
||||
match device.get_feature_report(&mut read_buffer) {
|
||||
Ok(bytes_read) => {
|
||||
// --- Use correct unpack_state function name ---
|
||||
if let Some(current_state) = receiver_format.unpack_state(&read_buffer[0..bytes_read]) {
|
||||
// --- End change ---
|
||||
receiver_current_state = current_state;
|
||||
} else { /* warn unpack failed */ }
|
||||
}
|
||||
Err(e_read) => { /* warn read failed */ }
|
||||
}
|
||||
state_to_send |= receiver_current_state; // Merge
|
||||
// --- End Read current state ---
|
||||
|
||||
|
||||
@@ -172,10 +172,9 @@ impl eframe::App for ShiftTool {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
log::debug!("Update Called.");
|
||||
// Request repaint ensures GUI updates even if worker is slow
|
||||
ctx.request_repaint_after(Duration::from_millis(50)); // e.g., 10 FPS target
|
||||
ctx.request_repaint_after(Duration::from_millis(50));
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
// Use show_inside_add to handle resize correctly
|
||||
egui::Resize::default()
|
||||
.default_width(INITIAL_WIDTH)
|
||||
.default_height(INITIAL_HEIGHT)
|
||||
|
||||
Reference in New Issue
Block a user