Welcome!

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

Reply
Highlighted
Developer
Posts: 1,229
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) {
			MUTEX_LOCK();
			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];
				}
			}
			pollDevices();
			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]);
						}
					}
				}
			}
			MUTEX_UNLOCK();

			// Poll at 10 Hz
			usleep(100000);
		}
    }
    return NULL;
}

 




Click the like button if you find my posts useful!