Skip to content

Commit

Permalink
Splitting "Standard" from "Core"
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardtfn committed Nov 28, 2024
1 parent 4097349 commit beddc73
Show file tree
Hide file tree
Showing 52 changed files with 614 additions and 635 deletions.
45 changes: 45 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,51 @@ Updated scripts require adjustments to these customizations:

## Noteworthy Changes

### Core and Standard Functionality Split
In this release, we are introducing a new split between "Core" and "Standard" functionalities.
This change is aimed at advanced users who wish to customize their panel by selectively removing
certain functionalities to free up resources for other uses.

> [!IMPORTANT]
> Unless you want to remove some functionality, no changes are needed on your panel's yaml.

#### Background
Previously, we introduced the concept of `add-ons`, which allowed your panel to act as a Bluetooth proxy,
local thermostat, or cover control, extending its capabilities beyond the core functionality.
Now, we’re taking a step further by splitting the core functionality into "Core" and "Standard" categories:
- **Core Functionality:** Essential features required for any panel installation.
- **Standard Functionality:** Common features included by default in regular installations, but optional for advanced users.

#### Benefits of the Split
1. **Resource Optimization:**
Advanced users can remove unused functionalities, freeing up memory for custom uses unrelated to this project.
- Example: If you’re not using hardware relays, you can remove the package for Hardware Relays to free up resources.
- Similarly, if cover control is not used, you can exclude the related code.

2. **Improved Code Management:**
Each feature is now encapsulated in a dedicated package, making it easier to locate and customize specific functionality.
Developers and troubleshooters can focus on isolated areas of the code without interfering with unrelated parts.

3. **Future Accessibility:**
While currently targeted at advanced users, this split lays the groundwork for making functionality selection
more accessible for all users, including entry-level users, in future releases.

#### Example Use Case
To customize your installation and include only the functionalities you need:
```yaml
packages:
# Include only the features you need:
standard_relay: !include packages/standard_relay.yaml # Remove this line if relays are not needed
standard_cover: !include packages/standard_cover.yaml # Remove this line if cover control is not needed
core: !include packages/core.yaml # Core functionality (mandatory)
```
This split not only optimizes resources but also simplifies customization, troubleshooting, and development,
making it easier to focus on specific areas of the code without affecting others.

#### What's Next
While this change is currently focused on advanced users, we are working towards making it easier for all users,
allowing everyone to select what functionalities they want during installation in a more intuitive way.

### Dynamic QR Code
Assign an entity (input text or sensor) to a QR code. The QR code updates dynamically with entity value changes.
QR code length limit extended to 96 chars for more complex codes.
Expand Down
63 changes: 33 additions & 30 deletions components/nspanel_ha_blueprint/core_boot.cpp
Original file line number Diff line number Diff line change
@@ -1,80 +1,83 @@
// core_boot.cpp

#ifdef NSPANEL_HA_BLUEPRINT_CORE_BOOT

#include "core_boot.h" // Include the header file for function and variable declarations.

namespace nspanel_ha_blueprint {

// Definition of the global variable to track completed boot steps.
// Each bit in this variable represents whether a boot step has been completed.
DRAM_ATTR uint32_t completed_boot_steps = 0;
// Total number of defined boot steps.
uint8_t total_boot_steps = 0;
uint32_t completed_boot_steps = 0;
uint32_t registered_applications = 0;

// Function to mark a boot step as completed.
// Parameters:
// step - The boot step constant representing the step to be marked as completed.
bool complete_boot_step(const uint32_t step) {
// Validate that the step is a power of two (i.e., only one bit is set).
// This ensures that only valid boot step constants are accepted.
if (step == 0 || (step & (step - 1)) != 0) {
// If the step is zero or not a power of two, it's invalid.
return false;
}
// Use bitwise OR to set the corresponding bit in completed_boot_steps.
// This marks the boot step as completed.
completed_boot_steps |= step;
return true;
}

// Function to register an application for boot.
bool register_application(const uint32_t app_bit) {
// Validate that the app_bit is a power of two (i.e., only one bit is set).
if (app_bit == 0 || (app_bit & (app_bit - 1)) != 0) {
return false;
}
// Check if the application is already registered, if not, increment total_boot_steps.
if ((registered_applications & app_bit) == 0) {
total_boot_steps++;
}
// Use bitwise OR to set the corresponding bit in registered_applications.
registered_applications |= app_bit;
return true;
}

// Helper function to count the number of bits set to '1' in a uint32_t value.
// Parameters:
// value - The uint32_t value whose bits are to be counted.
// Returns:
// The number of bits set to '1' as an integer.
uint8_t count_bits_set(uint32_t value) {
uint8_t count = 0;
while (value) {
// Increment count if the least significant bit is '1'.
count += value & 1;
// Right-shift the value to check the next bit.
value >>= 1;
}
return count;
}

// Function to get the number of unique boot steps that have been completed.
// Returns:
// The count of completed boot steps as an integer.
uint8_t get_boot_steps_completed() {
return count_bits_set(completed_boot_steps);
}

// Function to calculate the boot progress percentage with rounding.
// Returns:
// The boot progress percentage as a uint8_t between 0 and 100.
uint8_t get_boot_progress_percentage() {
// Calculate the percentage with rounding
return static_cast<uint8_t>((get_boot_steps_completed() * 100 + TOTAL_BOOT_STEPS / 2) / TOTAL_BOOT_STEPS);
if (total_boot_steps == 0) {
return 0;
}
return static_cast<uint8_t>((get_boot_steps_completed() * 100 + total_boot_steps / 2) / total_boot_steps);
}

// Function to check if all boot steps have been completed.
// Returns:
// true if all boot steps are completed, false otherwise.
// Function to check if all registered applications have completed boot.
bool is_boot_complete() {
return get_boot_steps_completed() == TOTAL_BOOT_STEPS;
// Boot is complete if all bits set in registered_applications are also set in completed_boot_steps.
return (registered_applications & completed_boot_steps) == registered_applications;
}

// Function to reset the completed boot steps to zero.
// This clears all tracked boot steps.
// Function to reset the completed boot steps and registered applications to zero.
void reset_boot_steps() {
total_boot_steps = 0;
completed_boot_steps = 0;
registered_applications = 0;
}

// Function to check if a specific boot step has been completed.
// Parameters:
// step - The boot step constant representing the step to check.
// Returns:
// true if the boot step has been completed; false otherwise.
bool is_boot_step_completed(uint32_t step) {
return (completed_boot_steps & step) != 0;
}

} // namespace nspanel_ha_blueprint

#endif // NSPANEL_HA_BLUEPRINT_CORE_BOOT
29 changes: 19 additions & 10 deletions components/nspanel_ha_blueprint/core_boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@

#pragma once // Include guard to prevent multiple inclusions of this header file

#ifdef NSPANEL_HA_BLUEPRINT_CORE_BOOT

#include <stdint.h> // Include standard integer types
#include "esp_attr.h" // Include for PSRAM attributes

namespace nspanel_ha_blueprint {
// Total number of defined boot steps.
const uint8_t TOTAL_BOOT_STEPS = 30; // Update as needed.

// Extern declaration of the global variable to track completed boot steps.
// This variable is defined in boot.cpp.
extern uint8_t total_boot_steps;
extern uint32_t completed_boot_steps;
extern uint32_t registered_applications;

// Function to mark a boot step as completed.
// Parameters:
// step - The boot step constant representing the step to be marked as completed.
// Returns:
// true if the boot step has been sucessfuly marked completed;
// true if the boot step has been successfully marked completed;
// false otherwise (like in the case of an invalid step constant).
bool complete_boot_step(const uint32_t step);

// Function to register an application for boot.
// Parameters:
// app_bit - The application bit representing the application to be registered.
// Returns:
// true if the application has been successfully registered;
// false otherwise (e.g., invalid bit).
bool register_application(const uint32_t app_bit);

// Function to get the number of unique boot steps that have been completed.
// Returns:
// The count of completed boot steps as an integer.
Expand All @@ -31,13 +38,13 @@ namespace nspanel_ha_blueprint {
// The boot progress percentage as a uint8_t between 0 and 100.
uint8_t get_boot_progress_percentage();

// Function to check if all boot steps have been completed.
// Function to check if all registered applications have completed boot.
// Returns:
// true if all boot steps are completed, false otherwise.
// true if all registered applications have completed boot, false otherwise.
bool is_boot_complete();

// Function to reset the completed boot steps to zero.
// This clears all tracked boot steps.
// Function to reset the completed boot steps and registered applications to zero.
// This clears all tracked boot steps and applications.
void reset_boot_steps();

// Function to check if a specific boot step has been completed.
Expand All @@ -48,3 +55,5 @@ namespace nspanel_ha_blueprint {
bool is_boot_step_completed(uint32_t step);

} // namespace nspanel_ha_blueprint

#endif // NSPANEL_HA_BLUEPRINT_CORE_BOOT
44 changes: 0 additions & 44 deletions components/nspanel_ha_blueprint/core_page_utilities.h

This file was deleted.

Loading

0 comments on commit beddc73

Please sign in to comment.