Exemple #1
0
void SamplesGame::exitActiveSample()
{
    Gamepad* virtualGamepad = getGamepad(0, false);
    if (virtualGamepad && virtualGamepad->isVirtual())
    {
        virtualGamepad->getForm()->setEnabled(false);
    }

    if (_activeSample)
    {
        _activeSample->finalize();
        SAFE_DELETE(_activeSample);

        _sampleSelectForm->setEnabled(true);
        _sampleSelectForm->setFocus();
    }

    // Reset some game options
    setMultiTouch(false);
    setMouseCaptured(false);
}
int lua_Gamepad_getTriggerValue(lua_State* state)
{
    // Get the number of parameters.
    int paramCount = lua_gettop(state);

    // Attempt to match the parameters to a valid binding.
    switch (paramCount)
    {
        case 2:
        {
            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
                lua_type(state, 2) == LUA_TNUMBER)
            {
                // Get parameter 1 off the stack.
                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);

                Gamepad* instance = getInstance(state);
                float result = instance->getTriggerValue(param1);

                // Push the return value onto the stack.
                lua_pushnumber(state, result);

                return 1;
            }

            lua_pushstring(state, "lua_Gamepad_getTriggerValue - Failed to match the given parameters to a valid function signature.");
            lua_error(state);
            break;
        }
        default:
        {
            lua_pushstring(state, "Invalid number of parameters (expected 2).");
            lua_error(state);
            break;
        }
    }
    return 0;
}
int lua_Gamepad_isButtonDown(lua_State* state)
{
    // Get the number of parameters.
    int paramCount = lua_gettop(state);

    // Attempt to match the parameters to a valid binding.
    switch (paramCount)
    {
        case 2:
        {
            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
            {
                // Get parameter 1 off the stack.
                Gamepad::ButtonMapping param1 = (Gamepad::ButtonMapping)lua_enumFromString_GamepadButtonMapping(luaL_checkstring(state, 2));

                Gamepad* instance = getInstance(state);
                bool result = instance->isButtonDown(param1);

                // Push the return value onto the stack.
                lua_pushboolean(state, result);

                return 1;
            }

            lua_pushstring(state, "lua_Gamepad_isButtonDown - Failed to match the given parameters to a valid function signature.");
            lua_error(state);
            break;
        }
        default:
        {
            lua_pushstring(state, "Invalid number of parameters (expected 2).");
            lua_error(state);
            break;
        }
    }
    return 0;
}
Exemple #4
0
	Gamepad LinuxJoystickPoll(const Gamepad &oldGamepad) {
		Gamepad newGamepad = oldGamepad;
		LinuxJoystickEvent lje;
		Int bytesRead = 0;
		do {
			bytesRead = read(newGamepad.GetDeviceInfo().mHandle,
				&lje, sizeof(LinuxJoystickEvent));
			if (0 < bytesRead) {
				switch (lje.mType & ~JS_EVENT_INIT) {
				case JS_EVENT_AXIS: {
						switch (lje.mNumber % 3) {
						case 0:
							newGamepad.SetStickXAxis(
								lje.mNumber / 3, lje.mValue);
							break;
						case 1:
							newGamepad.SetStickYAxis(
								lje.mNumber / 3, lje.mValue);
							break;
						case 2:
							newGamepad.SetStickOtherAxis(
								lje.mNumber / 3, lje.mValue);
							break;
						default:
							break;
						}
						break;
					}
				case JS_EVENT_BUTTON:
					lje.mValue ? newGamepad.PressButton(lje.mNumber) :
						newGamepad.ReleaseButton(lje.mNumber);
					break;
				default:
					// TODO: Error
					break;
				}
			}
		} while (0 < bytesRead);
		return newGamepad;
	}
Exemple #5
0
void NavigatorGamepad::pageVisibilityChanged()
{
    // Inform the embedder whether it needs to provide gamepad data for us.
    bool visible = page()->visibilityState() == PageVisibilityStateVisible;
    if (visible && (m_hasEventListener || m_gamepads))
        startUpdating();
    else
        stopUpdating();

    if (!visible || !m_hasEventListener)
        return;

    // Tell the page what has changed. m_gamepads contains the state before we became hidden.
    // We create a new snapshot and compare them.
    GamepadList* oldGamepads = m_gamepads.release();
    gamepads();
    GamepadList* newGamepads = m_gamepads.get();
    ASSERT(newGamepads);

    for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
        Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0;
        Gamepad* newGamepad = newGamepads->item(i);
        bool oldWasConnected = oldGamepad && oldGamepad->connected();
        bool newIsConnected = newGamepad && newGamepad->connected();
        bool connectedGamepadChanged = oldWasConnected && newIsConnected && oldGamepad->id() != newGamepad->id();
        if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) {
            oldGamepad->setConnected(false);
            m_pendingEvents.append(oldGamepad);
        }
        if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) {
            m_pendingEvents.append(newGamepad);
        }
    }

    if (!m_pendingEvents.isEmpty())
        m_dispatchOneEventRunner.runAsync();
}
Exemple #6
0
void VRPN_CALLBACK Gamepad::handle_button_states_stub(void* userData, const vrpn_BUTTONSTATESCB b)
{
	Gamepad *gamepad = static_cast<Gamepad*>(userData);
	gamepad->handle_button_states(NULL, b);
}
/**
 * Periodic code for teleop mode should go here.
 *
 * Use this method for code which will be called periodically at a regular
 * rate while the robot is in teleop mode.
 */
void RobotDemo::TeleopPeriodic()
{
	drive->TeleopDrive(driverPad->GetLeftY() *DRIVER_LEFT_DIRECTION, driverPad->GetRightY() *DRIVER_RIGHT_DIRECTION);
	shooter->handle();
	shooter->debug();
	
	//shooter->setShooterPower(operatorPad->GetRightY());
	
	if((intakeMode == IN_INTAKE_MANUAL_MODE) && operatorPad->GetNumberedButton(INTAKE_AUTO_MODE_BUTTON))
	{
		intakeMode = IN_INTAKE_AUTO_MODE;
		printf ("set into auto roller mode");
		intake->setExtenderMode(IN_INTAKE_AUTO_MODE);
	}
	//sets intake mode to auto if previously in manual and operator presses auto button
	else if((intakeMode == IN_INTAKE_AUTO_MODE) && operatorPad->GetNumberedButton(INTAKE_MANUAL_MODE_BUTTON))
	{
		intakeMode = IN_INTAKE_MANUAL_MODE;
		printf ("set into manual roller mode");
		intake->setExtenderMode(IN_INTAKE_MANUAL_MODE);
	}
	
	intake->handle();
	
	if(intakeMode == IN_INTAKE_MANUAL_MODE)
	{
		intake->move(operatorPad->GetLeftY()*OPERATOR_LEFT_DIRECTION);
	}
	else
	{
		//Extender DPad control
		curPadDir = operatorPad->GetDPad();
		
		if(lastPadDir != curPadDir)
		{
			switch(curPadDir)
			{
			case Gamepad::kUp:
				intake->setExtenderTarget(FULL_EXTEND_DISTANCE);
				break;
			case Gamepad::kDown:
				intake->setExtenderTarget(FULL_RETRACT_DISTANCE);
				break;
			default:
				break;
			}
		}
		
		lastPadDir = curPadDir;
	}
	
	//intake->spinRoller(operatorPad->GetRightY()*OPERATOR_RIGHT_DIRECTION);
	intake->getCurrentPosition();
	
	
	//if operator taps in button roller continually spins inward
	if(operatorPad->GetNumberedButton(ROLLER_IN_BUTTON))
	{
		intakeCont = INTAKE_ROLLER_IN_STATE;
	}
	//if operator taps stop button roller stops continually
	else if(operatorPad->GetNumberedButton(ROLLER_OFF_BUTTON))
	{
		intakeCont = INTAKE_ROLLER_STOP_STATE;
	}
	
	//if operator holds spit button roller spins backwards no matter what
	if(operatorPad->GetNumberedButton(ROLLER_OUT_BUTTON))
	{
		intake->spinRoller(INTAKE_ROLLER_SPIT_POWER);
	}
	//not holding spit button
	else
	{
		//roller either spins or is stopped depending on previous code
		if(intakeCont)
		{
			intake->spinRoller(INTAKE_ROLLER_IN_POWER);
		}
		else
		{
			intake->spinRoller(INTAKE_ROLLER_STOP_POWER);
		}
	}
		

	
	if(operatorPad->GetNumberedButton(RIGHT_TRIGGER_BUTTON)) // low shot = Right Trigger
	{
		shooter->initShot(SHOT_LOW_ANGLE, SHOT_LOW_SPEED);
		printf("test button 1 is pressed");
	}
	else if(operatorPad->GetNumberedButton(LEFT_TRIGGER_BUTTON)) // pass = Left Trigger
	{
		shooter->initShot(SHOT_PASS_ANGLE, SHOT_PASS_SPEED);
		printf("test button 2 is pressed");
	}
	else if(operatorPad->GetNumberedButton(RIGHT_BUMPER_BUTTON)) // high shot = Right Bumper
	{
		shooter->initShot(SHOT_HIGH_ANGLE, SHOT_HIGH_SPEED);
		printf("test button 3 is pressed");
	}
	else if(operatorPad->GetNumberedButton(LEFT_BUMPER_BUTTON)) // truss = Left Bumper
	{
		shooter->initShot(SHOT_TRUSS_ANGLE, SHOT_TRUSS_SPEED);
		printf("test button 4 is pressed");
	}	
		
		//printf("right Joystick distance: %f  left Joystick distance: %f \n", driverPad->GetRightY(), driverPad->GetLeftY());
}
void GamepadController::AdvanceFrame(WorldTime /*delta_time*/) {
  went_down_ = went_up_ = 0;
  Gamepad gamepad = input_system_->GetGamepad(controller_id_);
  SetLogicalInputs(LogicalInputs_Up,
                   gamepad.GetButton(Gamepad::kUp).is_down());
  SetLogicalInputs(LogicalInputs_Down,
                   gamepad.GetButton(Gamepad::kDown).is_down());
  SetLogicalInputs(LogicalInputs_Left,
                   gamepad.GetButton(Gamepad::kLeft).is_down());
  SetLogicalInputs(LogicalInputs_Right,
                   gamepad.GetButton(Gamepad::kRight).is_down());

  SetLogicalInputs(LogicalInputs_ThrowPie,
                   gamepad.GetButton(Gamepad::kUp).is_down() ||
                   gamepad.GetButton(Gamepad::kButtonA).is_down());
  SetLogicalInputs(LogicalInputs_Deflect,
                   gamepad.GetButton(Gamepad::kDown).is_down() ||
                   gamepad.GetButton(Gamepad::kButtonB).is_down());

  SetLogicalInputs(LogicalInputs_Select,
                   gamepad.GetButton(Gamepad::kButtonA).is_down());
  SetLogicalInputs(LogicalInputs_Cancel,
                   gamepad.GetButton(Gamepad::kButtonB).is_down());
}
Exemple #9
0
    void TeleopPeriodic() {
    	//Target * target = GetLatestTarget();
    	//Begin DRIVER input section
    	if(driverGamepad->GetDPad()==Gamepad::kUp)
    		lc->setMode(1);
    	else if(driverGamepad->GetDPad()==Gamepad::kDown)
    		lc->setMode(6);
    	else
    		lc->setMode(0);
    	if(driverGamepad->GetDPad() == Gamepad::kRight)
    	{
    		cameraLight->Set(Relay::kOff);
    	}
    	else if(driverGamepad->GetDPad() == Gamepad::kLeft)
    	{
    		cameraLight->Set(Relay::kOn);
    	}
    	
    	if(driverGamepad->GetB())
    	{
    		cout << "Resetting the gyro! :D" << endl;
    		//driveGyro->Reset();
    		magicBox->resetGyro();
   		}
    	
    	bool modifySpeed = driverGamepad->GetRightBumper();
    	bool halfSpeed = driverGamepad->GetLeftBumper();
    	
    	/*
    	try {
    		std::string temp = SmartDashboard::GetString("TargetInfo");
    		cout << "temp: " << endl;
    	} catch (exception ex) {
    		cout << "bah! " << ex.what() << endl;
    	}*/
    	
    	//Target t = GetLatestTarget();
    	
    	/*
    	if (t.IsValid()) {
    		cout << "Valid target (" << (t.IsCenter() ? "center" : "side") << "):" << t.Distance() << " ft, " << t.X() << "," << t.Y() << endl;
    	} else {
    		//cout << "No valid target." << endl;
    	} */
    		
    	if(driverGamepad->GetBack())
    	{
    		cout << "Now driving in relation to the robot" << endl;
    			myDrive->setGyroDrive(false);
    	}
    	if(driverGamepad->GetStart())
    	{
    		cout << "Now driving in relation to the field (gyro)" << endl;
    		myDrive->setGyroDrive(true);
    	}
    	
    	// If the driver is holding the X button 
    	/*
    	if (driverGamepad->GetX()) {
    		// Stop using the joysticks to drive the robot, and let this function do it
    	    PointAtTarget(t);
    	} else { */
    		// We aren't auto-targeting. Reset the sequence.
    		target_state = RA13Robot::READY;
    		// Drive based on joysticks.
    		myDrive->Drive(driverGamepad->GetLeftX(), driverGamepad->GetLeftY(), 
    		    			driverGamepad->GetRightX(), magicBox->getGyroAngle(), modifySpeed,halfSpeed);
    	//}
    	//End DRIVER input section
    	
    	Gamepad::DPadDirection dir = operatorGamepad->GetDPad();
    	
    	if (dir != lastdir) {
    		switch(dir) {
    		case Gamepad::kUp:
    			manualAngle += 1;
    			break;
    		case Gamepad::kDown:
    			manualAngle -= 1;
    			break;
    		case Gamepad::kRight:
    			manualAngle += 0.25;
    			break;
    		case Gamepad::kLeft:
    			manualAngle -= 0.25;
    			break;
    		default:
    			break;
    		}
    	}
    	
    	//cout << "Current target angle: " << manualAngle << endl;
    	
    	//Begin OPERATOR input section
    		
    	if(operatorGamepad->GetBack())
    	{
    		myShooter->ResetShooterProcess(); // Re-homes the shooter
    	}
    	
    	if(operatorGamepad->GetLeftTrigger())
		{
    		myShooter->SetSpeeds(SHOOTER_FRONTWHEEL_SPEED,SHOOTER_REARWHEEL_SPEED); // (RPM,RPM)
		}
    	else if (operatorGamepad->GetLeftBumper())
    	{
    		myShooter->SetSpeeds(Config::GetSetting("shooter_main_speed_pyramid", 1500),
    							 Config::GetSetting("shooter_secondary_speed_pyramid", 2000));
    	}
    	else
    	{
    		myShooter->SetSpeeds(0,0); // (RPM,RPM)
    	}
    	
    	if(operatorGamepad->GetRightTrigger())
    	{
    		// TODO: Make this selectable somehow. This is probably too powerful for
    		// distant shots.
    		myShooter->ChamberFrisbee(Config::GetSetting("loader_power",-1));
    	}
    	else
    	{
    		myShooter->StopLoader();
    	}
    	
    	if(operatorGamepad->GetY())
    	{
    		myShooter->SetAngle(manualAngle);
    	}
    	if(operatorGamepad->GetX())
    	{
    		myShooter->SetAngle(Config::GetSetting("shooter_loading_angle",0)); //Angle for reloading
    		manualAngle = Config::GetSetting("shooter_loading_angle",0);
    	}
    	if(operatorGamepad->GetA()) //Shooting from load zone
    	{
    		myShooter->SetAngle(Config::GetSetting("load_zone_shooting_angle",13.25));
    		manualAngle = Config::GetSetting("load_zone_shooting_angle",13.25);
    	}
    	if(operatorGamepad->GetB())
    	{
    		myShooter->SetAngle(Config::GetSetting("pyramid_shooting_angle",23.25));
    		manualAngle = Config::GetSetting("pyramid_shooting_angle",23.25);
    	}
    	if(operatorGamepad->GetRightBumper())
    	{
    		//myShooter->SetAngle(Config::GetSetting("funnel_release_angle",35));
    		myShooter->SetAngle(Config::GetSetting("pyramid_basket_angle", 45));
    		manualAngle = Config::GetSetting("pyramid_basket_angle", 45);
    	}
    	if (operatorGamepad->GetLeftPush()) {
    		myShooter->ResetShooterProcess();
    	}
    	
    	// Do something similar, but don't touch the AngleJag.
    	if (operatorGamepad->GetRightPush()) {
    		myShooter->ResetShooterMotors();
    	}
    	
    	//pneumatics section
    	if(!driverGamepad->GetLeftTrigger())
    	{
    		pneumatics->extendEndgame();
    	}
    	else
    	{
    		pneumatics->retractEndgame();
    		myShooter->SetAngle(3);
    	}
    	
    	if(driverGamepad->GetRightTrigger())
    	{
    		pneumatics->extendCollector();
    	}
    	else
    	{
    		pneumatics->retractCollector();
    	}
    	//end pneumatics section
    	
    	lastdir = dir;
    	
    	myShooter->Process();
    	
    	//cout << "Shooter rear wheel" << myShooter->getRearWheelSpeed() << endl;
    	//End OPERATOR input section
   
    	
    	/*Manual control of the angle motor position using PID
    	 * THIS ASSUMES THE SHOOTER HAS BEEN ZERO'ED TO THE HOME POSITION SOMEHOW
    	if(operatorGamepad->GetLeftTrigger())
    	{
    		myShooter->ManualAngleControl(16); // (theta)
    	}
    	else
    	{
    		myShooter->ManualAngleControl(0);
    	}
    	*/ 
    	/*if (target != NULL) {
    		cout << "Target located. (" << target->X() << ',' << target->Y() << ") range is " << target->Distance() << " feet" << endl;
    	}
    	*/
//    	switch(myShooter->getFiringState())
//    	{
//    	case 1:
//    		lc->setMode(4);
////    		cout << "Spinning up!!" << endl;
//    		break;
//    	case 2:
//    		lc->setMode(5);
////    		cout << "Firing!!" << endl;
//    		break;
//    	default:
//    		lc->setMode(1);
//    		break;
//    	}
    	lc->useLights();
    	BuildAndSendPacket();
    	logdata();
    }
static v8::Handle<v8::Value> indexAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    Gamepad* imp = V8Gamepad::toNative(info.Holder());
    return v8UnsignedInteger(imp->index(), info.GetIsolate());
}
int main(int argc, char ** argv) {
	std::cout << "Starting Controller Mouse Emulator" << std::endl;

	float mouseSpeed = 15;
	float scrollSpeed = 25;

	MouseInput mouseInput;
	Gamepad gamepad;
	int dx, dy;
	int sy;

	while (true) {
		gamepad.update();

		dx = (int)(gamepad.getLThumbX() * mouseSpeed);
		dy = (int)(-gamepad.getLThumbY() * mouseSpeed);

		sy = (int)(gamepad.getRThumbY() * scrollSpeed);

		mouseInput.moveMouse(dx, dy);
		mouseInput.scrollWheel(sy);

		if (gamepad.aPressed())
			mouseInput.setLeftMouseDown(true);
		else if (gamepad.aReleased())
			mouseInput.setLeftMouseDown(false);

		if (gamepad.bPressed())
			mouseInput.setRightMouseDown(true);
		else if (gamepad.bReleased())
			mouseInput.setRightMouseDown(false);

		if (gamepad.rsPressed())
			mouseInput.setMiddleMouseDown(true);
		else if (gamepad.rsReleased())
			mouseInput.setMiddleMouseDown(false);

		if (gamepad.rbPressed() && mouseSpeed < MAX_MOUSE_SPEED) {
			mouseSpeed += SPEED_INCREMENT;
			std::cout << "Mouse speed: " << mouseSpeed << std::endl;
		}

		if (gamepad.lbPressed() && mouseSpeed > SPEED_INCREMENT) {
			mouseSpeed -= SPEED_INCREMENT;
			std::cout << "Mouse speed: " << mouseSpeed << std::endl;
		}

		gamepad.updateInput();

		Sleep(15);
	}

	return 0;
}
Exemple #12
0
uint16_t get_PICH(Gamepad mando) {
    uint16_t anglePICH;
    float leftStic_Y = mando.LeftStick_Y();
    anglePICH = mando.float_UINT16(leftStic_Y);
    return anglePICH;
}
Exemple #13
0
//Funciones para obtener YAW,PITCH y ROLL con valores UINT16
uint16_t get_YAW(Gamepad mando) {
    uint16_t angleYaw;
    float leftStic_X = mando.LeftStick_X();
    angleYaw = mando.float_UINT16(leftStic_X);
    return angleYaw;
}
Exemple #14
0
	/**
	 * Periodic code for teleop mode should go here.
	 *
	 * Use this method for code which will be called periodically at a regular
	 * rate while the robot is in teleop mode.
	 */
	void RA14Robot::TeleopPeriodic() {
		StartOfCycleMaintenance();

		//Input Acquisition
		DriverLeftY = DriverGamepad->GetLeftY();
		DriverRightY = DriverGamepad->GetRightY();
		DriverLeftBumper = DriverGamepad->GetLeftBumper(); // Reads state of left bumper 
		DriverRightBumper = DriverGamepad->GetRightBumper(); // Gets state of right bumper
		RingLightButton = OperatorGamepad->GetY();
		ShouldFireButton = DriverGamepad->GetRightTrigger();
		BallCollectPickupButton = DriverGamepad->GetBack();
		DriverDPad = DriverGamepad->GetDPad();
		OperatorDPad = OperatorGamepad->GetDPad();
		//End Input Acquisition


		//Current Sensing
		//myCurrentSensor->Toggle(DriverGamepad->GetStart());
		//End Current Sensing


		//Target Processing
		target->Parse(server->GetLatestPacket());

		/*
		 if (target->IsValid()) {
		 cout << "\tx = " << target->GetX() << ", y = " << target->GetY() << ", distance = " << target->GetDistance() << "ft";
		 cout << "\tside = " << (target->IsLeft() ? "LEFT" : "RIGHT") << ", hot = " << (target->IsHot() ? "HOT" : "NOT") << endl;
		 }
		 else {
		 cout << "No Target Received..." << endl;
		 }
		 */

		//End Target Processing


		//Ball Collection

		/*
		 if(BallCollectPickupButton)
		 {
		 myCollection->Collect();
		 }
		 else
		 {
		 myCollection->ResetPosition();
		 }
		 */

		float spinSpeed = Config::GetSetting("intake_roller_speed", 1);
		int armPosition = 0;
		int rollerPosition = 0;

		switch (OperatorDPad) {
		case Gamepad::kCenter:
			armPosition = 0;
			rollerPosition = 0;
			break;
		case Gamepad::kUp:
			armPosition = -1;
			break;
		case Gamepad::kUpLeft:
			armPosition = -1;
			rollerPosition = -1;
			break;
		case Gamepad::kUpRight:
			armPosition = -1;
			rollerPosition = 1;
			break;
		case Gamepad::kDown:
			armPosition = 1;
			break;
		case Gamepad::kDownLeft:
			armPosition = 1;
			rollerPosition = -1;
			break;
		case Gamepad::kDownRight:
			armPosition = 1;
			rollerPosition = 1;
			break;
		case Gamepad::kLeft:
			rollerPosition = -1;
			break;
		case Gamepad::kRight:
			rollerPosition = 1;
			break;
		}

		if (DriverGamepad->GetLeftTrigger()) {
			armPosition = 0;
			rollerPosition = -1;
		}
		
		if(DriverGamepad->GetB())
		{
			armPosition = -1;
			rollerPosition = 1;
		}

		spinSpeed *= rollerPosition;
		myCollection->SpinMotor(spinSpeed);

		if (armPosition > 0)
			myCollection->ExtendArm();
		else if (armPosition < 0)
			myCollection->RetractArm();
		//End Ball Collection

		//Fire Control

#ifndef DISABLE_SHOOTER
		myCam->Process(ShouldFireButton, (OperatorGamepad->GetX() || DriverGamepad->GetX() ), DriverGamepad->GetB());
		//myCam->Debug(cout);
#endif //Ends DISABLE_SHOOTER
		
		//End Fire Control


		//Ring Light
		if (RingLightButton) {
			RingLightButtonRecentlyPressed = true;
		}

		if (!RingLightButton && RingLightButtonRecentlyPressed) {
			if (myCamera->Get() == Relay::kOff)
				myCamera->Set(Relay::kForward);
			else
				myCamera->Set(Relay::kOff);

			RingLightButtonRecentlyPressed = false;
		}
		//End Ring Light


		//Drive Processing
		if(DriverDPad == Gamepad::kUp)
		{
			cout << "Forward" << endl;
			myDrive->reverseDirectionForward();
		}
		else if(DriverDPad == Gamepad::kDown)
		{
			cout << "Backward"<<endl;
			myDrive->reverseDirectionReverse();
		}
		
		if (DriverLeftBumper) {
			myDrive->ShiftUp();
		} else if (DriverRightBumper) {
			myDrive->ShiftDown();
		}

		//myDrive->Drive(DriverLeftY, DriverRightY);
		myDrive->DriveArcade(DriverGamepad->GetRightX(), DriverGamepad->GetRightY());
		myDrive->Debug(cout);
		//End Drive Processing


		EndOfCycleMaintenance();
	}
Exemple #15
0
void VRPN_CALLBACK Gamepad::handle_analog_stub(void* userData, const vrpn_ANALOGCB a)
{
	Gamepad *gamepad = static_cast<Gamepad*>(userData);
	gamepad->handle_analog(NULL, a);
}
void SamplesGame::initialize()
{
	LOGI(">SamplesGame::initialize ()");
	LOGI(">SamplesGame::initialize FileSystem::getAssetPath() = '%s'", FileSystem::getAssetPath());
	LOGI(">SamplesGame::initialize FileSystem::getResourcePath() = '%s'", FileSystem::getResourcePath());

	Bundle* bundle = Bundle::create("res/ui/arial.gpb");
	LOGI(">SamplesGame::initialize bundle=%p", bundle);

	_font = bundle->loadFont(bundle->getObjectId(0));
	LOGI(">SamplesGame::initialize _font=%p", _font);

    _font = Font::create("res/ui/arial.gpb");
    LOGI(">SamplesGame::initialize _font=%p", _font);

    for (size_t i = 0; i < _categories->size(); ++i)
    {
        std::sort((*_samples)[i].begin(), (*_samples)[i].end());
    }

    // Load camera script
    getScriptController()->loadScript("res/common/camera.lua");

    // Create the selection form
    _sampleSelectForm = Form::create("sampleSelect", NULL, Layout::LAYOUT_VERTICAL);
    _sampleSelectForm->setWidth(220);
    _sampleSelectForm->setHeight(1, true);
    _sampleSelectForm->setScroll(Container::SCROLL_VERTICAL);
    const size_t size = _samples->size();
    LOGI(">SamplesGame::initialize _samples->size()=%d", size);

    for (size_t i = 0; i < size; ++i)
    {
		Label* categoryLabel = Label::create((*_categories)[i].c_str());
        categoryLabel->setFontSize(22);
        categoryLabel->setText((*_categories)[i].c_str());
        _sampleSelectForm->addControl(categoryLabel);
        categoryLabel->release();

        SampleRecordList list = (*_samples)[i];
        const size_t listSize = list.size();
        for (size_t j = 0; j < listSize; ++j)
        {
            SampleRecord sampleRecord = list[j];
			Button* sampleButton = Button::create(sampleRecord.title.c_str());
            sampleButton->setText(sampleRecord.title.c_str());
            sampleButton->setWidth(1, true);
            sampleButton->setHeight(50);
            sampleButton->addListener(this, Control::Listener::CLICK);
            _sampleSelectForm->addControl(sampleButton);
            sampleButton->release();
        }
    }
    _sampleSelectForm->setFocus();

    // Disable virtual gamepads.
    unsigned int gamepadCount = getGamepadCount();

    for (unsigned int i = 0; i < gamepadCount; i++)
    {
        Gamepad* gamepad = getGamepad(i, false);
        if (gamepad->isVirtual())
        {
            gamepad->getForm()->setEnabled(false);
        }
    }

    /*
    for (size_t i = 0; i < size; ++i)
    {
        SampleRecordList list = (*_samples)[i];
        const size_t listSize = list.size();
        for (size_t j = 0; j < listSize; ++j)
        {
            SampleRecord sampleRecord = list[j];
            // TODO if (sampleRecord.title.compare(control->getId()) == 0)
            {
                _sampleSelectForm->setEnabled(false);
                runSample(sampleRecord.funcPtr);
                LOGI("<SamplesGame::initialize _activeSample=%lx", (long )_activeSample);
                return;
            }
        }
    }
    */
    LOGI("<SamplesGame::initialize _activeSample=%lx", (long )_activeSample);
}
static v8::Handle<v8::Value> timestampAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    Gamepad* imp = V8Gamepad::toNative(info.Holder());
    return v8::Number::New(static_cast<double>(imp->timestamp()));
}
Exemple #18
0
int main(int argc, char** argv)
{
	sceRtcGetCurrentTick( &fpsTickLast );
	tickResolution = sceRtcGetTickResolution();
	
	Gamepad gamepad;
	
	App_Initialize();
	
	timerTest.start();
	
	float nextUpdate = 0;
	
	while(1)
	{
		
		timerTest.update();
		(*mySceneMotion).evaluate(timerTest.getSeconds());

		App_Render();

		if(gamepad.Poll())
		{
			if(gamepad.ButtonDown(PSP_CTRL_TRIANGLE))
			{
				timerTest.paused(true);
			}
			
			if(gamepad.ButtonDown(PSP_CTRL_SQUARE))
			{
				timerTest.paused(false);
			}

			if(timerTest.paused())
			{
				if(fabs(gamepad.AnalogX()) > 0.1)
				{
					if(gamepad.ButtonDown(PSP_CTRL_RTRIGGER))
					{
						if(timerTest.getSeconds() - 0.5f > 0 || gamepad.AnalogX() > 0)	timerTest.setSeconds(timerTest.getSeconds() + (gamepad.AnalogX() * 0.5));
					}
					else
					{
						if(timerTest.getSeconds() - 0.1f > 0 || gamepad.AnalogX() > 0)	timerTest.setSeconds(timerTest.getSeconds() + (gamepad.AnalogX() * 0.1));
					}
				}
			}
						
			if(gamepad.ButtonDown(PSP_CTRL_LEFT))
			{
				if(gamepad.ButtonDown(PSP_CTRL_RTRIGGER))
				{
					if(timerTest.getSeconds() - 0.1f > 0)	timerTest.setSeconds(timerTest.getSeconds() - 0.1);
				}
				else
				{
					if(timerTest.getSeconds() - 0.01f > 0)	timerTest.setSeconds(timerTest.getSeconds() - 0.01);
				}
			}
			
			if(gamepad.ButtonDown(PSP_CTRL_RIGHT))
			{
				if(gamepad.ButtonDown(PSP_CTRL_RTRIGGER))
				{
					timerTest.setSeconds(timerTest.getSeconds() + 0.1);
				}
				else
				{
					timerTest.setSeconds(timerTest.getSeconds() + 0.01);
				}
			}
		}		
	}

	App_Shutdown();

	return 0;
}
static v8::Handle<v8::Value> buttonsAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    Gamepad* imp = V8Gamepad::toNative(info.Holder());
    return v8Array(imp->buttons(), info.GetIsolate());
}
	void TeleopPeriodic(void) {
		float x = gamepad->GetLeftX();
		float y = gamepad->GetLeftY();
		float rot = gamepad->GetRightX();
		
		//small gamepad values are ignored
		if (x < 0.1f && x > -0.1f)
			{
				x = 0;
			}
		if (y < 0.1f && y > -0.1f)
			{
				y = 0;
			}
		
		if (rot < 0.1f && rot > -0.1f)
			{
				rot = 0;
			}
		
		drive->MecanumDrive_Cartesian(SPEED_LIMIT * x, SPEED_LIMIT * y, SPEED_LIMIT * rot);
		
		//shoot smoke if button is pressed
		if (gamepad2->GetNumberedButton(FIRE_SMOKE_BUTTON)){
			//SHOOT SMOKE!
			//makingSmoke = !makingSmoke;
			smoke_cannon->Set(SMOKE_CANNON_SPEED);
			lcd->PrintfLine(DriverStationLCD::kUser_Line5, "Shooting");
				
			firing_smoke_timer->Start(); //measure how long we've fired smoke, so we know if it's ok to make more
			
		}
		else
		{
			smoke_cannon->Set(0.0f);
			lcd->PrintfLine(DriverStationLCD::kUser_Line5, "Not shooting");
			firing_smoke_timer->Stop(); //stop the timer, since we're not firing smoke.
										//don't reset, cuz we need to how much smoke we've fired.

		}
		//Eye Code
		
//		float eye_pos = gamepad2->GetLeftX();
//		
//		right_eye_x->Set((eye_pos * 60) + default_eye_position);
//		left_eye_x->Set((eye_pos * 60) + default_eye_position - LEFT_EYE_OFFSET);
//		
//		//button lock code
//		if(gamepad2->GetNumberedButtonPressed(EYE_LOCK_BUTTON)){
//			default_eye_position = eye_pos;
//		}
//		
		
		
		//left eye control
		//If A isn't pressed the value should stay the same as before
		if (!gamepad2->GetNumberedButton(1)){
			float left_joystick_x = gamepad2->GetLeftX();
			float left_eye_x_axis = (1 - left_joystick_x)*60;
			left_eye_val = left_eye_x_axis + 50;
			
			float right_joystick_x = gamepad2->GetRawAxis(4);//right x axis
			float right_eye_x_axis = (1-right_joystick_x)*60;
			right_eye_val = right_eye_x_axis+20;
		}
		left_eye_x->SetAngle(left_eye_val);		
		right_eye_x->SetAngle(right_eye_val);
		
		//float right_joystick_y = gamepad2->GetRawAxis(4);
		//float right_eye_y_axis = (right_joystick_y+1)*60;
		//right_eye_y->SetAngle(right_eye_y_axis);

		/*
		bool rbutton = gamepad2->GetNumberedButton(HEAD_UP_BUTTON);
		bool lbutton = gamepad2->Ge tNumberedButton(HEAD_DOWN_BUTTON);
		if (rbutton){
			lcd->PrintfLine(DriverStationLCD::kUser_Line6, "rb pressed");
			jaw_motor->Set(0.2f);
		}else if(lbutton){
			lcd->PrintfLine(DriverStationLCD::kUser_Line6, "lb pressed");
			jaw_motor->Set(-0.15f);
		}else{
			lcd->PrintfLine(DriverStationLCD::kUser_Line6, "no buttons");
			jaw_motor->Set(0.0f);
		}
		*/

		//REAL head & jaw code
		//move head down
		if(gamepad2->GetRightX()<=-0.5f && can_move_head_down() && can_move_jaw_down()){
			head_motor->Set(-0.3f);
			jaw_motor->Set(0.3f);
		}
		//move head up
		else if(gamepad2->GetNumberedButton(HEAD_UP_BUTTON) && can_move_head_up()){
			head_motor->Set(0.3f);
			jaw_motor->Set(-0.3f);
		}
		//move jaw down
		else if(gamepad2->GetRightX()>=0.5f && can_move_jaw_down()){
			jaw_motor->Set(0.3f);
		}
		//move jaw up
		else if(gamepad2->GetNumberedButton(JAW_UP_BUTTON) && can_move_jaw_up()){
			jaw_motor->Set(-0.3f);
		}
		//sets to zero if no buttons pressed
		else {
			jaw_motor->Set(0.0f);
			head_motor->Set(0.0f);
		}
		
		
		lcd->PrintfLine(DriverStationLCD::kUser_Line6, "b:%d t:%d c:%d", bottomjaw_limit->Get(), tophead_limit->Get(), crash_limit->Get());
		
		

		//Smoke code
		if (gamepad2->GetNumberedButton(MAKE_SMOKE_BUTTON)){
			//MAKE SMOKE!!!!!!!!!!!
			//only if we don't have too much excess smoke
			if (making_smoke_timer->Get() - firing_smoke_timer->Get() < MAX_EXCESS_SMOKE_TIME){
				lcd->PrintfLine(DriverStationLCD::kUser_Line4, "smoke");
				smoke_machine->Set(true);
			} else {
				lcd->PrintfLine(DriverStationLCD::kUser_Line4, "too much smoke");
				smoke_machine->Set(false);
			}
			making_smoke_timer->Start(); //measure how long we've been making smoke, so we don't overflow the machine
										//doesn't do anything if we've already started the timer
		}
		else
		{
			lcd->PrintfLine(DriverStationLCD::kUser_Line4, "not smoke");
			smoke_machine->Set(false);
			making_smoke_timer->Stop(); 	//stop the timer, since we're not making smoke
											//don't reset it, cuz we need to know how much smoke we've made
		}
		
		//if both timers are the same, we can set them both to zero to ensure we don't overflow them or something
		if (making_smoke_timer->Get() == firing_smoke_timer->Get()){
			making_smoke_timer->Reset();
			firing_smoke_timer->Reset();
		}
		
		lcd->PrintfLine(DriverStationLCD::kUser_Line1, "x:%f", x);
		lcd->PrintfLine(DriverStationLCD::kUser_Line2, "y:%f", y);
		lcd->PrintfLine(DriverStationLCD::kUser_Line3, "r:%f", rot);
		
		
		lcd->UpdateLCD();

		
		
	}
Exemple #21
0
Gamepad *tryDetectController(void)
{
	Gamepad *pad = NULL;

	gamepadVibrate(0);

	// this must be called at each 50 ms or less
	usbPoll();

	pad = fournsnesGetGamepad();
	if(pad == NULL)
	{	
		transferGamepadReport(1); // We know they all have only one
		//_delay_ms(30);
		usbPoll();
		if (SREG & 0x80) 
		{
			sleepsync();
		}
		char i = 0;
		for (i=0;i <= 1;i++)
		{
			switch(gcn64_detectController(i))
			{
				case CONTROLLER_IS_N64:
					pad = n64GetGamepad();
					//pad->setID(i);
					//pad->init();
					break;

				case CONTROLLER_IS_GC:
					pad = gamecubeGetGamepad();
					//pad->setID(i);
					//pad->init();
					break;

				case CONTROLLER_IS_GC_KEYBOARD:
					pad = gc_kb_getGamepad();
					//pad->setID(i);
					//pad->init();
					break;

					// Unknown means weird reply from the controller
					// try the old, bruteforce approach.
				case CONTROLLER_IS_UNKNOWN:
					// Check for gamecube controller
					/*pad = gamecubeGetGamepad();
					pad->setID(i);
					pad->init();
					if (pad->probe()) {
						break;
					}

					usbPoll();
					_delay_ms(40);
					usbPoll();

					//Check for n64 controller
					pad = n64GetGamepad();
					pad->setID(i);
					pad->init();
					if (pad->probe())  {
						break;
					}
					pad = NULL;*/
					break;
			}
			if(pad != NULL)
			{
				pad->setID(i);
				break;
			}
		}
	}

	if(pad != NULL)
	{
		pad->init();
	}
	return pad;
}