I am writing C code with multiple modules like LCD display, flash memory, and GSM module etc. The project consists of thousands of lines of code, in different files.
The behavior of the system can be changed with run-time parameters (eg LCD brightness) using a buttons. And during compile time by redefining #define
directives and const
variables.
Currently all of these variables and constants lie with the rest of the modules in their respective files. I am finding is very hard to maintain the settings without losing modularity.
My question is two part:
- How do I make the compile time parameters more accessible? Moving all the variables to a separate file would certainly make life easier by making all the settings available in one place. Also some settings go in groups, so it makes more sense to change one
#define
in one file rather than fishing for many#defines
in multiple files. But it does not seem right to destroy the modularity this way. - I need to write code that will save all the runtime parameters to flash memory, and retrieve them on reboot. Ideally this should be done in getter and setter functions. But the problem is that all the settings and configurations are stored in a sector in flash memory. A parameter can't just be rewritten without erasing the flash memory. So LCD module can't change its brightness without being aware of all the other parameters. It makes more sense to keep all the settings in a struct, but the cost is moving the variables away from the modules.
What is the best way to tackle this problem without compromising on the readability and modularity of code.