Example #1
0
/* button */
int l_guitar_button_pressed(lua_State* L)
{
	int top = lua_gettop(L);
	int pressed = 1;
	int i;
	struct guitar_hero_3_t* guitar = get_guitar();
	for (i = 1; i <= top && pressed; i++)
	{
		int type = lua_type(L, i);
		luaL_argcheck(L, type == LUA_TTABLE || type == LUA_TNUMBER, i, "must be a table or a number");
		if (type == LUA_TTABLE)
		{
			size_t size = lua_objlen(L, i);
			int j;
			for (j = 1; j <= size && pressed; j++)
			{
				lua_pushinteger(L, j);
				lua_gettable(L, -2);
				int button = lua_tointeger(L, -1);
				pressed = IS_PRESSED(guitar, button);
			}
		}
		else
		{
			int button = lua_tointeger(L, i);
			pressed = IS_PRESSED(guitar, button);
		}
	}
	lua_pushboolean(L, pressed);
	return 1;
}
Example #2
0
int
main(int argc, char *argv[])
{
	int		 i, c, done;
	int		 offset;
	char	 buf[128], str[64];
	short	 temp;

	i = 0;
	offset = 0;
	init_board();

read_input:
	if (IS_PRESSED(BUTTON1)) {
		UART0_puts("_BALANCE:1_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON2)) {
		UART0_puts("_RECHARGE:1:", 64);
		escrevenum(leds_state);
		UART0_puts("_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON3)) {
		UART0_puts("_DISCHARGE:1:", 64);
		escrevenum(leds_state);
		UART0_puts("_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON4)) {
		leds_state++;
		UPDATE_LED();
		uwait(1000);
	} else if (IS_PRESSED(BUTTON5)) {
		leds_state--;
		UPDATE_LED();
		uwait(1000);
	}
	goto read_input;

	/* NOTREACHED */
	return (0);
}
Example #3
0
/** Prints debug information to Log::verbose about accelerometer and button
 *  states.
 */
void Wiimote::printDebugInfo() const
{
    struct WiimoteAction
    {
        int         wiimote_action_id;
        const char* wiimote_action_name;
    };   // struct WiimoteAction

    static WiimoteAction wiimote_actions[] = {
        {WIIMOTE_BUTTON_LEFT,   "WIIMOTE_BUTTON_LEFT" },
        {WIIMOTE_BUTTON_RIGHT,  "WIIMOTE_BUTTON_RIGHT"},
        {WIIMOTE_BUTTON_UP,     "WIIMOTE_BUTTON_UP"   },
        {WIIMOTE_BUTTON_DOWN,   "WIIMOTE_BUTTON_DOWN" },
        {WIIMOTE_BUTTON_A,      "WIIMOTE_BUTTON_A"    },
        {WIIMOTE_BUTTON_B,      "WIIMOTE_BUTTON_B"    },
        {WIIMOTE_BUTTON_PLUS,   "WIIMOTE_BUTTON_PLUS" },
        {WIIMOTE_BUTTON_MINUS,  "WIIMOTE_BUTTON_MINUS"},
        {WIIMOTE_BUTTON_ONE,    "WIIMOTE_BUTTON_ONE"  },
        {WIIMOTE_BUTTON_TWO,    "WIIMOTE_BUTTON_TWO"  },
        {WIIMOTE_BUTTON_HOME,   "WIIMOTE_BUTTON_HOME" },
    };   // wiimote_actions

    const unsigned int count = sizeof(wiimote_actions)/sizeof(WiimoteAction);
    for(unsigned int i=0 ; i<count; i++)
    {
        if(IS_PRESSED(m_wiimote_handle, wiimote_actions[i].wiimote_action_id))
        {
            Log::verbose("wiimote", "%d: pressed button %s -> button id: %d",
                m_wiimote_id, wiimote_actions[i].wiimote_action_name,
                i);
        }
    }   // for i < count
}   // printDebugInfo
Example #4
0
bool process_steno(uint16_t keycode, keyrecord_t *record) {
  switch (keycode) {
    case QK_STENO_BOLT:
      if (IS_PRESSED(record->event)) {
        steno_set_mode(STENO_MODE_BOLT);
      }
      return false;

    case QK_STENO_GEMINI:
      if (IS_PRESSED(record->event)) {
        steno_set_mode(STENO_MODE_GEMINI);
      }
      return false;

    case STN__MIN...STN__MAX:
      if (IS_PRESSED(record->event)) {
        uint8_t key = keycode - QK_STENO;
        ++pressed;
        switch(mode) {
          case STENO_MODE_BOLT:
            return update_state_bolt(key);
          case STENO_MODE_GEMINI:
            return update_state_gemini(key);
          default:
            return false;
        }
      } else {
        --pressed;
        if (pressed <= 0) {
          pressed = 0;
          switch(mode) {
            case STENO_MODE_BOLT:
              return send_state_bolt();
            case STENO_MODE_GEMINI:
              return send_state_gemini();
            default:
              return false;
          }
        }
      }

  }
  return true;
}
Example #5
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 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;
  }
}
Example #7
0
int handle_event(struct wiimote_t *wm)
{
  if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A)) { 
    currently_training = 1 - currently_training; 
  }

  int button = STOP_BUTTON; 

  //if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP))
  //  button = FORWARD_BUTTON; 

  if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) { 
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) { 
      button = FORWARD_BUTTON; 
    }
    else if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) { 
      button = FORWARD_BUTTON + 1000; 
    }
    }
  //else if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) { 
   // button = BACKWARD_BUTTON; 
  //}
  else if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) { 
    button = LEFT_TURN_BUTTON; 
  }
  else if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) { 
    button = RIGHT_TURN_BUTTON; 
  }
  else if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) { 
    button = ONE_BUTTON; 
  }
  else if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) { 
    button = TWO_BUTTON; 
  }

  return button; 
}
	/**
 *	@brief Callback that handles an event.
 *
 *	@param wm		Pointer to a wiimote_t structure.
 *
 *	This function is called automatically by the wiiuse library when an
 *	event occurs on the specified wiimote.
 */
void handle_event(struct wiimote_t* wm) {
	CryLogAlways("\n\n--- EVENT [id %i] ---\n", wm->unid);

	/* if a button is pressed, report it */
	
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_A))			{CryLogAlways("A pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_B))			{CryLogAlways("B pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP))			{CryLogAlways("UP pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN))		{CryLogAlways("DOWN pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))		{CryLogAlways("LEFT pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT))		{CryLogAlways("RIGHT pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS))		{CryLogAlways("MINUS pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS))		{CryLogAlways("PLUS pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE))			{CryLogAlways("ONE pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO))			{CryLogAlways("TWO pressed\n");}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME))		{CryLogAlways("HOME pressed\n");}
	
	/*
	 *	Pressing minus will tell the wiimote we are no longer interested in movement.
	 *	This is useful because it saves battery power.
	 */
	
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {wiiuse_motion_sensing(wm, 0);}
	
	/*
	 *	Pressing plus will tell the wiimote we are interested in movement.
	 */
	
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {wiiuse_motion_sensing(wm, 1);}
	
	/*
	 *	Pressing B will toggle the rumble
	 *
	 *	if B is pressed but is not held, toggle the rumble
	 */
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) {wiiuse_toggle_rumble(wm);}
	
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) {wiiuse_set_ir(wm, 1);}
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {wiiuse_set_ir(wm, 0);}
	
	/*
	 * Motion+ support
	 */
	
	/* if the accelerometer is turned on then print angles */
	
	if (WIIUSE_USING_ACC(wm)) {
		CryLogAlways("wiimote roll  = %f [%f]\n", wm->orient.roll, wm->orient.a_roll);
		CryLogAlways("wiimote pitch = %f [%f]\n", wm->orient.pitch, wm->orient.a_pitch);
		CryLogAlways("wiimote yaw   = %f\n", wm->orient.yaw);
	}
	
	/*
	 *	If IR tracking is enabled then print the coordinates
	 *	on the virtual screen that the wiimote is pointing to.
	 *
	 *	Also make sure that we see at least 1 dot.
	 */

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

		/* go through each of the 4 possible IR sources */
		for (; i < 4; ++i) {
			/* check if the source is visible */
			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) {
		struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;

		if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) {
			CryLogAlways("Nunchuk: C pressed\n");
		}
		if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) {
			CryLogAlways("Nunchuk: Z pressed\n");
		}

		CryLogAlways("nunchuk roll  = %f\n", nc->orient.roll);
		CryLogAlways("nunchuk pitch = %f\n", nc->orient.pitch);
		CryLogAlways("nunchuk yaw   = %f\n", nc->orient.yaw);

		CryLogAlways("nunchuk joystick angle:     %f\n", nc->js.ang);
		CryLogAlways("nunchuk joystick magnitude: %f\n", nc->js.mag);
	} 
	
	
	else if (wm->exp.type == EXP_CLASSIC) {
		
		struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic;

		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL))			{CryLogAlways("Classic: ZL pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B))			{CryLogAlways("Classic: B pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y))			{CryLogAlways("Classic: Y pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A))			{CryLogAlways("Classic: A pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X))			{CryLogAlways("Classic: X pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR))			{CryLogAlways("Classic: ZR pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT))		{CryLogAlways("Classic: LEFT pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP))			{CryLogAlways("Classic: UP pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT))		{CryLogAlways("Classic: RIGHT pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN))		{CryLogAlways("Classic: DOWN pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L))		{CryLogAlways("Classic: FULL L pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS))		{CryLogAlways("Classic: MINUS pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME))		{CryLogAlways("Classic: HOME pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS))		{CryLogAlways("Classic: PLUS pressed\n");}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R))		{CryLogAlways("Classic: FULL R pressed\n");}

		CryLogAlways("classic L button pressed:         %f\n", cc->l_shoulder);
		CryLogAlways("classic R button pressed:         %f\n", cc->r_shoulder);
		CryLogAlways("classic left joystick angle:      %f\n", cc->ljs.ang);
		CryLogAlways("classic left joystick magnitude:  %f\n", cc->ljs.mag);
		CryLogAlways("classic right joystick angle:     %f\n", cc->rjs.ang);
		CryLogAlways("classic right joystick magnitude: %f\n", cc->rjs.mag);
	} 
	else if (wm->exp.type == EXP_WII_BOARD){
		struct wii_board_t* wb = (wii_board_t*)&wm->exp.wb;
		CryLogAlways("WiiBoard roll  = [%f]\n", wb->update_calib);
		
		CryLogAlways("WiiBoard roll  = %f [%f]\n", wb->bl, wb->br);
		CryLogAlways("WiiBoard pitch = %f [%f]\n", wb->tl,wb->tr);
	}
	
}
Example #9
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();
}
Example #10
0
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
	{
		int found =-1;
		int connected;
		
		
		switch (event)
		{
		case eFE_Initialize:{
			//Sleep(3000);
			wiimotes = wiiuse_init(1); 
			found = wiiuse_find(wiimotes, 1, 5);
			if (found!=0) handle_ctrl_status(wiimotes[0]);

			connected = wiiuse_connect(wiimotes, 1);
			if (connected) CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found);
			else CryLogAlways("Failed to connect to any wiimote.\n");
			wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
			
			wiiuse_motion_sensing(wiimotes[0], 1);
			wiiuse_set_ir(wiimotes[0], 1);

			//trop rapide !
			
		}
		case eFE_Activate:
			{	

				//Sleep(3000);

				//wiimotes = wiiuse_init(1); 
				//found = wiiuse_find(wiimotes, 1, 5);
				//if (found==0) CryLogAlways("No wiimotes found.\n");
				
				/*
				connected = wiiuse_connect(wiimotes, 1);
				if (connected) CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found);
				else CryLogAlways("Failed to connect to any wiimote.\n");
				wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);

				wiiuse_motion_sensing(wiimotes[0], 1);
				wiiuse_set_ir(wiimotes[0], 1);
				//WIIUSE_USING_EXP(wiimotes[0]);
				//WIIUSE_U

				//wiimotes[0]->exp.type = EXP_NUNCHUK;
				
				*/
				

				pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,true);
			}
			break;
		
		case eFE_Update:
			{
				//int connected = wiiuse_connect(wiimotes, 1); 
				wiiuse_poll(wiimotes, 1);
				wiimote* wm =  wiimotes[0];
				//Ne change rien ! juste qu'on a un retour d'IR
				//handle_ctrl_status(wiimotes[0]);
				CryLogAlways("attachment:      %i",wm->exp.type);

				/*

				Gestion des evts

				*/

				
				
				// A commenter
				switch (wiimotes[0]->event) {
					case WIIUSE_EVENT:
						/* a generic event occured */
						handle_event(wiimotes[0]);
						break;

					case WIIUSE_STATUS:
						/* a status event occured */
						handle_ctrl_status(wiimotes[0]);
						break;

					case WIIUSE_DISCONNECT:
					case WIIUSE_UNEXPECTED_DISCONNECT:
						/* the wiimote disconnected */
						handle_disconnect(wiimotes[0]);
						break;

					case WIIUSE_READ_DATA:
						/*
						 *	Data we requested to read was returned.
						 *	Take a look at wiimotes[i]->read_req
						 *	for the data.
						 */
						break;

					case WIIUSE_NUNCHUK_INSERTED:
						/*
						 *	a nunchuk was inserted
						 *	This is a good place to set any nunchuk specific
						 *	threshold values.  By default they are the same
						 *	as the wiimote.
						 */
						//struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[0]->exp.nunchuk;
						 wiiuse_set_nunchuk_orient_threshold(wiimotes[0], 90.0f);
						 wiiuse_set_nunchuk_accel_threshold(wiimotes[0], 100);
						CryLogAlways("Nunchuk inserted.\n");
						break;

					case WIIUSE_CLASSIC_CTRL_INSERTED:
						CryLogAlways("Classic controller inserted.\n");
						break;

					case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
						/* some expansion was inserted */
						handle_ctrl_status(wiimotes[0]);
						//printf("Guitar Hero 3 controller inserted.\n");
						break;

					case WIIUSE_NUNCHUK_REMOVED:
					case WIIUSE_CLASSIC_CTRL_REMOVED:
					case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
						/* some expansion was removed */
						handle_ctrl_status(wiimotes[0]);
						//printf("An expansion was removed.\n");
						break;

					default:
						break;
				}














				
					//if (wiiuse_poll(wiimotes, 1)) {
						//int i = 0;
				
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_A))			ActivateOutput(pActInfo, WIIMOTE_A,true); else ActivateOutput(pActInfo, WIIMOTE_A,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_B))			ActivateOutput(pActInfo, WIIMOTE_B,true); else ActivateOutput(pActInfo, WIIMOTE_B,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_UP))			ActivateOutput(pActInfo, WIIMOTE_UP,true); else ActivateOutput(pActInfo, WIIMOTE_UP,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_DOWN))		ActivateOutput(pActInfo, WIIMOTE_DOWN,true); else ActivateOutput(pActInfo, WIIMOTE_DOWN,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_LEFT))		ActivateOutput(pActInfo, WIIMOTE_LEFT,true); else ActivateOutput(pActInfo, WIIMOTE_LEFT,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_RIGHT))		ActivateOutput(pActInfo, WIIMOTE_RIGHT,true); else ActivateOutput(pActInfo, WIIMOTE_RIGHT,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_MINUS))		ActivateOutput(pActInfo, WIIMOTE_MINUS,true); else ActivateOutput(pActInfo, WIIMOTE_MINUS,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_PLUS))		ActivateOutput(pActInfo, WIIMOTE_PLUS,true); else ActivateOutput(pActInfo, WIIMOTE_PLUS,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_ONE))		ActivateOutput(pActInfo, WIIMOTE_ONE,true); else ActivateOutput(pActInfo, WIIMOTE_ONE,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_TWO))		ActivateOutput(pActInfo, WIIMOTE_TWO,true); else ActivateOutput(pActInfo, WIIMOTE_TWO,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_HOME))		ActivateOutput(pActInfo, WIIMOTE_HOME,true); else ActivateOutput(pActInfo, WIIMOTE_HOME,false);

						if (WIIUSE_USING_ACC(wiimotes[0])) {
							Vec3 output = Vec3(wiimotes[0]->orient.roll,wiimotes[0]->orient.pitch,wiimotes[0]->orient.yaw);
							ActivateOutput(pActInfo, WIIMOTE_RPY,output);
						}
						if (WIIUSE_USING_IR(wiimotes[0])) {
							Vec3 output = Vec3((float)wiimotes[0]->ir.x,(float)wiimotes[0]->ir.y,(float)wiimotes[0]->ir.z);
							ActivateOutput(pActInfo, WIIMOTE_IR,output);
						}
						/* nunchuk */
						//Toujours faux !
						
						if (wm->exp.type == EXP_NUNCHUK) {
							
							//nunchuk_t* pt =  wm->exp.nunchuk;
						//REssort 0 a chaque fois !!!!
							struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;
							CryLogAlways("nun gravity x EXPANSION : %f",nc->gforce.x);
							if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) ActivateOutput(pActInfo, NUNCHUK_C,true); else ActivateOutput(pActInfo, NUNCHUK_C,false);
							if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) ActivateOutput(pActInfo, NUNCHUK_Z,true); else ActivateOutput(pActInfo, NUNCHUK_Z,false);
							
							Vec3 output = Vec3(nc->orient.a_roll,nc->orient.a_pitch,nc->orient.yaw);
							ActivateOutput(pActInfo, NUNCHUK_RPY,output);
							
							Vec3 output2 = Vec3(nc->js.ang,nc->js.mag,0);
							ActivateOutput(pActInfo, NUNCHUK_JOYSTICK,output2);
						} 


						/*
						switch (wiimotes[0]->event) {
							//case WIIUSE_EVENT:
								//{
								//}
								//break;

							case WIIUSE_STATUS:
								handle_ctrl_status(wiimotes[0]);
								break;

							case WIIUSE_DISCONNECT:
							case WIIUSE_UNEXPECTED_DISCONNECT:
								handle_disconnect(wiimotes[0]);
								break;
								
							default:
								break;
						}
						*/
					//}
				//}
			}
				
		}
	}
/**
 *	@brief Callback that handles an event.
 *
 *	@param wm		Pointer to a wiimote_t structure.
 *
 *	This function is called automatically by the wiiuse library when an
 *	event occurs on the specified wiimote.
 */
void handle_event(struct wiimote_t* wm) {
	printf("\n\n--- EVENT [id %i] ---\n", wm->unid);

	/* if a button is pressed, report it */
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_A))		printf("A pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_B))		printf("B pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP))		printf("UP pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN))	printf("DOWN pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))	printf("LEFT pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT))	printf("RIGHT pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS))	printf("MINUS pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS))	printf("PLUS pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE))		printf("ONE pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO))		printf("TWO pressed\n");
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME))	printf("HOME pressed\n");

	/*
	 *	Pressing minus will tell the wiimote we are no longer interested in movement.
	 *	This is useful because it saves battery power.
	 */
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
		wiiuse_motion_sensing(wm, 0);

	/*
	 *	Pressing plus will tell the wiimote we are interested in movement.
	 */
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
		wiiuse_motion_sensing(wm, 1);

	/*
	 *	Pressing B will toggle the rumble
	 *
	 *	if B is pressed but is not held, toggle the rumble
	 */
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
		wiiuse_toggle_rumble(wm);

	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP))
		wiiuse_set_ir(wm, 1);
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
		wiiuse_set_ir(wm, 0);

	/* if the accelerometer is turned on then print angles */
	if (WIIUSE_USING_ACC(wm)) {
		printf("wiimote roll  = %f [%f]\n", wm->orient.roll, wm->orient.a_roll);
		printf("wiimote pitch = %f [%f]\n", wm->orient.pitch, wm->orient.a_pitch);
		printf("wiimote yaw   = %f\n", wm->orient.yaw);
	}

	/*
	 *	If IR tracking is enabled then print the coordinates
	 *	on the virtual screen that the wiimote is pointing to.
	 *
	 *	Also make sure that we see at least 1 dot.
	 */
	if (WIIUSE_USING_IR(wm)) {
		int i = 0;

		/* go through each of the 4 possible IR sources */
		for (; i < 4; ++i) {
			/* check if the source is visible */
			if (wm->ir.dot[i].visible)
				printf("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y);
		}

		printf("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
		printf("IR z distance: %f\n", wm->ir.z);
	}

	/* show events specific to supported expansions */
	if (wm->exp.type == EXP_NUNCHUK) {
		/* nunchuk */
		struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;

		if (IS_PRESSED(nc, NUNCHUK_BUTTON_C))		printf("Nunchuk: C pressed\n");
		if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z))		printf("Nunchuk: Z pressed\n");

		printf("nunchuk roll  = %f\n", nc->orient.roll);
		printf("nunchuk pitch = %f\n", nc->orient.pitch);
		printf("nunchuk yaw   = %f\n", nc->orient.yaw);

		printf("nunchuk joystick angle:     %f\n", nc->js.ang);
		printf("nunchuk joystick magnitude: %f\n", nc->js.mag);
	} else if (wm->exp.type == EXP_CLASSIC) {
		/* classic controller */
		struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic;

		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL))			printf("Classic: ZL pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B))			printf("Classic: B pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y))			printf("Classic: Y pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A))			printf("Classic: A pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X))			printf("Classic: X pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR))			printf("Classic: ZR pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT))		printf("Classic: LEFT pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP))			printf("Classic: UP pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT))		printf("Classic: RIGHT pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN))		printf("Classic: DOWN pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L))		printf("Classic: FULL L pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS))		printf("Classic: MINUS pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME))		printf("Classic: HOME pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS))		printf("Classic: PLUS pressed\n");
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R))		printf("Classic: FULL R pressed\n");

		printf("classic L button pressed:         %f\n", cc->l_shoulder);
		printf("classic R button pressed:         %f\n", cc->r_shoulder);
		printf("classic left joystick angle:      %f\n", cc->ljs.ang);
		printf("classic left joystick magnitude:  %f\n", cc->ljs.mag);
		printf("classic right joystick angle:     %f\n", cc->rjs.ang);
		printf("classic right joystick magnitude: %f\n", cc->rjs.mag);
	} else if (wm->exp.type == EXP_GUITAR_HERO_3) {
		/* guitar hero 3 guitar */
		struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3;

		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP))		printf("Guitar: Strum Up pressed\n");
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN))	printf("Guitar: Strum Down pressed\n");
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW))		printf("Guitar: Yellow pressed\n");
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN))		printf("Guitar: Green pressed\n");
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE))			printf("Guitar: Blue pressed\n");
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED))			printf("Guitar: Red pressed\n");
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE))		printf("Guitar: Orange pressed\n");
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS))			printf("Guitar: Plus pressed\n");
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS))		printf("Guitar: Minus pressed\n");

		printf("Guitar whammy bar:          %f\n", gh3->whammy_bar);
		printf("Guitar joystick angle:      %f\n", gh3->js.ang);
		printf("Guitar joystick magnitude:  %f\n", gh3->js.mag);
	}
}
bool controllerClass::get()
{
  Uint8 *keyStates;
  Uint8 keyDown[3]; //Need this since its not a good idea to write to keyStates for some reason
  shotTime += globalTicks;
  SDL_PumpEvents();
  keyStates = SDL_GetKeyState( NULL );
  keyDown[0] = keyStates[setting.keyLeft];
  keyDown[1] = keyStates[setting.keyRight];
  keyDown[2] = keyStates[setting.keyShoot];
  
  itemSelectTime += globalTicks;
  //Read joystick here so we can override keypresses if the joystick is digital
  //We shouldn't need to check if the joystick is enabled, since it won't be opened if its not enabled anyway.
  if(setting.joyEnabled && SDL_JoystickOpened(0))
  {
    joystickx = SDL_JoystickGetAxis(joystick, 0);
    joysticky = SDL_JoystickGetAxis(joystick, 1);
    joystickbtnA = SDL_JoystickGetButton(joystick, 0);
    joystickbtnB = SDL_JoystickGetButton(joystick, 1);


    if(joystickbtnA)
    {
      keyDown[2] = 1;
    }
    if(joystickbtnB && itemSelectTime > ITEMSELECTTIME)
    {
      itemSelectTime=0;
      gVar.shopBuyItem=1;
    }

    if(setting.joyIsDigital)
    {
      if(joystickx < -200)
      {
        keyDown[0]=1;
      } else if(joystickx > 200)
      {
        keyDown[1]=1;
      }
      if(joysticky < -200 && itemSelectTime > ITEMSELECTTIME)
      {
        itemSelectTime=0;
        gVar.shopNextItem = 1;
      } else if(joysticky > 200 && itemSelectTime > ITEMSELECTTIME)
      {
        itemSelectTime=0;
        gVar.shopPrevItem = 1;
      }
      
    } else {
      GLfloat x; //This is the actual traveling speed of the paddle
      if(joystickx > setting.JoyCalHighJitter)
      {
        x = joystickRightX * joystickx;
      } else if(joystickx < setting.JoyCalLowJitter)
      {
        x = -(joystickLeftX * joystickx);
      }
      
      if(joysticky < setting.JoyCalLowJitter && itemSelectTime > ITEMSELECTTIME)
      {
        itemSelectTime=0;
        gVar.shopNextItem = 1;
      } else if(joysticky > setting.JoyCalHighJitter && itemSelectTime > ITEMSELECTTIME)
      {
        itemSelectTime=0;
        gVar.shopPrevItem = 1;
      }
      //Move the paddle:
      movePaddle( paddle->posx += (x*globalMilliTicks) );
    }
  }

  #ifdef WITH_WIIUSE
  if(var.wiiConnect)
  {
    if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
      switch(wiimotes[0]->event)
      {
        case WIIUSE_EVENT:
          if(IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_TWO))
          {
            keyDown[2]=1;
          } else if(IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_ONE) && itemSelectTime > ITEMSELECTTIME)
          {
            gVar.shopBuyItem = 1;
            itemSelectTime=0;
          }else if(IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_UP) && itemSelectTime > ITEMSELECTTIME)
          {
            itemSelectTime=0;
            gVar.shopPrevItem = 1;
          }else if(IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_DOWN) && itemSelectTime > ITEMSELECTTIME)
          {
            itemSelectTime=0;
            gVar.shopNextItem = 1;
          } else if(WIIUSE_USING_ACC(wiimotes[0]))
          {
            motePitch = wiimotes[0]->orient.pitch;
            motePitch *=-1;
	  }

        break;
        case WIIUSE_DISCONNECT:
        case WIIUSE_UNEXPECTED_DISCONNECT:
          var.wiiConnect=0;
          cout << "WiiMote disconnected." << endl;
          wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
        break;
      }
    }
    if(motePitch < -0.2 || motePitch > 0.2)
    {
      movePaddle( paddle->posx += ( moteAccel*motePitch)*globalMilliTicks );
    }
  }
  #endif

  //React to keystates here, this way, if joyisdig it will press keys
  if(keyDown[0])
  {
    accel+=globalMilliTicks*setting.controlAccel;
    if(accel > setting.controlMaxSpeed)
      accel=setting.controlMaxSpeed;
    movePaddle( paddle->posx - ( accel*globalMilliTicks) );
  } else if(keyDown[1])
  {
    accel+=globalMilliTicks*setting.controlAccel;
    if(accel > setting.controlMaxSpeed)
      accel=setting.controlMaxSpeed;
    movePaddle( paddle->posx + ( accel*globalMilliTicks) );
  } else {
      accel = setting.controlStartSpeed;
  }

  if(keyDown[2])
  {
    btnPress();
    return(1);
  } else {
    return(0);
  }
}
        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 );
            }

        }
Example #14
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;
}
Example #15
0
void triple_buffer(BITMAP **page) {
	int i = 0, w, repeat, active_page = 0;
	int time_diff, bar_number, *used_voices = NULL, hw_voices;
	int text_bar_height, half_bar_size;
	unsigned int radius;
	
	coord_t dot[2], dot_old[2], cal[2], cal_tmp[2];
	
	wiimote *wiimote;
	
	char *fonts[NUM_MAX_FONTS] = FONTS;
	FONT *font_msg, *font_notes;
	BITMAP *background;
	bars *bar;
	
	/* dot_old data initialization. dot_old's X coord is not used */
	dot_old[0].y = SCREEN_H;
	dot_old[1].y = SCREEN_H;
	
	/* Wiimote initialization*/
	wiimote = *wiiuse_init(1);
	
	/* Load fonts, size of font is related to SCREEN_W */
	do {
		font_msg = load_font(fonts[i], NULL, NULL);
		__ASSERT(font_msg, ERROR_CANT_LOAD_FONT(fonts[i]));
		w = text_length(font_msg, WIIMOTE_CONNECTION_MSG);
	} while (w >= SCREEN_W && ++i < (NUM_MAX_FONTS-1));
	
	/* Notes' font is smaller than messages' font */
	font_notes = load_font(fonts[i], NULL, NULL);
	__ASSERT(font_notes, ERROR_CANT_LOAD_FONT(fonts[i]));
	
	/* Initialize and calculate bars size, point radius, text bar height, and calculate half bar size for text output under bars */
	bar = bar_create(NUM_BARS);
	radius = RADIUS(bar);
	text_bar_height = TEXT_BAR_HEIGHT;
	half_bar_size = HALF_BAR_SIZE(bar);
	
	/* Control the max number of available hardware voices. Though ALSA driver voices are up to 64, max hardware voices generally are 8-16. Checking the allocated voices after the driver allocation seems to be the only way */
	hw_voices = get_mixer_voices();
	if (hw_voices < NUM_BARS)
		used_voices = reallocate_voices(bar, hw_voices);
	
	/* Install timer, 10 ticks a second */
	LOCK_VARIABLE(timer);
	LOCK_FUNCTION(inc_timer);
	install_int_ex(inc_timer, BPS_TO_TIMER(10));
	
	/* Load background from file */
	background = load_tga("images/back.tga", NULL);
	__ASSERT(background, ERROR_CANT_LOAD_IMAGE("back.tga"));
	
	/* Enables vertical syncronization*/
	vsync();
	
	i = 0;
	/* First frame, this lasts until wiimote is connected, the user is prompted to activate the wiimote by pressing 1 & 2 keys on the wiimote */
	while(i == 0 && !keypressed()) {
		active_page = start_credits3buf(page, active_page);
		
		clear_keybuf();
		
		title3buf(page, active_page, font_msg);
		
		clear_keybuf();
		
		repeat = 0;
		while(repeat++ < 8 && i == 0 && !keypressed()) {
			stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H); // background
			if(repeat%2 == 1)
				textout_centre_ex(page[active_page], font_msg, WIIMOTE_CONNECTION_MSG, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
			
			release_bitmap(page[active_page]);
			/* make sure the last flip request has actually happened */
			do {
			} while (poll_scroll());
			
			/* post a request to display the page we just drew */
			request_video_bitmap(page[active_page]);

			/* update counters to point to the next page */
			switch (active_page) {
				case 0: active_page = 1; break;
				case 1: active_page = 2; break;
				case 2: active_page = 0; break;
			}

			/* Search for a wiimote */
			i = wiiuse_find(&wiimote, 1, 1);
		}
	}
	
	/* Try to connect to the wiimote */
	__ASSERT(wiiuse_connect(&wiimote, 1) > 0, ERROR_CANT_OPEN_WIIMOTE);
	
	/* Activate the first led on the wiimote */
	wiiuse_set_leds(wiimote, WIIMOTE_LED_1);
	
	/* Activate the ir module on the wiimote */
	wiiuse_set_ir(wiimote, TRUE);
	
	wiiuse_motion_sensing(wiimote, FALSE);
	
	wiiuse_set_ir_sensitivity(wiimote, 1);
	wiiuse_set_flags(wiimote, WIIUSE_CONTINUOUS, 0);
	
	cal[0].x = 0;
	cal[0].y = 0;
	cal[1].x = 1023;
	cal[1].y = 767;
	
	/* CALIBRATION LOOP */
	for(repeat=0;repeat<2;repeat++) {
		clear_keybuf();
		
		while(!keypressed()) {
			if (wiiuse_poll(&wiimote, 1)) // if there are datas pending from/to wiimote or ESC is pressed
				if (key[KEY_ESC] || wiimote->event == WIIUSE_DISCONNECT || wiimote->event == WIIUSE_UNEXPECTED_DISCONNECT || IS_PRESSED(wiimote, WIIMOTE_BUTTON_HOME)) { // if ESC is pressed, if wiimote update fails, or if HOME key on wiimote is pressed
				wiiuse_disconnect(wiimote);
				destroy_bitmap(background);
				destroy_font(font_msg);
				destroy_font(font_notes);
				for (i=0;i<NUM_BARS;i++) {
					deallocate_voice(bar[i].voice);
					destroy_sample(bar[i].sound);
				}
				free(bar); // YO!! :-)
				free(used_voices);
				
				return;
				}
			/* background */
			stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H);
			
			if (wiimote->ir.dot[0].visible) { // if ir source is visible
				/* Read coords from the wiimote's ir*/
				dot[0] = transpose(wiimote->ir.dot[0], cal, 0);
			}
			
			switch(repeat) {
				case 0:
					textout_centre_ex(page[active_page], font_msg, WIIMOTE_CAL_ASX, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
					rect(page[active_page], dot[0].x, dot[0].y, SCREEN_W+1, SCREEN_H+1, makecol(0, 0, 0));
					break;
				case 1:
					textout_centre_ex(page[active_page], font_msg, WIIMOTE_CAL_BDX, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
					
					rect(page[active_page], dot[1].x, dot[1].y, SCREEN_W+1, SCREEN_H+1, makecol(0, 0, 0));
					rect(page[active_page], -1, -1, dot[0].x, dot[0].y, makecol(0, 0, 0));
					break;
			}
			circlefill(page[active_page], dot[0].x, dot[0].y, radius, makecol(0, 0, 0));

			release_bitmap(page[active_page]);
			
			/* make sure the last flip request has actually happened */
			do {
			} while (poll_scroll());

			/* post a request to display the page we just drew */
			request_video_bitmap(page[active_page]);

			/* update counters to point to the next page */
			switch (active_page) {
				case 0: active_page = 1; break;
				case 1: active_page = 2; break;
				case 2: active_page = 0; break;
			}
		}
		
		cal_tmp[repeat].x = wiimote->ir.dot[0].x;
		cal_tmp[repeat].y = wiimote->ir.dot[0].y;
		dot[1] = dot[0];
	}
	
	__ASSERT((cal_tmp[0].x < cal_tmp[1].x && cal_tmp[0].y > cal_tmp[1].y), ERROR_WHILE_CALIBRATING);
	
	cal[0].x = cal_tmp[0].x;
	cal[0].y = 767-cal_tmp[0].y;
	cal[1].x = cal_tmp[1].x;
	cal[1].y = 767-cal_tmp[1].y;
	
	/* MAIN LOOP */
	while (TRUE) {
		/* Draw a frame */
		if (wiiuse_poll(&wiimote, 1) || key[KEY_ESC]) // if there are datas pending from/to wiimote or ESC is pressed
			if (key[KEY_ESC] || wiimote->event == WIIUSE_DISCONNECT || wiimote->event == WIIUSE_UNEXPECTED_DISCONNECT || IS_PRESSED(wiimote, WIIMOTE_BUTTON_HOME)) { // if ESC is pressed, if wiimote update fails, or if HOME key on wiimote is pressed
				wiiuse_disconnect(wiimote);
				destroy_bitmap(background);
				destroy_font(font_msg);
				destroy_font(font_notes);
				for (i=0;i<NUM_BARS;i++) {
					deallocate_voice(bar[i].voice);
					destroy_sample(bar[i].sound);
				}
				free(bar); // YO!! :-)
				free(used_voices);
				
				return;
			}
		
		/* background */
		stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H);
		
		/* Xylophone's bars and notes names */
		for(i=0;i<NUM_BARS;i++) {
			if (bar[i].t_start != -1 && (time_diff = timer-bar[i].t_start) > TICKS_TO_BLACK) // if color animation ends
				bar[i].t_start = -1;
			if (bar[i].t_start == -1) // if no color animation
				bar[i].color = 0;
			else	bar[i].color = COLORVAL(time_diff); // if color animation is running
			
			/* Draw bar */
			rectfill(page[active_page], bar[i].min.x, bar[i].min.y, bar[i].max.x, bar[i].max.y, makecol(bar[i].color, bar[i].color, bar[i].color));
			/* Print bar's associated note */
			textout_centre_ex(page[active_page], font_notes, bar[i].note, (bar[i].min.x + half_bar_size), text_bar_height, makecol(0, 0, 0), -1);
		}
		
		// da normalizzare e da contenere nello schermo, ir
		for(i=0;i<MAX_IR_DOTS;i++) {
			if (wiimote->ir.dot[i].visible) { // if ir source is visible
				/* Read coords from the wiimote's ir*/
				dot[i] = transpose(wiimote->ir.dot[i], cal, radius);
				
				/* If the ir source is under the bars and in previous frame it was above the bars, then play the sound and start the animation */
				if (dot[i].y > bar[0].min.y-radius) {
					if(dot_old[i].y <= bar[0].min.y-radius) {
						/* This calculates on which bar the ir source actually is */
						bar_number = is_onbar(bar, dot[i].x, NUM_BARS);
						
						/* play bar_number's sound with specified volume */
						play_bar_voice(bar, bar_number, volume(dot[i].y-dot_old[i].y), used_voices, hw_voices);
					}
					
					/* The dot have not to go under the bars or out of the screen */
					circlefill(page[active_page], dot[i].x, bar[0].min.y-radius, radius, makecol(0, 0, 0));
				}
				else	circlefill(page[active_page], dot[i].x, dot[i].y, radius, makecol(0, 0, 0));
				
				dot_old[i].y = dot[i].y;
			}
			else dot_old[i].y = SCREEN_H;
		}

		release_bitmap(page[active_page]);

		/* make sure the last flip request has actually happened */
		do {
		} while (poll_scroll());

		/* post a request to display the page we just drew */
		request_video_bitmap(page[active_page]);

		/* update counters to point to the next page */
		switch (active_page) {
			case 0: active_page = 1; break;
			case 1: active_page = 2; break;
			case 2: active_page = 0; break;
		}
	}
}
void handle_event(struct wiimote_t* wm)
{
    static uint8_t controls = ABS | TC | STABILITY;
#if 0
    printf("\n\n--- EVENT [id %i] ---\n", wm->unid);

    /* if a button is pressed, report it */
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_A))		printf("A pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_B))		printf("B pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP))		printf("UP pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN))	printf("DOWN pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))	printf("LEFT pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT))	printf("RIGHT pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS))	printf("MINUS pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS))	printf("PLUS pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE))		printf("ONE pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO))		printf("TWO pressed\n");
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME))	printf("HOME pressed\n");
#endif
    /*
     *	Pressing home will tell the wiimote we are interested in movement.
     */
    if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_HOME))
    {
        wiiuse_set_orient_threshold(wm, 0.5);
        wiiuse_motion_sensing(wm, 1);
    }

    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)){
	carInputs.gear++;
	if(carInputs.gear>7)	carInputs.gear = 7;
        controls ^= ABS;
	}
    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)){
	carInputs.cruisedist = carInputs.cruisedist +10;
	if(carInputs.cruisedist > 100) carInputs.cruisedist = 100;
    }
    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)){
	carInputs.cruisedist = carInputs.cruisedist -10;
        if(carInputs.cruisedist <50) carInputs.cruisedist = 50;
    }
    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)){
	if(carInputs.gear>=2)
	carInputs.gear--;

        controls ^= TC;
	}
    if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)){
	controls ^= STABILITY;
	carInputs.gear = 0;
    	}

    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A))
        controls ^= CRUISE;

    if (WIIUSE_USING_ACC(wm))
    {
        // obtain the steering angle input from wiimote
        float steer_temp =  wm->orient.pitch;
        if(steer_temp < -90)
            steer_temp = -90;
        else if(steer_temp > 90)
            steer_temp = 90;

        if(steer_temp != 0)
            carInputs.steer = (steer_temp/abs(steer_temp))*pow(steer_temp/90,2)*50;
        else
            carInputs.steer = 0;
        //printf("steer: %d\n", carInputs.steer);
    }

    // obtain acceleration input from WiiMote
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE))
    {
        carInputs.accel = 100;
    }
    else
        carInputs.accel = 0;

    // obtain brake input from WiiMote
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO))
    {
        carInputs.brake = 100;
        controls &= ~(CRUISE);
    }
    else
        carInputs.brake = 0;

    if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))
        carInputs.gear = -1;
    carInputs.clutch = 0;
    carInputs.controls = controls;
}
int main(void) {
  uint8_t zahleins = 1;
  uint8_t zahlnull = 0;
  uint16_t tmp	   = 0;
  uint16_t counter = 0;

  bool     pressed = false;

  /* confige peripherals */
  CFG_PULLUP(BUTTON_PROG);
  CFG_OUTPUT(LED_B);
  CFG_OUTPUT(LED_PWM);
  CFG_OUTPUT(LED_LEFT);
  CFG_OUTPUT(LED_RIGHT);

  hidInit();
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */

  /* usb disconnect delay */
  _delay_ms(300);
  wdt_reset();

  /* connect the usb */
  usbDeviceConnect();
  usbInit();
  sei();



  for(;;) {
    wdt_reset();

#if (!(defined(USB_CFG_HID_NOMOUSE))) && (defined(USB_CFG_HID_WHEELMOUSE))
    if (IS_PRESSED(BUTTON_PROG)) {
      if /*(!(pressed))*/ (true) {
	if (!(mouse_report_dirty)) {
	  pressed=true;
	  mouse_report_clear(&current_mouse_report);
	  current_mouse_report.displacement[mouse_report_displacement_wheel]=+1;
	  mouse_report_dirty |= 0x2;
	}
      }
    } else {
      if (pressed) {
	if (!(mouse_report_dirty)) {
	  pressed=false;
	  mouse_report_clear(&current_mouse_report);
	  mouse_report_dirty |= 0x2;
	}
      }
    }
#endif
    
    counter++;
#define counterthreshold 555 /* calibrated to about 4ms - LED_RIGHT should flash every 4sec then */
    if (counter >= counterthreshold) {
      counter-=counterthreshold;
      hidPoll(&zahleins);
      tmp++;
#define tmpthreshold 1000
      if (tmp >= tmpthreshold) {
	tmp-=tmpthreshold;
	TOGGLE(LED_RIGHT);
      }
    } else hidPoll(&zahlnull);

  }
  return 0;
}
Example #18
0
void handle_event(struct wiimote_t* wm)
{
   if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
   {
      sSensitivity++;
      if (sSensitivity > 5) sSensitivity = 5;
      wiiuse_set_ir_sensitivity(wm, sSensitivity);
      Log("Sensitivity set to " + boost::lexical_cast<std::string, int>(sSensitivity) + "\n");
   }
   if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
   {
      sSensitivity--;
      if (sSensitivity < 0) sSensitivity = 0;
      wiiuse_set_ir_sensitivity(wm, sSensitivity);
      Log("Sensitivity set to " + boost::lexical_cast<std::string, int>(sSensitivity) + "\n");
   }


   // Button A switches to track mode
   if (IS_PRESSED(wm, WIIMOTE_BUTTON_A))
   {
      change_control_mode(ControlMode::Seeking);
   }

   // B fires the missile
   if (IS_PRESSED(wm, WIIMOTE_BUTTON_B))
   {
      sResult.fire = true;
   }
   // Manually steer
   if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP))
   {
      sResult.steering_demand.y = -1;
      sResult.steering_demand.z = -1;
      change_control_mode(ControlMode::Slaved);
   }
   if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
   {
      sResult.steering_demand.y =  1;
      sResult.steering_demand.z = -1;
      change_control_mode(ControlMode::Slaved);
   }
   if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))
   {
      sResult.steering_demand.x = -1;
      sResult.steering_demand.z = -1;
      change_control_mode(ControlMode::Slaved);
   }
   if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT))
   {
      sResult.steering_demand.x =  1;
      sResult.steering_demand.z = -1;
      change_control_mode(ControlMode::Slaved);
   }

   /*
    *	If IR tracking is enabled then print the coordinates
    *	on the virtual screen that the wiimote is pointing to.
    *
    *	Also make sure that we see at least 1 dot.
    */
   if (sControlMode == ControlMode::Seeking || sControlMode == ControlMode::Searching)
   {
      if (wm->ir.num_dots > 0)
      {
         sResult.steering_demand.x = 512 - (float)wm->ir.ax;
         sResult.steering_demand.y = 384 - (float)wm->ir.ay;
         sResult.steering_demand.z = -1;
         // Dead zone of 25
         if (fabs(sResult.steering_demand.x) < 50) sResult.steering_demand.x = 0;
         if (fabs(sResult.steering_demand.y) < 50) sResult.steering_demand.y = 0;
         sTrackValid = true;
         change_control_mode(ControlMode::Seeking);
         sTrackAge = clock();

         Log(boost::lexical_cast<std::string, int>(wm->ir.num_dots) + " dots. Centre (" + 
             boost::lexical_cast<std::string, int>(wm->ir.ax) + "," +
             boost::lexical_cast<std::string, int>(wm->ir.ay) + ")\n");
      }
   }

}
void FWiimoteInputDevice::handle_event(struct wiimote_t* wm, int id)
{
    UE_LOG(LogWiimote, Log, TEXT("\n\n--- EVENT [id %i] ---"), wm->unid);

    CurrentStates[0] = IS_PRESSED(wm, WIIMOTE_BUTTON_A) || IS_HELD(wm, WIIMOTE_BUTTON_A);
    CurrentStates[1] = IS_PRESSED(wm, WIIMOTE_BUTTON_B) || IS_HELD(wm, WIIMOTE_BUTTON_B);
    CurrentStates[2] = IS_PRESSED(wm, WIIMOTE_BUTTON_ONE) || IS_HELD(wm, WIIMOTE_BUTTON_ONE);
    CurrentStates[3] = IS_PRESSED(wm, WIIMOTE_BUTTON_TWO) || IS_HELD(wm, WIIMOTE_BUTTON_TWO);
    CurrentStates[4] = IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS) || IS_HELD(wm, WIIMOTE_BUTTON_PLUS);
    CurrentStates[5] = IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS) || IS_HELD(wm, WIIMOTE_BUTTON_MINUS);
    CurrentStates[6] = IS_PRESSED(wm, WIIMOTE_BUTTON_UP) || IS_HELD(wm, WIIMOTE_BUTTON_UP);
    CurrentStates[7] = IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN) || IS_HELD(wm, WIIMOTE_BUTTON_DOWN);
    CurrentStates[8] = IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT) || IS_HELD(wm, WIIMOTE_BUTTON_LEFT);
    CurrentStates[9] = IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT) || IS_HELD(wm, WIIMOTE_BUTTON_RIGHT);

    if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME))
    {
        UE_LOG(LogWiimote, Log, TEXT("HOME pressed"));
    }

    /* show events specific to supported expansions */
    if (wm->exp.type == EXP_NUNCHUK || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK)
    {
        /* nunchuk */
        struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;

        const float DEADZONE = 0.6f;

        CurrentStates[10] = IS_PRESSED(nc, NUNCHUK_BUTTON_C) || IS_HELD(wm, NUNCHUK_BUTTON_C);
        CurrentStates[11] = IS_PRESSED(nc, NUNCHUK_BUTTON_Z) || IS_HELD(wm, NUNCHUK_BUTTON_Z);
        CurrentStates[12] = nc->js.y > DEADZONE;
        CurrentStates[13] = nc->js.y < -DEADZONE;
        CurrentStates[14] = nc->js.x < -DEADZONE;
        CurrentStates[15] = nc->js.x > DEADZONE;

        UE_LOG(LogWiimote, Log, TEXT("nunchuk roll  = %f"), nc->orient.roll);
        UE_LOG(LogWiimote, Log, TEXT("nunchuk pitch = %f"), nc->orient.pitch);
        UE_LOG(LogWiimote, Log, TEXT("nunchuk yaw   = %f"), nc->orient.yaw);

        UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick angle:     %f"), nc->js.ang);
        UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick magnitude: %f"), nc->js.mag);

        UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick vals:      %f, %f"), nc->js.x, nc->js.y);
        UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick calibration (min, center, max): x: %i, %i, %i  y: %i, %i, %i"),
               nc->js.min.x,
               nc->js.center.x,
               nc->js.max.x,
               nc->js.min.y,
               nc->js.center.y,
               nc->js.max.y);
    }

    /*
    *   If IR tracking is enabled then print the coordinates
    *   on the virtual screen that the wiimote is pointing to.
    *
    *   Also make sure that we see at least 1 dot.
    */
    if (WIIUSE_USING_IR(wm))
    {
        /* go through each of the 4 possible IR sources */
        for (int i = 0; i < 4; ++i)
        {
            /* check if the source is visible */
            if (wm->ir.dot[i].visible)
            {
                UE_LOG(LogWiimote, Log, TEXT("IR source %i: (%u, %u)"), i, wm->ir.dot[i].x, wm->ir.dot[i].y);
            }
        }

        UE_LOG(LogWiimote, Log, TEXT("IR cursor: (%u, %u)"), wm->ir.x, wm->ir.y);
        UE_LOG(LogWiimote, Log, TEXT("IR z distance: %f"), wm->ir.z);
    }
    // Update motion controls.
    FVector Tilt(0, 0, 0);
    FVector RotationRate(0, 0, 0);
    FVector Gravity(0, 0, 0);
    FVector Acceleration(0, 0, 0);

    /* if the accelerometer is turned on then print angles */
    if (WIIUSE_USING_ACC(wm))
    {
        Tilt.X = -wm->orient.pitch;
        Tilt.Y = wm->orient.yaw;
        Tilt.Z = wm->orient.roll;

        Acceleration.X = wm->accel.x;
        Acceleration.Y = wm->accel.y;
        Acceleration.Z = wm->accel.z;
    }

    if (wm->exp.type == EXP_MOTION_PLUS || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK)
    {
        RotationRate.X = -wm->exp.mp.angle_rate_gyro.pitch;
        RotationRate.Y = wm->exp.mp.angle_rate_gyro.yaw;
        RotationRate.Z = wm->exp.mp.angle_rate_gyro.roll;
    }

    Gravity.X = wm->gforce.x;
    Gravity.Y = wm->gforce.y;
    Gravity.Z = wm->gforce.z;

    MessageHandler->OnMotionDetected(Tilt, RotationRate, Gravity, Acceleration, id);
}
Example #20
0
void EventReceiver::checkEvents()
{
    //Need to capture/update each device
    keyboard->capture();
    if (joystick) joystick->capture();

    OIS::JoyStickState joystickState;
    if (joystick) joystickState = joystick->getJoyStickState();
    
#if 0
    if (test_kc == 0)
    {
        test_kc = KeyConfig::getKeyConfig(keyboard, joystickState, deadZone, false);
        if (test_kc)
        {
            dprintf(MY_DEBUG_INFO, "test_kc assigned: %d\n", test_kc->key);
            //assert(0);
        }
    }
    else
    {
        float pressed = test_kc->getPercentage(keyboard, joystickState);
        if (pressed > deadZone)
        {
            dprintf(MY_DEBUG_INFO, "test_kc pressed: %f\n", pressed);
        }
    }
    if (keyboard->isKeyDown(OIS::KC_ESCAPE))
    {
        delete test_kc;
        test_kc = 0;
    }
    

    //printf("%s\n", keyboard->isKeyDown(OIS::KC_K)?"true":"false");
    /*
    printf("Axes: %lu\n", joystickState.mAxes.size());
    for (unsigned int i = 0; i < joystickState.mAxes.size(); i++)
    {
        printf("\t%u: %d (%d)\n", i, joystickState.mAxes[i].abs, joystickState.mAxes[i].rel);
    }
    printf("Sliders:\n");
    for (unsigned int i = 0; i < 4; i++)
    {
        printf("\t%u: %d, %d\n", i, joystickState.mSliders[i].abX, joystickState.mSliders[i].abY);
    }
    */
#else // 0 or 1
    
    if (MenuManager::getInstance()->getMenuInput())
    {
        /*
        if (IS_PRESSED(SWITCH_INPUT))
        {
            MenuManager::getInstance()->clearEventReceiver();
            MenuPageEditor::menuPageEditor->activateAction();
        }
        */
    }
    else
    {
    
        // the real event check

        // mouse
        /*
        mouse->capture();
        const OIS::MouseState mouseState = mouse->getMouseState();
        if (mouseState.buttonDown(OIS::MB_Left))
        {
            printf("mouse button left down\n");
        }

        if (mouseState.buttonDown(OIS::MB_Right))
        {
            printf("mouse button right down\n");
        }

        if (mouseState.buttonDown(OIS::MB_Middle))
        {
            printf("mouse button middle down\n");
        }
        */

        // other
            float perc = 0.f;
            if (IS_PRESSED(BRAKE) && (perc = getPercentage(BRAKE, joystickState))/* > Settings::getInstance()->joystickDeadZone*/)
            {
                //dprintf(MY_DEBUG_NOTE, "brake pressed: %f\n", perc);
                Player::getInstance()->setFirstPressed();
                Player::getInstance()->getVehicle()->setTorque(perc/*perc*/);
            }
            else
            if (IS_PRESSED(ACCELERATE) && (perc = getPercentage(ACCELERATE, joystickState))/* > Settings::getInstance()->joystickDeadZone*/)
            {
                //dprintf(MY_DEBUG_NOTE, "accelerate pressed: %f\n", perc);
                Player::getInstance()->setFirstPressed();
                Player::getInstance()->getVehicle()->setTorque(-1.0f*perc/*perc*/);
            }
            else
            {
                if (Settings::getInstance()->AIPlayer == false ||
                    Settings::getInstance()->editorMode ||
                    Player::getInstance()->getStarter() == 0)
                {
                    Player::getInstance()->getVehicle()->setTorque(0);
                }
            }

        if (Settings::getInstance()->AIPlayer == false ||
            Settings::getInstance()->editorMode ||
            Player::getInstance()->getStarter() == 0)
        {
            if (IS_PRESSED(CLUTCH) && (perc = getPercentage(CLUTCH, joystickState))/* > Settings::getInstance()->joystickDeadZone*/)
            {
                //dprintf(MY_DEBUG_NOTE, "accelerate pressed: %f\n", perc);
                Player::getInstance()->getVehicle()->setClutch(perc*perc);
            }

            const float steerRatePressed = Settings::getInstance()->steerRatePressed; // 0.2f
            float steerRate = Settings::getInstance()->steerRate; // 0.5f
            float desiredSteer = 0.0f;
            perc = 0.0f;
            if (Settings::getInstance()->linearSteering)
            {
                if (IS_PRESSED(LEFT) && (perc = getPercentage(LEFT, joystickState))/* > Settings::getInstance()->joystickDeadZone*/)
                {
                    //dprintf(MY_DEBUG_NOTE, "left pressed: %f\n", perc);
                    //Player::getInstance()->getVehicle()->setSteer(-1.0f*perc*perc);
                    desiredSteer = -1.0f*perc;
                }
                else
                if (IS_PRESSED(RIGHT) && (perc = getPercentage(RIGHT, joystickState))/* > Settings::getInstance()->joystickDeadZone*/)
                {
                    //dprintf(MY_DEBUG_NOTE, "right pressed: %f\n", perc);
                    //Player::getInstance()->getVehicle()->setSteer(perc*perc);
                    desiredSteer = perc;
                }
                else
                {
                    //Player::getInstance()->getVehicle()->setSteer(0.0f);
                }
                if (perc > Settings::getInstance()->joystickDeadZone)
                {
                    steerRate = steerRatePressed;
                }
            }
            else
            {
                if (IS_PRESSED(LEFT) && (perc = getPercentage(LEFT, joystickState))/* > Settings::getInstance()->joystickDeadZone*/)
                {
                    //dprintf(MY_DEBUG_NOTE, "left pressed: %f\n", perc);
                    //Player::getInstance()->getVehicle()->setSteer(-1.0f*perc*perc);
                    desiredSteer = -1.0f*perc*perc;
                }
                else
                if (IS_PRESSED(RIGHT) && (perc = getPercentage(RIGHT, joystickState))/* > Settings::getInstance()->joystickDeadZone*/)
                {
                    //dprintf(MY_DEBUG_NOTE, "right pressed: %f\n", perc);
                    //Player::getInstance()->getVehicle()->setSteer(perc*perc);
                    desiredSteer = perc*perc;
                }
                else
                {
                    //Player::getInstance()->getVehicle()->setSteer(0.0f);
                }
                if (perc*perc > Settings::getInstance()->joystickDeadZone)
                {
                    steerRate = steerRatePressed;
                }
            }
            //printf("steer rate: %f\n", steerRate);
            if (lastSteer + steerRate < desiredSteer)
            {
                lastSteer += steerRate;
            }
            else if (lastSteer - steerRate > desiredSteer)
            {
                lastSteer -= steerRate;
            }
            else
            {
                lastSteer = desiredSteer;
            }

            Player::getInstance()->getVehicle()->setSteer(lastSteer);

            if (IS_PRESSED(HANDBRAKE))
            {
                //dprintf(MY_DEBUG_NOTE, "brake pressed\n");
                Player::getInstance()->getVehicle()->setHandbrake(1.0f);
            }
            else
            {
                Player::getInstance()->getVehicle()->setHandbrake(0);
            }

            if (Settings::getInstance()->manualGearShifting)
            {
                if (Settings::getInstance()->sequentialGearShifting)
                {
                    if (IS_PRESSED(GEAR_UP) && getPressed(GEAR_UP))
                    {
                        Player::getInstance()->getVehicle()->incGear();
                    }
                    if (IS_PRESSED(GEAR_DOWN) && getPressed(GEAR_DOWN))
                    {
                        Player::getInstance()->getVehicle()->decGear();
                    }
                }
                else
                {
                    if (IS_PRESSED(GEAR_1))
                    {
                        Player::getInstance()->getVehicle()->setGear(1);
                    }
                    else
                    if (IS_PRESSED(GEAR_2))
                    {
                        Player::getInstance()->getVehicle()->setGear(2);
                    }
                    else
                    if (IS_PRESSED(GEAR_3))
                    {
                        Player::getInstance()->getVehicle()->setGear(3);
                    }
                    else
                    if (IS_PRESSED(GEAR_4))
                    {
                        Player::getInstance()->getVehicle()->setGear(4);
                    }
                    else
                    if (IS_PRESSED(GEAR_5))
                    {
                        Player::getInstance()->getVehicle()->setGear(5);
                    }
                    else
                    if (IS_PRESSED(GEAR_6))
                    {
                        Player::getInstance()->getVehicle()->setGear(6);
                    }
                    else
                    if (IS_PRESSED(GEAR_R))
                    {
                        Player::getInstance()->getVehicle()->setGear(-1);
                    }
                    else
                    {
                        Player::getInstance()->getVehicle()->setGear(0);
                    }
                }
            }
        } // if (Settings::getInstance()->AIPlayer == false || Settings::getInstance()->editorMode)

        if (IS_PRESSED(PHYSICS))
        {
            TheGame::getInstance()->setPhysicsOngoing(!TheGame::getInstance()->getPhysicsOngoing());
        }
        /*else
        {
            TheGame::getInstance()->setPhysicsOngoing(false);
        }*/

        if (IS_PRESSED(FPS_CAMERA))
        {
            dprintf(MY_DEBUG_NOTE, "switch camera\n");
            TheGame::getInstance()->switchCamera();
        }

        if (IS_PRESSED(SWITCH_HUD))
        {
            dprintf(MY_DEBUG_NOTE, "switch hud\n");
            Hud::getInstance()->setVisible(!Hud::getInstance()->getVisible());
        }

        if (IS_PRESSED(LOOK_LEFT) && getPressed(LOOK_LEFT))
        {
            Player::getInstance()->lookLeft(true);
        }
        else if (getReleased(LOOK_LEFT))
        {
            Player::getInstance()->lookLeft(false);
        }

        if (IS_PRESSED(LOOK_RIGHT) && getPressed(LOOK_RIGHT))
        {
            Player::getInstance()->lookRight(true);
        }
        else if (getReleased(LOOK_RIGHT))
        {
            Player::getInstance()->lookRight(false);
        }

        if (IS_PRESSED(CHANGE_VIEW))
        {
            Player::getInstance()->switchToNextView();
        }

        if (IS_PRESSED(OPEN_EDITOR))
        {
            if (Settings::getInstance()->editorMode)
            {
                MenuManager::getInstance()->open(MenuManager::MP_EDITOR);
            }
        }

        if (IS_PRESSED(RESET_VEHICLE))
        {
            Player::getInstance()->resetVehicle(irr::core::vector3df(
                    TheGame::getInstance()->getCamera()->getPosition().X,
                    TheEarth::getInstance()->getHeight(TheGame::getInstance()->getCamera()->getPosition())+2.5f,
                    TheGame::getInstance()->getCamera()->getPosition().Z));
        }

        if (IS_PRESSED(REPAIR_VEHICLE))
        {
            Player::getInstance()->repairVehicle();
        }

        if (IS_PRESSED(SWITCH_INPUT))
        {
            MenuManager::getInstance()->refreshEventReceiver();
            MenuPageEditor::menuPageEditor->refreshAction();
        }

        if (IS_PRESSED(INC_FPS_SPEED))
        {
            TheGame::getInstance()->incFPSSpeed();
        }

        if (IS_PRESSED(DEC_FPS_SPEED))
        {
            TheGame::getInstance()->decFPSSpeed();
        }

        //if (Settings::getInstance()->navigationAssistant == false)
        //{
            if (IS_PRESSED(ROADBOOK_NEXT))
            {
                Player::getInstance()->stepItiner();
                Hud::getInstance()->updateRoadBook();
            }
            else if (IS_PRESSED(ROADBOOK_PREV))
            {
                Player::getInstance()->stepBackItiner();
                Hud::getInstance()->updateRoadBook();
            }
            if (IS_PRESSED(RESET_PARTIAL))
            {
                Player::getInstance()->resetDistance();
            }
        //}

        if (IS_PRESSED(EXIT_TO_MENU))
        {
            MenuManager::getInstance()->open(MenuManager::MP_INGAME);
        }
#ifdef DETECT_MEM_LEAKS
        if (IS_PRESSED(PRINT_MEM_LEAKS))
        {
            VLDReportLeaks();
            //_CrtDumpMemoryLeaks();
            //assert(0);
        }
        if (IS_PRESSED(PRINT_MEM_LEAKS_IRR))
        {
            TheGame::getInstance()->getSmgr()->addTerrainSceneNode("fake/path");
            //_CrtDumpMemoryLeaks();
            //assert(0);
        }
#endif // DETECT_MEM_LEAKS
    }
#endif // 0 or 1
}
Example #21
0
/**
 *	@brief Callback that handles an event.
 *
 *	@param wm		Pointer to a wiimote_t structure.
 *
 *	This function is called automatically by the wiiuse library when an
 *	event occurs on the specified wiimote.
 */
void handle_event(struct wiimote_t* wm) {
	printf("\n\n--- EVENT [id %i] ---\n", wm->unid);

	/* if a button is pressed, report it */
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) {
		printf("A pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) {
		printf("B pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) {
		printf("UP pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN))	{
		printf("DOWN pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))	{
		printf("LEFT pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT))	{
		printf("RIGHT pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS))	{
		printf("MINUS pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS))	{
		printf("PLUS pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
		printf("ONE pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {
		printf("TWO pressed\n");
	}
	if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME))	{
		printf("HOME pressed\n");
	}

	/*
	 *	Pressing minus will tell the wiimote we are no longer interested in movement.
	 *	This is useful because it saves battery power.
	 */
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {
		wiiuse_motion_sensing(wm, 0);
	}

	/*
	 *	Pressing plus will tell the wiimote we are interested in movement.
	 */
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {
		wiiuse_motion_sensing(wm, 1);
	}

	/*
	 *	Pressing B will toggle the rumble
	 *
	 *	if B is pressed but is not held, toggle the rumble
	 */
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) {
		wiiuse_toggle_rumble(wm);
	}

	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) {
		wiiuse_set_ir(wm, 1);
	}
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {
		wiiuse_set_ir(wm, 0);
	}

	/*
	 * Motion+ support
	 */
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
		if (WIIUSE_USING_EXP(wm)) {
			wiiuse_set_motion_plus(wm, 2);    // nunchuck pass-through
		} else {
			wiiuse_set_motion_plus(wm, 1);    // standalone
		}
	}

	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {
		wiiuse_set_motion_plus(wm, 0); // off
	}

	/* if the accelerometer is turned on then print angles */
	if (WIIUSE_USING_ACC(wm)) {
		printf("wiimote roll  = %f [%f]\n", wm->orient.roll, wm->orient.a_roll);
		printf("wiimote pitch = %f [%f]\n", wm->orient.pitch, wm->orient.a_pitch);
		printf("wiimote yaw   = %f\n", wm->orient.yaw);
	}

	/*
	 *	If IR tracking is enabled then print the coordinates
	 *	on the virtual screen that the wiimote is pointing to.
	 *
	 *	Also make sure that we see at least 1 dot.
	 */
	if (WIIUSE_USING_IR(wm)) {
		int i = 0;

		/* go through each of the 4 possible IR sources */
		for (; i < 4; ++i) {
			/* check if the source is visible */
			if (wm->ir.dot[i].visible) {
				printf("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y);
			}
		}

		printf("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
		printf("IR z distance: %f\n", wm->ir.z);
	}

	/* show events specific to supported expansions */
	if (wm->exp.type == EXP_NUNCHUK || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) {
		/* nunchuk */
		struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;

		if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) {
			printf("Nunchuk: C pressed\n");
		}
		if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) {
			printf("Nunchuk: Z pressed\n");
		}

		printf("nunchuk roll  = %f\n", nc->orient.roll);
		printf("nunchuk pitch = %f\n", nc->orient.pitch);
		printf("nunchuk yaw   = %f\n", nc->orient.yaw);

		printf("nunchuk joystick angle:     %f\n", nc->js.ang);
		printf("nunchuk joystick magnitude: %f\n", nc->js.mag);

		printf("nunchuk joystick vals:      %f, %f\n", nc->js.x, nc->js.y);
		printf("nunchuk joystick calibration (min, center, max): x: %i, %i, %i  y: %i, %i, %i\n",
		    nc->js.min.x,
		    nc->js.center.x,
		    nc->js.max.x,
		    nc->js.min.y,
		    nc->js.center.y,
		    nc->js.max.y);
	} else if (wm->exp.type == EXP_CLASSIC) {
		/* classic controller */
		struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic;

		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL)) {
			printf("Classic: ZL pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B)) {
			printf("Classic: B pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y)) {
			printf("Classic: Y pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A)) {
			printf("Classic: A pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X)) {
			printf("Classic: X pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR)) {
			printf("Classic: ZR pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT)) {
			printf("Classic: LEFT pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP)) {
			printf("Classic: UP pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT)) {
			printf("Classic: RIGHT pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN)) {
			printf("Classic: DOWN pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L)) {
			printf("Classic: FULL L pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS)) {
			printf("Classic: MINUS pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME)) {
			printf("Classic: HOME pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS)) {
			printf("Classic: PLUS pressed\n");
		}
		if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R)) {
			printf("Classic: FULL R pressed\n");
		}

		printf("classic L button pressed:         %f\n", cc->l_shoulder);
		printf("classic R button pressed:         %f\n", cc->r_shoulder);
		printf("classic left joystick angle:      %f\n", cc->ljs.ang);
		printf("classic left joystick magnitude:  %f\n", cc->ljs.mag);
		printf("classic right joystick angle:     %f\n", cc->rjs.ang);
		printf("classic right joystick magnitude: %f\n", cc->rjs.mag);
	} else if (wm->exp.type == EXP_GUITAR_HERO_3) {
		/* guitar hero 3 guitar */
		struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3;

		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP)) {
			printf("Guitar: Strum Up pressed\n");
		}
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN))	{
			printf("Guitar: Strum Down pressed\n");
		}
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW)) {
			printf("Guitar: Yellow pressed\n");
		}
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN)) {
			printf("Guitar: Green pressed\n");
		}
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE)) {
			printf("Guitar: Blue pressed\n");
		}
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED)) {
			printf("Guitar: Red pressed\n");
		}
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE)) {
			printf("Guitar: Orange pressed\n");
		}
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS)) {
			printf("Guitar: Plus pressed\n");
		}
		if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS)) {
			printf("Guitar: Minus pressed\n");
		}

		printf("Guitar whammy bar:          %f\n", gh3->whammy_bar);
		printf("Guitar joystick angle:      %f\n", gh3->js.ang);
		printf("Guitar joystick magnitude:  %f\n", gh3->js.mag);
	} else if (wm->exp.type == EXP_WII_BOARD) {
		/* wii balance board */
		struct wii_board_t* wb = (wii_board_t*)&wm->exp.wb;
		float total = wb->tl + wb->tr + wb->bl + wb->br;
		float x = ((wb->tr + wb->br) / total) * 2 - 1;
		float y = ((wb->tl + wb->tr) / total) * 2 - 1;
		printf("Weight: %f kg @ (%f, %f)\n", total, x, y);
		/* printf("Interpolated weight: TL:%f  TR:%f  BL:%f  BR:%f\n", wb->tl, wb->tr, wb->bl, wb->br); */
		/* printf("Raw: TL:%d  TR:%d  BL:%d  BR:%d\n", wb->rtl, wb->rtr, wb->rbl, wb->rbr); */
	}

	if (wm->exp.type == EXP_MOTION_PLUS ||
	        wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) {
		printf("Motion+ angular rates (deg/sec): pitch:%03.2f roll:%03.2f yaw:%03.2f\n",
		       wm->exp.mp.angle_rate_gyro.pitch,
		       wm->exp.mp.angle_rate_gyro.roll,
		       wm->exp.mp.angle_rate_gyro.yaw);
	}
}