From 4b5bcc668412cfa0cdbaf600fdb5bc082c32e2d6 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Fri, 3 Jun 2011 15:40:31 +0000 Subject: [PATCH] Introduce a BJoystick::GetButtonValues() function that aligns with the other Get*Values() functions but retrieves an arbitrary amount of button states using a boolean array. This overcomes the 32 button limitation on the API side. Right now the function does simply set the first 32 states from the button bitmap, as the BJoystick to driver interface hasn't been adapted yet. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41882 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/device/Joystick.h | 10 ++++++++++ src/kits/device/Joystick.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/headers/os/device/Joystick.h b/headers/os/device/Joystick.h index 776124d4ff..82fdd45244 100644 --- a/headers/os/device/Joystick.h +++ b/headers/os/device/Joystick.h @@ -64,6 +64,16 @@ public: int32 CountButtons(); uint32 ButtonValues(int32 forStick = 0); + // Allows access to the first 32 buttons where + // each set bit indicates a pressed button. + status_t GetButtonValues(bool* outButtons, + int32 forStick = 0); + // Haiku extension. Allows to retrieve the state + // of an arbitrary count of buttons. The + // outButtons argument is an array of boolean + // values with at least CountButtons() elements. + // True means the button is pressed and false + // means it is released. status_t GetButtonNameAt(int32 index, BString* outName); diff --git a/src/kits/device/Joystick.cpp b/src/kits/device/Joystick.cpp index 2b52e0ee18..8c5f120e52 100644 --- a/src/kits/device/Joystick.cpp +++ b/src/kits/device/Joystick.cpp @@ -4,6 +4,7 @@ * Distributed under the terms of the MIT License. */ + #include #include @@ -433,6 +434,35 @@ BJoystick::ButtonValues(int32 forStick) } +status_t +BJoystick::GetButtonValues(bool *outButtons, int32 forStick) +{ + CALLED(); + + if (fJoystickInfo == NULL || fExtendedJoystick == NULL) + return B_NO_INIT; + + if (forStick < 0 + || forStick >= (int32)fJoystickInfo->module_info.num_sticks) + return B_BAD_INDEX; + + extended_joystick *extendedJoystick + = (extended_joystick *)fExtendedJoystick->ItemAt(forStick); + if (extendedJoystick == NULL) + return B_NO_INIT; + + int16 buttonCount = fJoystickInfo->module_info.num_buttons; + for (int16 i = 0; i < buttonCount; i++) { + if (buttonCount >= 32) + outButtons[i] = false; + else + outButtons[i] = (extendedJoystick->buttons & (1 << i)) != 0; + } + + return B_OK; +} + + status_t BJoystick::GetButtonNameAt(int32 index, BString *outName) {