src/joystick/haiku/SDL_haikujoystick.cc
changeset 10745 7461fcef6ae2
parent 10737 3406a0f8b041
child 10753 220a81177cfb
equal deleted inserted replaced
10744:f42f107a6035 10745:7461fcef6ae2
   174             SDL_HAT_DOWN,
   174             SDL_HAT_DOWN,
   175             SDL_HAT_LEFTDOWN,
   175             SDL_HAT_LEFTDOWN,
   176             SDL_HAT_LEFT,
   176             SDL_HAT_LEFT,
   177             SDL_HAT_LEFTUP
   177             SDL_HAT_LEFTUP
   178         };
   178         };
   179         const int JITTER = (32768 / 10);        /* 10% jitter threshold (ok?) */
       
   180 
   179 
   181         BJoystick *stick;
   180         BJoystick *stick;
   182         int i, change;
   181         int i, change;
   183         int16 *axes;
   182         int16 *axes;
   184         uint8 *hats;
   183         uint8 *hats;
   195         stick->GetHatValues(hats);
   194         stick->GetHatValues(hats);
   196         buttons = stick->ButtonValues();
   195         buttons = stick->ButtonValues();
   197 
   196 
   198         /* Generate axis motion events */
   197         /* Generate axis motion events */
   199         for (i = 0; i < joystick->naxes; ++i) {
   198         for (i = 0; i < joystick->naxes; ++i) {
   200             change = ((int32) axes[i] - joystick->axes[i].value);
   199             SDL_PrivateJoystickAxis(joystick, i, axes[i]);
   201             if ((change > JITTER) || (change < -JITTER)) {
       
   202                 SDL_PrivateJoystickAxis(joystick, i, axes[i]);
       
   203             }
       
   204         }
   200         }
   205 
   201 
   206         /* Generate hat change events */
   202         /* Generate hat change events */
   207         for (i = 0; i < joystick->nhats; ++i) {
   203         for (i = 0; i < joystick->nhats; ++i) {
   208             if (hats[i] != joystick->hats[i]) {
   204             SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]);
   209                 SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]);
       
   210             }
       
   211         }
   205         }
   212 
   206 
   213         /* Generate button events */
   207         /* Generate button events */
   214         for (i = 0; i < joystick->nbuttons; ++i) {
   208         for (i = 0; i < joystick->nbuttons; ++i) {
   215             if ((buttons & 0x01) != joystick->buttons[i]) {
   209             SDL_PrivateJoystickButton(joystick, i, (buttons & 0x01));
   216                 SDL_PrivateJoystickButton(joystick, i, (buttons & 0x01));
       
   217             }
       
   218             buttons >>= 1;
   210             buttons >>= 1;
   219         }
   211         }
   220     }
   212     }
   221 
   213 
   222 /* Function to close a joystick after use */
   214 /* Function to close a joystick after use */