From d378bda62cf82b41ab81bbdf1bcb7624013a1e2c Mon Sep 17 00:00:00 2001 From: dario Date: Tue, 4 Jun 2024 22:05:23 +0200 Subject: [PATCH] cleanup in logger code --- include/sta/utils/logger.hpp | 16 ++++++++++++---- include/sta/utils/logger.tpp | 12 ++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/sta/utils/logger.hpp b/include/sta/utils/logger.hpp index 4288a80..5491e23 100644 --- a/include/sta/utils/logger.hpp +++ b/include/sta/utils/logger.hpp @@ -58,12 +58,20 @@ namespace sta size_t capacity(); /** - * @brief Allows reading a single data point from the segment. + * @brief Get the ith element stored in the flash storage. * - * @param idx The index of the segement. - * @return T The read data value. + * @param i The index of the element to read. + * @return T The ith element stored in the flash storage. */ - T operator[](std::size_t idx); + T get(std::size_t i); + + /** + * @brief Get the ith element stored in the flash storage. + * + * @param i The index of the element to read. + * @return T The ith element stored in the flash storage. + */ + T operator[](std::size_t i); private: void findLast(); diff --git a/include/sta/utils/logger.tpp b/include/sta/utils/logger.tpp index c0885b1..cad2da6 100644 --- a/include/sta/utils/logger.tpp +++ b/include/sta/utils/logger.tpp @@ -115,15 +115,13 @@ namespace sta } template - T Logger::operator[](std::size_t idx) + T Logger::get(std::size_t i) { - uint32_t address = start_ * W25QXX_SECTOR_SIZE + idx * sizeof(T); - STA_DEBUG_PRINTF("Reading from address %d\n", address); + uint32_t address = start_ * W25QXX_SECTOR_SIZE + i * sizeof(T); // If the requested element is in the cache, read it from there. if (address / W25QXX_PAGE_SIZE == address_ / W25QXX_PAGE_SIZE) { - STA_DEBUG_PRINTLN("Reading data from buffer!"); uint8_t * ptr = buffer_ + address % W25QXX_PAGE_SIZE; return *reinterpret_cast(ptr); } @@ -134,6 +132,12 @@ namespace sta return *reinterpret_cast(buffer); } } + + template + T Logger::operator[](std::size_t i) + { + return this->get(i); + } } // namespace sta #endif // STA_UTILS_LOGGER_TPP