Beispiel #1
0
// This sets up an empty controller data packet and sends it out
//  to all the controllers attached.
void setControllersToZero(void){
	dataForController_t emptyData;
	emptyData.leftStickX = 128;
	emptyData.leftStickY = 128;
	emptyData.rightStickX = 128;
	emptyData.rightStickY = 128;
	sendPS3Data(emptyData);
}
Beispiel #2
0
int main(void) {
	// Make sure our watchdog timer is disabled!
	wdt_reset(); 
	MCUSR &= ~(1 << WDRF); 
	wdt_disable();

	// Start up the USART for serial communications
	// 25 corresponds to 38400 baud - see datasheet for more values
	USART_Init(25);// 103 corresponds to 9600, 8 corresponds to 115200 baud, 3 for 250000
	
	// set the prescale for the USB for our 16 MHz clock
	CPU_PRESCALE(0);

	// Initialize our USB connection
	usb_init();
	while (!usb_configured()){
		LEDon(TXLED);
		_delay_ms(50);
		LEDoff(TXLED);
		_delay_ms(50);
	} // wait

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	// This wait also gives the Arduino bootloader time to timeout,
	//  so the serial data you'll be properly aligned.
	_delay_ms(500);
	dataForController_t dataToSend;
	char buttonData1;
	char buttonData2;
	char buttonData3;

	while (1) {
		// Delay so we're not going too fast
		_delay_ms(10);
		
        // We get our data from the ATmega328p by writing which byte we
        //  want from the dataForController_t, and then wait for the
        //  ATmega328p to send that back to us.
        // The serialRead(number) function reads the serial port, and the
        //  number is a timeout (in ms) so if there's a transmission error,
        //  we don't stall forever.
		LEDon(TXLED);
		flushSerialRead();
		serialWrite(0);
		buttonData1 = serialRead(25);
		       
		serialWrite(1);
		buttonData2 = serialRead(25);
        
		serialWrite(2);
		buttonData3 = serialRead(25);
        
		serialWrite(3);
		dataToSend.leftStickX = serialRead(25);
        
		serialWrite(4);
		dataToSend.leftStickY = serialRead(25);
        
		serialWrite(5);
		dataToSend.rightStickX = serialRead(25);
        
		serialWrite(6);
		dataToSend.rightStickY= serialRead(25);
		
		serialWrite(7);
		dataToSend.centerStickX = serialRead(25);
		
		serialWrite(8);
		dataToSend.centerStickY= serialRead(25);
		
		LEDoff(TXLED);
		
		// Now, we take the button data we got in and input that information
        //  into our controller data we want to send
		dataToSend.triangleOn = 1 & (buttonData1 >> 0);
		dataToSend.circleOn = 1 & (buttonData1 >> 1);
		dataToSend.squareOn = 1 & (buttonData1 >> 2);
		dataToSend.crossOn = 1 & (buttonData1 >> 3);
		dataToSend.l1On = 1 & (buttonData1 >> 4);
		dataToSend.l2On = 1 & (buttonData1 >> 5);
		dataToSend.l3On = 1 & (buttonData1 >> 6);
		dataToSend.r1On = 1 & (buttonData1 >> 7);
		
		dataToSend.r2On = 1 & (buttonData2 >> 0);
		dataToSend.r3On = 1 & (buttonData2 >> 1);
		dataToSend.selectOn = 1 & (buttonData2 >> 2);
		dataToSend.startOn = 1 & (buttonData2 >> 3);
		dataToSend.homeOn = 1 & (buttonData2 >> 4);
		dataToSend.dpadLeftOn = 1 & (buttonData2 >> 5);
		dataToSend.dpadUpOn = 1 & (buttonData2 >> 6);
		dataToSend.dpadRightOn = 1 & (buttonData2 >> 7);
		
		dataToSend.dpadDownOn = 1 & (buttonData3 >> 0);
		
        
        // Finally, we send the data out via the USB port
		sendPS3Data(dataToSend);	
		
	}
}