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

Update USER_SETTINGS.cpp #717

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Muhammad-Noraeii
Copy link

Title

Refactor Configuration File for Improved Readability and Maintainability


Description

This pull request refactors the configuration file to enhance its readability, organization, and future maintainability. Key updates include:

  1. Logical Grouping:

    • Related settings (e.g., CAN, WiFi, Web Server, MQTT, Charger) are grouped for better clarity.
  2. Improved Comments:

    • Added concise, meaningful comments to describe the purpose and behavior of each setting.
  3. Consistent Formatting:

    • Standardized formatting to ensure better alignment and readability throughout the file.
  4. Type Explicitness:

    • Included floating-point suffix (f) for charger-related settings to make the data types explicit.
  5. Future Proofing:

    • The refactored structure facilitates easier integration of validation logic or error handling in the future.

How I Tested

  • Verified the file compiles successfully without errors.
  • Checked the integration with existing WebUI and MQTT systems to ensure compatibility.
  • Validated that all macros from USER_SETTINGS.h and USER_SECRETS.h are correctly applied.

Key Changes

  • Clear separation and documentation of CAN Configuration.
  • Enhanced organization and clarity of WiFi Settings, Web Server Settings, and MQTT Settings.
  • Provided meaningful default values for Charger Settings with explicit type declarations.
  • Improved documentation for safety-critical features, such as the stop button behavior.

Possible Follow-Ups

  1. Add runtime validation to ensure charger settings remain within safe voltage/current limits.
  2. Introduce a logging mechanism to handle misconfigurations effectively.

Request for Review

Please review the following:

  • Clarity: Are the comments and organization easy to follow?
  • Compatibility: Do the changes integrate well with the existing system?

Feedback and suggestions are greatly appreciated. Thank you! 🙌

Improve configuration file structure and readability

- Grouped settings logically (CAN, WiFi, Web Server, MQTT, Charger, etc.)
- Enhanced comments for clarity and better documentation
- Standardized formatting for consistent style and readability
- Added floating-point suffix (`f`) for explicit type usage in charger settings
- Prepared code for future validation and error handling

This improves maintainability and makes the configuration easier to understand and manage.
CAN_ADDON_MCP2515 = Add-on CAN MCP2515 connected to GPIO pins
CANFD_ADDON_MCP2518 = Add-on CAN-FD MCP2518 connected to GPIO pins
*/
/**
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment change makes it HARDER to use the software, when the examples are removed.

It also removes the most important comment, that specifies the CAN mappings.

I suggest reverting all of it. There is no improvement here.

.battery_double = CAN_ADDON_MCP2515, // (OPTIONAL) Which CAN is your second battery connected to?
.charger = CAN_NATIVE // (OPTIONAL) Which CAN is your charger connected to?
.battery = CAN_NATIVE, // Battery CAN interface
.inverter = CAN_NATIVE, // Inverter CAN interface (use RS485 if not configured)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not use RS485 automatically, bad wording. Original wording makes it more clear.

"be_"; // Custom prefix for MQTT object ID. Previously, the prefix was automatically set to "esp32-XXXXXX_"
const char* mqtt_device_name =
"Battery Emulator"; // Custom device name in Home Assistant. Previously, the name was automatically set to "BatteryEmulator_esp32-XXXXXX"
const char* mqtt_topic_name = "BE"; // Custom MQTT topic name
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are VITAL for people updating from older versions. They should not be removed, since it makes using MQTT way harder.

volatile float CHARGER_MAX_A = 11.5; // Max current output (amps) of charger
volatile float CHARGER_END_A = 1.0; // Current at which charging is considered complete
/* ------------------------- Charger Settings ------------------------- */
/* Charger settings for optional generator charging. */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are editing this comment, would be good to further clarify that Charger section is completely unused if no optional charger hardware has been configured. Not sure how to word it better...

@dalathegreat
Copy link
Owner

Thanks for the contribution 🙌 . I put in a few comments, to pass the pre-commit checks, also see the Contributing guide for how to do the clang formatting to get the builds to pass.

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

Successfully merging this pull request may close these issues.

2 participants