Beispiel #1
0
/*
DualShock::DualShock(int idArg){
	canId=idArg;
	psbutton.start.value=0;
	psbutton.select.value=0;
	psbutton.L1.value=0;
	psbutton.L2.value=0;
	psbutton.R1.value=0;
	psbutton.R2.value=0;
	psbutton.Triangle.value=0;
	psbutton.Circle.value=0;
	psbutton.Cross.value=0;
	psbutton.Square.value=0;
	psbutton.Up.value=0;
	psbutton.Right.value=0;
	psbutton.Down.value=0;
	psbutton.Left.value=0;
	psbutton.CError.value=0;
	psbutton.Pitch.value=0;
	psbutton.Roll.value=0;
	psbutton.left_x.value=0;
	psbutton.left_y.value=0;
	psbutton.right_x.value=0;
	psbutton.right_y.value=0;

	psbutton.start.tolerance=0;
	psbutton.select.tolerance=0;
	psbutton.L1.tolerance=0;
	psbutton.L2.tolerance=0;
	psbutton.R1.tolerance=0;
	psbutton.R2.tolerance=0;
	psbutton.Triangle.tolerance=0;
	psbutton.Circle.tolerance=0;
	psbutton.Cross.tolerance=0;
	psbutton.Square.tolerance=0;
	psbutton.Up.tolerance=0;
	psbutton.Right.tolerance=0;
	psbutton.Down.tolerance=0;
	psbutton.Left.tolerance=0;
	psbutton.CError.tolerance=0;
	psbutton.Pitch.tolerance=0;
	psbutton.Roll.tolerance=0;
	psbutton.left_x.tolerance=0;
	psbutton.left_y.tolerance=0;
	psbutton.right_x.tolerance=0;
	psbutton.right_y.tolerance=0;

	time=millis();
	oldPitch=0;
	oldRoll=0;
	disconnectTimeData=500;
}
*/
int DualShock::setup(){
	if(mode==modeCan){
		if(canSetup()) return 1;
		canSetId(CAN_CONTROLLER_ID);
	}else if(mode==modeSerial){
		serial->setup(115200,(*this));
	}
	return 0;
}
Beispiel #2
0
/**
 * @brief Configura todo o sistema
 */
void configSystem(void)
{
	// Configure USART
	usartSetup();

	// Configure CAN
	canSetup();

	// Configure inputs and outputs
	ioSetup();

	// Enable global interrupts
	//sei();
}
Beispiel #3
0
void main (void) {
	vuint32_t i = 0;
	initModesAndClock(); /* Initialize mode entries and system clock */
	disableWatchdog(); /* Disable watchdog */
	initPeriClkGen(); /* Initialize peripheral clock generation for DSPIs */
	
	initADC();
	initLED();
	
	//can stuff	
	initDSPI_1();                /* Initialize DSPI_1 as Slave SPI and init CTAR0 */
	canSetup();
	
	initEnergizeButton();
	
	energizePacket.ID = ENERGIZE_ID;
	energizePacket.DATA.W[0] = 0xFFFFFFFF;
	energizePacket.DATA.W[1] = 0xFFFFFFFF;
	
	deenergizePacket.ID = DEENERGIZE_ID;
	deenergizePacket.DATA.W[0] = 0x00000000;
	deenergizePacket.DATA.W[1] = 0x00000000;
	
	torquePacket.ID = TORQUE_ID;
	speedPacket.ID = SPEED_ID;
	
	shutdownPacket.ID = SHUTDOWN_ID;
	shutdownPacket.DATA.W[0] = 0xDEADBEEF;
	shutdownPacket.DATA.W[1] = 0xDEADBEEF;
	
	/* Loop forever */
	while (1) 
	{
		prevEnergizeButton = energizeButton;
		getEnergizeButton();
		switch (currentState) {
			case NOT_ENERGIZED:
				if (!energizeButton && prevEnergizeButton) {
					currentState = ENERGIZED;
					canSend(energizePacket);
				}
				break;
			case ENERGIZED:
				if (!energizeButton && prevEnergizeButton) {
					currentState = NOT_ENERGIZED;
					canSend(deenergizePacket);
				} else {
					getADC();
					processAnalog();
					if (imp_count < 2 || torque0 < 20) {
						convertSpeed();
						convertTorque();
						if (MODE == 0) {
							canSend(speedPacket);
						} else {
							canSend(torquePacket);
						}
					} else {
						currentState = SHUTDOWN;
						canSend(deenergizePacket);
					}
				}
				break;
			case SHUTDOWN:
				canSend(shutdownPacket);
				SHUTDOWN_CIRCUIT = TRUE;
				break;
		}
		
		toLED(currentState);
		
		//canReceive();
		
		delay();
		i++;
	}
}