Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change config.h #define statement architecture #44

Open
doppelhub opened this issue Jan 3, 2024 · 0 comments
Open

Change config.h #define statement architecture #44

doppelhub opened this issue Jan 3, 2024 · 0 comments

Comments

@doppelhub
Copy link
Owner

I'd like to change the way the #define statements in config.h are implemented behind the scenes. The existing code literally just builds the various defined parameter values into the code at compile time. At runtime there's nothing that needs to happen... it's already all built into the compiled code.

The proposed feature retains the existing #define statements in config.h, but behind the scenes the runtime code updates values stored in EEPROM for each #define statement that isn't commented out. The goal is that we can change config.h so that every single #define statement is commented out by default... the user only needs to uncomment those values that they want to change.

So basically whenever LiBCM sees that new firmware is installed (see function "wasFirmwareJustUpdated"), the runtime code should update the values in EEPROM corresponding to each #define statement the user has uncommented in config.h.

You can probably just add something like the following for each #define statement in config.h to wasFirmwareJustUpdated():
#ifdef BATTERY_TYPE_5AhG3
EEPROM.update(EEPROM_ADDRESS_BATTERY_TYPE, BATTERY_IS_5AhG3);
#elif defined BATTERY_TYPE_47AhFoMoCo
EEPROM.update(EEPROM_ADDRESS_BATTERY_TYPE, BATTERY_IS_47AhFoMoCo);
#endif

After making the above changes, you'd of course need to change all the existing #ifdef commands that reference config.h #define statements to read the value from EEPROM during runtime. Reading from EEPROM is slower than RAM, but is probably fast enough... I already read from EEPROM every single loop to determine if the firmware is expired. You can read from EEPROM infinity times (i.e. read lifetime count is infinite).

The primary objective here is that the user no longer has to modify config.h each time they load the firmware... they only need to uncomment the specific config.h #define parameters they want to change... if they leave everything commented out, then LiBCM just uses the latest values stored in EEPROM.

Runtime code should certainly verify a valid hardware configuration exists... similar to the various #error preprocessor checks that exist now. Basically all #error checks will need to be rewritten to occur at runtime (inside the wasFirmwareJustUpdated function).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready
Development

No branches or pull requests

1 participant