示例#1
0
static void scan_left_joystick(struct kp *kp)
{
	if (kp->suspend_flag) {
		kp->value[0] = 0x7f;
		kp->value[1] = 0x7f;
	} else {
		//left_h, left_v, right_h, right_v
		soc_value(kp->value);
	}
	scan_joystick(kp, 0);
	scan_joystick(kp, 1);
}
示例#2
0
static void scan_right_joystick(struct kp *kp)
{
	if (kp->suspend_flag) {
		kp->value[2] = 0x7f;
		kp->value[3] = 0x7f;
	} else {
		//left_h, left_v, right_h, right_v
		soc_value(kp->value);
	}
	scan_joystick(kp, 2);
	scan_joystick(kp, 3);
	//scan_joystick_absnormal(kp, 2);
	//scan_joystick_absnormal(kp, 3);
}
示例#3
0
static void scan_right_joystick(struct kp *kp)
{
	scan_joystick(kp, 0);
	scan_joystick(kp, 1);
	return 0;
}
示例#4
0
文件: event.c 项目: MrAlert/megazeux
static void poll_input(void)
{
  static Sint32 old_x = 1000, old_y = 1000;
  static Uint32 old_point = 0;
  static Uint32 old_btns[4] = {0};
  static Sint16 old_axes[4][4] = {{0}};
  static int old_type[4] =
  {
    WPAD_EXP_NONE, WPAD_EXP_NONE,
    WPAD_EXP_NONE, WPAD_EXP_NONE
  };
  static Uint32 old_gcbtns[4] = {0};
  static Sint8 old_gcaxes[4][4] = {{0}};
  static Uint16 old_modifiers = 0;
  static Uint8 old_mousebtns = 0;

  WPADData *wd;
  PADStatus pad[4];
  keyboard_event ke;
  mouse_event me;
  u32 type;
  union event ev;
  Uint32 i, j;

  WPAD_ScanPads();
  for(i = 0; i < 4; i++)
  {
    if(WPAD_Probe(i, &type) == WPAD_ERR_NONE)
    {
      wd = WPAD_Data(i);
      if((int)type != old_type[i])
      {
        scan_buttons(i, old_btns[i], 0);
        old_btns[i] = 0;
        ev.type = EVENT_AXIS_MOVE;
        ev.axis.pad = i;
        ev.axis.pos = 0;
        for(j = 0; j < 4; j++)
        {
          if(old_axes[i][j])
          {
            ev.axis.axis = j;
            write_eq(&ev);
            old_axes[i][j] = 0;
          }
        }
        ev.type = EVENT_CHANGE_EXT;
        ev.ext.pad = i;
        old_type[i] = ev.ext.ext = type;
        write_eq(&ev);
      }
      if(i == 0)
      {
        if(wd->ir.valid)
        {
          ev.pointer.x = wd->ir.x - PTR_BORDER_W;
          ev.pointer.y = wd->ir.y - PTR_BORDER_H;
          if (ev.pointer.x < 0)
            ev.pointer.x = 0;
          if (ev.pointer.y < 0)
            ev.pointer.y = 0;
          if (ev.pointer.x >= 640)
            ev.pointer.x = 639;
          if (ev.pointer.y >= 350)
            ev.pointer.y = 349;
          if ((ev.pointer.x != old_x) || (ev.pointer.y != old_y))
          {
            ev.type = EVENT_POINTER_MOVE;
            write_eq(&ev);
            old_point = 1;
            old_x = ev.pointer.x;
            old_y = ev.pointer.y;
          }
        }
        else
        {
          if(old_point)
          {
            ev.type = EVENT_POINTER_OUT;
            write_eq(&ev);
            old_point = 0;
            old_x = old_y = 1000;
          }
        }
      }
      scan_buttons(i, old_btns[i], wd->btns_h);
      old_btns[i] = wd->btns_h;
      switch(type)
      {
        case WPAD_EXP_NUNCHUK:
        {
          scan_joystick(i, 0, wd->exp.nunchuk.js, old_axes[i]);
          break;
        }
        case WPAD_EXP_CLASSIC:
        {
          scan_joystick(i, 0, wd->exp.classic.ljs, old_axes[i]);
          scan_joystick(i, 2, wd->exp.classic.rjs, old_axes[i] + 2);
          break;
        }
        case WPAD_EXP_GUITARHERO3:
        {
          scan_joystick(i, 0, wd->exp.gh3.js, old_axes[i]);
          j = (int)(wd->exp.gh3.whammy_bar * 32767.0);
          if((int)j != old_axes[i][2])
          {
            ev.type = EVENT_AXIS_MOVE;
            ev.axis.pad = i;
            ev.axis.pos = j;
            write_eq(&ev);
          }
          break;
        }
        default: break;
      }
    }
    else
    {
      scan_buttons(i, old_btns[i], 0);
      old_btns[i] = 0;
      ev.type = EVENT_AXIS_MOVE;
      ev.axis.pad = i;
      ev.axis.pos = 0;
      for(j = 0; j < 4; j++)
      {
        if(old_axes[i][j])
        {
          ev.axis.axis = j;
          write_eq(&ev);
          old_axes[i][j] = 0;
        }
      }
    }
  }

  PAD_Read(pad);
  for(i = 0; i < 4; i++)
  {
    if(pad[i].err == PAD_ERR_NONE)
    {
      scan_buttons(i + 4, old_gcbtns[i], pad[i].button);
      old_gcbtns[i] = pad[i].button;
      ev.type = EVENT_AXIS_MOVE;
      ev.axis.pad = i + 4;
      if(pad[i].stickX != old_gcaxes[i][0])
      {
        ev.axis.axis = 0;
        ev.axis.pos = pad[i].stickX << 8;
        write_eq(&ev);
        old_gcaxes[i][0] = pad[i].stickX;
      }
      if(pad[i].stickY != old_gcaxes[i][1])
      {
        ev.axis.axis = 1;
        ev.axis.pos = -(pad[i].stickY << 8);
        write_eq(&ev);
        old_gcaxes[i][1] = pad[i].stickY;
      }
      if(pad[i].substickX != old_gcaxes[i][2])
      {
        ev.axis.axis = 2;
        ev.axis.pos = pad[i].substickX << 8;
        write_eq(&ev);
        old_gcaxes[i][0] = pad[i].substickX;
      }
      if(pad[i].substickY != old_gcaxes[i][3])
      {
        ev.axis.axis = 3;
        ev.axis.pos = -(pad[i].substickY << 8);
        write_eq(&ev);
        old_gcaxes[i][1] = pad[i].substickY;
      }
    }
    else
    {
      scan_buttons(i + 4, old_gcbtns[i], 0);
      old_gcbtns[i] = 0;
      ev.type = EVENT_AXIS_MOVE;
      ev.axis.pad = i + 4;
      ev.axis.pos = 0;
      for(j = 0; j < 4; j++)
      {
        if(old_gcaxes[i][j])
        {
          ev.axis.axis = j;
          write_eq(&ev);
          old_gcaxes[i][j] = 0;
        }
      }
    }
  }

  while(KEYBOARD_GetEvent(&ke))
  {
    ke.modifiers &= MOD_CAPSLOCK | MOD_NUMLOCK;
    if(ke.modifiers != old_modifiers)
    {
      ev.type = EVENT_KEY_LOCKS;
      ev.locks.locks = ke.modifiers;
      write_eq(&ev);
      old_modifiers = ke.modifiers;
    }
    ev.key.key = ke.keycode;
    // Non-character keys mapped to the private use area
    if((ke.symbol >= 0xE000) && (ke.symbol < 0xF900))
      ev.key.unicode = 0;
    else
      ev.key.unicode = ke.symbol;
    switch(ke.type)
    {
      default:
      case KEYBOARD_CONNECTED:
      case KEYBOARD_DISCONNECTED:
        break;
      case KEYBOARD_PRESSED:
        ev.type = EVENT_KEY_DOWN;
        write_eq(&ev);
        break;
      case KEYBOARD_RELEASED:
        ev.type = EVENT_KEY_UP;
        write_eq(&ev);
        break;
    }
  }

  ev.type = EVENT_MOUSE_MOVE;
  ev.mmove.dx = ev.mmove.dy = 0;
  while(MOUSE_GetEvent(&me))
  {
    ev.mmove.dx += me.rx;
    ev.mmove.dy += me.ry;
    me.button &= USB_MOUSE_BTN_MASK;
    if(me.button != old_mousebtns)
    {
      if(ev.mmove.dx || ev.mmove.dy)
        write_eq(&ev);
      for(i = 1; i <= (me.button | old_mousebtns); i <<= 1)
      {
        if(i & (me.button ^ old_mousebtns))
        {
          if(i & me.button)
            ev.type = EVENT_MOUSE_BUTTON_DOWN;
          else
            ev.type = EVENT_MOUSE_BUTTON_UP;
          ev.mbutton.button = i;
          write_eq(&ev);
        }
      }
      old_mousebtns = me.button;
      ev.type = EVENT_MOUSE_MOVE;
      ev.mmove.dx = ev.mmove.dy = 0;
    }
  }
  if(ev.mmove.dx || ev.mmove.dy)
    write_eq(&ev);
}
示例#5
0
static void scan_left_joystick(struct kp *kp)
{
	scan_joystick(kp, 2);
	scan_joystick(kp, 3);
	return 0;
}