Skip to content

Commit

Permalink
Support hot-plugging the GameCube adapter itself
Browse files Browse the repository at this point in the history
Disconnecting and reconnecting the adapter is not implemented, but the
adapter read thread will at least start without an adapter plugged in.

Fixes #11
  • Loading branch information
amatho committed Sep 12, 2022
1 parent a2eda43 commit 154950c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
22 changes: 12 additions & 10 deletions src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ const READ_LEN: usize = 37;

pub static ADAPTER_STATE: AdapterState = AdapterState::new();

pub fn start_read_thread() -> Result<(), &'static str> {
let gc_adapter = if let Ok(gc) = GCAdapter::new() {
gc
} else {
debug_print!(M64Message::Error, "Could not connect to GameCube adapter");
return Err("could not initialize GameCube adapter");
};

pub fn start_read_thread() {
thread::spawn(move || {
debug_print!(M64Message::Info, "Adapter thread started");
debug_print!(M64Message::Info, "Trying to connect to GameCube adapter...");

let gc_adapter = loop {
if let Ok(gc) = GCAdapter::new() {
break gc;
}

thread::park_timeout(Duration::from_secs(1));
};

debug_print!(M64Message::Info, "Found a GameCube adapter");

while IS_INIT.load(Ordering::Acquire) {
*ADAPTER_STATE.buf.lock() = gc_adapter.read();
Expand All @@ -35,8 +39,6 @@ pub fn start_read_thread() -> Result<(), &'static str> {

debug_print!(M64Message::Info, "Adapter thread stopped");
});

Ok(())
}

pub struct GCAdapter {
Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ pub unsafe extern "C" fn PluginStartup(
return m64p_error_M64ERR_INCOMPATIBLE;
}

if adapter::start_read_thread().is_err() {
debug_print!(M64Message::Error, "Could not start adapter read thread");
return m64p_error_M64ERR_PLUGIN_FAIL;
}
adapter::start_read_thread();

let cfg_file_name = "mupen64plus-input-gca.toml";
let cfg_path = if let Ok(sym) =
Expand Down

0 comments on commit 154950c

Please sign in to comment.