Review components files

This commit is contained in:
Edward Firmo
2024-04-08 23:47:16 +02:00
parent 88cca0d1bf
commit 10e0a47b6f
18 changed files with 385 additions and 369 deletions

View File

@@ -1,73 +1,73 @@
// hardware.h
#pragma once
#include <cstdint>
// Namespace for nspanel_ha_blueprint, encapsulating definitions related to hardware settings.
namespace nspanel_ha_blueprint {
/**
* @enum ButtonsSettings
* Represents the settings for hardware buttons as individual bits within a uint8_t value.
* Each enum value corresponds to a specific bit position that represents a distinct setting
* for the buttons. This allows for efficient storage and manipulation of multiple buttons
* settings within a single byte.
* @enum ButtonSettings
* Represents the settings for hardware buttons using individual bits within a uint8_t value.
* This allows efficient storage and manipulation of settings for multiple buttons in a compact form.
*
* Bits are allocated as follows:
* - Bit 0: Left button - Enabled.
* - Bit 1: Left button - Current state (0 for `off` or 1 for `on`)
* The bit allocations are as follows:
* - Bit 0: Left button enabled.
* - Bit 1: Left button state (0 for `off`, 1 for `on`).
* - Bits 2-3: Reserved for future use.
* - Bit 4: Right button - Enabled.
* - Bit 5: Right button - Current state (0 for `off` or 1 for `on`)
* - Bit 4: Right button enabled.
* - Bit 5: Right button state (0 for `off`, 1 for `on`).
* - Bits 6-7: Reserved for future use.
*
* Usage involves bitwise operations to set, clear, and check these settings within a
* uint8_t variable. This approach enables compact representation and easy manipulation
* of relay settings.
* These settings facilitate easy manipulation of button states and configurations through bitwise operations.
*/
enum ButtonSettings {
ButtonLeft_Enabled = 1 << 0, ///< Bit 0: Enables left button visualization on screen.
ButtonLeft_State = 1 << 1, ///< Bit 1: Current state of left button.
ButtonLeft_Enabled = 1 << 0, ///< Enables left button visualization on screen.
ButtonLeft_State = 1 << 1, ///< Indicates current state of the left button.
// Bits 2 and 3 are reserved for future expansion.
ButtonRight_Enabled = 1 << 4, ///< Bit 4: Enables right button visualization on screen.
ButtonRight_State = 1 << 5, ///< Bit 5: Current state of right button.
ButtonRight_Enabled = 1 << 4, ///< Enables right button visualization on screen.
ButtonRight_State = 1 << 5, ///< Indicates current state of the right button.
// Bits 6 and 7 are reserved for future expansion.
};
/**
* @enum RelaySettings
* Represents the settings for relays as individual bits within a uint8_t value. Each
* enum value corresponds to a specific bit position that represents a distinct setting
* for the relays. This allows for efficient storage and manipulation of multiple relay
* settings within a single byte.
* Represents the settings for relays using individual bits within a uint8_t value.
* This approach allows for the efficient storage and manipulation of settings for multiple
* relays in a single byte, enabling compact representation and ease of setting manipulation.
*
* Bits are allocated as follows:
* - Bit 0: Relay 1 - Local control enabled.
* - Bit 1: Relay 1 - Fallback mode enabled.
* The bit allocations are as follows:
* - Bit 0: Relay 1 local control enabled.
* - Bit 1: Relay 1 fallback mode enabled.
* - Bits 2-3: Reserved for future use.
* - Bit 4: Relay 2 - Local control enabled.
* - Bit 5: Relay 2 - Fallback mode enabled.
* - Bit 4: Relay 2 local control enabled.
* - Bit 5: Relay 2 fallback mode enabled.
* - Bits 6-7: Reserved for future use.
*
* Usage involves bitwise operations to set, clear, and check these settings within a
* uint8_t variable. This approach enables compact representation and easy manipulation
* of relay settings.
* These settings support flexible relay configuration and state management through bitwise operations.
*/
enum RelaySettings {
Relay1_Local = 1 << 0, ///< Bit 0: Enables local control for Relay 1.
Relay1_Fallback = 1 << 1, ///< Bit 1: Enables fallback mode for Relay 1.
Relay1_Local = 1 << 0, ///< Enables local control for Relay 1.
Relay1_Fallback = 1 << 1, ///< Enables fallback mode for Relay 1.
// Bits 2 and 3 are reserved for future expansion.
Relay2_Local = 1 << 4, ///< Bit 4: Enables local control for Relay 2.
Relay2_Fallback = 1 << 5, ///< Bit 5: Enables fallback mode for Relay 2.
Relay2_Local = 1 << 4, ///< Enables local control for Relay 2.
Relay2_Fallback = 1 << 5, ///< Enables fallback mode for Relay 2.
// Bits 6 and 7 are reserved for future expansion.
};
/**
* Updates a settings byte according to a specified condition and flag.
*
* This function template applies a bitwise operation to modify the settings byte based on
* the provided condition and flag. If the condition is true, the bit corresponding to the flag
* is set; otherwise, it's cleared. This method enables dynamic and conditional settings updates.
*
* @param settings Reference to the settings byte to be modified.
* @param condition Boolean condition determining how the settings byte is modified.
* @param flag The specific bit flag (from ButtonSettings or RelaySettings) to modify.
*/
template<typename SettingsEnum>
void update_bitwise_setting(uint8_t& settings, bool condition, SettingsEnum flag) {
if (condition) {
settings |= flag; // Set bit
} else {
settings &= ~flag; // Clear bit
}
}
void update_bitwise_setting(uint8_t& settings, bool condition, SettingsEnum flag);
} // namespace nspanel_ha_blueprint