Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 1,230
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

joypad bug

I can't see it


My mask starts at 1 then I shift it


An I doing something stupid somewhere?


I take the old value - store - XOR compare to mask - send the right(?) event


Something I can't quite see is causing the logic to miss events


It cycles through 20 possible state changes and if any change found tells the world outside


Personally I see nothing wrong


void *HandleEvents(void *args)
	joypadNDK *parent = static_cast<joypadNDK *>(args);
	int i, j, mask, changed;
	OldControllerState oldState[MAX_CONTROLLERS];

    if(_screen_ctx) {
        m_eventsEnabled = true;

		while(1) {
			for(i=0; i<MAX_CONTROLLERS; i++) {
				oldState[i].buttons = _controllers[i].buttons;
				for(j=0; j<3; j++) {
					oldState[i].analog0[j] = _controllers[i].analog0[j];
					oldState[i].analog1[j] = _controllers[i].analog1[j];
			mask = 1;
			for(i=0; i<MAX_CONTROLLERS; i++) {
				if(_controllers[i].handle) {
					// XOR old and new state to get a bitmap of changed buttons
					changed = oldState[i].buttons ^ _controllers[i].buttons;
					// Use mask as a bitwise counter
					for(j=0; j<MAX_BUTTONS; j++) {
						// If the button has changed
						if(changed & mask) {
							// Signal JS the button has been pressed / released
							if(changed & _controllers[i].buttons) {
								parent->joypadEventCallback(0, i, j, 1);
							} else {
								parent->joypadEventCallback(0, i, j, 0);
						mask = mask << 1;
					for(j=0; j<3; j++) {
						if(oldState[i].analog0[j] != _controllers[i].analog0[j]) {
							parent->joypadEventCallback(1, i, j, _controllers[i].analog0[j]);
						if(oldState[i].analog1[j] != _controllers[i].analog1[j]) {
							parent->joypadEventCallback(2, i, j, _controllers[i].analog1[j]);

			// Poll at 10 Hz
    return NULL;


Click the like button if you find my posts useful!