예제 #1
0
파일: ps2.c 프로젝트: bechu/hexapod
boolean sonyPS2_calibrate(SONY_PS2* controller, uint8_t deadzone){
	controller->deadzone = deadzone;
	if(sonyPS2_setAnalogMode(controller)){
		controller->calibration[0] = sonyPS2_joystickRaw(controller,PS2_STICK_RIGHT_X);
		controller->calibration[1] = sonyPS2_joystickRaw(controller,PS2_STICK_RIGHT_Y);
		controller->calibration[2] = sonyPS2_joystickRaw(controller,PS2_STICK_LEFT_X);
		controller->calibration[3] = sonyPS2_joystickRaw(controller,PS2_STICK_LEFT_Y);
		return TRUE;
	}
	return FALSE;
}
예제 #2
0
// This routine is called once to allow you to set up any other variables in your
//program
// You can use 'clock' function here.
// The loopStart parameter has the current clock value in ìS
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){

    LED_off(&RightRed); 
    LED_off(&LeftRed); 
    LED_off(&SpotLightWhite); 
    LED_on(&PowerGreen);

    sonyPS2_setAnalogMode(&controller1);
    sonyPS2_calibrate(&controller1, 25);

return 0; // dont pause after
}
예제 #3
0
// This routine is called repeatedly - its your main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
    

if(sonyPS2_read(&controller1))
{
    xButton_pressure = sonyPS2_buttonPressure(&controller1, PS2_BTN_X);
    SqButton_pressure = sonyPS2_buttonPressure(&controller1, PS2_BTN_SQUARE);
    
    DL_Button_pressure = sonyPS2_buttonPressure(&controller1, PS2_DPAD_LEFT);
    DR_Button_pressure = sonyPS2_buttonPressure(&controller1, PS2_DPAD_RIGHT);
    
    if(sonyPS2_setAnalogMode(&controller1))
	{
		left_x = sonyPS2_joystick(&controller1, PS2_STICK_LEFT_X);
		left_y = sonyPS2_joystick(&controller1, PS2_STICK_LEFT_Y);
		right_x = sonyPS2_joystick(&controller1, PS2_STICK_RIGHT_X);
		right_y = sonyPS2_joystick(&controller1, PS2_STICK_RIGHT_Y);
		if((left_x+left_y+right_x+right_y) != 0)
		{
			SendData(PS2_B_BTN_NONE, PS2_B_BTN_NONE);
		}
	}
	if(sonyPS2_buttonHeld(&controller1, PS2_BTN_R1))
    {
        LED_on(&RightRed);
		SendData(PS2_B_BTN_R1, PS2_B_BTN_R1);
    }
	else if(sonyPS2_buttonHeld(&controller1, PS2_DPAD_RIGHT))
	{
		LED_on(&RightRed);
		SendData(PS2_B_DPAD_RIGHT, DR_Button_pressure);
	}
    else
    {
        LED_off(&RightRed);
    }

    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_L1))
    {
        LED_on(&LeftRed);
		rprintfChar(SYNC_PACKET);
		rprintfChar(PS2_B_BTN_L1);
		rprintfChar(right_x);
		rprintfChar(right_y);
		rprintfChar(left_x);
		rprintfChar(left_y);
		rprintfChar(END_PACKET);
    }
	else if(sonyPS2_buttonHeld(&controller1, PS2_DPAD_LEFT))
	{
		LED_on(&LeftRed);
		SendData(PS2_B_DPAD_LEFT, DL_Button_pressure);
	}
    else
    {
        LED_off(&LeftRed);
    }
    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_R2))
    {
		SendData(PS2_B_BTN_R2, PS2_B_BTN_R2);
	}
    else
    {
        
    }

    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_L2))
    {
		SendData(PS2_B_BTN_L2, PS2_B_BTN_L2);
    }
    else
    {
        
    }

    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_TRIANGLE))
    {
		SpotLightState++;
		if(SpotLightState % 2 == 0)
		{
			LED_off(&SpotLightWhite);
		}
		else
		{
			LED_on(&SpotLightWhite);
		}
        
		SendData(PS2_B_BTN_TRIANGLE, PS2_B_BTN_TRIANGLE);
    }
    else
    {
        
    }

    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_CIRCLE))
    {
		SendData(PS2_B_BTN_CIRCLE, PS2_B_BTN_CIRCLE);
    }
    else
    {
    
    }

  
    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_SQUARE))
    {
		SendData(PS2_B_BTN_SQUARE, SqButton_pressure);
	
		if(SqButton_pressure == 255)
        {
        	sonyPS_setRumble(&controller1, SqButton_pressure/2, false);
        }
        else
        {
            sonyPS_setRumble(&controller1, SqButton_pressure/2, false);
        }
    }
    else if(sonyPS2_buttonHeld(&controller1, PS2_BTN_X))
    {
		SendData(PS2_B_BTN_X, xButton_pressure);

		if(xButton_pressure == 255)
        {
        	sonyPS_setRumble(&controller1, xButton_pressure/2, false);
        }
        else
        {
        	sonyPS_setRumble(&controller1, xButton_pressure/2, false);
        }
    }
    else
    {
        sonyPS_setRumble(&controller1, 0, false);
    }
    
    if(sonyPS2_buttonHeld(&controller1, PS2_DPAD_UP))
    {
        SendData(PS2_B_DPAD_UP, PS2_B_DPAD_UP);
    }
	else
	{

	}
	if(sonyPS2_buttonHeld(&controller1, PS2_DPAD_DOWN))
    {
		SendData(PS2_B_DPAD_DOWN, PS2_B_DPAD_DOWN);
    }
    else
    {
        
    }

    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_SELECT))
    {
		SendData(PS2_B_BTN_SELECT, PS2_B_BTN_SELECT);
    }
    else
    {
    
    }

    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_START))
    {
		SendData(PS2_B_BTN_START, PS2_B_BTN_START);
    }
    else
    {
    
    }

    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_L3))
    {
		SendData(PS2_B_BTN_L3, PS2_B_BTN_L3);
    }
    else
    {
    
    }

    if(sonyPS2_buttonHeld(&controller1, PS2_BTN_R3))
    {
		SendData(PS2_B_BTN_R3, PS2_B_BTN_R3);
    }
    else
    {
    
    }
}
else
{
    
}
        
        //act_setSpeed(&engine, FrontSpeed);
        //act_setSpeed(&rudder, RudderPos);
    
return 200000; // wait for 1 second before calling me again. 1000000us = 1
//second
}