Пример #1
0
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
  switch (id) {
    // The OS-Toggle function toggles our concept of mac or windows
    case FNOSTOGGLE:
      if (IS_RELEASED(record->event)) {
        is_mac = !is_mac;
        // Blink blue for mac, red otherwise
        blink_led(is_mac ? 3 : 1);
      }
      return;

    // The copy-cut function sends the copy key sequence for mac or windows
    // when it is pressed.  If shift is held down, it will send the cut key
    // sequence instead, and cancels the shift modifier.
    case FNCOPYCUT:
      if (IS_RELEASED(record->event)) {
        int8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));

        // Implicitly release the shift key so that it doesn't
        // mess with the macro that we play back
        unregister_mods(shifted);

        if (shifted) {
          action_macro_play(is_mac ? mac_cut : win_cut);
        } else {
          action_macro_play(is_mac ? mac_copy : win_copy);
        }
      }
      return;
  }
}
Пример #2
0
/** \brief Called to execute an action.
 *
 * FIXME: Needs documentation.
 */
void action_exec(keyevent_t event)
{
    if (!IS_NOEVENT(event)) {
        dprint("\n---- action_exec: start -----\n");
        dprint("EVENT: "); debug_event(event); dprintln();
#ifdef RETRO_TAPPING
        retro_tapping_counter++;
#endif
    }

#ifdef FAUXCLICKY_ENABLE
    if (IS_PRESSED(event)) {
        FAUXCLICKY_ACTION_PRESS;
    }
    if (IS_RELEASED(event)) {
        FAUXCLICKY_ACTION_RELEASE;
    }
    fauxclicky_check();
#endif

#ifdef SWAP_HANDS_ENABLE
    if (!IS_NOEVENT(event)) {
        process_hand_swap(&event);
    }
#endif

    keyrecord_t record = { .event = event };

#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
    if (has_oneshot_layer_timed_out()) {
        clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
    }
    if (has_oneshot_mods_timed_out()) {
        clear_oneshot_mods();
    }
#endif

#ifndef NO_ACTION_TAPPING
    action_tapping_process(record);
#else
    process_record(&record);
    if (!IS_NOEVENT(record.event)) {
        dprint("processed: "); debug_record(record); dprintln();
    }
#endif
}
void handle_event(struct wiimote_t* wm) {
	
	if (wm->exp.type == EXP_GUITAR_HERO_3) 
	{
		
		struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3;

		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP))				ActivateOutput(&m_actInfo, GH3_STRUM_UP, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN))			ActivateOutput(&m_actInfo, GH3_STRUM_DOWN, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW))				ActivateOutput(&m_actInfo, GH3_YELLOW, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN))				ActivateOutput(&m_actInfo, GH3_GREEN, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE))					ActivateOutput(&m_actInfo, GH3_BLUE, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED))					ActivateOutput(&m_actInfo, GH3_RED, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE))				ActivateOutput(&m_actInfo, GH3_ORANGE, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS))					ActivateOutput(&m_actInfo, GH3_PLUS, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS))				ActivateOutput(&m_actInfo, GH3_MINUS, true);
			
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP))					ActivateOutput(&m_actInfo, GH3_STRUM_UP, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN))				ActivateOutput(&m_actInfo, GH3_STRUM_DOWN, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_YELLOW))					ActivateOutput(&m_actInfo, GH3_YELLOW, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_GREEN))					ActivateOutput(&m_actInfo, GH3_GREEN, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_BLUE))						ActivateOutput(&m_actInfo, GH3_BLUE, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_RED))						ActivateOutput(&m_actInfo, GH3_RED, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_ORANGE))					ActivateOutput(&m_actInfo, GH3_ORANGE, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_PLUS))						ActivateOutput(&m_actInfo, GH3_PLUS, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_MINUS))					ActivateOutput(&m_actInfo, GH3_MINUS, false);
		
		
		if(!gh3_move) {
			ActivateOutput(&m_actInfo, GH3_BAR,  gh3->whammy_bar);
			ActivateOutput(&m_actInfo, GH3_JOYSTICK_ANGLE, gh3->js.ang);
			ActivateOutput(&m_actInfo, GH3_JOYSTICK_MAG, gh3->js.mag);
		}

		gh3_move=true;
	}
}
Пример #4
0
void CWiiController::get_keys(wiimote* wm)
{
  m_buttonHeld = 0;
  m_buttonPressed = 0;
  m_buttonReleased = 0;

  m_repeatableHeld = (wm->btns & (m_repeatFlags));
  m_holdableHeld = (wm->btns & (m_holdFlags));
  m_repeatableReleased = (wm->btns_released & (m_repeatFlags));
  m_holdableReleased = (wm->btns_released & (m_holdFlags));

  for (int i = 1;i <= WIIMOTE_NUM_BUTTONS; i++)
  {
    if (IS_PRESSED(wm,convert_code(i)))
      m_buttonPressed = i;
    if (IS_RELEASED(wm,convert_code(i)))
      m_buttonReleased = i;
    if (IS_HELD(wm,convert_code(i)))
      m_buttonHeld = i;
  }
}
Пример #5
0
/* return true when key event is processed or consumed. */
bool process_tapping(keyrecord_t *keyp)
{
    keyevent_t event = keyp->event;

    // if tapping
    if (IS_TAPPING_PRESSED()) {
        if (WITHIN_TAPPING_TERM(event)) {
            if (tapping_key.tap.count == 0) {
                if (IS_TAPPING_KEY(event.key) && !event.pressed) {
                    // first tap!
                    debug("Tapping: First tap(0->1).\n");
                    tapping_key.tap.count = 1;
                    debug_tapping_key();
                    process_action(&tapping_key);

                    // copy tapping state
                    keyp->tap = tapping_key.tap;
                    // enqueue
                    return false;
                }
#if TAPPING_TERM >= 500
                /* Process a key typed within TAPPING_TERM
                 * This can register the key before settlement of tapping,
                 * useful for long TAPPING_TERM but may prevent fast typing.
                 */
                else if (IS_RELEASED(event) && waiting_buffer_typed(event)) {
                    debug("Tapping: End. No tap. Interfered by typing key\n");
                    process_action(&tapping_key);
                    tapping_key = (keyrecord_t){};
                    debug_tapping_key();
                    // enqueue
                    return false;
                }
#endif
                /* Process release event of a key pressed before tapping starts
                 * Without this unexpected repeating will occur with having fast repeating setting
                 * https://github.com/tmk/tmk_keyboard/issues/60
                 */
                else if (IS_RELEASED(event) && !waiting_buffer_typed(event)) {
                    // Modifier should be retained till end of this tapping.
                    action_t action = layer_switch_get_action(event.key);
                    switch (action.kind.id) {
                        case ACT_LMODS:
                        case ACT_RMODS:
                            if (action.key.mods && !action.key.code) return false;
                            if (IS_MOD(action.key.code)) return false;
                            break;
                        case ACT_LMODS_TAP:
                        case ACT_RMODS_TAP:
                            if (action.key.mods && keyp->tap.count == 0) return false;
                            if (IS_MOD(action.key.code)) return false;
                            break;
                    }
                    // Release of key should be process immediately.
                    debug("Tapping: release event of a key pressed before tapping\n");
                    process_action(keyp);
                    return true;
                }
                else {
                    // set interrupted flag when other key preesed during tapping
                    if (event.pressed) {
                        tapping_key.tap.interrupted = true;
                    }
                    // enqueue 
                    return false;
                }
            }
            // tap_count > 0
            else {
                if (IS_TAPPING_KEY(event.key) && !event.pressed) {
                    debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n");
                    keyp->tap = tapping_key.tap;
                    process_action(keyp);
                    tapping_key = *keyp;
                    debug_tapping_key();
                    return true;
                }
                else if (is_tap_key(event.key) && event.pressed) {
                    if (tapping_key.tap.count > 1) {
                        debug("Tapping: Start new tap with releasing last tap(>1).\n");
                        // unregister key
                        process_action(&(keyrecord_t){
                                .tap = tapping_key.tap,
                                .event.key = tapping_key.event.key,
                                .event.time = event.time,
                                .event.pressed = false
                        });
                    } else {
                        debug("Tapping: Start while last tap(1).\n");
                    }
                    tapping_key = *keyp;
                    waiting_buffer_scan_tap();
                    debug_tapping_key();
                    return true;
                }
                else {
                    if (!IS_NOEVENT(event)) {
Пример #6
0
void	kbd_add_char(int code)
{
  static int		flags = 0;
  static int		last_char_length = 0;
  int			kbd_ready = 0;
  int			scancode;

  if (kbd_off < sizeof(kbd_buf))
    {
      scancode = GET_SCANCODE(code);
      if (IS_RELEASED(code))
	flags &= ~KEY_PRESSED;
      else
	flags |= KEY_PRESSED;

      switch (scancode)
	{
	  /* Check for left and right maj keys. */
	case 0x36:
	case 0x2a:
	  if (IS_RELEASED(code))
	    flags &= ~UPCASE_MODE;
	  else
	    flags |= UPCASE_MODE;
	  break;
	default:
	  if (IS_UPCASE(flags))
	    {
	      if (!IS_KEYPRESS(flags))
		{
		  if (upcase_map[scancode] != NULL)
		    {
		      if (upcase_map[scancode][0] == '\b')
			kbd_off -= last_char_length;
		      else
			{
			  last_char_length = strlen(upcase_map[scancode]);
			  memcpy(kbd_buf + kbd_off,
				 upcase_map[scancode],
				 last_char_length);
			  kbd_off += last_char_length;
			}
		      if (last_char_length)
			puts(upcase_map[scancode]);
		    }
		  else
		    puts("Unknow escape code!");
		}
	    }
	  else
	    {
	      if (!IS_KEYPRESS(flags))
		{
		  if (locase_map[scancode] != NULL)
		    {
		      if (locase_map[scancode][0] == '\b')
			kbd_off -= last_char_length;
		      else
			{
			  last_char_length = strlen(locase_map[scancode]);
			  memcpy(kbd_buf + kbd_off,
				 locase_map[scancode],
				 last_char_length);
			  kbd_off += last_char_length;
			}
		      if (last_char_length)
			puts(locase_map[scancode]);
		    }
		  else
		    puts("Unknow escape code!");
		}
	    }
	}
    }
  if (kbd_off == sizeof(kbd_buf) || kbd_buf[kbd_off - 1] == '\n')
    kbd_ready = 1;
  if (kbd_ready == 1)
    {
      memcpy(kbd_ubuf, kbd_buf, kbd_off);
      kbd_usize = kbd_off;
      kbd_ubuf[kbd_usize] = '\0';
      kbd_off = 0;
    }
}
Пример #7
0
int main(int argc, char** argv)
{
    InitWiimotes();

    bool bLoop = true;
    int nCursorControl = CUR_CTRL_ARROWS;
    float fMouseSpeedX=0;
    float fMouseSpeedY=0;

    int nPrecX, nPrecY;


    while(bLoop)
    {

        int n;

        if(wiiuse_poll(WMTable, nConnectedWM))
        {
            for (n=0 ; n>nConnectedWM; n++);
            {
                switch(WMTable[n]->event)
                {
                    case WIIUSE_NONE:
                        break;

                    case WIIUSE_CONNECT:
                        printf("Wiimote connectee\n");break;
					case WIIUSE_DISCONNECT:
                        printf("Wiimote deconnectee\n");break;
					case WIIUSE_UNEXPECTED_DISCONNECT:
                        printf("Wiimote deconnectee a la bourrin\n");break;

                    case WIIUSE_EVENT:


                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_TWO)) printf("2 NON SUPPORTE\n");

                        //Touche combo !
                        while(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_ONE) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_ONE))
                        {
                            while(wiiuse_poll(WMTable, nConnectedWM))
                            {
                                if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_B))
                                {
                                    printf("Controle du curseur par pointage\n");
                                    nPrecX=-1;
                                    nPrecY=-1;
                                    nCursorControl = CUR_CTRL_MOTPOINT;
                                    break;
                                }
                                else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_A))
                                {
                                    printf("Controle du curseur en manette\n");
                                    nPrecX=-1;
                                    nPrecY=-1;
                                    nCursorControl = CUR_CTRL_MOTPAD;
                                    break;
                                }
                                else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_HOME))
                                {
                                    printf("Controle du curseur via IR\n");
                                    nPrecX=-1;
                                    nPrecY=-1;
                                    nCursorControl = CUR_CTRL_IR;
                                    break;
                                }
                                else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_UP) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_DOWN) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_RIGHT) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_LEFT))
                                {
                                    printf("Controle du curseur avec les fleches\n");
                                    nPrecX=-1;
                                    nPrecY=-1;
                                    nCursorControl = CUR_CTRL_ARROWS;
                                    break;
                                }
                            }
                        }


                        //Souris . Clic gauche = B
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_B))
                            mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
                        if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_B))
                            mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
                        //

                        //Souris . molette haut
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_MINUS))
                            mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 120, 0);
                        //

                        //Souris . Bouton milieu = HOME
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_HOME))
                            mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
                        if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_HOME))
                            mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
                        //

                        //Souris . molette bas
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_PLUS))
                            mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -120, 0);
                        //

                        //Souris . Clic droit = A
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_A))
                            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_A))
                            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                        //
                        break;

					case WIIUSE_STATUS:
                        printf("Wiimote status\n");
                        printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", WMTable[n]->unid);
                        printf("leds:            %i %i %i %i\n", WIIUSE_IS_LED_SET(WMTable[n], 1), WIIUSE_IS_LED_SET(WMTable[n], 2), WIIUSE_IS_LED_SET(WMTable[n], 3), WIIUSE_IS_LED_SET(WMTable[n], 4));
                        printf("battery:         %.1f %%\n", 100*WMTable[n]->battery_level);
                        break;

					case WIIUSE_READ_DATA:
                        printf("Wiimote read\n");
                        break;


					case WIIUSE_NUNCHUK_INSERTED:
                        printf("Nunchuk insere\n");break;
					case WIIUSE_NUNCHUK_REMOVED:
                        printf("Nunchuk enleve\n");break;

					case WIIUSE_CLASSIC_CTRL_INSERTED:
					case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
					case WIIUSE_CLASSIC_CTRL_REMOVED:
					case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
                        break;
                }
            }
        }
        //else//Pas d'event
        {
            for (n=0 ; n>nConnectedWM; n++);
            {

                //Déplacement de la souris
                tagPOINT CursorPos;

                if(nCursorControl==CUR_CTRL_MOTPOINT || nCursorControl==CUR_CTRL_MOTPAD)
                {
                    //Décélération permanente
                    if(fMouseSpeedX<0)
                    {
                        if(fMouseSpeedX+ABSOLUTE_DECEL>0)fMouseSpeedX=0;
                        else fMouseSpeedX+=ABSOLUTE_DECEL;
                    }
                    else if(fMouseSpeedX>0)
                    {
                        if(fMouseSpeedX-ABSOLUTE_DECEL<0)fMouseSpeedX=0;
                        else fMouseSpeedX-=ABSOLUTE_DECEL;
                    }
                    if(fMouseSpeedY<0)
                    {
                        if(fMouseSpeedY+ABSOLUTE_DECEL>0)fMouseSpeedY=0;
                        else fMouseSpeedY+=ABSOLUTE_DECEL;
                    }
                    else if(fMouseSpeedY>0)
                    {
                        if(fMouseSpeedY-ABSOLUTE_DECEL<0)fMouseSpeedY=0;
                        else fMouseSpeedY-=ABSOLUTE_DECEL;
                    }



                    //Calcul des coordonnées sur l'écran du point donné par la wiimote
                    int nWiimoteX;
                    int nWiimoteY;
                    if(nCursorControl==CUR_CTRL_MOTPOINT)
                    {
                        nWiimoteX = ((WMTable[0]->orient.roll+45)/90)*SCREEN_WIDTH;
                        nWiimoteY = ((WMTable[0]->orient.pitch+60)/90)*SCREEN_HEIGHT;
                    }
                    else if(nCursorControl==CUR_CTRL_MOTPAD)
                    {
                        nWiimoteX = ((WMTable[0]->orient.pitch+45)/90)*SCREEN_WIDTH;
                        nWiimoteY = ((-WMTable[0]->orient.roll+45)/90)*SCREEN_HEIGHT;
                    }

                    //Calcul de la vitesse du curseur
                    GetCursorPos(&CursorPos);


                    //Elimination des valeurs parasites
                    //if((abs(nWiimoteX-nPrecX)<10 && abs(nWiimoteY-nPrecY)<10) || (nPrecX==-1 && nPrecY==-1))
                    {
                        fMouseSpeedX = (nWiimoteX - CursorPos.x)/RELATIVE_ACCEL_RATIO;
                        fMouseSpeedY = (nWiimoteY - CursorPos.y)/RELATIVE_ACCEL_RATIO;
                    }
                    /*else
                    {
                        fMouseSpeedX = (nPrecX - CursorPos.x)/RELATIVE_ACCEL_RATIO;
                        fMouseSpeedY = (nPrecY - CursorPos.y)/RELATIVE_ACCEL_RATIO;
                    }*/
                    //

                    SetCursorPos(CursorPos.x+fMouseSpeedX, CursorPos.y+fMouseSpeedY);

                    nPrecX=nWiimoteX;
                    nPrecY=nWiimoteY;


                }
                else if(nCursorControl==CUR_CTRL_IR)
                {

                    int nSommeX=0, nSommeY=0, nDots=0;
                    for(int i=0 ; i<4 ; i++)
                    {
                        if(WMTable[n]->ir.dot[i].visible)
                        {
                            nDots++;
                            nSommeX+=WMTable[n]->ir.dot[i].x;
                            nSommeY+=WMTable[n]->ir.dot[i].y;
                        }
                    }

                    float fCenterX=-1.0, fCenterY=-1.0;

                    if(nDots!=0)
                    {
                        fCenterX=nSommeX/nDots;
                        fCenterY=nSommeY/nDots;
                    }


                    if(fCenterX!=-1.0 && fCenterY!=-1.0)
                    {


                        int nWiimoteX = (fCenterX/1024)*(SCREEN_WIDTH+512)-256;
                        int nWiimoteY = (fCenterY/768)*(SCREEN_HEIGHT+384)-192;
                        SetCursorPos(nWiimoteX, nWiimoteY);
                    }



                }
                else
                {
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_UP) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_UP))
                    {
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x, CursorPos.y-ARROW_SPEED);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_DOWN) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_DOWN))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x, CursorPos.y+ARROW_SPEED);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_LEFT) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_LEFT))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x-ARROW_SPEED, CursorPos.y);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_RIGHT) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_RIGHT))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x+ARROW_SPEED, CursorPos.y);
                    }
                }
            }
        }
    }
    EndWiimotes();
}
        void handle_event( struct wiimote_t* wm )
        {

            if ( wm->exp.type == EXP_CLASSIC )
            {

                struct classic_ctrl_t* cc = ( classic_ctrl_t* )&wm->exp.classic;

                //OK
                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_A ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_A, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_B ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_B, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_X ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_X, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_Y ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_Y, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_ZL ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ZL, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_ZR ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ZR, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_UP ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_TOP, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_DOWN ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_DOWN, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_LEFT ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_LEFT, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_RIGHT ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_RIGHT, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_FULL_L ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_FULL_L, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_FULL_R ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_FULL_R, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_MINUS ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_MINUS, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_PLUS ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_PLUS, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_HOME ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_HOME, true );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_A ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_A, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_B ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_B, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_X ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_X, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_Y ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_Y, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_ZL ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ZL, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_ZR ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ZR, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_UP ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_TOP, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_DOWN ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_DOWN, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_LEFT ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_LEFT, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_RIGHT ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_RIGHT, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_FULL_L ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_FULL_L, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_FULL_R ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_FULL_R, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_MINUS ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_MINUS, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_PLUS ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_PLUS, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_HOME ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_HOME, false );
                }


                //Optimisation
                if ( !classic_move )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_SHOULDER_L, cc->l_shoulder );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_SHOULDER_R, cc->r_shoulder );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_LEFT_ANGLE, cc->ljs.ang );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_LEFT_MAG, cc->ljs.mag );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_RIGHT_ANGLE, cc->rjs.ang );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_RIGHT_MAG, cc->rjs.mag );

                    classic_move = true;
                }
            }

            /*
            else {
                //ActivateOutput(&m_actInfo, 0, "Incompatible expansion type");
                //CryLogAlways("Bad Expansion type");
            }
            */
        }
        void handle_event( struct wiimote_t* wm )
        {

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_A ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_A, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_A ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_A, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_B ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_B, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_B ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_B, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_DOWN ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_DOWN, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_DOWN ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_DOWN, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_LEFT ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_LEFT, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_LEFT ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_LEFT, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_RIGHT ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_RIGHT, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_RIGHT ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_RIGHT, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_UP ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_UP, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_UP ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_UP, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_MINUS ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_MINUS, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_MINUS ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_MINUS, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_PLUS ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_PLUS, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_PLUS ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_PLUS, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_HOME ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_HOME, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_HOME ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_HOME, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_ONE ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_ONE, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_ONE ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_ONE, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_TWO ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_TWO, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_TWO ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_TWO, false );
            }



            if ( WIIUSE_USING_ACC( wm ) && !wiimote_move )
            {
                //Optimisation v0.1
                wiimote_move = true;
                Vec3 orient = Vec3( wm->orient.a_roll, wm->orient.a_pitch, wm->orient.yaw );
                ActivateOutput( &m_actInfo, WIIMOTE_RPY, orient );
            }

            /*
            if (WIIUSE_USING_IR(wm)) {
                int i = 0;

                for (; i < 4; ++i) {
                    if (wm->ir.dot[i].visible) {
                        CryLogAlways("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y);
                    }
                }

                //CryLogAlways("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
                //CryLogAlways("IR z distance: %f\n", wm->ir.z);
            }
            */
            /* show events specific to supported expansions */

            if ( wm->exp.type == EXP_NUNCHUK && !nunchuk_move )
            {
                nunchuk_move = true;
                struct nunchuk_t* nc = ( nunchuk_t* )&wm->exp.nunchuk;

                if ( IS_PRESSED( nc, NUNCHUK_BUTTON_C ) )
                {
                    ActivateOutput( &m_actInfo, NUNCHUK_C, true );

                }

                if ( IS_PRESSED( nc, NUNCHUK_BUTTON_Z ) )
                {
                    ActivateOutput( &m_actInfo, NUNCHUK_Z, true );

                }

                //Optimisation necessaire ici !
                Vec3 orient = Vec3( nc->orient.roll, nc->orient.pitch, nc->orient.yaw );
                ActivateOutput( &m_actInfo, NUNCHUK_RPY, orient );

                Vec3 joy = Vec3( nc->js.ang, nc->js.mag, 0 );
                ActivateOutput( &m_actInfo, NUNCHUK_JOYSTICK, joy );
            }

        }
Пример #10
0
enum state input_wiimote(struct game* game, enum state state2) { // state : 0 = MENU, 1 = GAME

	key_event_t key_event;
	SDLKey key;
	enum state state = state2;

	if(wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
		for (int i = 0; i < MAX_WIIMOTES; ++i) {
			//printf("wiimote %d: btns: %d,  held, %d releaded: %d\n", i, wiimotes[i]->btns, wiimotes[i]->btns_held, wiimotes[i]->btns_released);
			if(wiimotes[i]->event == WIIUSE_EVENT) {

				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_RIGHT)) {
					switch(i) {
					case 0:
						key = SDLK_UP;
						break;
					case 1:
						key = SDLK_z;
						break;
					case 2:
						key = SDLK_t;
						break;
					case 3:
						key = SDLK_i;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_LEFT)) {
					switch(i) {
					case 0:
						key = SDLK_DOWN;
						break;
					case 1:
						key = SDLK_s;
						break;
					case 2:
						key = SDLK_g;
						break;
					case 3:
						key = SDLK_k;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_UP)) {
					switch(i) {
					case 0:
						key = SDLK_LEFT;
						break;
					case 1:
						key = SDLK_q;
						break;
					case 2:
						key = SDLK_f;
						break;
					case 3:
						key = SDLK_j;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_DOWN)) {
					switch(i) {
					case 0:
						key = SDLK_RIGHT;
						break;
					case 1:
						key = SDLK_d;
						break;
					case 2:
						key = SDLK_h;
						break;
					case 3:
						key = SDLK_l;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_ONE)) {
					switch(i) {
					case 0:
						key = SDLK_SPACE;
						break;
					case 1:
						key = SDLK_a;
						break;
					case 2:
						key = SDLK_r;
						break;
					case 3:
						key = SDLK_u;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[0], WIIMOTE_BUTTON_TWO)) {
					key = SDLK_RETURN;
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[0], WIIMOTE_BUTTON_HOME)) {
					key = SDLK_ESCAPE;
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}

				if(IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_RIGHT)) {
					switch(i) {
					case 0:
						key = SDLK_UP;
						break;
					case 1:
						key = SDLK_z;
						break;
					case 2:
						key = SDLK_t;
						break;
					case 3:
						key = SDLK_i;
						break;
					}
					key_event = UP;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_LEFT)) {
					switch(i) {
					case 0:
						key = SDLK_DOWN;
						break;
					case 1:
						key = SDLK_s;
						break;
					case 2:
						key = SDLK_g;
						break;
					case 3:
						key = SDLK_k;
						break;
					}
					key_event = UP;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_UP)) {
					switch(i) {
					case 0:
						key = SDLK_LEFT;
						break;
					case 1:
						key = SDLK_q;
						break;
					case 2:
						key = SDLK_f;
						break;
					case 3:
						key = SDLK_j;
						break;
					}
					key_event = UP;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_DOWN)) {
					switch(i) {
					case 0:
						key = SDLK_RIGHT;
						break;
					case 1:
						key = SDLK_d;
						break;
					case 2:
						key = SDLK_h;
						break;
					case 3:
						key = SDLK_l;
						break;
					}
					key_event = UP;
					state = wiimote_send_event(state, game, key, key_event);
				}
			}
		}
	}
	return state;
}
Пример #11
0
int32_t wii_data(CSOUND *csound, WIIMOTE *p)
{
    wiimote **wii = p->wii;
    wiirange_t *wiir = p->wiir;
    int32_t n = (int32_t)*p->num;
    int32_t kontrol = (int32_t)(*p->kControl+FL(0.5));
    if (UNLIKELY(n>=MAX_WIIMOTES || !(wii[n]->state & WIIMOTE_STATE_CONNECTED))) {
      printf("state of wii %d is %x\n", n, wii[n]->state);
      return csound->PerfError(csound, &(p->h),
                               Str("wiimote %d does not exist"), n);
    }
    if (kontrol<0) {
      printf("%f -- %.4x: "
             "tilt=[%f %f];\nforce=(%f %f %f)\n",
             100.0*wii[n]->battery_level, wii[n]->btns,
             wiir[n].pitch_min+wiir[n].pitch_scale*(FL(90.0)+
                                                    (MYFLT)wii[n]->orient.pitch),
             wiir[n].roll_min+wiir[n].roll_scale*(FL(90.0)-
                                                  (MYFLT)wii[n]->orient.roll),
             wii[n]->gforce.x, wii[n]->gforce.y, wii[n]->gforce.z);
      *p->res = FL(0.0);
      return OK;
    }
    if (kontrol>0 && kontrol<17) {
      *p->res = (MYFLT)IS_JUST_PRESSED(wii[n], 1<<(kontrol-1));
    }
    if (kontrol>100 && kontrol<117) {
      *p->res = (MYFLT)IS_PRESSED(wii[n], 1<<(kontrol-101));
      return OK;
     }
    if (kontrol>200 && kontrol<217) {
      *p->res = (MYFLT)IS_HELD(wii[n], 1<<(kontrol-201));
      return OK;
     }
    if (kontrol>300 && kontrol<317) {
      *p->res = (MYFLT)IS_RELEASED(wii[n], 1<<(kontrol-301));
      return OK;
     }
    else switch (kontrol) {
    case WII_BUTTONS:
      *p->res = (MYFLT)(wii[n]->btns&WIIMOTE_BUTTON_ALL);
      return OK;
    /* case 17: */
    /*   *p->res = wiir[n].axis_x_min+wiir[n].axis_x_scale*(MYFLT)wii[n]->axis.x; */
    /*   return OK; */
    /* case 18: */
    /*   *p->res = wiir[n].axis_y_min+wiir[n].axis_y_scale*(MYFLT)wii[n]->axis.y; */
    /*   return OK; */
    /* case 19: */
    /*   *p->res = wiir[n].axis_z_min+wiir[n].axis_z_scale*(MYFLT)wii[n]->axis.z; */
    /*   return OK; */
    case WII_PITCH:
      /* I think the sign is wrong so negated; inplies negative is down */
      *p->res = wiir[n].pitch_min+
        wiir[n].pitch_scale*(FL(90.0)-(MYFLT)wii[n]->orient.pitch);
      return OK;
    case WII_ROLL:
      *p->res = wiir[n].roll_min+
        wiir[n].roll_scale*(FL(90.0)+(MYFLT)wii[n]->orient.roll);
      return OK;
    /* case 22: */
    /*   *p->res = wiir[n].tilt_z_min+
         wiir[n].tilt_z_scale*(FL(90.0)-(MYFLT)wii[n]->tilt.z); */
    /*   return OK; */
    case WII_FORCE_X:
      *p->res = (MYFLT)wii[n]->gforce.x;
      return OK;
    case WII_FORCE_Y:
      *p->res = (MYFLT)wii[n]->gforce.y;
      return OK;
    case WII_FORCE_Z:
      *p->res = (MYFLT)wii[n]->gforce.z;
      return OK;
    case WII_FORCE_TOTAL:
      *p->res = SQRT(wii[n]->gforce.x*wii[n]->gforce.x+
                     wii[n]->gforce.y*wii[n]->gforce.y+
                     wii[n]->gforce.z*wii[n]->gforce.z);
      return OK;
    case WII_BATTERY:
      *p->res = FL(100.0)*(MYFLT)wii[n]->battery_level;
      return OK;
    case WII_NUNCHUK_ANG:
      *p->res = (MYFLT)wii[n]->exp.nunchuk.js.ang;
      return OK;
    case WII_NUNCHUK_MAG:
      *p->res = (MYFLT)wii[n]->exp.nunchuk.js.mag;
      return OK;
    case WII_NUNCHUK_PITCH:
      *p->res = wiir[n].nunchuk_pitch_min+
        wiir[n].nunchuk_pitch_scale*(FL(90.0)-
                                     (MYFLT)wii[n]->exp.nunchuk.orient.pitch);
      return OK;
    case WII_NUNCHUK_ROLL:
      *p->res = wiir[n].nunchuk_roll_min+
        wiir[n].nunchuk_roll_scale*(FL(90.0)-
                                    (MYFLT)wii[n]->exp.nunchuk.orient.roll);
     return OK;
    /* case 32: */
    /*   *p->res = (MYFLT)wii[n]->exp.nunchuk.axis.z; */
    /*   return OK; */
    case WII_NUNCHUK_Z:
      *p->res = (MYFLT)((wii[n]->exp.nunchuk.btns & NUNCHUK_BUTTON_Z)==
                        NUNCHUK_BUTTON_Z);
      return OK;
    case WII_NUNCHUK_C:
      *p->res = (MYFLT)((wii[n]->exp.nunchuk.btns & NUNCHUK_BUTTON_C)==
                        NUNCHUK_BUTTON_C);
      return OK;
    case WII_IR1_X:
      *p->res = (MYFLT)wii[n]->ir.x;
      return OK;
    case WII_IR1_Y:
      *p->res = (MYFLT)wii[n]->ir.y;
      return OK;
    case WII_IR1_Z:
      *p->res = (MYFLT)wii[n]->ir.z;
      return OK;
    }
    return NOTOK;
}