static void
joy_handler( int ev, int number, char value, int which )
{
  input_event_t event;

  switch ( ev ) {
  case JOY_EVENTAXIS:
    if( number == 0 )
      do_axis( which, value, INPUT_JOYSTICK_LEFT, INPUT_JOYSTICK_RIGHT );
    else if( number == 1 )
      do_axis( which, value, INPUT_JOYSTICK_UP, INPUT_JOYSTICK_DOWN );
    break;
  case JOY_EVENTBUTTONDOWN:
  case JOY_EVENTBUTTONUP:
    if( number >= buttons[which] ) return;
    event.types.joystick.which = which;
    event.types.joystick.button = INPUT_JOYSTICK_FIRE_1 + number;
    event.type = ( ev == JOY_EVENTBUTTONDOWN )
               ? INPUT_EVENT_JOYSTICK_PRESS
               : INPUT_EVENT_JOYSTICK_RELEASE;
    input_event( &event );
    break;
  default:
    break;
  }
}
Beispiel #2
0
/*
 * Process accelerometer data
 */
static void accel_data_handler(AccelData *data, uint32_t num_samples) {

  // Average the data
  uint32_t avg_x = 0;
  uint32_t avg_y = 0;
  uint32_t avg_z = 0;
  AccelData *dx = data;
  for (uint32_t i = 0; i < num_samples; i++, dx++) {
    // If vibe went off then discount everything - we're only loosing a 2.5 second set of samples, better than an
    // unwanted spike
    if (dx->did_vibrate) {
      return;
    }
    avg_x += scale_accel(dx->x);
    avg_y += scale_accel(dx->y);
    avg_z += scale_accel(dx->z);
  }

  avg_x /= num_samples;
  avg_y /= num_samples;
  avg_z /= num_samples;

  // Work out deviations
  uint16_t biggest = 0;
  AccelData *d = data;
  for (uint32_t i = 0; i < num_samples; i++, d++) {
    do_axis(d->x, &biggest, avg_x);
    do_axis(d->y, &biggest, avg_y);
    do_axis(d->z, &biggest, avg_z);
  }

  store_sample(biggest);
}
Beispiel #3
0
void
win32joystick_move( int which_joystick, unsigned short pos_x,
                    unsigned short pos_y )
{
  do_axis( which_joystick, pos_x,
    INPUT_JOYSTICK_LEFT, INPUT_JOYSTICK_RIGHT );
  do_axis( which_joystick, pos_y,
    INPUT_JOYSTICK_UP,   INPUT_JOYSTICK_DOWN  );
}
void
sdljoystick_axismove( SDL_JoyAxisEvent *axisevent )
{
  if( axisevent->axis == 0 ) {
    do_axis( axisevent->which, axisevent->value,
	     INPUT_JOYSTICK_LEFT, INPUT_JOYSTICK_RIGHT );
  } else if( axisevent->axis == 1 ) {
    do_axis( axisevent->which, axisevent->value,
	     INPUT_JOYSTICK_UP,   INPUT_JOYSTICK_DOWN  );
  }
}
Beispiel #5
0
static void
poll_joystick( int which )
{
  js_data_struct *joystick;
  double position;
  int fire, buttons;
  input_event_t event;
  size_t i;

  joystick = &jsd[which];

  if( JSUpdate( joystick ) != JSGotEvent ) return;

  position = JSGetAxisCoeffNZ( joystick, 0 );
  do_axis( which, position, INPUT_JOYSTICK_LEFT, INPUT_JOYSTICK_RIGHT );

  position = JSGetAxisCoeffNZ( joystick, 1 );
  do_axis( which, position, INPUT_JOYSTICK_UP,   INPUT_JOYSTICK_DOWN  );

  event.types.joystick.which = which;

  buttons = joystick->total_buttons;
  if( buttons > 10 ) buttons = 10;	/* We support 'only' 10 fire buttons */

  for( i = 0; i < buttons; i++ ) {

    fire = JSGetButtonState( joystick, i );
    if( fire == JSButtonStateOn ) {
      event.type = INPUT_EVENT_JOYSTICK_PRESS;
    } else {
      event.type = INPUT_EVENT_JOYSTICK_RELEASE;
    }

    event.types.joystick.button = INPUT_JOYSTICK_FIRE_1 + i;
  }

  input_event( &event );
}