diff --git a/headers/os/device/Joystick.h b/headers/os/device/Joystick.h index 2666bec292..2c09dc8a40 100644 --- a/headers/os/device/Joystick.h +++ b/headers/os/device/Joystick.h @@ -41,6 +41,12 @@ public: status_t GetDeviceName(int32 index, char* name, size_t bufSize = B_OS_NAME_LENGTH); + status_t RescanDevices(); + // Haiku extension. Updates the list of devices + // as enumerated by CountDevices() and + // GetDeviceName() with possibly newly plugged + // in devices. + bool EnterEnhancedMode(const entry_ref* ref = NULL); int32 CountSticks(); diff --git a/src/kits/device/Joystick.cpp b/src/kits/device/Joystick.cpp index 016bfb1ebf..3d5d27f2af 100644 --- a/src/kits/device/Joystick.cpp +++ b/src/kits/device/Joystick.cpp @@ -68,6 +68,8 @@ BJoystick::BJoystick() if (fJoystickInfo != NULL) memset(fJoystickInfo, 0, sizeof(joystick_info)); + + RescanDevices(); } @@ -200,12 +202,10 @@ BJoystick::CountDevices() { CALLED(); - // Refresh devices list - ScanDevices(true); + if (fDevices == NULL) + return 0; - int32 count = 0; - if (fDevices != NULL) - count = fDevices->CountItems(); + int32 count = fDevices->CountItems(); LOG("Count = %d\n", count); return count; @@ -219,8 +219,7 @@ BJoystick::GetDeviceName(int32 index, char *name, size_t bufSize) if (fDevices == NULL) return B_NO_INIT; - // CountDevices() also calls ScanDevices() and therefore updates our list. - if (index >= CountDevices()) + if (index >= fDevices->CountItems()) return B_BAD_INDEX; if (name == NULL) @@ -236,6 +235,19 @@ BJoystick::GetDeviceName(int32 index, char *name, size_t bufSize) } +status_t +BJoystick::RescanDevices() +{ + CALLED(); + + if (fDevices == NULL) + return B_NO_INIT; + + ScanDevices(true); + return B_OK; +} + + bool BJoystick::EnterEnhancedMode(const entry_ref *ref) {