From 4a6ccfb4482a1eb8e9bcf51727db4031dc65b1ce Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Sun, 6 Dec 2015 16:36:33 -0500 Subject: [PATCH] Gamecube hotplugging infrastructure --- gamecube.c | 6 ++++++ gamepads.h | 1 + main.c | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/gamecube.c b/gamecube.c index e978572..baf73cc 100644 --- a/gamecube.c +++ b/gamecube.c @@ -156,6 +156,11 @@ static char gamecubeUpdate() return 0; } +static void gamecubeHotplug(void) +{ + // Make sure next read becomes the refence center values + origins_set = 0; +} static char gamecubeProbe(void) { @@ -191,6 +196,7 @@ Gamepad GamecubeGamepad = { .getReport = gamecubeGetReport, .probe = gamecubeProbe, .setVibration = gamecubeVibration, + .hotplug = gamecubeHotplug, }; Gamepad *gamecubeGetGamepad(void) diff --git a/gamepads.h b/gamepads.h index 33c47a2..7a60726 100644 --- a/gamepads.h +++ b/gamepads.h @@ -75,6 +75,7 @@ typedef struct { void (*init)(void); char (*update)(void); char (*changed)(void); + void (*hotplug)(void); void (*getReport)(gamepad_data *dst); void (*setVibration)(char enable); char (*probe)(void); /* return true if found */ diff --git a/main.c b/main.c index 03c0d81..7e7096f 100644 --- a/main.c +++ b/main.c @@ -305,6 +305,12 @@ int main(void) /* Try to auto-detect controller if none*/ if (!pad) { pad = detectPad(); + if (pad->hotplug) { + // For gamecube, this make sure the next + // analog values we read become the center + // reference. + pad->hotplug(); + } } if (pad) { if (pad->update()) {