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
This commit is contained in:
Michael Lotz
2011-06-03 15:40:31 +00:00
parent f3997b74b3
commit 4b5bcc6684
2 changed files with 40 additions and 0 deletions
+10
View File
@@ -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);
+30
View File
@@ -4,6 +4,7 @@
* Distributed under the terms of the MIT License.
*/
#include <Joystick.h>
#include <JoystickTweaker.h>
@@ -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)
{