Example #1
0
void HandleEvent(CWiimote &wm)
{
  char prefixString[64];

  if(wm.Buttons.isJustPressed(CButtons::BUTTON_MINUS))
  {
    wm.SetMotionSensingMode(CWiimote::OFF);
  }

  if(wm.Buttons.isJustPressed(CButtons::BUTTON_PLUS))
  {
    wm.SetMotionSensingMode(CWiimote::ON);
  }

  if(wm.Buttons.isJustPressed(CButtons::BUTTON_DOWN))
  {
    wm.IR.SetMode(CIR::OFF);
  }

  if(wm.Buttons.isJustPressed(CButtons::BUTTON_UP))
  {
    wm.IR.SetMode(CIR::ON);
  }

  if(wm.Buttons.isJustPressed(CButtons::BUTTON_RIGHT))
  {
    wm.EnableMotionPlus(CWiimote::ON);
  }

  if(wm.Buttons.isJustPressed(CButtons::BUTTON_LEFT))
  {
    wm.EnableMotionPlus(CWiimote::OFF);
  }

  if(wm.Buttons.isJustPressed(CButtons::BUTTON_B))
  {
    wm.ToggleRumble();
  }

  sprintf(prefixString, "Controller [%i]: ", wm.GetID());

  if(wm.Buttons.isPressed(CButtons::BUTTON_A))
  {
    printf("%s A pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_B))
  {
    printf("%s B pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_UP))
  {
    printf("%s Up pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_DOWN))
  {
    printf("%s Down pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_LEFT))
  {
    printf("%s Left pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_RIGHT))
  {
    printf("%s Right pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_MINUS))
  {
    printf("%s Minus pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_PLUS))
  {
    printf("%s Plus pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_ONE))
  {
    printf("%s One pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_TWO))
  {
    printf("%s Two pressed\n", prefixString);
  }

  if(wm.Buttons.isPressed(CButtons::BUTTON_HOME))
  {
    printf("%s Home pressed\n", prefixString);
  }

  // if the accelerometer is turned on then print angles
  if(wm.isUsingACC())
  {
    float pitch, roll, yaw;
    wm.Accelerometer.GetOrientation(pitch, roll, yaw);
    printf("%s wiimote roll  = %f\n", prefixString, roll);
    printf("%s wiimote pitch = %f\n", prefixString, pitch);
    printf("%s wiimote yaw   = %f\n", prefixString, yaw);
  }

  // if the Motion Plus is turned on then print angles
  if(wm.isUsingMotionPlus()) {
    float roll_rate, pitch_rate, yaw_rate;
    wm.ExpansionDevice.MotionPlus.Gyroscope.GetRates(roll_rate,pitch_rate,yaw_rate);

    printf("%s motion plus roll rate  = %f\n", prefixString,roll_rate);
    printf("%s motion plus pitch rate = %f\n", prefixString,pitch_rate);
    printf("%s motion plus yaw rate   = %f\n", prefixString,yaw_rate);
  }

  // if(IR tracking is on then print the coordinates
  if(wm.isUsingIR())
  {
    std::vector<CIRDot>::iterator i;
    int x, y;
    int index;

    printf("%s Num IR Dots: %i\n", prefixString, wm.IR.GetNumDots());
    printf("%s IR State: %u\n", prefixString, wm.IR.GetState());

    std::vector<CIRDot>& dots = wm.IR.GetDots();

    for(index = 0, i = dots.begin(); i != dots.end(); ++index, ++i)
    {
      if((*i).isVisible())
      {
        (*i).GetCoordinate(x, y);
        printf("%s IR source %i: (%i, %i)\n", prefixString, index, x, y);

        wm.IR.GetCursorPosition(x, y);
        printf("%s IR cursor: (%i, %i)\n", prefixString, x, y);
        printf("%s IR z distance: %f\n", prefixString, wm.IR.GetDistance());
      }
    }
  }

  int exType = wm.ExpansionDevice.GetType();
  if(exType == wm.ExpansionDevice.TYPE_NUNCHUK)
  {
    float pitch, roll, yaw, a_pitch, a_roll;
    float angle, magnitude;

    CNunchuk &nc = wm.ExpansionDevice.Nunchuk;

    sprintf(prefixString, "Nunchuk [%i]: ", wm.GetID());

    if(nc.Buttons.isPressed(CNunchukButtons::BUTTON_C))
    {
      printf("%s C pressed\n", prefixString);
    }

    if(nc.Buttons.isPressed(CNunchukButtons::BUTTON_Z))
    {
      printf("%s Z pressed\n", prefixString);
    }

    nc.Accelerometer.GetOrientation(pitch, roll, yaw);
    printf("%s roll = %f\n", prefixString, roll);
    printf("%s pitch = %f\n", prefixString, pitch);
    printf("%s yaw = %f\n", prefixString, yaw);

    nc.Joystick.GetPosition(angle, magnitude);
    printf("%s joystick angle = %f\n", prefixString, angle);
    printf("%s joystick magnitude = %f\n", prefixString, magnitude);
  }
  else if(exType == wm.ExpansionDevice.TYPE_CLASSIC)
  {
    float angle, magnitude;

    CClassic &cc = wm.ExpansionDevice.Classic;

    sprintf(prefixString, "Classic [%i]: ", wm.GetID());

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_A))
    {
      printf("%s A pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_B))
    {
      printf("%s B pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_X))
    {
      printf("%s X pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_Y))
    {
      printf("%s Y pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_LEFT))
    {
      printf("%s Left pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_UP))
    {
      printf("%s Up pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_RIGHT))
    {
      printf("%s Right pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_DOWN))
    {
      printf("%s Down pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_PLUS))
    {
      printf("%s Plus pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_MINUS))
    {
      printf("%s Minus pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_HOME))
    {
      printf("%s Home pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_ZL))
    {
      printf("%s ZL pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_FULL_L))
    {
      printf("%s ZR pressed\n", prefixString);
    }

    if(cc.Buttons.isPressed(CClassicButtons::BUTTON_FULL_R))
    {
      printf("%s ZR pressed\n", prefixString);
    }

    printf("%s L button pressed = %f\n", prefixString, cc.GetLShoulderButton());
    printf("%s R button pressed = %f\n", prefixString, cc.GetRShoulderButton());

    cc.LeftJoystick.GetPosition(angle, magnitude);
    printf("%s left joystick angle = %f\n", prefixString, angle);
    printf("%s left joystick magnitude = %f\n", prefixString, magnitude);

    cc.RightJoystick.GetPosition(angle, magnitude);
    printf("%s right joystick angle = %f\n", prefixString, angle);
    printf("%s right joystick magnitude = %f\n", prefixString, magnitude);
  }
  else if(exType == wm.ExpansionDevice.TYPE_GUITAR_HERO_3)
  {
    float angle, magnitude;

    CGuitarHero3 &gh = wm.ExpansionDevice.GuitarHero3;

    sprintf(prefixString, "Guitar [%i]: ", wm.GetID());

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_STRUM_UP))
    {
      printf("%s Strum Up pressed\n", prefixString);
    }

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_STRUM_DOWN))
    {
      printf("%s Strum Down pressed\n", prefixString);
    }

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_YELLOW))
    {
      printf("%s Yellow pressed\n", prefixString);
    }

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_GREEN))
    {
      printf("%s Green pressed\n", prefixString);
    }

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_BLUE))
    {
      printf("%s Blue pressed\n", prefixString);
    }

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_RED))
    {
      printf("%s Red pressed\n", prefixString);
    }

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_ORANGE))
    {
      printf("%s Orange pressed\n", prefixString);
    }

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_PLUS))
    {
      printf("%s Plus pressed\n", prefixString);
    }

    if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_MINUS))
    {
      printf("%s Minus pressed\n", prefixString);
    }

    printf("%s whammy bar = %f\n", prefixString, gh.GetWhammyBar());

    gh.Joystick.GetPosition(angle, magnitude);
    printf("%s joystick angle = %f\n", prefixString, angle);
    printf("%s joystick magnitude = %f\n", prefixString, magnitude);
  }
  else if(exType == wm.ExpansionDevice.TYPE_BALANCE_BOARD) 
  {
    CBalanceBoard &bb = wm.ExpansionDevice.BalanceBoard;
    float total, topLeft, topRight, bottomLeft, bottomRight;
		
    bb.WeightSensor.GetWeight(total, topLeft, topRight, bottomLeft, bottomRight);
    printf("balance board top left weight: %f\n", topLeft);
    printf("balance board top right weight: %f\n", topRight);
    printf("balance board bottom left weight: %f\n", bottomLeft);
    printf("balance board bottom right weight: %f\n", bottomRight);
    printf("balance board total weight: %f\n", total);
  }
}
Example #2
0
void HandleEvent(CWiimote &wm)
{
    char prefixString[64];

    if(wm.Buttons.isJustPressed(CButtons::BUTTON_MINUS)) wm.SetMotionSensingMode(CWiimote::OFF) ;
    if(wm.Buttons.isJustPressed(CButtons::BUTTON_PLUS))  wm.SetMotionSensingMode(CWiimote::ON) ;
    if(wm.Buttons.isJustPressed(CButtons::BUTTON_DOWN))  wm.IR.SetMode(CIR::OFF);
    if(wm.Buttons.isJustPressed(CButtons::BUTTON_UP))    wm.IR.SetMode(CIR::ON);
    if(wm.Buttons.isJustPressed(CButtons::BUTTON_B))     wm.ToggleRumble();

    sprintf(prefixString, "Controller [%i]: ", wm.GetID());

    if(wm.Buttons.isJustChanged()) printf("%s State of Wiimote buttons changed\n", prefixString);

    if(wm.Buttons.isPressed(CButtons::BUTTON_A)) printf("%s A pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_B)) printf("%s B pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_UP))printf("%s Up pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_DOWN))printf("%s Down pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_LEFT))printf("%s Left pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_RIGHT))printf("%s Right pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_MINUS))printf("%s Minus pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_PLUS))printf("%s Plus pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_ONE))printf("%s One pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_TWO))printf("%s Two pressed\n", prefixString);
    if(wm.Buttons.isPressed(CButtons::BUTTON_HOME))printf("%s Home pressed\n", prefixString);

    // if(the accelerometer is turned on then print angles
    if(wm.isUsingACC())
    {
        float pitch, roll, yaw, a_pitch, a_roll;
        wm.Accelerometer.GetOrientation(pitch, roll, yaw);
        wm.Accelerometer.GetRawOrientation(a_pitch, a_roll);
        //printf("%s wiimote roll = %f [%f]\n", prefixString, roll, a_roll);
        //printf("%s wiimote pitch = %f [%f]\n", prefixString, pitch, a_pitch);
        //printf("%s wiimote yaw = %f\n", prefixString, yaw);
        
        double x, y, z, a ; 
        wm.Accelerometer.GetGForceInG( x, y, z ) ;
        printf("\n%s wiimote gForce = %2.5f, %2.5f:%2.5f:%2.5f\n", prefixString, wm.Accelerometer.GetGForceInG(), x, y, z );
        wm.Accelerometer.GetJerkInMS3( x, y, z ) ;
        printf("%s wiimote jerk = %2.5f, %2.5f:%2.5f:%2.5f\n", prefixString, wm.Accelerometer.GetJerkInMS3(), x, y, z );
        wm.Accelerometer.GetVelocity( x, y, z ) ;
        printf("%s wiimote velocity = %2.5f, %2.5f:%2.5f:%2.5f\n", prefixString, wm.Accelerometer.GetVelocity(), x, y, z );
        wm.Accelerometer.GetDistance( x, y, z ) ;
        a = wm.Accelerometer.GetDistance() ;
        traveledDistance += a ;
        printf("%s wiimote distance:%2.5f, %2.5f:%2.5f:%2.5f ;\n", prefixString, a, x, y, z );
        printf("%s wiimote traveled distance :%2.5f ;\n", prefixString, traveledDistance );
    }

    // if(IR tracking is on then print the coordinates
    if(wm.isUsingIR())
    {
        int x, y;

        printf("%s Num IR Dots: %i\n", prefixString, wm.IR.GetNumDots());
        printf("%s IR State: %u\n", prefixString, wm.IR.GetState());

        std::vector<CIRDot*>& dots = wm.IR.GetDots();

        int index=0 ;
        for( std::vector<CIRDot*>::iterator i=dots.begin() ; i != dots.end() ; ++i )
        {
            if( (*i)->isVisible() )
            {
                (*i)->GetCoordinate(x, y);
                printf("%s IR source %i: (%i, %i)\n", prefixString, ++index, x, y);

                wm.IR.GetCursorPosition(x, y);
                printf("%s IR cursor: (%i, %i)\n", prefixString, x, y);
                printf("%s IR z distance: %f\n", prefixString, wm.IR.GetDistance());
            }
        }
    }

    int exType = wm.ExpansionDevice.GetType() ;
    if(exType == wm.ExpansionDevice.TYPE_NUNCHUK)
    {
        float pitch, roll, yaw, a_pitch, a_roll;
        float angle, magnitude;

        CNunchuk &nc = wm.ExpansionDevice.Nunchuk;

        sprintf(prefixString, "Nunchuk [%i]: ", wm.GetID());

        if(nc.Buttons.isJustChanged()) printf("%s State of Wiimote buttons changed\n", prefixString);
        if(nc.Buttons.isPressed(CNunchukButtons::BUTTON_C))printf("%s C pressed\n", prefixString);
        if(nc.Buttons.isPressed(CNunchukButtons::BUTTON_Z))printf("%s Z pressed\n", prefixString);

        nc.Accelerometer.GetOrientation(pitch, roll, yaw);
        nc.Accelerometer.GetRawOrientation(a_pitch, a_roll);
        printf("%s roll = %f [%f]\n", prefixString, roll, a_roll);
        printf("%s pitch = %f [%f]\n", prefixString, pitch, a_pitch);
        printf("%s yaw = %f\n", prefixString, yaw);

        nc.Joystick.GetPosition(angle, magnitude);
        printf("%s joystick angle = %f\n", prefixString, angle);
        printf("%s joystick magnitude = %f\n", prefixString, magnitude);
    }
    else if(exType == wm.ExpansionDevice.TYPE_CLASSIC)
    {
        float angle, magnitude;
        CClassic &cc = wm.ExpansionDevice.Classic;

        sprintf(prefixString, "Classic [%i]: ", wm.GetID());

        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_A)) printf("%s A pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_B)) printf("%s B pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_X)) printf("%s X pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_Y)) printf("%s Y pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_LEFT))printf("%s Left pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_UP))printf("%s Up pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_RIGHT))printf("%s Right pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_DOWN))printf("%s Down pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_PLUS))printf("%s Plus pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_MINUS))printf("%s Minus pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_HOME))printf("%s Home pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_ZL))printf("%s ZL pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_FULL_L))printf("%s ZR pressed\n", prefixString);
        if(cc.Buttons.isPressed(CClassicButtons::BUTTON_FULL_R))printf("%s ZR pressed\n", prefixString);

        printf("%s L button pressed = %f\n", prefixString, cc.GetLShoulderButton());
        printf("%s R button pressed = %f\n", prefixString, cc.GetRShoulderButton());

        cc.LeftJoystick.GetPosition(angle, magnitude);
        printf("%s left joystick angle = %f\n", prefixString, angle);
        printf("%s left joystick magnitude = %f\n", prefixString, magnitude);

        cc.RightJoystick.GetPosition(angle, magnitude);
        printf("%s right joystick angle = %f\n", prefixString, angle);
        printf("%s right joystick magnitude = %f\n", prefixString, magnitude);
    }
    else if(exType == wm.ExpansionDevice.TYPE_GUITAR_HERO_3)
    {
        float angle, magnitude;
        CGuitarHero3 &gh = wm.ExpansionDevice.GuitarHero3;

        sprintf(prefixString, "Guitar [%i]: ", wm.GetID());

        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_STRUM_UP)) printf("%s Strum Up pressed\n", prefixString);
        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_STRUM_DOWN))printf("%s Strum Down pressed\n", prefixString);
        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_YELLOW)) printf("%s Yellow pressed\n", prefixString);
        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_GREEN))  printf("%s Green pressed\n", prefixString);
        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_BLUE))   printf("%s Blue pressed\n", prefixString);
        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_RED))    printf("%s Red pressed\n", prefixString);
        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_ORANGE)) printf("%s Orange pressed\n", prefixString);
        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_PLUS))   printf("%s Plus pressed\n", prefixString);
        if(gh.Buttons.isPressed(CGH3Buttons::BUTTON_MINUS))  printf("%s Minus pressed\n", prefixString);

        printf("%s whammy bar = %f\n", prefixString, gh.GetWhammyBar());

        gh.Joystick.GetPosition(angle, magnitude);
        printf("%s joystick angle = %f\n", prefixString, angle);
        printf("%s joystick magnitude = %f\n", prefixString, magnitude);
    }
}