void CameraSpherical::init() {

    Camera::init();

    initTrackBall();
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: HexTank/KADE
int main(void) {
	// Set clock @ 16Mhz
	CPU_PRESCALE(0);		

	//Set initial pin states.
    DDRB=0x00;
    DDRC=0x00;
    DDRD=0x00;
    PORTB=0xFF;
    PORTC=0xFF;
    PORTD=0xFF;
	
	//Generic functions used with this firmware	(there are others)
    uint8_t func_dpad_up       = 1;
    uint8_t func_dpad_down     = 2;
    uint8_t func_dpad_left     = 3;
    uint8_t func_dpad_right    = 4;
    uint8_t func_restrict_4way = 22;
    uint8_t func_invert_y_axis = 23;
    uint8_t func_autofire_1    = 24;
    uint8_t func_autofire_2    = 25;
    uint8_t func_autofire_3    = 26;
    uint8_t func_autofire_4    = 27;
	uint8_t func_ext_shift_led = 28;
    uint8_t func_ext_power_led = 29;	
	uint8_t func_program_mode  = 30;	
	
	//Use default restriction logic (in generic_main_preloop.c)
	uint8_t default_restrict   = 0;	
	
	//Generic main
	#include "../shared/generic_main_init.c"
	
	// Init USB pad emulation
	vs_init(true);
	
	// Init Trackball if needed
	if (setting_enable_tb1==1){
		PORTD |= (1<<6);
		initTrackBall(setting_tb1_counts, setting_tb1_samples);
	}

	// Pins polling and gamepad status updates
	for (;;) {
		vs_reset_watchdog();
				
		//generic stuff at start of main loop
		#include "../shared/generic_main_preloop.c"

		//set default button states - reset direction to centre
		gamepad_state.direction=8;
		gamepad_state.l_y_axis=0x80;
		gamepad_state.l_x_axis=0x80;
		gamepad_state.r_y_axis=0x80;
		gamepad_state.r_x_axis=0x80;
		gamepad_state.square_btn=0x00;
		gamepad_state.cross_btn=0x00;
		gamepad_state.circle_btn=0x00;
		gamepad_state.triangle_btn=0x00;
		gamepad_state.l1_btn=0x00;
		gamepad_state.r1_btn=0x00;					
		gamepad_state.l2_btn=0x00;
		gamepad_state.r2_btn=0x00;
		gamepad_state.l3_btn=0x00;
		gamepad_state.r3_btn=0x00;
		gamepad_state.square_axis=0x00;
		gamepad_state.cross_axis=0x00;
		gamepad_state.circle_axis=0x00;
		gamepad_state.triangle_axis=0x00;
		gamepad_state.l1_axis=0x00;
		gamepad_state.r1_axis=0x00;
		gamepad_state.l2_axis=0x00;
		gamepad_state.r2_axis=0x00;
		gamepad_state.select_btn=0x00;
		gamepad_state.start_btn=0x00;
		gamepad_state.ps_btn=0x00;		
				
		//Handle dpad and restricted movement
		//PS3 restriction is easier to manage - ignore mainloop
		if(restrict4==1){
			if (u==1){gamepad_state.direction=0;}
			if (d==1){gamepad_state.direction=4;}
			if (l==1){gamepad_state.direction=6;}
			if (r==1){gamepad_state.direction=2;}
		} else {				
			//left and right directions
			if (l==1){gamepad_state.direction=6;}  //Left
			if (r==1){gamepad_state.direction=2;}	//Right						
			
			//up, down and diagonal directions
			if (u==1){								//Up
				if (l==1){							//left
					gamepad_state.direction=7;		//up-left
				}
				else if (r==1){    					//right
					gamepad_state.direction=1;		//up-right
				} else {
					gamepad_state.direction=0;		//up
				}		
			}
			if (d==1){								//down
				if (l==1){							//left
					gamepad_state.direction=5;		//down-left
				}
				else if (r==1){   	 				//right
					gamepad_state.direction=3;		//down-right
				} else {
					gamepad_state.direction=4;		//down
				}
			}		
		}

		//Trackballs Analog
		//NOTE: COME BACK AND TIDY THIS LOGIC IF IT WORKS WELL
		if (setting_enable_tb1==1){
			if(setting_tb1_trackball==1){
				if (setting_tb1_stick==1){ 
					//Right Analog (1=Right)
					//
					//Y Axis (Trackball)
					if(abs(ps2_y) < 32){
						gamepad_state.r_y_axis = 255 - (ps2_y + 128);
					} else {
						if (ps2_y > 31){gamepad_state.r_y_axis = 0x00;}
						if (ps2_y < -31){gamepad_state.r_y_axis = 0xFF;}		
					}
					//X Axis (Trackball)
					if(abs(ps2_x) < 32){
						gamepad_state.r_x_axis = ps2_x + 128;
					} else {
						if (ps2_x > 31){gamepad_state.r_x_axis = 0xFF;}
						if (ps2_x < -31){gamepad_state.r_x_axis = 0x00;}		
					}			
				} else {
					//Left Analog (0=Left)
					//
					//Y Axis (Trackball)
					if(abs(ps2_y) < 32){
						gamepad_state.l_y_axis = 255 - (ps2_y + 128);
					} else {
						if (ps2_y > 31){gamepad_state.l_y_axis = 0x00;}
						if (ps2_y < -31){gamepad_state.l_y_axis = 0xFF;}		
					}
					//X Axis (Trackball)
					if(abs(ps2_x) < 32){
						gamepad_state.l_x_axis = ps2_x + 128;
					} else {
						if (ps2_x > 31){gamepad_state.l_x_axis = 0xFF;}
						if (ps2_x < -31){gamepad_state.l_x_axis = 0x00;}		
					}			
				}			
			} else {
				if (setting_tb1_stick==1){ 
					//Right Analog (1=Right)
					gamepad_state.r_y_axis = 255 - (ps2_y + 128);
					gamepad_state.r_x_axis = ps2_x + 128;
				} else {
					//Left Analog (0=Left)
					gamepad_state.l_y_axis = 255 - (ps2_y + 128);
					gamepad_state.l_x_axis = ps2_x + 128;
				}			
			}
		}
		

		//loop through pins checking for inputs from those that are assigned a function
		//for(cnt=0;cnt<20;cnt++) {
		for(cnt=0;cnt<20;cnt++) {
			pos=cnt;					
			if (!(state[cnt])) {
				//there is input on this pin
				if (shift==1){pos=pos+20;}  //+20 if this is shifted input
				
				if (ass[pos]>0) {
					//there is an assignment to a function
					action = ass[pos];
					#include "main_actions.c"
				}
			}
		}
		
		//Trackball Buttons
		if (setting_enable_tb1==1){
			for(pos=0;pos<3;pos++) {
				if (shift==1){
					if (pos==0){action = setting_tb1_but1s;}
					if (pos==1){action = setting_tb1_but2s;}
					if (pos==2){action = setting_tb1_but3s;}
				} else {
					if (pos==0){action = setting_tb1_but1;}
					if (pos==1){action = setting_tb1_but2;}
					if (pos==2){action = setting_tb1_but3;}
				}
			
				if (action > 0) {
					if (((0b00000001 & ps2data[0])&&(pos==0))||((0b00000010 & ps2data[0])&&(pos==1))||((0b00000100 & ps2data[0])&&(pos==2))){
						#include "main_actions.c"
					}
				}
			}
		}
		
		
		_delay_ms(2);  //debounce
		vs_send_pad_state();		
	}
}