View Single Post
  #12   Spotlight this post!  
Unread 04-29-2005, 06:03 PM
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: #define and #ifdef/endif

Quote:
Originally Posted by dhoizner
So theoretically, i could call
Code:
switch(check_switch_box()){}
instead of
Code:
switch(command_list[current_command].command){}
?
I think that would work as long as check_switch_box can see current_command. Depending on where it is defined you may need an extern.

It may be a little cleaner to do it in two steps
Code:
new_cmd = check_switch_box();
switch(new_cmd)
That way you have a chance to sneak in and add debug for the return value of your function.

An even cleaner way to do it would be to get your program number up front and then use pass that in to your function.
Code:
//Outside of autonomous loop....
if(rc_dig_in01==1)
{
  g_prog_num = 1;
}
else if(rc_dig_in02==1)
{
  g_prog_num = 2;
}
...
//Inside autonomous loop....
//Assuming that the function can see current_command
new_cmd = get_auton_command(g_prog_num);
switch(new_cmd)
{
.....
}
...
// Using unsigned ints for the sake of argument
unsigned int get_auton_command(unsigned int prog_num)
{
  unsigned int command = DO_NOTHING;
  if(prog_num == 1)
  {
    command = command_list_prog1[current_command].command
  }
  else if(prog_num == 2)
  {
    command = command_list_prog2[current_command].command
  }
  return command;
}