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,20 +1,44 @@
// utilities.h
#pragma once
#include <cstdint>
#include <cstring> // For std::strcpy
#include <string>
namespace nspanel_ha_blueprint {
struct UtilitiesGroupValues {
char group_id[8]; // 7 characters + null terminator
char value1[11]; // 10 characters + null terminator
char value2[11]; // 11 characters + null terminator
char value1[11]; // 10 characters + null terminator
char value2[11]; // 10 characters + null terminator
int8_t direction;
};
extern UtilitiesGroupValues UtilitiesGroups[8];
extern UtilitiesGroupValues *UtilitiesGroups;
void resetUtilitiesGroups();
void cleanupUtilitiesGroups();
uint8_t findUtilitiesGroupIndex(const char* group_id);
/**
* Copies the contents of a std::string to a fixed-size char array, ensuring
* null termination. The destination array size is automatically deduced.
* Designed for fixed-size char arrays only.
*
* @param dest A reference to the destination char array.
* @param src The source std::string to copy.
*/
template <unsigned int N>
void copyStringToCharArray(char (&dest)[N], const std::string& src) {
// Ensure we do not exceed the buffer size, leaving space for the null terminator
size_t length = std::min(src.size(), N - 1);
// Copy the string data into the destination buffer
std::strncpy(dest, src.c_str(), length);
// Explicitly null-terminate the destination buffer
dest[length] = '\0';
}
} // namespace nspanel_ha_blueprint