Ejemplo n.º 1
0
static int tilt_func(void *data)
{
    wiimote_t   wiimote = WIIMOTE_INIT;
    const char *address = config_get_s(CONFIG_WIIMOTE_ADDR);

    if (strlen(address) > 0)
    {
        if (wiimote_connect(&wiimote, address) < 0)
            log_printf("Wiimote error (%s)\n", wiimote_get_error());
        else
        {
            int running = 1;

            wiimote.mode.bits = WIIMOTE_MODE_ACC;
            wiimote.led.one   = 1;

            SDL_mutexP(mutex);
            state.status = running;
            SDL_mutexV(mutex);

            while (mutex && running && wiimote_is_open(&wiimote))
            {
                if (wiimote_update(&wiimote) < 0)
                    break;

                SDL_mutexP(mutex);
                {
                    running = state.status;

                    set_button(&state.A,     wiimote.keys.a);
                    set_button(&state.B,     wiimote.keys.b);
                    set_button(&state.plus,  wiimote.keys.plus);
                    set_button(&state.minus, wiimote.keys.minus);
                    set_button(&state.home,  wiimote.keys.home);
                    set_button(&state.L,     wiimote.keys.left);
                    set_button(&state.R,     wiimote.keys.right);
                    set_button(&state.U,     wiimote.keys.up);
                    set_button(&state.D,     wiimote.keys.down);

                    if (isnormal(wiimote.tilt.y))
                    {
                        state.x = (state.x * (FILTER - 1) +
                                   wiimote.tilt.y) / FILTER;
                    }
                    if (isnormal(wiimote.tilt.x))
                    {
                        state.z = (state.z * (FILTER - 1) +
                                   wiimote.tilt.x) / FILTER;
                    }
                }
                SDL_mutexV(mutex);
            }

            wiimote_disconnect(&wiimote);
        }
    }
    return 0;
}
Ejemplo n.º 2
0
int wiimote_close(wiimote_t *wiimote)
{
	if (wiimote_is_open(wiimote)) {
		if (wiimote_disconnect(wiimote) < 0) {
			wiimote_set_error("wiimote_close(): unable to disconnect");
			return WIIMOTE_ERROR;
		}
	}
	
	free(wiimote);
	
	return WIIMOTE_OK;
}
Ejemplo n.º 3
0
// ######################################################################
void WiiMote::run()
{
#ifdef HAVE_LIBWIIMOTE
  running = true;

  while(wiimote_is_open(&itsWiimote) && running)
  {
    pthread_mutex_lock(&itsLock);
    int rc = wiimote_update(&itsWiimote);
    pthread_mutex_unlock(&itsLock);

    if (rc < 0) {
      wiimote_disconnect(&itsWiimote);
      break;
    }
    //// sleep a little:
    //usleep(5000);
  }

  // we got an order to stop:
  //running = f;  // FIXME: bogus! other thread may unlock too soon
  pthread_exit(0);
#endif
}
Ejemplo n.º 4
0
/*****************************************************************
  関数名	: WindowEvent
  機能	: メインウインドウに対するイベント処理を行う
  引数	: int		num		: 全クライアント数
  出力	: なし
 *****************************************************************/
void WindowEvent(int num)
{
    if(wiimote_is_open(&data.wiimote)){ //wiiリモコンの入力の場合
        //wiiリモコンの状態を取得・更新する 
        if(wiimote_update(&data.wiimote) < 0){
            wiimote_disconnect(&data.wiimote);
            return;
        }

        //-------wiiのキーごとに処理--------------------------------
        //HOMEボタンが押された時
        if(data.wiimote.keys.home){
            wiimote_speaker_free(&data.wiimote);
            wiimote_disconnect(&data.wiimote);
            SendEndCommand(data);
        }else{
		data.command = WII_COMMAND;
		SendWiimoteCommand(data);
	}
	/*
        //左に移動(十字キーの上ボタン)
        if(data.wiimote.keys.up==1){ //押された時
            printf("UP!\n");
            SendKeyCommand(LEFT_KEYBOARD);
        }
        //右に移動(十字キーの下ボタン)
        if(data.wiimote.keys.down==1){
            printf("DOWN!\n");
            SendKeyCommand(RIGHT_KEYBOARD);
        }
        //上に移動(十字キーの右ボタン)
        if(data.wiimote.keys.right==1){
            printf("LEFT!\n");
            SendKeyCommand(UP_KEYBOARD);
        }
        //下に移動(十字キーの左ボタン)
        if(data.wiimote.keys.left==1){
            printf("RIGHT!\n");
            SendKeyCommand(DOWN_KEYBOARD);
        }
	*/

        //else { //十字キーをどれも押してない時
        //  jhat_stts=0; //(0:押してない,1:左,2:右)
        // }
    }
    else{ //キーボード入力の場合
        SDL_Event event;
        SDL_MouseButtonEvent *mouse;
        int buttonNO;

        /* 引き数チェック */
        assert(0<num && num<=MAX_CLIENTS);
        //キーボードのイベントチェック
        if(SDL_PollEvent(&event)){
            //printf("Event!\n");
            switch(event.type){
                case SDL_QUIT:
                    SendEndCommand(data);
                    break;
                case SDL_KEYDOWN:
                    printf("The pressed key is %s.\n",SDL_GetKeyName(event.key.keysym.sym));//どのキーが押されたか表示する
                    switch(event.key.keysym.sym){//方向キーの時データを送る またはエスケープキーの時終わらせる
                        case SDLK_ESCAPE:
                            SendEndCommand(data);
                            break;
                        case SDLK_UP:
                            printf("UP!\n");
                            SendKeyCommand(UP_KEYBOARD);
                            break;
                        case SDLK_DOWN:
                            printf("DOWN!\n");
                            SendKeyCommand(DOWN_KEYBOARD);
                            break;
                        case SDLK_LEFT:
                            printf("LEFT!\n");
                            SendKeyCommand(LEFT_KEYBOARD);
                            break;
                        case SDLK_RIGHT:
                            printf("RIGHT!\n");
                            SendKeyCommand(RIGHT_KEYBOARD);
                            break;
                    }
                    break;		
            }
        }
    }

}