View Single Post
  #2   Spotlight this post!  
Unread 30-04-2013, 01:18
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: Reducing code complexity

If you just want to remove the if statements, here's a few things you can do:
Code:
if (xbox.isReleased(JStick.XBOX_A)) {
	usingCheesy = !usingCheesy;
}
can become:
Code:
usingCheesy=usingCheesy^xbox.isReleased(JStick.XBOX_A);
Code:
if(slowMode){
	driveGear.set(false);
}else{
	driveGear.set(normalGear);
}
can become:
Code:
driveGear.set(slowMode?false:normalGear);
Also, this:
Code:
if (shooterMode == SHOOTER_MODE_VOLTAGE) {
	lcd.println(DriverStationLCD.Line.kUser1,1,"Shooter mode:voltage ");
} else if (shooterMode == SHOOTER_BANG_BANG) {
	lcd.println(DriverStationLCD.Line.kUser1,1,"Shooter mode:bangbang");
} else if (shooterMode == SHOOTER_COMBINED) {
	lcd.println(DriverStationLCD.Line.kUser1,1,"Shooter mode:combined");
} else {
	lcd.println(DriverStationLCD.Line.kUser1,1,"Shooter mode:????????");
}
can become:
Code:
{
	const char *out;
	switch(shooterMode){
		case SHOOTER_MODE_VOLTAGE: out="Shooter mode:voltage "; break;
		case SHOOTER_BANG_BANG: out="Shooter mode:bangbang"; break;
		case SHOOTER_COMBINED: out="Shooter mode:combined"; break;
		default: out="Shooter mode:????????";
	}
	lcd.println(DriverStationLCD.Line.kUser1,1,out);
}