There are a few places in the code you will have to change if you are adding a new function. Let's assume that FUNC_FADE did not exist before and we are adding it. First, you will probably want to define a new mode line. This is a handy short cut and makes reading the EEPROM set up easier. It looks like this:
#ifdef FUNC_FADE
#define MODE_FADE 0x04, 0xFF, 0x01, 0x01 // fade in/out. Just a gimmick
#endif
MODE_FADE is the name for the mode, the first number is the offset into the function-array (more on this later) and the three remaining numbers are the three parameters the function may use.
Next you set up the EEPROM. This is where you add the mode line:
const uint8_t EEMEM eeprom[64] =
{ 0x00, 0xFF, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
// initial mode programming, indices to mode lines in the following array
0x03, 0x06, 0x08, 0x00, 0x00,
// mode configuration starts here. Format is:
// offset in mode_func_arr, func data1, func data2, func data3
MODE_LVL001, // 0x00
MODE_LVL002, // 0x01
MODE_LVL004, // 0x02
MODE_LVL008, // 0x03
MODE_LVL016, // 0x04
MODE_LVL032, // 0x05
MODE_LVL064, // 0x06
MODE_LVL128, // 0x07
MODE_LVL255, // 0x08
MODE_STROBE, // 0x09
MODE_POLICE, // 0x0A
MODE_FADE // 0x0B <= new mode line replaces another
};
By placing the #define for the mode lines inside the #ifdef FUNC_<name> earlier, this will result in a compile time error if the EEPROM config contains a mode which has not been compiled into the binary. This is a Good Thing™. You got the compiler error because you disabled the code for the SOS-function, but your EEPROM set up still contained MODE_SOS.
Next you will have to give a forward declaration for the new mode function:
#ifdef FUNC_FADE
void fade(uint8_t offset);
#endif
This is necessary to add the function pointer to the function pointer array:
mode_func mode_func_arr[] =
{
&const_level
#ifdef FUNC_STROBE
, &strobe
#else
, &nullmode
#endif
#ifdef FUNC_SOS
, &sos
#else
, &nullmode
#endif
#ifdef FUNC_ALPINE
, &alpine
#else
, &nullmode
#endif
#ifdef FUNC_FADE
, &fade
#else
, &nullmode
#endif
};
Why this #ifdef FUNC_<name>, &func #else , &nullmode #endif construct? This makes sure that the functions keep their place in the array by replacing functions that are not compiled in with a pointer to a dummy function. Remember the bit about the function offset earlier, when defining the mode line? This is where this offset comes from. Count the functions in this array, starting at zero, until you reach your new function. Fade is the fifth function in the array, so its offset is four.
Now all you have to do is write the actual mode function. If you want to know how to get the parameters from the mode line, look at the strobe function, where it reads its parameters from the EEPROM.