Skip to content

Commit

Permalink
Improve handling of failed USB devices
Browse files Browse the repository at this point in the history
Update `FRAME_GENERATION_COUNTER` when polling the device status, to ensure that
disconnected devices are flagged as failed.

References #161
  • Loading branch information
X3n0m0rph59 committed Oct 7, 2022
1 parent a8c3e8c commit 6549dab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
10 changes: 1 addition & 9 deletions eruption/src/dbus_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use dbus_tree::{
};
use flume::Sender;
use log::*;
use std::path::PathBuf;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::{path::PathBuf, thread, time::Duration};

use crate::{
color_scheme::ColorScheme,
Expand Down Expand Up @@ -1020,14 +1020,6 @@ impl DbusApi {
))
.map_err(|_| error!("D-Bus error during send call"));

// this is required for hotplug to work correctly in case we didn't transfer
// data to the device for an extended period of time
script::FRAME_GENERATION_COUNTER.fetch_add(1, Ordering::SeqCst);
thread::sleep(Duration::from_millis(120));

// we need to terminate and then re-enter the main loop to update all global state
crate::REENTER_MAIN_LOOP.store(true, Ordering::SeqCst);

Ok(())
}

Expand Down
9 changes: 7 additions & 2 deletions eruption/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,11 @@ fn run_main_loop(
.send(DbusApiEvent::DeviceStatusChanged)
.unwrap_or_else(|e| error!("Could not send a pending dbus API event: {}", e));
}

// use 'device status poll' code to detect failed/disconnected devices as well,
// by forcing a write to the device. This is required for hotplug to work correctly in
// case we didn't transfer data to the device for an extended period of time
script::FRAME_GENERATION_COUNTER.fetch_add(1, Ordering::SeqCst);
}

// now, process events from all available sources...
Expand Down Expand Up @@ -1139,8 +1144,8 @@ fn run_main_loop(
1000 / constants::TARGET_FPS
);
} /* else if elapsed_after_sleep < 5_u128 {
debug!("Short loop detected");
debug!(
warn!("Short loop detected");
warn!(
"Loop took: {} milliseconds, goal: {}",
elapsed_after_sleep,
1000 / constants::TARGET_FPS
Expand Down

0 comments on commit 6549dab

Please sign in to comment.