示例#1
0
/*
 * If necessary, write back uncomitted buffer contents to block device.
 */
static int Sync_Buffer(struct FS_Buffer_Cache *cache, struct FS_Buffer *buf) {
    int rc = 0;

    KASSERT(IS_HELD(&cache->lock));

    if (buf->flags & FS_BUFFER_DIRTY) {
        if ((rc = Do_Buffer_IO(cache, buf, Block_Write)) == 0)
            buf->flags &= ~(FS_BUFFER_DIRTY);
    }

    return rc;
}
示例#2
0
/*
 * Synchronize cache with disk.
 */
static int Sync_Cache(struct FS_Buffer_Cache *cache) {
    int rc = 0;
    struct FS_Buffer *buf;

    KASSERT(IS_HELD(&cache->lock));

    buf = Get_Front_Of_FS_Buffer_List(&cache->bufferList);
    while (buf != 0) {
        if ((rc = Sync_Buffer(cache, buf)) != 0)
            break;
        buf = Get_Next_In_FS_Buffer_List(buf);
    }

    return rc;
}
示例#3
0
/*
 * Lock given mutex.
 * Preemption must be disabled.
 */
static __inline__ void Mutex_Lock_Imp(struct Mutex* mutex)
{
    KASSERT(g_preemptionDisabled);

    /* Make sure we're not already holding the mutex */
    KASSERT(!IS_HELD(mutex));

    /* Wait until the mutex is in an unlocked state */
    while (mutex->state == MUTEX_LOCKED) {
	Mutex_Wait(mutex);
    }

    /* Now it's ours! */
    mutex->state = MUTEX_LOCKED;
    mutex->owner = g_currentThread;
}
void CWiiController::get_keys(wiimote* wm)
{
  m_buttonHeld = 0;
  m_buttonPressed = 0;
  m_buttonReleased = 0;

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

  for (int i = 1;i <= WIIMOTE_NUM_BUTTONS; i++)
  {
    if (IS_PRESSED(wm,convert_code(i)))
      m_buttonPressed = i;
    if (IS_RELEASED(wm,convert_code(i)))
      m_buttonReleased = i;
    if (IS_HELD(wm,convert_code(i)))
      m_buttonHeld = i;
  }
}
示例#5
0
/*
 * Wait on given condition (protected by given mutex).
 */
void Cond_Wait(struct Condition* cond, struct Mutex* mutex)
{
    KASSERT(Interrupts_Enabled());

    /* Ensure mutex is held. */
    KASSERT(IS_HELD(mutex));

    /* Turn off scheduling. */
    g_preemptionDisabled = true;

    /*
     * Release the mutex, but leave preemption disabled.
     * No other threads will be able to run before this thread
     * is able to wait.  Therefore, this thread will not
     * miss the eventual notification on the condition.
     */
    Mutex_Unlock_Imp(mutex);

    /*
     * Atomically reenable preemption and wait in the condition wait queue.
     * Other threads can run while this thread is waiting,
     * and eventually one of them will call Cond_Signal() or Cond_Broadcast()
     * to wake up this thread.
     * On wakeup, disable preemption again.
     */
    Disable_Interrupts();
    g_preemptionDisabled = false;
    Wait(&cond->waitQueue);
    g_preemptionDisabled = true;
    Enable_Interrupts();

    /* Reacquire the mutex. */
    Mutex_Lock_Imp(mutex);

    /* Turn scheduling back on. */
    g_preemptionDisabled = false;
}
示例#6
0
/*
 * Unlock given mutex.
 * Preemption must be disabled.
 */
static __inline__ void Mutex_Unlock_Imp(struct Mutex* mutex)
{
    KASSERT(g_preemptionDisabled);

    /* Make sure mutex was actually acquired by this thread. */
    KASSERT(IS_HELD(mutex));

    /* Unlock the mutex. */
    mutex->state = MUTEX_UNLOCKED;
    mutex->owner = 0;

    /*
     * If there are threads waiting to acquire the mutex,
     * wake one of them up.  Note that it is legal to inspect
     * the queue with interrupts enabled because preemption
     * is disabled, and therefore we know that no thread can
     * concurrently add itself to the queue.
     */
    if (!Is_Thread_Queue_Empty(&mutex->waitQueue)) {
	Disable_Interrupts();
	Wake_Up_One(&mutex->waitQueue);
	Enable_Interrupts();
    }
}
示例#7
0
int main(int argc, char** argv)
{
    InitWiimotes();

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

    int nPrecX, nPrecY;


    while(bLoop)
    {

        int n;

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

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

                    case WIIUSE_EVENT:


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

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


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

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

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

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

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

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

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


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

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

                //Déplacement de la souris
                tagPOINT CursorPos;

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



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

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


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

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

                    nPrecX=nWiimoteX;
                    nPrecY=nWiimoteY;


                }
                else if(nCursorControl==CUR_CTRL_IR)
                {

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

                    float fCenterX=-1.0, fCenterY=-1.0;

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


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


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



                }
                else
                {
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_UP) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_UP))
                    {
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x, CursorPos.y-ARROW_SPEED);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_DOWN) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_DOWN))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x, CursorPos.y+ARROW_SPEED);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_LEFT) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_LEFT))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x-ARROW_SPEED, CursorPos.y);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_RIGHT) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_RIGHT))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x+ARROW_SPEED, CursorPos.y);
                    }
                }
            }
        }
    }
    EndWiimotes();
}
void 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);
}
示例#9
0
/*
 * Get buffer for given block, and mark it in use.
 * Must be called with cache mutex held.
 */
static int Get_Buffer(struct FS_Buffer_Cache *cache, ulong_t fsBlockNum,
                      struct FS_Buffer **pBuf) {
    struct FS_Buffer *buf, *lru = 0;
    int rc;

    Debug("Request block %lu\n", fsBlockNum);

    KASSERT(IS_HELD(&cache->lock));

    /*
     * Look for existing buffer.
     * As a side-effect, finds the least recently used
     * buffer that is not in use (if any).
     */
    buf = Get_Front_Of_FS_Buffer_List(&cache->bufferList);
    while (buf != 0) {
        if (buf->fsBlockNum == fsBlockNum) {
            /* If buffer is in use, wait until it is available. */
            while (buf->flags & FS_BUFFER_INUSE) {
                Debug("Waiting for block %lu\n", fsBlockNum);
                Cond_Wait(&cache->cond, &cache->lock);
            }
            goto done;
        }

        /* If buffer isn't in use, it's a candidate for LRU. */
        if (!(buf->flags & FS_BUFFER_INUSE))
            lru = buf;

        buf = Get_Next_In_FS_Buffer_List(buf);
    }

    /*
     * If number of allocated buffers does not exceed the
     * limit, allocate a new one.
     */
    if (cache->numCached < FS_BUFFER_CACHE_MAX_BLOCKS) {
        buf = (struct FS_Buffer *)Malloc(sizeof(*buf));
        if (buf != 0) {
            buf->data = Alloc_Page();
            if (buf->data == 0)
                Free(buf);
            else {
                /* Successful creation */
                buf->fsBlockNum = fsBlockNum;
                buf->flags = 0;
                Add_To_Front_Of_FS_Buffer_List(&cache->bufferList, buf);
                ++cache->numCached;
                goto readAndAcquire;
            }
        }
    }

    /*
     * If there is no LRU buffer, then we have exceeded
     * the number of available buffers.
     */
    if (lru == 0)
        return ENOMEM;

    KASSERT(!noEvict);

    /* Make sure the LRU buffer is clean. */
    if ((rc = Sync_Buffer(cache, lru)) != 0)
        return rc;

    /* LRU buffer is clean, so we can steal it. */
    buf = lru;
    buf->flags = 0;
    buf->fsBlockNum = fsBlockNum;       /* bugfix by neil. */

    Move_To_Front(cache, buf);

  readAndAcquire:
    /*
     * The buffer selected should be clean (no uncommitted data),
     * and should have been moved to the front of the buffer list
     * (to show it has just been referenced).
     */
    KASSERT(!(buf->flags & FS_BUFFER_DIRTY));
    KASSERT(Get_Front_Of_FS_Buffer_List(&cache->bufferList) == buf);

    /* Read block data into buffer. */
    if ((rc = Do_Buffer_IO(cache, buf, Block_Read)) != 0)
        return rc;

  done:
    /* Buffer is now in use. */
    buf->flags |= FS_BUFFER_INUSE;

    /* Success! */
    Debug("Acquired block %lu\n", fsBlockNum);
    *pBuf = buf;
    return 0;
}
示例#10
0
gboolean handle_hit(gpointer *data)
{
	static int down[2] = { 0 };
	started = 1;
	for(;!exitting;)
	{
		if(wiiuse_poll(wiimotes,found))
		{
			if(wiimotes[0]->event == WIIUSE_EVENT)
			{
				if(wiimotes[0]->gforce.z<gtk_range_get_value(GTK_RANGE(dwn[0])) && !down[0])
				{
					lhit[0] = SDL_GetTicks();
					down[0] = 1;
					if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_A))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_CRASH],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_B))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_HIHAT],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_MINUS))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_HTOM],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_HOME))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_MTOM],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_PLUS))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_LTOM],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_DOWN))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_RIDE],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_LEFT))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_CHCRASH],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_RIGHT))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SPLASH],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_ONE) || IS_HELD(wiimotes[0], WIIMOTE_BUTTON_TWO))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SNAREST],0);
					}
					else
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SNAREL],0);
					}
				}
				if(wiimotes[0]->gforce.z>gtk_range_get_value(GTK_RANGE(up[0])) && down[0])
				{
					down[0] = 0;
				}
			}
			if(wiimotes[1]->event == WIIUSE_EVENT)
			{
				if(wiimotes[1]->gforce.z<gtk_range_get_value(GTK_RANGE(dwn[1])) && !down[1])
				{
					lhit[1] = SDL_GetTicks();
					down[1] = 1;
					if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_A))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_CRASH],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_B))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_HIHAT],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_MINUS))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_HTOM],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_HOME))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_MTOM],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_PLUS))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_LTOM],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_DOWN))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_RIDE],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_LEFT))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_CHCRASH],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_RIGHT))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SPLASH],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_ONE) || IS_HELD(wiimotes[0], WIIMOTE_BUTTON_TWO))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SNAREST],0);
					}
					else
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SNARER],0);
					}
				}
				if(wiimotes[1]->gforce.z>gtk_range_get_value(GTK_RANGE(up[1])) && down[1])
				{
					down[1] = 0;
				}
			}
		}		
		gtk_widget_queue_draw(ggraph);
	}
}
示例#11
0
文件: wiimote.c 项目: csound/csound
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;
}