View Single Post
  #5   Spotlight this post!  
Unread 29-01-2007, 14:12
buddy.smith buddy.smith is offline
Master Control
FRC #1795
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: atlanta
Posts: 20
buddy.smith is an unknown quantity at this point
Re: Pointers/References?

Quote:
Originally Posted by htwiz2002 View Post
I think I (might) have fixed it. (at least, it's not giving me errors anymore...)
The following is the example in entirety:
Code:
unsigned char version1 = 0;
unsigned char version2 = 1;
unsigned char version3 = 1;
unsigned char version4 = 0;
I was just suggesting the array method to show the possibility. You can do it the way you were doing it before.... (details below)

Quote:
Originally Posted by htwiz2002 View Post
Code:
//end verify codes...
// Verify codes are supposed to be for version check so in case the wrong version data is stored the robot will not use it (until saveing, which the robot will post a warning of overwrite (still in the works...))

// EEprom section:
void Terminal_eepromwriteset(char data1, char data2, char data3, char data4, unsigned char set) 
{
    //Consolidate this on verify that it works!!!
    unsigned int address = set * 4 -1;
    EEPROM_Write(address + 1, data1);
    EEPROM_Write(address + 2, data2);
    EEPROM_Write(address + 3, data3);
    EEPROM_Write(address + 4, data4);
}
What's the -1 for? Why not just set*4, then add 0, 1, 2, 3?

[quote=htwiz2002;567274]
Code:
void Terminal_eepromreadset(unsigned char set, unsigned char *data1, unsigned char *data2, unsigned char *data3, unsigned char *data4)
{
    //Consolidate this on verify that it works!!!
    unsigned int address = set * 4 -1;
    *data1 = EEPROM_Read(address + 1);
    *data2 = EEPROM_Read(address + 2);
    *data3 = EEPROM_Read(address + 3);
    *data4 = EEPROM_Read(address + 4);
}
This looks right. I'd recommend changing 'data1' to pData1, and so forth. This lets you know that it's a pointer. I sometimes prefer to put the * next to 'char' as well, but that's something that C programmers argue about constantly

Quote:
Originally Posted by htwiz2002 View Post
Code:
char Terminal_loadFromEeprom(char set)
{
char rtn = 0;
    //This routine loads four char values from eeprom using a set switch te determine which bits to load.
    //Set starts with zero and also indicates what address to use (starting with zero)
    //Returns 0 if send to buffer success, 1 if read failed, 999 if set number is invalid
    //Make sure this information is mirrored in Terminal_saveToEeprom() !!!
switch (set)
{
case 0: //this is an example set, meant only for verification of data...
        //This is also viable for version verify, for automatic reset...
        Terminal_eepromreadset(0, &version1, &version2, &version3, &version4); break;
I'd work on the formatting here. Move the 'break' to a line by itself.

Also, why are you using global variables here instead of declaring them inside this function?

Also, perhaps you should name your case....
Code:
#define VERSION_SET (0)
....
...
case VERSION_SET:
....
Quote:
Originally Posted by htwiz2002 View Post
Code:
default: return 999; break;
Again i'd improve the formatting:
Code:
default:
      return 999;
      break;
I hope this doesn't come off as critical. I'm trying to be constructive and help you come up with code that is clear to the human.

A programmer's job is to write documentation that happens to compile....

Suggestions: Use whitespace, it's free. Avoid global variables like the plague.

If you must use globals, stick a 'g' in front of the name, again so that you know it's a global.

Make all your globals 'static'. This means that they won't conflict with another global in a different file. That can cause huge headaches.

ttyl,

--buddy